class Keyleds::Device

Overview

Represents a physical Logitech device that can be interfaced with.

Defined in:

bridge.cr
device.cr

Constant Summary

APP_IDS = LibKeyleds::APP_ID_MIN..LibKeyleds::APP_ID_MAX

The full range of valid application IDs that can be used for initialization (i.e. Device.open.)

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(path : String, app_id : UInt8) #

Creates a new Device. Must be explicitly closed with Device#close after usage.

  • path must be a valid path to the device's corresponding HID file (i.e. /dev/hidraw1).
  • app_id is a constant identifier for use with all further device communication. See APP_IDS for valid arguments.

[View source]

Class Method Detail

def self.open(path : String, app_id : UInt8, &) #

Creates a new Device with the given parameters, yields it to a block, and automatically closes the device.


[View source]

Instance Method Detail

def blocks : Array(Keyblock) #

Gets all device LED Keyblocks.


[View source]
def close #

Closes the device handle.


[View source]
def commit_leds #

Applies pending lighting changes set by Device#set_leds or Device#set_led_block.


[View source]
def custom_gkeys(enabled : Bool) #

Enables or disable custom G-key behavior. If false, G-keys will default to their corresponding F-keys.


[View source]
def fd : IO::FileDescriptor #

Returns the device's underlying file descriptor.


[View source]
def feature_count : UInt32 #

Gets the number of HID++ features supported by the device.


[View source]
def feature_id(feature_index : UInt8) : UInt16 #

Finds the feature ID of a feature, given its index in the device's internal feature table.


[View source]
def feature_index(feature_id : UInt16) : UInt8 #

Given a feature's ID, returns its index in the device's internal table.


[View source]
def flush #

Flushes pending inbound events, processing G-key presses if present.


[View source]
def gamemode_add(scancodes : Array(UInt8)) #

Adds the given keys, represented by their scancodes, to the game mode block list.


[View source]
def gamemode_max_blocked : UInt32 #

Returns the maximum possible number of keys that can be blocked at a time during game mode.


[View source]
def gamemode_remove(scancodes : Array(UInt8)) #

Remove the given keys, represented by their scancodes, from the game mode block list.


[View source]
def gamemode_reset #

Resets the game mode blocked key list to empty.


[View source]
def gkeys_count : UInt32 #

Returns the number of G-keys available on the device.


[View source]
def keyboard_layout : KeyboardLayout #

Returns the device's declared international keyboard layout.


[View source]
def leds(block : BlockId, key_offset : UInt16, num_keys : UInt32) : Array(KeyColor) #

Starting at key_offset within the given block, returns num_keys current LED states.


[View source]
def name : String #

Returns the name of the device.


[View source]
def on_gkey(&callback : GkeysType, BitArray -> ) #

Defines a callback that should be run whenever a G-key (or M/MR-key) is pressed. The second parameter is a BitArray, with the first bit representing the first key in the group. Triggered by Device#flush.

Keyleds::Device.open("/dev/hidraw1", 1) do |dev|
  dev.custom_gkeys(true)

  dev.on_gkey do |type, keys|
    puts "is the first key on? #{keys[0]}"
  end

  loop { dev.flush } # is the first key on? false
end

[View source]
def ping #

Resynchronizes with the device. Use as a recovery mechanism after another call has errored.


[View source]
def protocol : ProtocolSpec #

Returns the device's current protocol.


[View source]
def reportrate : UInt32 #

Returns the device's current report rate.


[View source]
def set_led_block(block : BlockId, red : UInt8, green : UInt8, blue : UInt8) #

Sets the entire LED block to a single uniform color. Must be committed with Device#commit_leds.


[View source]
def set_leds(block : BlockId, keys : Array(KeyColor)) #

Sets the LED color for the given keys. Must be committed with Device#commit_leds.


[View source]
def set_mkeys(state : Tuple(Bool, Bool, Bool)) #

Sets the lighting state for the M keys.


[View source]
def set_mrkey(state : Bool) #

Sets the lighting state for the MR key.


[View source]
def set_reportrate(rate : UInt32) #

Sets the keyboard's report rate to rate.


[View source]
def set_timeout(microseconds : UInt32) #

Sets the device's HID++ command timeout.


[View source]
def supported_rates : Array(UInt32) #

Gets all supported report rates.


[View source]
def type : Type #

Returns the device's type. See Type for more info.


[View source]
def version : Version #

Returns the device's current firmware version.


[View source]