pub trait Plugin {
// Required methods
fn name(&mut self) -> SDKResult<&'static str>;
fn initialise(
&mut self,
callback: Box<dyn Fn(DeviceEventType, &DeviceInfo) + Send>,
) -> SDKResult<u32>;
fn is_initialised(&mut self) -> bool;
fn device_info(&mut self) -> SDKResult<Vec<DeviceInfo>>;
fn read_analog(&mut self, code: u16, device: DeviceID) -> SDKResult<f32>;
fn read_full_buffer(
&mut self,
max_length: usize,
device: DeviceID,
) -> SDKResult<HashMap<c_ushort, c_float>>;
// Provided method
fn unload(&mut self) { ... }
}
Expand description
The core Plugin trait which needs to be implemented for an Analog Plugin to function
Required Methods§
Sourcefn initialise(
&mut self,
callback: Box<dyn Fn(DeviceEventType, &DeviceInfo) + Send>,
) -> SDKResult<u32>
fn initialise( &mut self, callback: Box<dyn Fn(DeviceEventType, &DeviceInfo) + Send>, ) -> SDKResult<u32>
Initialise the plugin with the given function for device events. Returns an int indicating the number of connected devices
Sourcefn is_initialised(&mut self) -> bool
fn is_initialised(&mut self) -> bool
A function fired to check if the plugin is currently initialised
Sourcefn device_info(&mut self) -> SDKResult<Vec<DeviceInfo>>
fn device_info(&mut self) -> SDKResult<Vec<DeviceInfo>>
This function is fired by the SDK to collect up all Device Info structs. The memory for the struct should be retained and only dropped when the device is disconnected or the plugin is unloaded. This ensures that the Device Info is not garbled when it’s being accessed by the client.
§Notes
Although, the client should be copying any data they want to use for a prolonged time as there is no lifetime guarantee on the data.
Sourcefn read_analog(&mut self, code: u16, device: DeviceID) -> SDKResult<f32>
fn read_analog(&mut self, code: u16, device: DeviceID) -> SDKResult<f32>
Function called to get the analog value for a particular HID key code
from the device with ID device
.
If device
is 0 then no specific device is specified and the value should be read from all devices and combined
Sourcefn read_full_buffer(
&mut self,
max_length: usize,
device: DeviceID,
) -> SDKResult<HashMap<c_ushort, c_float>>
fn read_full_buffer( &mut self, max_length: usize, device: DeviceID, ) -> SDKResult<HashMap<c_ushort, c_float>>
Function called to get the full analog read buffer for a particular device with ID device
. max_length
is the maximum amount
of keys that can be accepted, any more beyond this will be ignored by the SDK.
If device
is 0 then no specific device is specified and the data should be read from all devices and combined