Documentation ¶
Overview ¶
Package ckb provides an interface to ckb-daemon, a daemon for communicating with Corsair peripherals.
See https://github.com/ckb-next/ckb-next
Example ¶
// list devices devices, err := Devices() if err != nil { panic(err) } // open first device dev, err := Open(devices[0].Index) if err != nil { panic(err) } // use independant notification channel so we don't interfere with other applications using this device err = dev.SetNotificationChannel(3, true) if err != nil { panic(err) } // erase the state of the third mode err = dev.EraseMode(3) if err != nil { panic(err) } // and switch to it err = dev.SwitchMode(3) if err != nil { panic(err) } // make every LED blue err = dev.SetAllLEDs(3, &color.RGBA{0, 0, 255, 255}) if err != nil { panic(err) } for { // poll for events ev, err := dev.Poll() if err != nil { panic(err) } // handle event switch ev := ev.(type) { case *KeyEvent: if ev.Pressed { fmt.Printf("%s pressed\n", ev.Key) } else { fmt.Printf("%s released\n", ev.Key) } } }
Output:
Index ¶
- Variables
- type Device
- func (dev *Device) Close() error
- func (dev *Device) EraseMode(mode int) error
- func (dev *Device) GetMode() (int, error)
- func (dev *Device) NotifyAllKeys() error
- func (dev *Device) NotifyKeys(keys []string) error
- func (dev *Device) Poll() (Event, error)
- func (dev *Device) SetAllLEDs(mode int, col color.Color) error
- func (dev *Device) SetLED(mode int, key string, col color.Color) error
- func (dev *Device) SetLEDs(mode int, keys []string, col color.Color) error
- func (dev *Device) SetNotificationChannel(i int, captive bool) error
- func (dev *Device) SwitchMode(mode int) error
- func (dev *Device) UnnotifyAllKeys() error
- func (dev *Device) UnnotifyKeys(keys []string) error
- type DeviceError
- type DeviceIndex
- type DeviceInfo
- type Event
- type KeyEvent
- type MultiError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDeviceNotFound = errors.New("ckb: device not found")
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents a connection to a CKB daemon device. It is not safe for use by multiple goroutines. In order to use multiple programs/goroutines, create separate Devices and ensure that both of them call Device.SetNotificationChannel() with unique indexes.
func (*Device) NotifyAllKeys ¶
NotifyAllKeys enables notifications for all key events.
func (*Device) NotifyKeys ¶
NotifyKeys enables notifications for events on the given keys.
func (*Device) SetAllLEDs ¶
SetAllLEDs sets the color of every LED on the device to the given color.
func (*Device) SetNotificationChannel ¶
SetNotificationChannel sets the channel this device will use to receive notifications from the CKB daemon. By default, devices will use notify0 for all notifications. It can be any integer from 0 to 9. If captive is true, this notification channel will be closed when we are done with it; otherwise it will be left open. When in doubt, set captive to true.
See https://github.com/ckb-next/ckb-next/wiki/CKB-Daemon-Manual#notifications
func (*Device) SwitchMode ¶
SwitchMode switches to the given mode.
func (*Device) UnnotifyAllKeys ¶
UnnotifyAllKeys disables notifications for all key events.
func (*Device) UnnotifyKeys ¶
UnnotifyKeys disables notifications for events on the given keys.
type DeviceError ¶
type DeviceError struct { Index DeviceIndex Err error }
func (*DeviceError) Error ¶
func (e *DeviceError) Error() string
func (*DeviceError) Unwrap ¶
func (e *DeviceError) Unwrap() error
type DeviceIndex ¶
type DeviceIndex int
type DeviceInfo ¶
type DeviceInfo struct { Index DeviceIndex Path string SerialNumber string Description string }
DeviceInfo represents information about a connected device.
type MultiError ¶
type MultiError struct {
Errs []error
}
func (*MultiError) Error ¶
func (e *MultiError) Error() string