vbfgh
Dependencies: BLE_API HCSR04 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_LED_Button_Nucleo by
ButtonService.h@14:c75f17f554c1, 2016-05-04 (annotated)
- Committer:
- vseyok
- Date:
- Wed May 04 16:17:49 2016 +0000
- Revision:
- 14:c75f17f554c1
- Parent:
- 11:5e43f35f64a8
it is not working(ultrasonic sensor)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
janjongboom | 11:5e43f35f64a8 | 1 | /* mbed Microcontroller Library |
janjongboom | 11:5e43f35f64a8 | 2 | * Copyright (c) 2006-2013 ARM Limited |
janjongboom | 11:5e43f35f64a8 | 3 | * |
janjongboom | 11:5e43f35f64a8 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
janjongboom | 11:5e43f35f64a8 | 5 | * you may not use this file except in compliance with the License. |
janjongboom | 11:5e43f35f64a8 | 6 | * You may obtain a copy of the License at |
janjongboom | 11:5e43f35f64a8 | 7 | * |
janjongboom | 11:5e43f35f64a8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
janjongboom | 11:5e43f35f64a8 | 9 | * |
janjongboom | 11:5e43f35f64a8 | 10 | * Unless required by applicable law or agreed to in writing, software |
janjongboom | 11:5e43f35f64a8 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
janjongboom | 11:5e43f35f64a8 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
janjongboom | 11:5e43f35f64a8 | 13 | * See the License for the specific language governing permissions and |
janjongboom | 11:5e43f35f64a8 | 14 | * limitations under the License. |
janjongboom | 11:5e43f35f64a8 | 15 | */ |
janjongboom | 11:5e43f35f64a8 | 16 | |
janjongboom | 11:5e43f35f64a8 | 17 | #ifndef __BLE_BUTTON_SERVICE_H__ |
janjongboom | 11:5e43f35f64a8 | 18 | #define __BLE_BUTTON_SERVICE_H__ |
janjongboom | 11:5e43f35f64a8 | 19 | |
janjongboom | 11:5e43f35f64a8 | 20 | class ButtonService { |
janjongboom | 11:5e43f35f64a8 | 21 | public: |
janjongboom | 11:5e43f35f64a8 | 22 | const static uint16_t BUTTON_SERVICE_UUID = 0xA010; |
janjongboom | 11:5e43f35f64a8 | 23 | const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA011; |
janjongboom | 11:5e43f35f64a8 | 24 | |
vseyok | 14:c75f17f554c1 | 25 | ButtonService(BLE &_ble, uint16_t buttonPressedInitial) : |
janjongboom | 11:5e43f35f64a8 | 26 | ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
janjongboom | 11:5e43f35f64a8 | 27 | { |
janjongboom | 11:5e43f35f64a8 | 28 | GattCharacteristic *charTable[] = {&buttonState}; |
janjongboom | 11:5e43f35f64a8 | 29 | GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
janjongboom | 11:5e43f35f64a8 | 30 | ble.gattServer().addService(buttonService); |
janjongboom | 11:5e43f35f64a8 | 31 | } |
janjongboom | 11:5e43f35f64a8 | 32 | |
vseyok | 14:c75f17f554c1 | 33 | void updateButtonState(uint16_t newState) { |
vseyok | 14:c75f17f554c1 | 34 | ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(uint16_t)); |
janjongboom | 11:5e43f35f64a8 | 35 | } |
janjongboom | 11:5e43f35f64a8 | 36 | |
janjongboom | 11:5e43f35f64a8 | 37 | private: |
janjongboom | 11:5e43f35f64a8 | 38 | BLE &ble; |
vseyok | 14:c75f17f554c1 | 39 | ReadOnlyGattCharacteristic<uint16_t> buttonState; |
janjongboom | 11:5e43f35f64a8 | 40 | }; |
janjongboom | 11:5e43f35f64a8 | 41 | |
janjongboom | 11:5e43f35f64a8 | 42 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |
janjongboom | 11:5e43f35f64a8 | 43 |