BLE Feedbakc Service
Dependencies: BLE_API mbed nRF51822
Fork of BLE_HeartRate by
ble_feedback.h@65:5a78321ef3d3, 2015-06-12 (annotated)
- Committer:
- ReneM92
- Date:
- Fri Jun 12 09:07:19 2015 +0000
- Revision:
- 65:5a78321ef3d3
- Parent:
- 64:4ced7a1586b0
Kicking MrFeedback out
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ReneM92 | 63:3c5ca3832415 | 1 | #ifndef __BLE_FEEDBACK_H__ |
ReneM92 | 63:3c5ca3832415 | 2 | #define __BLE_FEEDBACK_H__ |
ReneM92 | 63:3c5ca3832415 | 3 | |
ReneM92 | 63:3c5ca3832415 | 4 | #include "BLEDevice.h" |
ReneM92 | 63:3c5ca3832415 | 5 | #include "mbed.h" |
ReneM92 | 63:3c5ca3832415 | 6 | |
ReneM92 | 63:3c5ca3832415 | 7 | |
ReneM92 | 63:3c5ca3832415 | 8 | |
ReneM92 | 63:3c5ca3832415 | 9 | class FeedbackService { |
ReneM92 | 63:3c5ca3832415 | 10 | |
ReneM92 | 63:3c5ca3832415 | 11 | public: |
ReneM92 | 64:4ced7a1586b0 | 12 | FeedbackService(); |
ReneM92 | 63:3c5ca3832415 | 13 | void updateBatteryValue(uint8_t newBatValue); |
ReneM92 | 63:3c5ca3832415 | 14 | void onDataWritten(const GattCharacteristicWriteCBParams *params); |
ReneM92 | 63:3c5ca3832415 | 15 | void setupService(); |
ReneM92 | 63:3c5ca3832415 | 16 | uint8_t getTest(); |
ReneM92 | 63:3c5ca3832415 | 17 | bool isConnected(); |
ReneM92 | 63:3c5ca3832415 | 18 | bool newValue(); |
ReneM92 | 63:3c5ca3832415 | 19 | |
ReneM92 | 63:3c5ca3832415 | 20 | private: |
ReneM92 | 63:3c5ca3832415 | 21 | void init(); |
ReneM92 | 63:3c5ca3832415 | 22 | void setupAdvertising(); |
ReneM92 | 63:3c5ca3832415 | 23 | /* |
ReneM92 | 63:3c5ca3832415 | 24 | struct BatteryValueBytes { |
ReneM92 | 63:3c5ca3832415 | 25 | BatteryValueBytes(uint8_t battery); |
ReneM92 | 63:3c5ca3832415 | 26 | void updateBattery(uint8_t battery); |
ReneM92 | 63:3c5ca3832415 | 27 | uint8_t *getPointer(void); |
ReneM92 | 63:3c5ca3832415 | 28 | const uint8_t *getPointer(void) const; |
ReneM92 | 63:3c5ca3832415 | 29 | unsigned getNumValueBytes(void) const; |
ReneM92 | 63:3c5ca3832415 | 30 | |
ReneM92 | 63:3c5ca3832415 | 31 | |
ReneM92 | 63:3c5ca3832415 | 32 | private: |
ReneM92 | 63:3c5ca3832415 | 33 | uint8_t valueBytes[1]; |
ReneM92 | 63:3c5ca3832415 | 34 | };*/ |
ReneM92 | 63:3c5ca3832415 | 35 | |
ReneM92 | 63:3c5ca3832415 | 36 | struct BatteryValueBytes { |
ReneM92 | 63:3c5ca3832415 | 37 | static const unsigned MAX_VALUE_BYTES = 1; |
ReneM92 | 63:3c5ca3832415 | 38 | static const unsigned FLAGS_BYTE_INDEX = 0; |
ReneM92 | 63:3c5ca3832415 | 39 | static const unsigned VALUE_FORMAT_BITNUM = 0; |
ReneM92 | 63:3c5ca3832415 | 40 | static const uint8_t VALUE_FORMAT_FLAG = (1 << VALUE_FORMAT_BITNUM); |
ReneM92 | 63:3c5ca3832415 | 41 | |
ReneM92 | 63:3c5ca3832415 | 42 | |
ReneM92 | 63:3c5ca3832415 | 43 | BatteryValueBytes(uint8_t battery) : valueBytes() { |
ReneM92 | 63:3c5ca3832415 | 44 | updateBattery(battery); |
ReneM92 | 63:3c5ca3832415 | 45 | } |
ReneM92 | 63:3c5ca3832415 | 46 | |
ReneM92 | 63:3c5ca3832415 | 47 | void updateBattery(uint8_t battery) { |
ReneM92 | 63:3c5ca3832415 | 48 | valueBytes[FLAGS_BYTE_INDEX ] = battery; |
ReneM92 | 63:3c5ca3832415 | 49 | } |
ReneM92 | 63:3c5ca3832415 | 50 | |
ReneM92 | 63:3c5ca3832415 | 51 | uint8_t *getPointer(void) { |
ReneM92 | 63:3c5ca3832415 | 52 | return valueBytes; |
ReneM92 | 63:3c5ca3832415 | 53 | } |
ReneM92 | 63:3c5ca3832415 | 54 | |
ReneM92 | 63:3c5ca3832415 | 55 | const uint8_t *getPointer(void) const { |
ReneM92 | 63:3c5ca3832415 | 56 | return valueBytes; |
ReneM92 | 63:3c5ca3832415 | 57 | } |
ReneM92 | 63:3c5ca3832415 | 58 | |
ReneM92 | 63:3c5ca3832415 | 59 | unsigned getNumValueBytes(void) const { |
ReneM92 | 63:3c5ca3832415 | 60 | return MAX_VALUE_BYTES; |
ReneM92 | 63:3c5ca3832415 | 61 | } |
ReneM92 | 63:3c5ca3832415 | 62 | |
ReneM92 | 63:3c5ca3832415 | 63 | private: |
ReneM92 | 63:3c5ca3832415 | 64 | uint8_t valueBytes[MAX_VALUE_BYTES]; |
ReneM92 | 63:3c5ca3832415 | 65 | }; |
ReneM92 | 63:3c5ca3832415 | 66 | |
ReneM92 | 63:3c5ca3832415 | 67 | private: |
ReneM92 | 63:3c5ca3832415 | 68 | BLEDevice &ble; |
ReneM92 | 63:3c5ca3832415 | 69 | |
ReneM92 | 63:3c5ca3832415 | 70 | BatteryValueBytes bValueBytes; |
ReneM92 | 63:3c5ca3832415 | 71 | uint16_t FServiceUUID; |
ReneM92 | 63:3c5ca3832415 | 72 | uint16_t writeUUID; |
ReneM92 | 63:3c5ca3832415 | 73 | uint8_t writeValue; |
ReneM92 | 63:3c5ca3832415 | 74 | uint8_t test; |
ReneM92 | 63:3c5ca3832415 | 75 | bool newValueFlag; |
ReneM92 | 63:3c5ca3832415 | 76 | |
ReneM92 | 63:3c5ca3832415 | 77 | GattCharacteristic batteryChar; |
ReneM92 | 63:3c5ca3832415 | 78 | WriteOnlyGattCharacteristic<uint8_t> writeChar; |
ReneM92 | 63:3c5ca3832415 | 79 | }; |
ReneM92 | 63:3c5ca3832415 | 80 | |
ReneM92 | 63:3c5ca3832415 | 81 | #endif /* #ifndef __BLE_FEEDBACK_H__*/ |