Exemple #1
0
def get_device_info(device):
    DEVICE_INFO_SIZE = 96
    response = simple_command(device, CMD_GET_DEVICE_SETTINGS,
                              [INFO_MAIN_0])[1:]
    response += simple_command(device, CMD_GET_DEVICE_SETTINGS,
                               [INFO_MAIN_1])[1:]
    response = response[0:DEVICE_INFO_SIZE]

    # check if the flash has been initialized
    is_empty = sum([1 for byte in response if byte != 0xff]) == 0

    # uint8_t device_id;
    # char device_name[32];
    # uint8_t timestamp[8]; // utc time stamp of last update
    # uint8_t default_report_mode;
    # uint8_t scan_mode;
    # uint8_t row_count;
    # uint8_t col_count;
    # uint8_t feature_ctrl;
    # uint8_t _reserved[48];
    # uint16_t crc; // total size == 96

    crc = crc16_bytes(response[:DEVICE_INFO_SIZE - 2])

    x = struct.unpack("< B 32s q 5B 48s H", response)
    return KBInfoMain._make_with_crc(x, crc, is_empty)
Exemple #2
0
    def gen_global_settings(self, device_id):
        # uint8_t device_id;
        # char device_name[32];
        # uint8_t timestamp[8]; // utc time stamp of last update
        # uint8_t default_report_mode;
        # typedef struct matrix_scan_plan_t {
        #     uint8_t mode; // scanning method
        #     uint8_t rows; // number of rows in the scan matrix
        #     uint8_t cols; // number of cols in the scan matrix
        #     uint8_t debounce_time_press; // How long to debounce a key when it is pressed (ms)
        #     uint8_t debounce_time_release; // How long to debounce a key when it is released (ms)
        #     uint8_t trigger_time_press; // The key must be down this long before being registered (ms)
        #     uint8_t trigger_time_release; // The key must be up this long before being registered (ms)

        #     // Both delays are measured on a scale of 0-48µs
        #     uint8_t parasitic_discharge_delay_idle; // How long to hold a row low before reading the columns
        #     uint8_t parasitic_discharge_delay_debouncing; // How long to hold a row low when a key is debouncing

        #     uint8_t max_col_pin_num; // maximum column pin number used
        #     uint8_t max_key_num; // highest key number used
        # } matrix_scan_plan_t;
        # uint8_t _reserved0[8];
        # uint8_t feature_ctrl;
        # uint8_t _reserved1[32];
        # uint16_t crc; // total size == 96
        result = bytearray(0)

        device = self.get_device_by_id(device_id)

        # device_id
        result += struct.pack('<B', device.id)

        # device_id
        result += struct.pack('<32s', device.name.encode('utf-8'))

        # build timestamp, 64 bit UTC
        result += struct.pack('<q', int(time.time()))

        # default_report_mode
        result += struct.pack('<B', self.get_report_mode())

        # scan mode information
        result += self.gen_scan_mode_info(device_id)

        # resreved0
        result += bytearray(8)

        # feature control information
        result += device.feature_ctrl.to_bytes()
        # result += bytearray([0xff])

        result += bytearray(32)

        result += struct.pack('<H', crc16_bytes(result))

        return result
Exemple #3
0
def get_device_info(device):
    DEVICE_INFO_SIZE = 96
    response = simple_command(device, CMD_GET_INFO, [INFO_MAIN_0])[1:]
    response += simple_command(device, CMD_GET_INFO, [INFO_MAIN_1])[1:]
    response = response[0:DEVICE_INFO_SIZE]

    # check if the flash has been initialized
    is_empty = sum([1 for byte in response if byte != 0xff]) == 0

    # uint8_t device_id;
    # char device_name[32];
    # uint8_t timestamp[8]; // utc time stamp of last update
    # uint8_t default_report_mode;
    # typedef struct matrix_scan_plan_t {
    #     uint8_t mode; // scanning method
    #     uint8_t rows; // number of rows in the scan matrix
    #     uint8_t cols; // number of cols in the scan matrix
    #     uint8_t debounce_time_press; // How long to debounce a key when it is pressed (ms)
    #     uint8_t debounce_time_release; // How long to debounce a key when it is released (ms)
    #     uint8_t trigger_time_press; // The key must be down this long before being registered (ms)
    #     uint8_t trigger_time_release; // The key must be up this long before being registered (ms)

    #     // Both delays are measured on a scale of 0-48µs
    #     uint8_t parasitic_discharge_delay_idle; // How long to hold a row low before reading the columns
    #     uint8_t parasitic_discharge_delay_debouncing; // How long to hold a row low when a key is debouncing

    #     uint8_t max_col_pin_num; // maximum column pin number used
    #     uint8_t max_key_num; // highest key number used
    # } matrix_scan_plan_t;
    # uint8_t _reserved0[8];
    # uint8_t feature_ctrl;
    # uint8_t _reserved1[32];
    # uint16_t crc; // total size == 96

    crc = crc16_bytes(response[:DEVICE_INFO_SIZE - 2])

    x = struct.unpack("< B 32s q 12B 8s 1B 32s H", response)
    return KBInfoMain._make_with_crc(x, crc, is_empty)