StepOne (store accelerometer value)

Dependencies:   I2C_FUNCTION LSM6DS0 MAX30100 mbed BLE_API

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ButtonService.h Source File

ButtonService.h

00001 #ifndef __BLE_BUTTON_SERVICE_H__
00002 #define __BLE_BUTTON_SERVICE_H__
00003 
00004 class StepCounterService
00005 {
00006 public:
00007     const static uint16_t STEPCOUNTER_SERVICE_UUID              = 0xA000;
00008     const static uint16_t STEPCOUNTER_STATE_CHARACTERISTIC_UUID = 0xA001;
00009 
00010     StepCounterService(BLEDevice &_ble, bool buttonPressedInitial) :
00011         ble(_ble), StepCounterState(STEPCOUNTER_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
00012         GattCharacteristic *characteristics[] = {&StepCounterState};
00013         GattService         StepCounterService(StepCounterService::STEPCOUNTER_SERVICE_UUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
00014         ble.addService(StepCounterService);
00015     }
00016 
00017     void updateStepCounterState(int newState) {
00018         ble.updateCharacteristicValue(StepCounterState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
00019     }
00020 
00021 private:
00022     BLEDevice                        &ble;
00023     ReadOnlyGattCharacteristic<bool>  StepCounterState;
00024 };
00025 
00026 class ButtonServiceB
00027 {
00028 public:
00029     const static uint16_t BUTTON_SERVICE_UUID              = 0xB000;
00030     const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xB001;
00031     const static uint16_t READWRITE_CHARACTERISTIC_UUID = 0xB002;
00032 
00033     ButtonServiceB(BLEDevice &_ble, bool buttonPressedInitial) :
00034         ble(_ble),
00035         buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00036         readWrite(READWRITE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)  {
00037             
00038         GattCharacteristic *charTable[] = {&buttonState, &readWrite};
00039         GattService         buttonService(ButtonServiceB::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
00040         ble.addService(buttonService);
00041     }
00042 
00043     void updateButtonState(int newState) {
00044         ble.updateCharacteristicValue(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
00045     }
00046 
00047 private:
00048     BLEDevice                        &ble;
00049     ReadOnlyGattCharacteristic<bool>  buttonState;
00050     ReadWriteGattCharacteristic<uint8_t>  readWrite;
00051 };
00052 
00053 #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */