Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
aconno_ble/lizzy_service.h
- Committer:
- jurica238814
- Date:
- 2018-09-13
- Branch:
- SimpleGATTExample
- Revision:
- 22:7dae8496b97c
- Parent:
- 8:7ba4f82de9b6
File content as of revision 22:7dae8496b97c:
#ifndef __LIZZY_SERVICE_H__ #define __LIZZY_SERVICE_H__ #include "mbed.h" #include "ble/BLE.h" #define NUM_LEDS (3) #define NUM_AXIS (3) typedef struct { bool buzz; bool leds[NUM_LEDS]; uint16_t acc_lsb; int16_t acc_data[NUM_AXIS]; } init_lizzy_t; class LizzyService{ public: const static uint16_t LIZZY_SERVICE_UUID = 0xAB00; const static uint16_t RED_UUID = 0xAB02; const static uint16_t GREEN_UUID = 0xAB03; LizzyService(BLEDevice &_ble, init_lizzy_t *init) : ble(_ble), red_led(RED_UUID, &(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), green_led(GREEN_UUID, &(init->leds[1]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { // Add characteristics in table GattCharacteristic *charTable[] = {&red_led, &green_led}; GattService AckService(LIZZY_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *)); ble.gattServer().addService(AckService); // Add service in the BLE } inline BLEDevice *get_ble(){ return &ble; } // Characteristic setters. inline void set_red_state(bool new_state){ ble.gattServer().write(red_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state)); } inline void set_green_state(bool new_state){ ble.gattServer().write(green_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state)); } // Characteristic getters. inline bool get_red_state(){ bool tmp; uint16_t size = sizeof(tmp); ble.gattServer().read(red_led.getValueHandle(), (uint8_t*)&tmp, &size); return tmp; } inline bool get_green_state(){ bool tmp; uint16_t size = sizeof(tmp); ble.gattServer().read(green_led.getValueHandle(), (uint8_t*)&tmp, &size); return tmp; } inline GattAttribute::Handle_t get_red_handle(){ return red_led.getValueHandle(); } inline GattAttribute::Handle_t get_green_handle(){ return green_led.getValueHandle(); } private: BLEDevice &ble; // Create new characteristics ReadWriteGattCharacteristic<bool> red_led; ReadWriteGattCharacteristic<bool> green_led; }; #endif //__LIZZY_SERVICE_H__