HID-over-GATT implementation with the BLE API. This library allows to create devices such as mouse, keyboard or joystick, over Bluetooth Low Energy.

Dependents:   BLENano_HID BLE_HID_MouseScrollDemo BLE_HID_KeyboardStreamDemo Shervs_TestKeyboard_TinyBLE ... more

Embed: (wiki syntax)

« Back to documentation index

MouseService Class Reference

MouseService Class Reference

HID-over-Gatt mouse service. More...

#include <MouseService.h>

Inherits HIDServiceBase.

Public Member Functions

int setSpeed (int8_t x, int8_t y, int8_t wheel)
 Set X, Y, Z speed of the mouse.
int setButton (MouseButton button, ButtonState state)
 Toggle the state of one button.
virtual void sendCallback (void)
 Called by the report ticker.
virtual ble_error_t send (const report_t report)
 Send Report.
virtual ble_error_t read (report_t report)
 Read Report.

Protected Member Functions

virtual void onDataSent (unsigned count)
 Called by BLE API when data has been successfully sent.
virtual void startReportTicker (void)
 Start the ticker that sends input reports at regular interval.
virtual void stopReportTicker (void)
 Stop the input report ticker.
GattAttribute ** inputReportDescriptors ()
 Create the Gatt descriptor for a report characteristic.
HID_information_t * HIDInformation ()
 Create the HID information structure.

Detailed Description

HID-over-Gatt mouse service.

Send mouse moves and button informations over BLE.

 BLE ble;
 MouseService mouse(ble);

 Timeout timeout;

 void stop_mouse_move(void)
 {
      // Set mouse state to immobile
      mouse.setButton(MOUSE_BUTTON_LEFT, MOUSE_UP);
      mouse.setSpeed(0, 0, 0);
 }

 void start_mouse_move(void)
 {
      // Move left with a left button down. If the focus is on a drawing
      // software, for instance, this should draw a line.
      mouse.setButton(MOUSE_BUTTON_LEFT, MOUSE_DOWN);
      mouse.setSpeed(1, 0, 0);

      timeout.attach(stop_mouse_move, 0.2);
 }

Definition at line 100 of file MouseService.h.


Member Function Documentation

HID_information_t * HIDInformation (  ) [protected, inherited]

Create the HID information structure.

Definition at line 202 of file HIDServiceBase.cpp.

GattAttribute ** inputReportDescriptors (  ) [protected, inherited]

Create the Gatt descriptor for a report characteristic.

Definition at line 171 of file HIDServiceBase.cpp.

void onDataSent ( unsigned  count ) [protected, virtual, inherited]

Called by BLE API when data has been successfully sent.

Parameters:
countNumber of reports sent
Note:
Subclasses can override this to avoid starting the report ticker when there is nothing to send

Definition at line 167 of file HIDServiceBase.cpp.

ble_error_t read ( report_t  report ) [virtual, inherited]

Read Report.

Parameters:
reportReport to fill. Must be of size outputReportLength
Returns:
The read status

Definition at line 214 of file HIDServiceBase.cpp.

ble_error_t send ( const report_t  report ) [virtual, inherited]

Send Report.

Parameters:
reportReport to send. Must be of size inputReportLength
Returns:
The write status
Note:
Don't call send() directly for multiple reports! Use reportTicker for that, in order to avoid overloading the BLE stack, and let it handle events between each report.

Definition at line 208 of file HIDServiceBase.cpp.

virtual void sendCallback ( void   ) [virtual]

Called by the report ticker.

Definition at line 182 of file MouseService.h.

int setButton ( MouseButton  button,
ButtonState  state 
)

Toggle the state of one button.

Returns:
A status code

Definition at line 167 of file MouseService.h.

int setSpeed ( int8_t  x,
int8_t  y,
int8_t  wheel 
)

Set X, Y, Z speed of the mouse.

Parameters are sticky and will be transmitted on every tick. Users should therefore reset them to 0 when the device is immobile.

Parameters:
xSpeed on hoizontal axis
ySpeed on vertical axis
wheelScroll speed
Returns:
A status code
Note:
Directions depend on the operating system's configuration. It is customary to increase values on the X axis from left to right, and on the Y axis from top to bottom. Wheel is less standard, although positive values will usually scroll up.

Definition at line 151 of file MouseService.h.

void startReportTicker ( void   ) [protected, virtual, inherited]

Start the ticker that sends input reports at regular interval.

Note:
reportTickerIsActive describes the state of the ticker and can be used by HIDS implementations.

Definition at line 155 of file HIDServiceBase.cpp.

void stopReportTicker ( void   ) [protected, virtual, inherited]

Stop the input report ticker.

Definition at line 162 of file HIDServiceBase.cpp.