コード例 #1
0
def set_led_indicator_option(led_type, led_indicator_option, control_file=None):
    """
    Set the LED indicator option for the specified LED type,

    Args:
      control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
      led_indicator_option: The LED indicator option to set for the LED type.
      led_type: The LED type for which to set the LED indicator option.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    """

    set_led_indicator_option_byte_list = [METHOD_ID, led_type, led_indicator_option]

    write_control_file(set_led_indicator_option_byte_list, control_file=control_file)

    (
        error_code,
        reserved_byte_1,
        reserved_byte_2,
        reserved_byte_3
    ) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))
コード例 #2
0
ファイル: version.py プロジェクト: uboslinux/intel-nuc-led
def wmi_interface_spec_compliance_version(control_file=None):
    """
    Returns the version for the WMI interface spec compliance.

    Args:
       control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    Returns:
       Tuple of two bytes representing the version number.
    """

    wmi_version_byte_list = [
        METHOD_ID,
        VERSION_TYPE.index('wmi_interface_spec_compliance_version')
    ]

    write_control_file(wmi_version_byte_list, control_file=control_file)

    (error_code, version_byte_1, version_byte_2,
     reserved_byte) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(
            RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))

    return tuple([version_byte_2, version_byte_1])
コード例 #3
0
def query_leds(control_file=None):
    """
    List all LED types supported.

    Args:
      control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    Returns:
       List of available `nuc_wmi.LED_TYPE` indexes.
    """

    query_leds_byte_list = [METHOD_ID, QUERY_TYPE.index('query_leds')]

    write_control_file(query_leds_byte_list, control_file=control_file)

    # Bitmap [0:7], [8:15], [16:23]
    (error_code, led_type_bitmap_1, led_type_bitmap_2,
     led_type_bitmap_3) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(
            RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))

    led_type_bitmaps = [
        led_type_bitmap_3, led_type_bitmap_2, led_type_bitmap_1
    ]
    led_type_bitmap = byte_list_to_bitmap(led_type_bitmaps)[::-1]

    return [
        index for index, bit in enumerate(led_type_bitmap)
        if int(bit) and index < len(LED_TYPE['new'])
    ]
コード例 #4
0
ファイル: get_led.py プロジェクト: uboslinux/intel-nuc-led
def get_led(led, control_file=None):
    """
    Get legacy LED state with regard to brightness, frequency, and color.

    Args:
       control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
       led: Selects the legacy LED to get the state for.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    Returns:
       Tuple of legacy brightness, frequency, and color of the select LED.
    """

    get_led_byte_list = [METHOD_ID, led]

    write_control_file(get_led_byte_list, control_file=control_file)

    (
        error_code,
        brightness,
        frequency,
        color
    ) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))

    return tuple([brightness, frequency, color])
コード例 #5
0
def query_led_control_items(led_type, led_indicator_option, control_file=None):
    """
    Query the LED control items for the LED indicator option of the LED type.

    Args:
      control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
      led_indicator_option: The LED indicator option to use for the LED type when querying for the LED control items.
      led_type: The LED type for which to query the LED control items.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    Returns:
       List of available `nuc_wmi.CONTROL_ITEM` indexes for the specified LED type and LED indicator option.
    """

    led_color_type = query_led_color_type(led_type, control_file=control_file)

    query_led_control_item_byte_list = [
        METHOD_ID,
        QUERY_TYPE.index('query_led_control_items'), led_type,
        led_indicator_option
    ]

    write_control_file(query_led_control_item_byte_list,
                       control_file=control_file)

    # Bitmap [0:7], [8:15], [16:23]
    (error_code, led_control_item_bitmap_1, led_control_item_bitmap_2,
     led_control_item_bitmap_3) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(
            RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))

    led_control_item_bitmaps = [
        led_control_item_bitmap_3, led_control_item_bitmap_2,
        led_control_item_bitmap_1
    ]
    led_control_item_bitmap = byte_list_to_bitmap(
        led_control_item_bitmaps)[::-1]

    if led_indicator_option == LED_INDICATOR_OPTION_DISABLED or \
       CONTROL_ITEM[led_indicator_option][led_color_type] is None:
        return []

    return [
        index for index, bit in enumerate(led_control_item_bitmap) if int(bit)
        and index < len(CONTROL_ITEM[led_indicator_option][led_color_type])
    ]
コード例 #6
0
ファイル: set_led.py プロジェクト: uboslinux/intel-nuc-led
def set_led(led, brightness, frequency, color, control_file=None):
    """
    Set LED state with regard to brightness, frequency, and color.

    Args:
       brightness: Controls the brightness level of the LED.
       color: Sets legacy RGB-color for LED.
       control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
       frequency: Sets the legacy LED frequency.
       led: Selects the legacy LED to set a state for.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    """

    set_led_byte_list = [METHOD_ID, led, brightness, frequency, color]

    write_control_file(set_led_byte_list, control_file=control_file)

    (brightness_error, frequency_error, color_error,
     reserved_byte) = read_control_file(control_file=control_file)

    if brightness_error > 0:
        raise NucWmiError(
            RETURN_ERROR.get(brightness_error,
                             'Error (Unknown NUC WMI error code)'))

    if frequency_error > 0:
        raise NucWmiError(
            RETURN_ERROR.get(frequency_error,
                             'Error (Unknown NUC WMI error code)'))

    if color_error > 0:
        raise NucWmiError(
            RETURN_ERROR.get(color_error,
                             'Error (Unknown NUC WMI error code)'))
コード例 #7
0
def switch_led_type(led_color_group, control_file=None):
    """
    Switches the LED color group type.

    Args:
       led_color_group: The LED color group type to set.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    """

    switch_led_byte_list = [METHOD_ID, led_color_group]

    write_control_file(switch_led_byte_list, control_file=control_file)

    (error_code, reserved_byte_1, reserved_byte_2,
     reserved_byte_3) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(
            RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))
コード例 #8
0
def get_led_control_item(led_type, led_indicator_option, control_item, control_file=None):
    """
    Get the current control item value for the control item of the indicator option for the specified LED type.

    Args:
      control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
      control_item: The control item of the specified LED type indicator option for which to retrieve the value.
      led_indicator_option: The indicator option for the specified LED type for which to retrieve the current control
                            item value.
      led_type: The LED type for which to retrieve the current control item.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    Returns:
       `nuc_wmi.CONTROL_ITEM` value for the control item of the indicator option for the specified LED type.
    """

    get_led_control_item_byte_list = [
        METHOD_ID,
        GET_LED_TYPE.index('get_led_control_item'),
        led_type,
        led_indicator_option,
        control_item
    ]

    write_control_file(get_led_control_item_byte_list, control_file=control_file)

    (
        error_code,
        control_item_value,
        reserved_byte_1,
        reserved_byte_2
    ) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))

    return control_item_value
コード例 #9
0
def save_led_config(control_file=None):
    """
    Send a save LED configuration LED app notification.

    Args:
      control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    """

    notification_byte_list = [
        METHOD_ID, NOTIFICATION_TYPE.index('save_led_config')
    ]

    write_control_file(notification_byte_list, control_file=control_file)

    (error_code, reserved_byte_1, reserved_byte_2,
     reserved_byte_3) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(
            RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))
コード例 #10
0
def query_led_color_type(led_type, control_file=None):
    """
    Query the LED color type for the LED type.

    Args:
      control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used.
      led_type: The LED type for which to query the LED color type.
    Exceptions:
       Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code,
       or if `read_control_file` or `write_control_file` raise an exception.
    Returns:
      `nuc_wmi.LED_COLOR_TYPE` index of current LED color type.
    """

    query_led_color_byte_list = [
        METHOD_ID,
        QUERY_TYPE.index('query_led_color_type'), led_type
    ]

    write_control_file(query_led_color_byte_list, control_file=control_file)

    # Bitmap [0:7], [8:15], [16:23]
    (error_code, led_color_type_bitmap_1, led_color_type_bitmap_2,
     led_color_type_bitmap_3) = read_control_file(control_file=control_file)

    if error_code > 0:
        raise NucWmiError(
            RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)'))

    led_color_type_bitmaps = [
        led_color_type_bitmap_3, led_color_type_bitmap_2,
        led_color_type_bitmap_1
    ]
    led_color_type_bitmap = byte_list_to_bitmap(led_color_type_bitmaps)

    return int(led_color_type_bitmap, 2)