Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
aconno_ble/lizzy_service.h@22:7dae8496b97c, 2018-09-13 (annotated)
- Committer:
- jurica238814
- Date:
- Thu Sep 13 15:14:14 2018 +0200
- Branch:
- SimpleGATTExample
- Revision:
- 22:7dae8496b97c
- Parent:
- 8:7ba4f82de9b6
LAUT example program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dbartolovic | 8:7ba4f82de9b6 | 1 | #ifndef __LIZZY_SERVICE_H__ |
dbartolovic | 8:7ba4f82de9b6 | 2 | #define __LIZZY_SERVICE_H__ |
dbartolovic | 8:7ba4f82de9b6 | 3 | |
dbartolovic | 8:7ba4f82de9b6 | 4 | #include "mbed.h" |
dbartolovic | 8:7ba4f82de9b6 | 5 | #include "ble/BLE.h" |
dbartolovic | 8:7ba4f82de9b6 | 6 | |
dbartolovic | 8:7ba4f82de9b6 | 7 | #define NUM_LEDS (3) |
dbartolovic | 8:7ba4f82de9b6 | 8 | #define NUM_AXIS (3) |
dbartolovic | 8:7ba4f82de9b6 | 9 | |
dbartolovic | 8:7ba4f82de9b6 | 10 | |
dbartolovic | 8:7ba4f82de9b6 | 11 | typedef struct |
dbartolovic | 8:7ba4f82de9b6 | 12 | { |
dbartolovic | 8:7ba4f82de9b6 | 13 | bool buzz; |
dbartolovic | 8:7ba4f82de9b6 | 14 | bool leds[NUM_LEDS]; |
dbartolovic | 8:7ba4f82de9b6 | 15 | uint16_t acc_lsb; |
dbartolovic | 8:7ba4f82de9b6 | 16 | int16_t acc_data[NUM_AXIS]; |
dbartolovic | 8:7ba4f82de9b6 | 17 | } init_lizzy_t; |
dbartolovic | 8:7ba4f82de9b6 | 18 | |
dbartolovic | 8:7ba4f82de9b6 | 19 | class LizzyService{ |
dbartolovic | 8:7ba4f82de9b6 | 20 | public: |
jurica238814 | 22:7dae8496b97c | 21 | const static uint16_t LIZZY_SERVICE_UUID = 0xAB00; |
jurica238814 | 22:7dae8496b97c | 22 | const static uint16_t RED_UUID = 0xAB02; |
jurica238814 | 22:7dae8496b97c | 23 | const static uint16_t GREEN_UUID = 0xAB03; |
dbartolovic | 8:7ba4f82de9b6 | 24 | |
dbartolovic | 8:7ba4f82de9b6 | 25 | LizzyService(BLEDevice &_ble, init_lizzy_t *init) : |
dbartolovic | 8:7ba4f82de9b6 | 26 | ble(_ble), |
jurica238814 | 22:7dae8496b97c | 27 | red_led(RED_UUID, &(init->leds[0]), |
jurica238814 | 22:7dae8496b97c | 28 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
jurica238814 | 22:7dae8496b97c | 29 | green_led(GREEN_UUID, &(init->leds[1]), |
jurica238814 | 22:7dae8496b97c | 30 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
dbartolovic | 8:7ba4f82de9b6 | 31 | { |
jurica238814 | 22:7dae8496b97c | 32 | // Add characteristics in table |
jurica238814 | 22:7dae8496b97c | 33 | GattCharacteristic *charTable[] = {&red_led, &green_led}; |
jurica238814 | 22:7dae8496b97c | 34 | GattService AckService(LIZZY_SERVICE_UUID, charTable, |
jurica238814 | 22:7dae8496b97c | 35 | sizeof(charTable)/sizeof(GattCharacteristic *)); |
dbartolovic | 8:7ba4f82de9b6 | 36 | ble.gattServer().addService(AckService); // Add service in the BLE |
dbartolovic | 8:7ba4f82de9b6 | 37 | } |
jurica238814 | 22:7dae8496b97c | 38 | |
dbartolovic | 8:7ba4f82de9b6 | 39 | inline BLEDevice *get_ble(){ |
dbartolovic | 8:7ba4f82de9b6 | 40 | return &ble; |
dbartolovic | 8:7ba4f82de9b6 | 41 | } |
jurica238814 | 22:7dae8496b97c | 42 | |
dbartolovic | 8:7ba4f82de9b6 | 43 | // Characteristic setters. |
dbartolovic | 8:7ba4f82de9b6 | 44 | inline void set_red_state(bool new_state){ |
jurica238814 | 22:7dae8496b97c | 45 | ble.gattServer().write(red_led.getValueHandle(), |
jurica238814 | 22:7dae8496b97c | 46 | (uint8_t*)&new_state, sizeof(new_state)); |
dbartolovic | 8:7ba4f82de9b6 | 47 | } |
dbartolovic | 8:7ba4f82de9b6 | 48 | inline void set_green_state(bool new_state){ |
jurica238814 | 22:7dae8496b97c | 49 | ble.gattServer().write(green_led.getValueHandle(), |
jurica238814 | 22:7dae8496b97c | 50 | (uint8_t*)&new_state, sizeof(new_state)); |
dbartolovic | 8:7ba4f82de9b6 | 51 | } |
jurica238814 | 22:7dae8496b97c | 52 | |
dbartolovic | 8:7ba4f82de9b6 | 53 | // Characteristic getters. |
dbartolovic | 8:7ba4f82de9b6 | 54 | inline bool get_red_state(){ |
dbartolovic | 8:7ba4f82de9b6 | 55 | bool tmp; |
dbartolovic | 8:7ba4f82de9b6 | 56 | uint16_t size = sizeof(tmp); |
jurica238814 | 22:7dae8496b97c | 57 | ble.gattServer().read(red_led.getValueHandle(), (uint8_t*)&tmp, |
jurica238814 | 22:7dae8496b97c | 58 | &size); |
dbartolovic | 8:7ba4f82de9b6 | 59 | return tmp; |
dbartolovic | 8:7ba4f82de9b6 | 60 | } |
dbartolovic | 8:7ba4f82de9b6 | 61 | inline bool get_green_state(){ |
dbartolovic | 8:7ba4f82de9b6 | 62 | bool tmp; |
dbartolovic | 8:7ba4f82de9b6 | 63 | uint16_t size = sizeof(tmp); |
jurica238814 | 22:7dae8496b97c | 64 | ble.gattServer().read(green_led.getValueHandle(), (uint8_t*)&tmp, |
jurica238814 | 22:7dae8496b97c | 65 | &size); |
dbartolovic | 8:7ba4f82de9b6 | 66 | return tmp; |
dbartolovic | 8:7ba4f82de9b6 | 67 | } |
jurica238814 | 22:7dae8496b97c | 68 | |
dbartolovic | 8:7ba4f82de9b6 | 69 | inline GattAttribute::Handle_t get_red_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 70 | return red_led.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 71 | } |
dbartolovic | 8:7ba4f82de9b6 | 72 | inline GattAttribute::Handle_t get_green_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 73 | return green_led.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 74 | } |
jurica238814 | 22:7dae8496b97c | 75 | |
dbartolovic | 8:7ba4f82de9b6 | 76 | private: |
dbartolovic | 8:7ba4f82de9b6 | 77 | BLEDevice &ble; |
dbartolovic | 8:7ba4f82de9b6 | 78 | // Create new characteristics |
dbartolovic | 8:7ba4f82de9b6 | 79 | ReadWriteGattCharacteristic<bool> red_led; |
dbartolovic | 8:7ba4f82de9b6 | 80 | ReadWriteGattCharacteristic<bool> green_led; |
dbartolovic | 8:7ba4f82de9b6 | 81 | }; |
dbartolovic | 8:7ba4f82de9b6 | 82 | |
jurica238814 | 22:7dae8496b97c | 83 | #endif //__LIZZY_SERVICE_H__ |