Auto updating alarm watch - accepts alarm settings from a BLE device like a Raspberry Pi and buzzes at the appropriate time - also displays binary time
Dependencies: BLE_API mbed-src nRF51822 nrf51_rtc
ButtonService.h@3:a4b8d67de1b1, 2015-07-27 (annotated)
- Committer:
- Bobty
- Date:
- Mon Jul 27 15:25:59 2015 +0000
- Revision:
- 3:a4b8d67de1b1
- Parent:
- 2:9090120e2656
Basic functionality of setting the time is working but no RTC is enabled
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bobty | 2:9090120e2656 | 1 | /* mbed Microcontroller Library |
Bobty | 2:9090120e2656 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Bobty | 2:9090120e2656 | 3 | * |
Bobty | 2:9090120e2656 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Bobty | 2:9090120e2656 | 5 | * you may not use this file except in compliance with the License. |
Bobty | 2:9090120e2656 | 6 | * You may obtain a copy of the License at |
Bobty | 2:9090120e2656 | 7 | * |
Bobty | 2:9090120e2656 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Bobty | 2:9090120e2656 | 9 | * |
Bobty | 2:9090120e2656 | 10 | * Unless required by applicable law or agreed to in writing, software |
Bobty | 2:9090120e2656 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Bobty | 2:9090120e2656 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Bobty | 2:9090120e2656 | 13 | * See the License for the specific language governing permissions and |
Bobty | 2:9090120e2656 | 14 | * limitations under the License. |
Bobty | 2:9090120e2656 | 15 | */ |
Bobty | 2:9090120e2656 | 16 | |
Bobty | 2:9090120e2656 | 17 | #ifndef __BLE_BUTTON_SERVICE_H__ |
Bobty | 2:9090120e2656 | 18 | #define __BLE_BUTTON_SERVICE_H__ |
Bobty | 2:9090120e2656 | 19 | |
Bobty | 2:9090120e2656 | 20 | class ButtonService { |
Bobty | 2:9090120e2656 | 21 | public: |
Bobty | 2:9090120e2656 | 22 | const static uint16_t BUTTON_SERVICE_UUID = 0xA000; |
Bobty | 2:9090120e2656 | 23 | const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA001; |
Bobty | 2:9090120e2656 | 24 | |
Bobty | 2:9090120e2656 | 25 | ButtonService(BLE &_ble, bool buttonPressedInitial) : |
Bobty | 2:9090120e2656 | 26 | ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
Bobty | 2:9090120e2656 | 27 | { |
Bobty | 2:9090120e2656 | 28 | GattCharacteristic *charTable[] = {&buttonState}; |
Bobty | 2:9090120e2656 | 29 | GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
Bobty | 2:9090120e2656 | 30 | ble.gattServer().addService(buttonService); |
Bobty | 2:9090120e2656 | 31 | } |
Bobty | 2:9090120e2656 | 32 | |
Bobty | 2:9090120e2656 | 33 | void updateButtonState(bool newState) { |
Bobty | 2:9090120e2656 | 34 | ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(bool)); |
Bobty | 2:9090120e2656 | 35 | } |
Bobty | 2:9090120e2656 | 36 | |
Bobty | 3:a4b8d67de1b1 | 37 | GattAttribute::Handle_t getValueHandle() |
Bobty | 3:a4b8d67de1b1 | 38 | { |
Bobty | 3:a4b8d67de1b1 | 39 | return buttonState.getValueHandle(); |
Bobty | 3:a4b8d67de1b1 | 40 | } |
Bobty | 3:a4b8d67de1b1 | 41 | |
Bobty | 2:9090120e2656 | 42 | private: |
Bobty | 2:9090120e2656 | 43 | BLE &ble; |
Bobty | 2:9090120e2656 | 44 | ReadOnlyGattCharacteristic<bool> buttonState; |
Bobty | 2:9090120e2656 | 45 | }; |
Bobty | 2:9090120e2656 | 46 | |
Bobty | 2:9090120e2656 | 47 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |