예제 #1
0
def set_gfx_driver(enabled):
    if enabled:
        set_config_value('dtoverlay', 'vc4-kms-v3d')
        try:
            try:
                os.makedirs(os.path.dirname(fpturbo_conf_backup_path))
            except OSError as e:
                if e.strerror == "File exists":
                    pass
                else:
                    raise
            shutil.copyfile(fpturbo_conf_path, fpturbo_conf_backup_path)
            os.remove(fpturbo_conf_path)
        except Exception as e:
            logger.error("Error restoring fpturbo_config", exception=e)

    else:
        set_config_value('dtoverlay', None)
        if not os.path.exists(fpturbo_conf_path):
            try:
                shutil.copyfile(fpturbo_conf_backup_path, fpturbo_conf_path)
            except Exception as e:
                logger.error("Error restoring fpturbo_config", exception=e)
    end_config_transaction()
    set_setting('Use_GLX', enabled)
예제 #2
0
def compare_and_set_full_range(edid,
                               status,
                               model,
                               dry_run=False,
                               force=False):
    """
    Returns True if full range is changed

    TODO: What is this for?
    """
    if status['full_range'] == edid['target_full_range'] and not force:
        logger.debug('Config full range change not needed.')
        return False

    hdmi_pixel_encoding = 2 if edid['target_full_range'] else 0

    logger.info(
        'Config full range change needed. Setting hdmi_pixel_encoding to {}'.
        format(hdmi_pixel_encoding))
    if dry_run and not force:
        return True

    set_config_value('hdmi_pixel_encoding',
                     hdmi_pixel_encoding,
                     config_filter=Filter.get_edid_filter(model))
    return True
예제 #3
0
def set_gfx_driver(enabled):
    if enabled:
        set_config_value('dtoverlay', 'vc4-kms-v3d')
        try:
            try:
                os.makedirs(os.path.dirname(fpturbo_conf_backup_path))
            except OSError as e:
                if e.strerror == "File exists":
                    pass
                else:
                    raise
            shutil.copyfile(fpturbo_conf_path, fpturbo_conf_backup_path)
            os.remove(fpturbo_conf_path)
        except Exception as e:
            logger.error("Error restoring fpturbo_config", exception=e)

    else:
        set_config_value('dtoverlay', None)
        if not os.path.exists(fpturbo_conf_path):
            try:
                shutil.copyfile(fpturbo_conf_backup_path, fpturbo_conf_path)
            except Exception as e:
                logger.error("Error restoring fpturbo_config", exception=e)
    end_config_transaction()
    set_setting('Use_GLX', enabled)
예제 #4
0
def change_overclock_value(config, is_pi2):
    try:
        values = CLOCK_MODES[is_pi2]['values'][config]
    except KeyError:
        logger.error(
            'kano-settings: set_overclock: SetOverclock: set_overclock(): '
            'was called with an invalid overclock setting={}'
            .format(config)
        )
        return

    logger.info(
        'set_overclock / apply_changes: '
        'config:{} arm_freq:{arm_freq} '
        'core_freq:{core_freq} '
        'sdram_freq:{sdram_freq} '
        'over_voltage:{over_voltage}'
        .format(config, **values)
    )

    # Apply changes
    for val in values:
        set_config_value(val, values[val])

    # Update config
    set_setting("Overclocking", config)
예제 #5
0
def change_overclock_value(config, board_name=None):
    board = get_board_props(board_name=board_name)

    if not board:
        logger.error("Could not get overclocking settings for board")
        return

    try:
        values = board.CLOCKING['values'][config]
    except KeyError:
        logger.error(
            "kano-settings: set_overclock: SetOverclock: set_overclock(): " \
            "was called with an invalid overclock setting={}"
            .format(config)
        )
        return

    logger.info(
        u"set_overclock / apply_changes: " \
        "config:{} arm_freq:{arm_freq} " \
        "core_freq:{core_freq} " \
        "sdram_freq:{sdram_freq} " \
        "over_voltage:{over_voltage}"
        .format(config, **values)
    )

    # Apply changes
    for val in values:
        set_config_value(val, values[val])

    # Update config
    set_setting('Overclocking', config)
예제 #6
0
def change_overclock_value(config, board_name=None):
    board = get_board_props(board_name=board_name)

    if not board:
        logger.error("Could not get overclocking settings for board")
        return

    try:
        values = board.CLOCKING['values'][config]
    except KeyError:
        logger.error(
            "kano-settings: set_overclock: SetOverclock: set_overclock(): " \
            "was called with an invalid overclock setting={}"
            .format(config)
        )
        return

    logger.info(
        u"set_overclock / apply_changes: " \
        "config:{} arm_freq:{arm_freq} " \
        "core_freq:{core_freq} " \
        "sdram_freq:{sdram_freq} " \
        "over_voltage:{over_voltage}"
        .format(config, **values)
    )

    # Apply changes
    for val in values:
        set_config_value(val, values[val])

    # Update config
    set_setting('Overclocking', config)
예제 #7
0
def compare_and_set_full_range(edid, status, model, dry_run=False, force=False):
    """
    Returns True if full range is changed

    TODO: What is this for?
    """
    if status['full_range'] == edid['target_full_range'] and not force:
        logger.debug('Config full range change not needed.')
        return False

    hdmi_pixel_encoding = 2 if edid['target_full_range'] else 0

    logger.info(
        'Config full range change needed. Setting hdmi_pixel_encoding to {}'
        .format(hdmi_pixel_encoding)
    )
    if dry_run and not force:
        return True

    set_config_value(
        'hdmi_pixel_encoding',
        hdmi_pixel_encoding,
        config_filter=Filter.get_edid_filter(model)
    )
    return True
예제 #8
0
 def enable_audio_device():
     from kano_settings.boot_config import set_config_value
     set_config_value("dtparam=audio", "on")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaction not present - update to kano-settings failed?")
예제 #9
0
 def disable_audio_dither():
     from kano_settings.boot_config import set_config_value
     set_config_value("disable_audio_dither", "1")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaction not present")
예제 #10
0
 def disable_audio_dither():
     from kano_settings.boot_config import set_config_value
     set_config_value("disable_audio_dither", "1")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaction not present")
예제 #11
0
        def test_write(configs):

            if self.backup_config_exists:
                which = random.randint(0, 2)
            else:
                which = random.randint(0, 1)

            present = random.randint(0, 1) == 1

            before_write = configs['current'].copy()

            if which == 0:
                # test set_config_value

                key = choose_key(present, configs['current'].values)
                if random.randint(0, 1):
                    value = None

                    print "testing set_config_value({},{})".format(key, value)
                    boot_config.set_config_value(key, value)
                    configs['written'].values[key] = 0
                    configs['written'].comment_keys[key] = True
                else:
                    value = random.randint(0, 1000)
                    print "testing set_config_value({},{})".format(key, value)
                    boot_config.set_config_value(key, value)
                    configs['written'].values[key] = value
                    configs['written'].comment_keys[key] = False

            elif which == 1:
                # test set_config_comment
                key = choose_key(present, configs['current'].comment_values)
                value = str(random.randint(0, 1000))

                print "testing set_config_comment({},{})".format(key, value)
                boot_config.set_config_comment(key, value)
                configs['written'].comment_values[key] = value

            elif which == 2:
                # test restore_backup

                self.assertTrue(
                    self.backup_config_exists)  # bug in test if triggered

                print "testing safe_mode_restore_backup"
                boot_config.safe_mode_restore_config()
                configs['written'] = read_config(
                    boot_config._trans().temp_path)

                self.backup_config_exists = False

                self.assertTrue(compare(configs['backup'], configs['written']))

            after_write = read_config()

            self.assertTrue(compare(before_write, after_write))
            self.assertTrue(boot_config._trans().state == 2)
            self.assertTrue(is_locked())
예제 #12
0
        def test_write(configs):

            if self.backup_config_exists:
                which = random.randint(0, 2)
            else:
                which = random.randint(0, 1)

            present = random.randint(0, 1) == 1

            before_write = configs['current'].copy()

            if which == 0:
                # test set_config_value

                key = choose_key(present, configs['current'].values)
                if random.randint(0, 1):
                    value = None

                    print "testing set_config_value({},{})".format(key, value)
                    boot_config.set_config_value(key, value)
                    configs['written'].values[key] = 0
                    configs['written'].comment_keys[key] = True
                else:
                    value = random.randint(0, 1000)
                    print "testing set_config_value({},{})".format(key, value)
                    boot_config.set_config_value(key, value)
                    configs['written'].values[key] = value
                    configs['written'].comment_keys[key] = False

            elif which == 1:
                # test set_config_comment
                key = choose_key(present, configs['current'].comment_values)
                value = str(random.randint(0, 1000))

                print "testing set_config_comment({},{})".format(key, value)
                boot_config.set_config_comment(key, value)
                configs['written'].comment_values[key] = value

            elif which == 2:
                # test restore_backup

                self.assertTrue(self.backup_config_exists)  # bug in test if triggered

                print "testing safe_mode_restore_backup"
                boot_config.safe_mode_restore_config()
                configs['written'] = read_config(boot_config._trans().temp_path)

                self.backup_config_exists = False


                self.assertTrue(compare(configs['backup'], configs['written']))

            after_write = read_config()

            self.assertTrue(compare(before_write, after_write))
            self.assertTrue(boot_config._trans().state == 2)
            self.assertTrue(is_locked())
예제 #13
0
 def _bootconfig_set_value_helper(self, setting, value):
     # Set a value in boot config; include compatibility with old API
     from kano_settings.boot_config import set_config_value
     set_config_value(setting, value)
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaciton not present - update to kano-settings failed?")
예제 #14
0
 def enable_audio_device():
     from kano_settings.boot_config import set_config_value
     set_config_value("dtparam=audio", "on")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error(
             "end_config_transaction not present - update to kano-settings failed?"
         )
예제 #15
0
 def _bootconfig_set_value_helper(self, setting, value):
     # Set a value in boot config; include compatibility with old API
     from kano_settings.boot_config import set_config_value
     set_config_value(setting, value)
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error(
             "end_config_transaciton not present - update to kano-settings failed?"
         )
예제 #16
0
def set_to_HDMI(HDMI):
    if not hdmi_supported:
        HDMI = False

    # 1 analog
    # 2 hdmi

    # These are the changes we'll apply if they have changed from what they were
    if HDMI:
        amixer_cmd = amixer_set_cmd.format(value=hdmi_value)
        set_config_value("hdmi_ignore_edid_audio", None)
        set_config_value("hdmi_drive", 2)
        config = "HDMI"
    else:
        amixer_cmd = amixer_set_cmd.format(value=analogue_value)
        set_config_value("hdmi_ignore_edid_audio", 1)
        set_config_value("hdmi_drive", None)
        config = "Analogue"

    # Set audio path in amixer
    o, e, rc = run_cmd(amixer_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(o, e, rc))

    # trigger alsa-utils to store the path in /var/lib/alsa/asound.state
    o, e, rc = run_cmd(store_cmd)
    if rc:
        logger.warn("error from alsa-utils: {} {} {}".format(o, e, rc))

    set_setting('Audio', config)
예제 #17
0
def set_hdmi_mode(group=None, mode=None):
    if not group or not mode:
        set_config_value("hdmi_group", None)
        set_config_value("hdmi_mode", None)
        return

    group = group.lower()
    mode = int(mode)

    if group == "cea":
        set_config_value("hdmi_group", 1)
    else:
        set_config_value("hdmi_group", 2)

    set_config_value("hdmi_mode", mode)
예제 #18
0
def set_safeboot_mode():
    logger.warn("Safe boot requested")

    set_screen_value('hdmi_force_hotplug', 1)
    set_screen_value('config_hdmi_boost', 4)

    set_screen_value('hdmi_group', 2)
    set_screen_value('hdmi_mode', 16)

    set_screen_value('hdmi_drive', None)
    set_config_value('hdmi_drive', None)

    set_screen_value('disable_overscan', 1)
    set_screen_value('overscan_left', 0)
    set_screen_value('overscan_right', 0)
    set_screen_value('overscan_top', 0)
    set_screen_value('overscan_bottom', 0)
예제 #19
0
def set_unflashed_sk_resolution():
    """
    Set the resolution globally for a screen that has corrupted EDID data.
    These are specific to the Kano screens.

    Returns:
        bool - Whether or not changes were made and a reboot is required.
    """
    hdmi_group = 2
    hdmi_mode = 28

    changes_required = (get_config_value('hdmi_group') != hdmi_group
                        or get_config_value('hdmi_mode') != hdmi_mode)
    if changes_required:
        set_config_value('hdmi_group', hdmi_group)
        set_config_value('hdmi_mode', hdmi_mode)

    return changes_required
예제 #20
0
def compare_and_set_overscan(edid, status, model, dry_run=False, force=False):
    """
    Check the overscan status and set it as required from EDID.

    Args:
        edid - dict as returned by the function get_edid()
        status - dict as returned by the function get_status()
        model - str as return by the function get_edid_name()
        dry_run - bool run the function, but do not apply any changes
        force - bool reconfigure settings even when the status says it's not needed

    Returns:
        changes - bool whether or not changes were applied
    """
    if status['overscan'] == edid['target_overscan'] and not force:
        logger.debug('Config overscan change not needed.')
        return False

    if edid['target_overscan']:
        disable_overscan = 0
        overscan_value = -48  # TODO: where does this value come from?
    else:
        disable_overscan = 1
        overscan_value = 0

    logger.info(
        'Overscan change needed. Setting disable_overscan to {} and overscan to {}'
        .format(disable_overscan, overscan_value)
    )
    if dry_run and not force:
        return True

    set_config_value(
        'disable_overscan',
        disable_overscan,
        config_filter=Filter.get_edid_filter(model)
    )
    for overscan in ['overscan_left', 'overscan_right', 'overscan_top', 'overscan_bottom']:
        set_config_value(
            overscan,
            overscan_value,
            config_filter=Filter.get_edid_filter(model)
        )
    return True
예제 #21
0
def compare_and_set_overscan(edid, status, model, dry_run=False, force=False):
    """
    Check the overscan status and set it as required from EDID.

    Args:
        edid - dict as returned by the function get_edid()
        status - dict as returned by the function get_status()
        model - str as return by the function get_edid_name()
        dry_run - bool run the function, but do not apply any changes
        force - bool reconfigure settings even when the status says it's not needed

    Returns:
        changes - bool whether or not changes were applied
    """
    if status['overscan'] == edid['target_overscan'] and not force:
        logger.debug('Config overscan change not needed.')
        return False

    if edid['target_overscan']:
        disable_overscan = 0
        overscan_value = -48  # TODO: where does this value come from?
    else:
        disable_overscan = 1
        overscan_value = 0

    logger.info(
        'Overscan change needed. Setting disable_overscan to {} and overscan to {}'
        .format(disable_overscan, overscan_value)
    )
    if dry_run and not force:
        return True

    set_config_value(
        'disable_overscan',
        disable_overscan,
        config_filter=Filter.get_edid_filter(model)
    )
    for overscan in ['overscan_left', 'overscan_right', 'overscan_top', 'overscan_bottom']:
        set_config_value(
            overscan,
            overscan_value,
            config_filter=Filter.get_edid_filter(model)
        )
    return True
예제 #22
0
def set_unflashed_sk_resolution():
    """
    Set the resolution globally for a screen that has corrupted EDID data.
    These are specific to the Kano screens.

    Returns:
        bool - Whether or not changes were made and a reboot is required.
    """
    hdmi_group = 2
    hdmi_mode = 28

    changes_required = (
        get_config_value('hdmi_group') != hdmi_group or
        get_config_value('hdmi_mode') != hdmi_mode
    )
    if changes_required:
        set_config_value('hdmi_group', hdmi_group)
        set_config_value('hdmi_mode', hdmi_mode)

    return changes_required
예제 #23
0
def set_to_HDMI(HDMI, force=False):
    '''
    Set audio output to HDMI if supported by the display,
    otherwise set it to Analogue output.

    Returns 'HDMI' or 'Analogue', whichever was applied.
    '''

    if not is_hdmi_audio_supported() and not force:
        HDMI = False

    # 1 analog
    # 2 hdmi

    # These are the changes we'll apply if they have changed from what they were
    if HDMI:
        amixer_cmd = hdmi_cmd
        set_config_value('hdmi_ignore_edid_audio', None)
        set_config_value('hdmi_drive', 2)
        config = _("HDMI")
    else:
        amixer_cmd = analogue_cmd
        set_config_value('hdmi_ignore_edid_audio', 1)
        set_config_value('hdmi_drive', None)
        config = _("Analogue")

    end_config_transaction()

    # Set audio path in amixer
    o, e, rc = run_cmd(amixer_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(o, e, rc))

    # trigger alsa-store to store the path in /var/lib/alsa/asound.state
    o, e, rc = run_cmd(store_cmd)
    if rc:
        logger.warn("error from alsa-store: {} {} {}".format(o, e, rc))

    set_setting('Audio', config)
    return config
예제 #24
0
def set_screen_value(key, value, and_global=False):
    monitor_edid_filter = Filter.get_edid_filter(get_edid_name())
    set_config_value(key, value, config_filter=monitor_edid_filter)

    if and_global:
        set_config_value(key, value)
예제 #25
0
def set_safeboot_mode():
    logger.warn("Safe boot requested")

    set_config_value("hdmi_force_hotplug", 1)
    set_config_value("config_hdmi_boost", 4)

    set_config_value("hdmi_group", 2)
    set_config_value("hdmi_mode", 16)

    set_config_value("disable_overscan", 1)
    set_config_value("overscan_left", 0)
    set_config_value("overscan_right", 0)
    set_config_value("overscan_top", 0)
    set_config_value("overscan_bottom", 0)
예제 #26
0
def restore_overclock_values(backup_config):
    for key in CLOCK_KEYS:
        set_config_value(key, backup_config.get_value(key))
예제 #27
0
def write_overscan_values(overscan_values):
    set_config_value('overscan_top', overscan_values['top'])
    set_config_value('overscan_bottom', overscan_values['bottom'])
    set_config_value('overscan_left', overscan_values['left'])
    set_config_value('overscan_right', overscan_values['right'])
예제 #28
0
def set_default_config():
    # restore factory defaults

    # setting the audio to analogue
    set_to_HDMI(False)

    set_config_value("hdmi_ignore_edid_audio", 1)
    set_config_value("hdmi_drive", None)

    # resetting HDMI settings
    set_config_value("disable_overscan", 1)
    set_config_value("overscan_left", 0)
    set_config_value("overscan_right", 0)
    set_config_value("overscan_top", 0)
    set_config_value("overscan_bottom", 0)
    set_config_value("hdmi_pixel_encoding", 2)
    set_config_value("hdmi_group", None)
    set_config_value("hdmi_mode", None)
    set_config_value("display_rotate", 0)
    set_config_comment("kano_screen_used", "xxx")

    # resetting overclocking settings
    set_default_overclock_values()

    # set the keyboard to default
    set_keyboard("en_US", "generic")

    end_config_transaction()
예제 #29
0
def restore_overclock_values(backup_config):
    for key in CLOCK_KEYS:
        set_config_value(key, backup_config.get_value(key))
예제 #30
0
def set_default_config():
    # restore factory defaults

    # setting the audio to analogue
    set_to_HDMI(False)

    set_config_value('hdmi_ignore_edid_audio', 1)
    set_config_value('hdmi_drive', None)

    # resetting HDMI settings
    set_config_value('disable_overscan', 1)
    set_config_value('overscan_left', 0)
    set_config_value('overscan_right', 0)
    set_config_value('overscan_top', 0)
    set_config_value('overscan_bottom', 0)
    set_config_value('hdmi_pixel_encoding', 2)
    set_config_value('hdmi_group', None)
    set_config_value('hdmi_mode', None)
    set_config_value('display_rotate', 0)

    # resetting overclocking settings
    set_default_overclock_values()

    # set the keyboard to default
    set_keyboard('en_US', 'generic')

    end_config_transaction()
예제 #31
0
def set_flip(display_rotate=None):
    if display_rotate:
        set_config_value("display_rotate", 2)
    else:
        set_config_value("display_rotate", 0)
예제 #32
0
def set_screen_value(key, value):
    monitor_edid_filter = Filter.get_edid_filter(get_edid_name())
    set_config_value(key, value, config_filter=monitor_edid_filter)
예제 #33
0
def set_screen_value(key, value):
    monitor_edid_filter = Filter.get_edid_filter(get_edid_name())
    set_config_value(key, value, config_filter=monitor_edid_filter)
def set_safe_mode_config():
    """
    Requires sudo.
    """

    set_screen_value('hdmi_force_hotplug', 1)
    set_config_value('hdmi_force_hotplug', 1)

    set_screen_value('config_hdmi_boost', 4)
    set_config_value('config_hdmi_boost', 4)

    set_screen_value('hdmi_group', None)
    set_config_value('hdmi_group', None)

    set_screen_value('hdmi_mode', None)
    set_config_value('hdmi_mode', None)

    set_screen_value('hdmi_drive', None)
    set_config_value('hdmi_drive', None)

    set_screen_value('disable_overscan', 1)
    set_config_value('disable_overscan', 1)

    set_screen_value('overscan_left', 0)
    set_config_value('overscan_left', 0)

    set_screen_value('overscan_right', 0)
    set_config_value('overscan_right', 0)

    set_screen_value('overscan_top', 0)
    set_config_value('overscan_top', 0)

    set_screen_value('overscan_bottom', 0)
    set_config_value('overscan_bottom', 0)
예제 #35
0
def set_screen_value(key, value, and_global=False):
    monitor_edid_filter = Filter.get_edid_filter(get_edid_name())
    set_config_value(key, value, config_filter=monitor_edid_filter)

    if and_global:
        set_config_value(key, value)