Trait Plugin

Source
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§

Source

fn name(&mut self) -> SDKResult<&'static str>

Get a name describing the Plugin.

Source

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

Source

fn is_initialised(&mut self) -> bool

A function fired to check if the plugin is currently initialised

Source

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.

Source

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

Source

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

Provided Methods§

Source

fn unload(&mut self)

A callback fired immediately before the plugin is unloaded. Use this if you need to do any cleanup.

Implementors§