se
Dependencies: SDFileSystem circular_buffer MPU6050 SoftSerial
source/ButtonService.h@6:75ed671f455e, 2018-11-22 (annotated)
- Committer:
- suads
- Date:
- Thu Nov 22 17:50:31 2018 +0000
- Revision:
- 6:75ed671f455e
- Parent:
- 4:147bbe6f9626
seismo;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OsmanKameric | 0:a4de55cab4e2 | 1 | /* mbed Microcontroller Library |
OsmanKameric | 0:a4de55cab4e2 | 2 | * Copyright (c) 2006-2013 ARM Limited |
OsmanKameric | 0:a4de55cab4e2 | 3 | * |
OsmanKameric | 0:a4de55cab4e2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
OsmanKameric | 0:a4de55cab4e2 | 5 | * you may not use this file except in compliance with the License. |
OsmanKameric | 0:a4de55cab4e2 | 6 | * You may obtain a copy of the License at |
OsmanKameric | 0:a4de55cab4e2 | 7 | * |
OsmanKameric | 0:a4de55cab4e2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
OsmanKameric | 0:a4de55cab4e2 | 9 | * |
OsmanKameric | 0:a4de55cab4e2 | 10 | * Unless required by applicable law or agreed to in writing, software |
OsmanKameric | 0:a4de55cab4e2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
OsmanKameric | 0:a4de55cab4e2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
OsmanKameric | 0:a4de55cab4e2 | 13 | * See the License for the specific language governing permissions and |
OsmanKameric | 0:a4de55cab4e2 | 14 | * limitations under the License. |
OsmanKameric | 0:a4de55cab4e2 | 15 | */ |
OsmanKameric | 0:a4de55cab4e2 | 16 | |
OsmanKameric | 0:a4de55cab4e2 | 17 | #ifndef __BLE_BUTTON_SERVICE_H__ |
OsmanKameric | 0:a4de55cab4e2 | 18 | #define __BLE_BUTTON_SERVICE_H__ |
OsmanKameric | 0:a4de55cab4e2 | 19 | |
OsmanKameric | 0:a4de55cab4e2 | 20 | class ButtonService { |
OsmanKameric | 0:a4de55cab4e2 | 21 | public: |
OsmanKameric | 0:a4de55cab4e2 | 22 | const static uint16_t BUTTON_SERVICE_UUID = 0xA000; |
OsmanKameric | 0:a4de55cab4e2 | 23 | const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA001; |
OsmanKameric | 3:b2087af18efe | 24 | const static uint16_t INTERRUPT_STATE_CHARACTERISTIC_UUID = 0xA002; |
OsmanKameric | 4:147bbe6f9626 | 25 | const static uint16_t GYRO_STATE_CHARACTERISTIC_UUID = 0xA003; |
OsmanKameric | 4:147bbe6f9626 | 26 | |
OsmanKameric | 4:147bbe6f9626 | 27 | |
OsmanKameric | 4:147bbe6f9626 | 28 | const static uint16_t MOTION_THRESHOLD_CHARACTERISTIC_UUID = 0xA004; |
OsmanKameric | 4:147bbe6f9626 | 29 | const static uint16_t MOTION_DURATION_CHARACTERISTIC_UUID = 0xA005; |
OsmanKameric | 4:147bbe6f9626 | 30 | |
OsmanKameric | 4:147bbe6f9626 | 31 | const static uint16_t ZERO_MOTION_THRESHOLD_CHARACTERISTIC_UUID = 0xA006; |
OsmanKameric | 4:147bbe6f9626 | 32 | const static uint16_t ZERO_MOTION_DURATION_CHARACTERISTIC_UUID = 0xA007; |
OsmanKameric | 0:a4de55cab4e2 | 33 | |
OsmanKameric | 4:147bbe6f9626 | 34 | ButtonService(BLE &_ble, float buttonPressedInitial, float interruptInitial, float gyroInitial, uint8_t motionThresholdInitial, uint8_t motionDurationInitial, uint8_t zeroMotionThresholdInitial, uint8_t zeroMotionDurationInitial) : |
OsmanKameric | 3:b2087af18efe | 35 | ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
OsmanKameric | 4:147bbe6f9626 | 36 | interruptState(INTERRUPT_STATE_CHARACTERISTIC_UUID, &interruptInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
OsmanKameric | 4:147bbe6f9626 | 37 | gyroState(GYRO_STATE_CHARACTERISTIC_UUID, &gyroInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
OsmanKameric | 4:147bbe6f9626 | 38 | motionThreshold(MOTION_THRESHOLD_CHARACTERISTIC_UUID, &motionThresholdInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
OsmanKameric | 4:147bbe6f9626 | 39 | motionDuration(MOTION_DURATION_CHARACTERISTIC_UUID, &motionDurationInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
OsmanKameric | 4:147bbe6f9626 | 40 | zeroMotionThreshold(ZERO_MOTION_THRESHOLD_CHARACTERISTIC_UUID, &zeroMotionThresholdInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
OsmanKameric | 4:147bbe6f9626 | 41 | zeroMotionDuration(ZERO_MOTION_DURATION_CHARACTERISTIC_UUID, &zeroMotionDurationInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
OsmanKameric | 0:a4de55cab4e2 | 42 | { |
OsmanKameric | 4:147bbe6f9626 | 43 | GattCharacteristic *charTable[] = {&buttonState,&interruptState, &gyroState, &motionThreshold, &motionDuration}; |
OsmanKameric | 0:a4de55cab4e2 | 44 | GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
OsmanKameric | 0:a4de55cab4e2 | 45 | ble.gattServer().addService(buttonService); |
OsmanKameric | 0:a4de55cab4e2 | 46 | } |
OsmanKameric | 0:a4de55cab4e2 | 47 | |
OsmanKameric | 0:a4de55cab4e2 | 48 | void updateButtonState(float newState) { |
OsmanKameric | 0:a4de55cab4e2 | 49 | |
OsmanKameric | 0:a4de55cab4e2 | 50 | ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
OsmanKameric | 0:a4de55cab4e2 | 51 | } |
OsmanKameric | 3:b2087af18efe | 52 | |
OsmanKameric | 3:b2087af18efe | 53 | void updateInterruptState(float newState) { |
OsmanKameric | 3:b2087af18efe | 54 | ble.gattServer().write(interruptState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
OsmanKameric | 3:b2087af18efe | 55 | } |
OsmanKameric | 0:a4de55cab4e2 | 56 | |
OsmanKameric | 4:147bbe6f9626 | 57 | void updateGyroState(float newState) { |
OsmanKameric | 4:147bbe6f9626 | 58 | ble.gattServer().write(gyroState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
OsmanKameric | 4:147bbe6f9626 | 59 | } |
OsmanKameric | 4:147bbe6f9626 | 60 | |
OsmanKameric | 0:a4de55cab4e2 | 61 | private: |
OsmanKameric | 0:a4de55cab4e2 | 62 | BLE &ble; |
OsmanKameric | 0:a4de55cab4e2 | 63 | ReadOnlyGattCharacteristic<float> buttonState; |
OsmanKameric | 3:b2087af18efe | 64 | ReadOnlyGattCharacteristic<float> interruptState; |
OsmanKameric | 4:147bbe6f9626 | 65 | ReadOnlyGattCharacteristic<float> gyroState; |
OsmanKameric | 4:147bbe6f9626 | 66 | WriteOnlyGattCharacteristic<uint8_t> motionThreshold; |
OsmanKameric | 4:147bbe6f9626 | 67 | WriteOnlyGattCharacteristic<uint8_t> motionDuration; |
OsmanKameric | 4:147bbe6f9626 | 68 | |
OsmanKameric | 4:147bbe6f9626 | 69 | WriteOnlyGattCharacteristic<uint8_t> zeroMotionThreshold; |
OsmanKameric | 4:147bbe6f9626 | 70 | WriteOnlyGattCharacteristic<uint8_t> zeroMotionDuration; |
OsmanKameric | 0:a4de55cab4e2 | 71 | }; |
OsmanKameric | 0:a4de55cab4e2 | 72 | |
OsmanKameric | 0:a4de55cab4e2 | 73 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |