Suad Suljic / Mbed OS Seismo2

Dependencies:   SDFileSystem circular_buffer MPU6050 SoftSerial

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ButtonService.h Source File

ButtonService.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef __BLE_BUTTON_SERVICE_H__
00018 #define __BLE_BUTTON_SERVICE_H__
00019 
00020 class ButtonService {
00021 public:
00022     const static uint16_t BUTTON_SERVICE_UUID              = 0xA000;
00023     const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA001;
00024     const static uint16_t INTERRUPT_STATE_CHARACTERISTIC_UUID = 0xA002;
00025     const static uint16_t GYRO_STATE_CHARACTERISTIC_UUID = 0xA003;
00026     
00027     
00028     const static uint16_t MOTION_THRESHOLD_CHARACTERISTIC_UUID = 0xA004;
00029     const static uint16_t MOTION_DURATION_CHARACTERISTIC_UUID = 0xA005;
00030     
00031       const static uint16_t ZERO_MOTION_THRESHOLD_CHARACTERISTIC_UUID = 0xA006;
00032     const static uint16_t ZERO_MOTION_DURATION_CHARACTERISTIC_UUID = 0xA007;
00033 
00034     ButtonService(BLE &_ble, float buttonPressedInitial, float interruptInitial, float gyroInitial, uint8_t motionThresholdInitial, uint8_t motionDurationInitial, uint8_t zeroMotionThresholdInitial, uint8_t zeroMotionDurationInitial) :
00035         ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00036                    interruptState(INTERRUPT_STATE_CHARACTERISTIC_UUID, &interruptInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00037                    gyroState(GYRO_STATE_CHARACTERISTIC_UUID, &gyroInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00038                    motionThreshold(MOTION_THRESHOLD_CHARACTERISTIC_UUID, &motionThresholdInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00039                    motionDuration(MOTION_DURATION_CHARACTERISTIC_UUID, &motionDurationInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00040                    zeroMotionThreshold(ZERO_MOTION_THRESHOLD_CHARACTERISTIC_UUID, &zeroMotionThresholdInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00041                    zeroMotionDuration(ZERO_MOTION_DURATION_CHARACTERISTIC_UUID, &zeroMotionDurationInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
00042     {
00043         GattCharacteristic *charTable[] = {&buttonState,&interruptState, &gyroState, &motionThreshold, &motionDuration};
00044         GattService         buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
00045         ble.gattServer().addService(buttonService);
00046     }
00047 
00048     void updateButtonState(float newState) {
00049         
00050         ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
00051     }
00052     
00053     void updateInterruptState(float newState) {
00054         ble.gattServer().write(interruptState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
00055         }
00056 
00057 void updateGyroState(float newState) {
00058         ble.gattServer().write(gyroState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
00059         }
00060 
00061 private:
00062     BLE                              &ble;
00063     ReadOnlyGattCharacteristic<float>  buttonState;
00064     ReadOnlyGattCharacteristic<float>  interruptState;
00065     ReadOnlyGattCharacteristic<float>  gyroState;
00066     WriteOnlyGattCharacteristic<uint8_t>  motionThreshold;
00067     WriteOnlyGattCharacteristic<uint8_t>  motionDuration;
00068     
00069     WriteOnlyGattCharacteristic<uint8_t>  zeroMotionThreshold;
00070     WriteOnlyGattCharacteristic<uint8_t>  zeroMotionDuration;
00071 };
00072 
00073 #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */