Example #1
0
def init_radiobot(config_file):
    """
        Initialize the different radiobot components :
        - Configuration loader, which will parse the json conf file and check
          attributes conformity
        - Display Manager, which is in charge of controling the LCD screen 
          and all the display behaviors (timers and so on)
        - Player manager, which is in charge of controlling VLC and Alsa 
          (starting and stoping network streams, applying volume modifications)
        - Radio manager, which is the overall manager, in charge of radio 
          selection and communication between the display and the player. 
    """
    global displayManager, configLoader, radioManager, playerManager

    # Loading GPIO configuration
    configure_GPIO()

    try:  # Trying to load configuration file
        configLoader = ConfigLoader(config_file)
        configLoader.parse_config_file()
        print("Configuration file loaded successfully")
    except Exception as e:
        print("Invalid configuration : " + str(e))
        print("Exciting.")
        sys.exit(2)

    # Loading display manager
    displayManager = DisplayManager(
        serial.Serial(configLoader.serial_device,
                      configLoader.serial_baud_rate,
                      timeout=1), configLoader.name, configLoader.halt_message,
        configLoader.volume_timer, configLoader.scroll_time_interval,
        configLoader.scroll_time_pause)
    displayManager.start()

    # Loading player
    playerManager = PlayerManager(configLoader.volume)

    # Loading the radio manager
    radioManager = RadioManager(configLoader.radios, configLoader.volume,
                                configLoader.volume_step,
                                configLoader.radio_info_check_interval,
                                configLoader.full_radio_name_pause,
                                configLoader.radio_indice, playerManager,
                                displayManager)

    # Declare radiobot "ready"
    set_as_ready()

    # Starting first radio
    radioManager.play_radio()