Handle
Haply::HardwareAPI::Devices::Handle
Encapsulates the logic required to interact with a Haply handle.
WARNING Handles are still an area of active development and the API is not stable or guaranteed to be backwards compatible.
This class must be specialized to override one of the protected virtual methods which will be invoked when a particular event is received from the device:
- OnReceiveHandleInfo: Invoked after waking up the device.
- OnReceiveHandleStatusMessage Invoked when a new state update is received from the device.
- OnReceiveHandleErrorResponse Invoked the device reports an error.
An instance of the SerialStream class representing the serial port of the handle is required as a parameter to the constructor. Once constructed, the SendDeviceWakeup command will wakeup the handle and allow for RequestStatus commands to be sent to retrieve the latest device status. The Receive method should follow any command method to process the device's response and trigger one of the overloaded virtual methods.
Handle implementations are customizable using a field in the device's status whose length is determined by the field. The Haply Quill's user fields are defined as follows:
- : The state of the button on the flat surface of the handle where 1 indicate that it's held down.
- : The battery level where the value 100 means that the battery is full.
All methods within this class will block until their respective IO operations are completed or error out. Handles operate at a frequency of approximately 50Hz. If multiple devices are managed by the same thread, the overall processing frequency will cap at the lowest frequency of all the device. Mixing handles and Inverse3 within the same thread is therefore not recommended.
Index
Classes
Members
Name | Type | Description |
---|---|---|
USER_DATA_MAX | static constexpr uint8_t | The maximum amount of bytes that can be contained in the ... |
Methods
Name | Type | Description |
---|---|---|
Handle | (std::iostream *) | Constructs a Handle object from the ... |
SendDeviceWakeup | void() | Wakeup the handle to allow for additional commands. |
RequestStatus | void() | Request the latest state from the handle. |
SendHandleState | void(const uint16_t, const uint8_t, ...) | Update the handle-specific user state with the provided ... |
SendHandleErrorRequest | void(const uint16_t) | Request the latest error information from the handle. |
Receive | int() | Receive and processe a response from the handle. |
GetVersegripStatus | VersegripStatusResponse(...) |
Members
USER_DATA_MAX
static constexpr uint8_t USER_DATA_MAX = 255
The maximum amount of bytes that can be contained in the user field of any any specialized implementations of the Haply handle.
Methods
Handle
Handle(std::iostream * stream)
Constructs a Handle object from the provided stream.
Parameters
- stream The stream object representing the serial port associated with the device. The lifetime of the stream must match or exceed the lifetime of the Handle object. We recommend constructing this stream using the SerialStream class.
SendDeviceWakeup
void SendDeviceWakeup()
Wakeup the handle to allow for additional commands.
This command is required to be sent to the device before any other commands can be sent.
Must be followed by a call to Receive to process the handle's response which will in turn call the OnReceiveHandleInfo overloaded method.
RequestStatus
void RequestStatus()
Request the latest state from the handle.
Must be followed by a call to Receive to process the handle's response which will in turn call the OnReceiveHandleStatusMessage overloaded method.
SendHandleState
void SendHandleState( const uint16_t device_id, const uint8_t user_data_length, const uint8_t * user_data)
Update the handle-specific user state with the provided arguments.
Must be followed by a call to Receive to process the handle's response which will in turn call the OnReceiveHandleStatusMessage overloaded method.
Parameters
-
device_id The id of the device. This field is currently ignored by the handle and can be safely set to 0.
-
user_data_length The number of bytes to read from user_data. Must be smaller then USER_DATA_MAX.
-
user_data The bytes that will be read and used to update the handle-specific state. Consult the documentation of your handle to determine how to format these bytes.
SendHandleErrorRequest
void SendHandleErrorRequest(const uint16_t device_id)
Request the latest error information from the handle.
Must be followed by a call to Receive to process the handle's response which will in turn call the OnReceiveHandleErrorResponse overloaded method.
Parameters
- device_id The id of the device. This field is currently be ignored by the handle and can be safely set to 0.
Receive
int Receive()
Receive and processe a response from the handle.
Must follow any call to one of the following methods and will invoke the associated overloaded method:
- SendDeviceWakeup -> OnReceiveHandleInfo
- RequestStatus -> OnReceiveHandleStatusMessage
- SendHandleState -> OnReceiveHandleStatusMessage
- SendHandleErrorRequest -> OnReceiveHandleErrorResponse
Will block until a message is received from the device or an error is encountered.
Returns
0 if the operation completed successfully. If an error occurred then the method will return a negative value, an error will be printed to stderr and may return false.
GetVersegripStatus
VersegripStatusResponse GetVersegripStatus()