class Keyleds::Device
- Keyleds::Device
- Reference
- Object
Overview
Represents a physical Logitech device that can be interfaced with.
Defined in:
bridge.crdevice.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
-
.new(path : String, app_id : UInt8)
Creates a new
Device
.
Class Method Summary
-
.open(path : String, app_id : UInt8, &)
Creates a new
Device
with the given parameters, yields it to a block, and automatically closes the device.
Instance Method Summary
-
#blocks : Array(Keyblock)
Gets all device LED
Keyblock
s. -
#close
Closes the device handle.
-
#commit_leds
Applies pending lighting changes set by
Device#set_leds
orDevice#set_led_block
. -
#custom_gkeys(enabled : Bool)
Enables or disable custom G-key behavior.
-
#fd : IO::FileDescriptor
Returns the device's underlying file descriptor.
-
#feature_count : UInt32
Gets the number of HID++ features supported by the device.
-
#feature_id(feature_index : UInt8) : UInt16
Finds the feature ID of a feature, given its index in the device's internal feature table.
-
#feature_index(feature_id : UInt16) : UInt8
Given a feature's ID, returns its index in the device's internal table.
-
#flush
Flushes pending inbound events, processing G-key presses if present.
-
#gamemode_add(scancodes : Array(UInt8))
Adds the given keys, represented by their scancodes, to the game mode block list.
-
#gamemode_max_blocked : UInt32
Returns the maximum possible number of keys that can be blocked at a time during game mode.
-
#gamemode_remove(scancodes : Array(UInt8))
Remove the given keys, represented by their scancodes, from the game mode block list.
-
#gamemode_reset
Resets the game mode blocked key list to empty.
-
#gkeys_count : UInt32
Returns the number of G-keys available on the device.
-
#keyboard_layout : KeyboardLayout
Returns the device's declared international keyboard layout.
-
#leds(block : BlockId, key_offset : UInt16, num_keys : UInt32) : Array(KeyColor)
Starting at
key_offset
within the given block, returnsnum_keys
current LED states. -
#name : String
Returns the name of the device.
-
#on_gkey(&callback : GkeysType, BitArray -> )
Defines a callback that should be run whenever a G-key (or M/MR-key) is pressed.
-
#ping
Resynchronizes with the device.
-
#protocol : ProtocolSpec
Returns the device's current protocol.
-
#reportrate : UInt32
Returns the device's current report rate.
-
#set_led_block(block : BlockId, red : UInt8, green : UInt8, blue : UInt8)
Sets the entire LED block to a single uniform color.
-
#set_leds(block : BlockId, keys : Array(KeyColor))
Sets the LED color for the given keys.
-
#set_mkeys(state : Tuple(Bool, Bool, Bool))
Sets the lighting state for the M keys.
-
#set_mrkey(state : Bool)
Sets the lighting state for the MR key.
-
#set_reportrate(rate : UInt32)
Sets the keyboard's report rate to
rate
. -
#set_timeout(microseconds : UInt32)
Sets the device's HID++ command timeout.
-
#supported_rates : Array(UInt32)
Gets all supported report rates.
-
#type : Type
Returns the device's type.
-
#version : Version
Returns the device's current firmware version.
Constructor Detail
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. SeeAPP_IDS
for valid arguments.
Class Method Detail
Creates a new Device
with the given parameters, yields it to a block, and automatically closes the device.
Instance Method Detail
Enables or disable custom G-key behavior. If false
, G-keys will default to their corresponding F-keys.
Finds the feature ID of a feature, given its index in the device's internal feature table.
Given a feature's ID, returns its index in the device's internal table.
Adds the given keys, represented by their scancodes, to the game mode block list.
Returns the maximum possible number of keys that can be blocked at a time during game mode.
Remove the given keys, represented by their scancodes, from the game mode block list.
Starting at key_offset
within the given block, returns num_keys
current LED states.
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
Resynchronizes with the device. Use as a recovery mechanism after another call has errored.
Sets the entire LED block to a single uniform color.
Must be committed with Device#commit_leds
.
Sets the LED color for the given keys.
Must be committed with Device#commit_leds
.