ble nano hid over gatt

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
83:2e940d154f8b
Parent:
82:af52d37b1946
--- a/HIDServiceBase.h	Sat Sep 03 23:16:07 2016 +0900
+++ b/HIDServiceBase.h	Sun Sep 04 01:12:45 2016 +0900
@@ -29,130 +29,131 @@
 typedef const uint8_t * report_t;
 
 typedef struct {
-    uint16_t bcdHID;
-    uint8_t  bCountryCode;
-    uint8_t  flags;
+	uint16_t bcdHID;
+	uint8_t  bCountryCode;
+	uint8_t  flags;
 } HID_information_t;
 
 enum ReportType {
-    INPUT_REPORT    = 0x1,
-    OUTPUT_REPORT   = 0x2,
-    FEATURE_REPORT  = 0x3,
+	INPUT_REPORT    = 0x1,
+	OUTPUT_REPORT   = 0x2,
+	FEATURE_REPORT  = 0x3,
 };
 
 enum ProtocolMode {
-    BOOT_PROTOCOL   = 0x0,
-    REPORT_PROTOCOL = 0x1,
+	BOOT_PROTOCOL   = 0x0,
+	REPORT_PROTOCOL = 0x1,
 };
 
 typedef struct {
-    uint8_t ID;
-    uint8_t type;
+	uint8_t ID;
+	uint8_t type;
 } report_reference_t;
 
 
 class HIDServiceBase {
 public:
-    /**
-     *  Constructor
-     *
-     *  @param _ble
-     *         BLE object to add this service to
-     *  @param reportMap
-     *         Byte array representing the input/output report formats. In USB HID jargon, it
-     *         is called "HID report descriptor".
-     *  @param reportMapLength 
-     *         Size of the reportMap array
-     *  @param outputReportLength
-     *         Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
-     *  @param inputReportLength
-     *         Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
-     */
-    HIDServiceBase(BLE &_ble,
-                   report_map_t reportMap,
-                   uint8_t reportMapLength,
-                   report_t inputReport,
-                   report_t outputReport,
-                   report_t featureReport,
-                   uint8_t inputReportLength = 0,
-                   uint8_t outputReportLength = 0,
-                   uint8_t featureReportLength = 0);
+	/**
+	 *  Constructor
+	 *
+	 *  @param _ble
+	 *         BLE object to add this service to
+	 *  @param reportMap
+	 *         Byte array representing the input/output report formats. In USB HID jargon, it
+	 *         is called "HID report descriptor".
+	 *  @param reportMapLength 
+	 *         Size of the reportMap array
+	 *  @param outputReportLength
+	 *         Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
+	 *  @param inputReportLength
+	 *         Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
+	 */
+	HIDServiceBase(
+		BLE &_ble,
+		report_map_t reportMap,
+		uint8_t reportMapLength,
+		report_t inputReport,
+		report_t outputReport,
+		report_t featureReport,
+		uint8_t inputReportLength = 0,
+		uint8_t outputReportLength = 0,
+		uint8_t featureReportLength = 0
+	);
 
-    /**
-     *  Send Report
-     *
-     *  @param report   Report to send. Must be of size @ref inputReportLength
-     *  @return         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.
-     */
-    virtual ble_error_t send(const report_t report);
+	/**
+	 *  Send Report
+	 *
+	 *  @param report   Report to send. Must be of size @ref inputReportLength
+	 *  @return         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.
+	 */
+	virtual ble_error_t send(const report_t report);
 
-    /**
-     *  Read Report
-     *
-     *  @param report   Report to fill. Must be of size @ref outputReportLength
-     *  @return         The read status
-     */
-    virtual ble_error_t read(report_t report);
+	/**
+	 *  Read Report
+	 *
+	 *  @param report   Report to fill. Must be of size @ref outputReportLength
+	 *  @return         The read status
+	 */
+	virtual ble_error_t read(report_t report);
 
-    virtual void onConnection(const Gap::ConnectionCallbackParams_t *params);
-    virtual void onDisconnection(const Gap::DisconnectionCallbackParams_t *params);
+	virtual void onConnection(const Gap::ConnectionCallbackParams_t *params);
+	virtual void onDisconnection(const Gap::DisconnectionCallbackParams_t *params);
 
-    virtual bool isConnected(void)
-    {
-        return connected;
-    }
+	virtual bool isConnected(void) {
+		return connected;
+	}
 
 	virtual void init(void);
+
 protected:
-
-    /**
-     * Called by BLE API when data has been successfully sent.
-     *
-     * @param count     Number of reports sent
-     *
-     * @note Subclasses can override this to avoid starting the report ticker when there is nothing
-     * to send
-     */
-    virtual void onDataSent(unsigned count);
+	/**
+	 * Called by BLE API when data has been successfully sent.
+	 *
+	 * @param count     Number of reports sent
+	 *
+	 * @note Subclasses can override this to avoid starting the report ticker when there is nothing
+	 * to send
+	 */
+	virtual void onDataSent(unsigned count);
 
 	/**
-	 */
-    virtual void onDataWritten(const GattWriteCallbackParams *params);
+	*/
+	virtual void onDataWritten(const GattWriteCallbackParams *params);
 
 	virtual void addExtraCharacteristics(GattCharacteristic** characteristics, uint8_t& charIndex);
 
 protected:
-    BLE &ble;
-    bool connected;
+	BLE &ble;
+	bool connected;
 
-    int reportMapLength;
+	int reportMapLength;
 
-    report_t inputReport;
-    report_t outputReport;
-    report_t featureReport;
+	report_t inputReport;
+	report_t outputReport;
+	report_t featureReport;
 
-    uint8_t inputReportLength;
-    uint8_t outputReportLength;
-    uint8_t featureReportLength;
+	uint8_t inputReportLength;
+	uint8_t outputReportLength;
+	uint8_t featureReportLength;
 
-    uint8_t controlPointCommand;
-    uint8_t protocolMode;
+	uint8_t controlPointCommand;
+	uint8_t protocolMode;
 
-    // Optional gatt characteristics:
-    GattCharacteristic protocolModeCharacteristic;
+	// Optional gatt characteristics:
+	GattCharacteristic protocolModeCharacteristic;
 
-    // Report characteristics (each sort of optional)
-    GattCharacteristic inputReportCharacteristic;
-    GattCharacteristic outputReportCharacteristic;
-    GattCharacteristic featureReportCharacteristic;
+	// Report characteristics (each sort of optional)
+	GattCharacteristic inputReportCharacteristic;
+	GattCharacteristic outputReportCharacteristic;
+	GattCharacteristic featureReportCharacteristic;
 
-    // Required gatt characteristics: Report Map, Information, Control Point
-    GattCharacteristic reportMapCharacteristic;
-    ReadOnlyGattCharacteristic<HID_information_t> HIDInformationCharacteristic;
-    GattCharacteristic HIDControlPointCharacteristic;
+	// Required gatt characteristics: Report Map, Information, Control Point
+	GattCharacteristic reportMapCharacteristic;
+	ReadOnlyGattCharacteristic<HID_information_t> HIDInformationCharacteristic;
+	GattCharacteristic HIDControlPointCharacteristic;
 };
 
 #endif /* !HID_SERVICE_BASE_H_ */