Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
aconno_ble/lizzy_service.h@29:b021b33cf666, 2019-01-31 (annotated)
- Committer:
- jurica238814
- Date:
- Thu Jan 31 15:50:52 2019 +0100
- Branch:
- master
- Revision:
- 29:b021b33cf666
- Parent:
- 26:6101bb09f70d
Scaling factor hardcoded for acnSENSA format
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 | 26:6101bb09f70d | 6 | #include "service_macros.h" |
dbartolovic | 26:6101bb09f70d | 7 | #include "proj_config.h" |
dbartolovic | 8:7ba4f82de9b6 | 8 | |
dbartolovic | 8:7ba4f82de9b6 | 9 | #define NUM_LEDS (3) |
dbartolovic | 8:7ba4f82de9b6 | 10 | #define NUM_AXIS (3) |
dbartolovic | 8:7ba4f82de9b6 | 11 | |
dbartolovic | 8:7ba4f82de9b6 | 12 | |
dbartolovic | 8:7ba4f82de9b6 | 13 | typedef struct |
dbartolovic | 8:7ba4f82de9b6 | 14 | { |
dbartolovic | 8:7ba4f82de9b6 | 15 | bool buzz; |
dbartolovic | 8:7ba4f82de9b6 | 16 | bool leds[NUM_LEDS]; |
dbartolovic | 8:7ba4f82de9b6 | 17 | uint16_t acc_lsb; |
dbartolovic | 8:7ba4f82de9b6 | 18 | int16_t acc_data[NUM_AXIS]; |
dbartolovic | 8:7ba4f82de9b6 | 19 | } init_lizzy_t; |
dbartolovic | 8:7ba4f82de9b6 | 20 | |
dbartolovic | 8:7ba4f82de9b6 | 21 | |
dbartolovic | 8:7ba4f82de9b6 | 22 | class LizzyService{ |
dbartolovic | 8:7ba4f82de9b6 | 23 | public: |
dbartolovic | 8:7ba4f82de9b6 | 24 | const static uint16_t LIZZY_SERVICE_UUID = 0xA000; |
dbartolovic | 8:7ba4f82de9b6 | 25 | const static uint16_t BUZZ_UUID = 0xA001; |
dbartolovic | 26:6101bb09f70d | 26 | const static uint16_t MAC_RED_UUID = 0xA002; |
dbartolovic | 8:7ba4f82de9b6 | 27 | const static uint16_t GREEN_UUID = 0xA003; |
dbartolovic | 8:7ba4f82de9b6 | 28 | const static uint16_t BLUE_UUID = 0xA004; |
dbartolovic | 8:7ba4f82de9b6 | 29 | const static uint16_t ACC_LSB_UUID = 0xA005; |
dbartolovic | 8:7ba4f82de9b6 | 30 | const static uint16_t ACC_DATA_UUID = 0xA006; |
dbartolovic | 8:7ba4f82de9b6 | 31 | |
dbartolovic | 8:7ba4f82de9b6 | 32 | LizzyService(BLEDevice &_ble, init_lizzy_t *init) : |
dbartolovic | 8:7ba4f82de9b6 | 33 | ble(_ble), |
dbartolovic | 26:6101bb09f70d | 34 | #if VODAFONE_COMPATIBILITY == 1 |
dbartolovic | 26:6101bb09f70d | 35 | buzz(BUZZ_UUID, (uint8_t*)&(init->buzz)), |
dbartolovic | 26:6101bb09f70d | 36 | mac(MAC_RED_UUID, (uint8_t*)&(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
dbartolovic | 26:6101bb09f70d | 37 | #else |
dbartolovic | 8:7ba4f82de9b6 | 38 | buzz(BUZZ_UUID, &(init->buzz), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
dbartolovic | 26:6101bb09f70d | 39 | redLed(MAC_RED_UUID, &(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
dbartolovic | 26:6101bb09f70d | 40 | #endif |
dbartolovic | 8:7ba4f82de9b6 | 41 | green_led(GREEN_UUID, &(init->leds[1]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
dbartolovic | 8:7ba4f82de9b6 | 42 | blue_led(BLUE_UUID, &(init->leds[2]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
dbartolovic | 8:7ba4f82de9b6 | 43 | acc_lsb(ACC_LSB_UUID, &(init->acc_lsb), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
dbartolovic | 8:7ba4f82de9b6 | 44 | acc_data(ACC_DATA_UUID, init->acc_data, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
dbartolovic | 8:7ba4f82de9b6 | 45 | { |
dbartolovic | 26:6101bb09f70d | 46 | GattCharacteristic *charTable[] = { |
dbartolovic | 26:6101bb09f70d | 47 | #if VODAFONE_COMPATIBILITY == 1 |
dbartolovic | 26:6101bb09f70d | 48 | &buzz, &mac, |
dbartolovic | 26:6101bb09f70d | 49 | #else |
dbartolovic | 26:6101bb09f70d | 50 | &buzz, &redLed, |
dbartolovic | 26:6101bb09f70d | 51 | #endif |
dbartolovic | 26:6101bb09f70d | 52 | &green_led, &blue_led, &acc_lsb, &acc_data}; // Add characteristick in table |
dbartolovic | 8:7ba4f82de9b6 | 53 | GattService AckService(LIZZY_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *)); |
dbartolovic | 8:7ba4f82de9b6 | 54 | ble.gattServer().addService(AckService); // Add service in the BLE |
dbartolovic | 8:7ba4f82de9b6 | 55 | } |
dbartolovic | 8:7ba4f82de9b6 | 56 | |
dbartolovic | 8:7ba4f82de9b6 | 57 | inline BLEDevice *get_ble(){ |
dbartolovic | 8:7ba4f82de9b6 | 58 | return &ble; |
dbartolovic | 8:7ba4f82de9b6 | 59 | } |
dbartolovic | 8:7ba4f82de9b6 | 60 | |
dbartolovic | 8:7ba4f82de9b6 | 61 | // Characteristic setters. |
dbartolovic | 26:6101bb09f70d | 62 | /* |
dbartolovic | 8:7ba4f82de9b6 | 63 | inline void set_buzz_state(bool new_state){ |
dbartolovic | 8:7ba4f82de9b6 | 64 | ble.gattServer().write(buzz.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state)); |
dbartolovic | 8:7ba4f82de9b6 | 65 | } |
dbartolovic | 8:7ba4f82de9b6 | 66 | inline void set_red_state(bool new_state){ |
dbartolovic | 8:7ba4f82de9b6 | 67 | ble.gattServer().write(red_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state)); |
dbartolovic | 26:6101bb09f70d | 68 | }*/ |
dbartolovic | 8:7ba4f82de9b6 | 69 | inline void set_green_state(bool new_state){ |
dbartolovic | 8:7ba4f82de9b6 | 70 | ble.gattServer().write(green_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state)); |
dbartolovic | 8:7ba4f82de9b6 | 71 | } |
dbartolovic | 8:7ba4f82de9b6 | 72 | inline void set_blue_state(bool new_state){ |
dbartolovic | 8:7ba4f82de9b6 | 73 | ble.gattServer().write(blue_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state)); |
dbartolovic | 8:7ba4f82de9b6 | 74 | } |
dbartolovic | 8:7ba4f82de9b6 | 75 | |
dbartolovic | 8:7ba4f82de9b6 | 76 | inline void set_acc_lsb(uint16_t new_value){ |
dbartolovic | 8:7ba4f82de9b6 | 77 | ble.gattServer().write(acc_lsb.getValueHandle(), (uint8_t*)&new_value, sizeof(new_value)); |
dbartolovic | 8:7ba4f82de9b6 | 78 | } |
dbartolovic | 8:7ba4f82de9b6 | 79 | inline void set_acc_data(int16_t *new_values){ |
dbartolovic | 8:7ba4f82de9b6 | 80 | ble.gattServer().write(acc_data.getValueHandle(), (uint8_t*)new_values, sizeof(int16_t)*NUM_AXIS); |
dbartolovic | 8:7ba4f82de9b6 | 81 | } |
dbartolovic | 8:7ba4f82de9b6 | 82 | |
dbartolovic | 8:7ba4f82de9b6 | 83 | // Characteristic getters. |
dbartolovic | 26:6101bb09f70d | 84 | /* |
dbartolovic | 8:7ba4f82de9b6 | 85 | inline bool get_buzz_state(){ |
dbartolovic | 8:7ba4f82de9b6 | 86 | bool tmp; |
dbartolovic | 8:7ba4f82de9b6 | 87 | uint16_t size = sizeof(tmp); |
dbartolovic | 8:7ba4f82de9b6 | 88 | ble.gattServer().read(buzz.getValueHandle(), (uint8_t*)&tmp, &size); |
dbartolovic | 8:7ba4f82de9b6 | 89 | return tmp; |
dbartolovic | 8:7ba4f82de9b6 | 90 | } |
dbartolovic | 8:7ba4f82de9b6 | 91 | inline bool get_red_state(){ |
dbartolovic | 8:7ba4f82de9b6 | 92 | bool tmp; |
dbartolovic | 8:7ba4f82de9b6 | 93 | uint16_t size = sizeof(tmp); |
dbartolovic | 8:7ba4f82de9b6 | 94 | ble.gattServer().read(red_led.getValueHandle(), (uint8_t*)&tmp, &size); |
dbartolovic | 8:7ba4f82de9b6 | 95 | return tmp; |
dbartolovic | 26:6101bb09f70d | 96 | }*/ |
dbartolovic | 8:7ba4f82de9b6 | 97 | inline bool get_green_state(){ |
dbartolovic | 8:7ba4f82de9b6 | 98 | bool tmp; |
dbartolovic | 8:7ba4f82de9b6 | 99 | uint16_t size = sizeof(tmp); |
dbartolovic | 8:7ba4f82de9b6 | 100 | ble.gattServer().read(green_led.getValueHandle(), (uint8_t*)&tmp, &size); |
dbartolovic | 8:7ba4f82de9b6 | 101 | return tmp; |
dbartolovic | 8:7ba4f82de9b6 | 102 | } |
dbartolovic | 8:7ba4f82de9b6 | 103 | inline bool get_blue_state(){ |
dbartolovic | 8:7ba4f82de9b6 | 104 | bool tmp; |
dbartolovic | 8:7ba4f82de9b6 | 105 | uint16_t size = sizeof(tmp); |
dbartolovic | 8:7ba4f82de9b6 | 106 | ble.gattServer().read(blue_led.getValueHandle(), (uint8_t*)&tmp, &size); |
dbartolovic | 8:7ba4f82de9b6 | 107 | return tmp; |
dbartolovic | 8:7ba4f82de9b6 | 108 | } |
dbartolovic | 26:6101bb09f70d | 109 | |
dbartolovic | 26:6101bb09f70d | 110 | /* |
dbartolovic | 8:7ba4f82de9b6 | 111 | inline GattAttribute::Handle_t get_buzz_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 112 | return buzz.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 113 | } |
dbartolovic | 8:7ba4f82de9b6 | 114 | inline GattAttribute::Handle_t get_red_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 115 | return red_led.getValueHandle(); |
dbartolovic | 26:6101bb09f70d | 116 | }*/ |
dbartolovic | 8:7ba4f82de9b6 | 117 | inline GattAttribute::Handle_t get_green_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 118 | return green_led.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 119 | } |
dbartolovic | 8:7ba4f82de9b6 | 120 | inline GattAttribute::Handle_t get_blue_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 121 | return blue_led.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 122 | } |
dbartolovic | 8:7ba4f82de9b6 | 123 | |
dbartolovic | 8:7ba4f82de9b6 | 124 | inline GattAttribute::Handle_t get_acc_lsb_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 125 | return acc_lsb.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 126 | }inline GattAttribute::Handle_t get_acc_data_handle(){ |
dbartolovic | 8:7ba4f82de9b6 | 127 | return acc_data.getValueHandle(); |
dbartolovic | 8:7ba4f82de9b6 | 128 | } |
dbartolovic | 26:6101bb09f70d | 129 | |
dbartolovic | 26:6101bb09f70d | 130 | #if VODAFONE_COMPATIBILITY == 1 |
dbartolovic | 26:6101bb09f70d | 131 | CHARACTERISTIC_A(WriteOnly, uint8_t, 4, buzz, Buzz); |
dbartolovic | 26:6101bb09f70d | 132 | CHARACTERISTIC_A(ReadOnly, uint8_t, 6, mac, Mac); |
dbartolovic | 26:6101bb09f70d | 133 | #else |
dbartolovic | 26:6101bb09f70d | 134 | CHARACTERISTIC_W(ReadWrite, bool, buzz, Buzz); |
dbartolovic | 26:6101bb09f70d | 135 | CHARACTERISTIC_W(ReadWrite, bool, redLed, RedLed); |
dbartolovic | 26:6101bb09f70d | 136 | #endif |
dbartolovic | 8:7ba4f82de9b6 | 137 | |
dbartolovic | 8:7ba4f82de9b6 | 138 | private: |
dbartolovic | 8:7ba4f82de9b6 | 139 | BLEDevice &ble; |
dbartolovic | 8:7ba4f82de9b6 | 140 | // Create new characteristics |
dbartolovic | 26:6101bb09f70d | 141 | /* |
dbartolovic | 8:7ba4f82de9b6 | 142 | ReadWriteGattCharacteristic<bool> buzz; |
dbartolovic | 26:6101bb09f70d | 143 | ReadWriteGattCharacteristic<bool> red_led;*/ |
dbartolovic | 8:7ba4f82de9b6 | 144 | ReadWriteGattCharacteristic<bool> green_led; |
dbartolovic | 8:7ba4f82de9b6 | 145 | ReadWriteGattCharacteristic<bool> blue_led; |
dbartolovic | 8:7ba4f82de9b6 | 146 | |
dbartolovic | 8:7ba4f82de9b6 | 147 | ReadOnlyGattCharacteristic<uint16_t> acc_lsb; |
dbartolovic | 8:7ba4f82de9b6 | 148 | ReadOnlyArrayGattCharacteristic<int16_t, NUM_AXIS> acc_data; |
dbartolovic | 8:7ba4f82de9b6 | 149 | }; |
dbartolovic | 8:7ba4f82de9b6 | 150 | |
dbartolovic | 8:7ba4f82de9b6 | 151 | #endif //__LIZZY_SERVICE_H__ |