Send notification to pi from ble nano using ButtonService

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_notifications by Zachary Newman

Committer:
nkosarek
Date:
Wed Apr 19 01:47:36 2017 +0000
Revision:
14:700ba072d1a0
Parent:
13:d4448d59ab69
Working code to send one byte via notification is commented out. Attempt to send 16 bytes is currently compiled.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 0:28f095301cb2 1 /* mbed Microcontroller Library
rgrover1 0:28f095301cb2 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 0:28f095301cb2 3 *
rgrover1 0:28f095301cb2 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 0:28f095301cb2 5 * you may not use this file except in compliance with the License.
rgrover1 0:28f095301cb2 6 * You may obtain a copy of the License at
rgrover1 0:28f095301cb2 7 *
rgrover1 0:28f095301cb2 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 0:28f095301cb2 9 *
rgrover1 0:28f095301cb2 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 0:28f095301cb2 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 0:28f095301cb2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 0:28f095301cb2 13 * See the License for the specific language governing permissions and
rgrover1 0:28f095301cb2 14 * limitations under the License.
rgrover1 0:28f095301cb2 15 */
rgrover1 0:28f095301cb2 16
rgrover1 0:28f095301cb2 17 #ifndef __BLE_BUTTON_SERVICE_H__
rgrover1 0:28f095301cb2 18 #define __BLE_BUTTON_SERVICE_H__
rgrover1 0:28f095301cb2 19
rgrover1 0:28f095301cb2 20 class ButtonService {
rgrover1 0:28f095301cb2 21 public:
rgrover1 0:28f095301cb2 22 const static uint16_t BUTTON_SERVICE_UUID = 0xA000;
rgrover1 1:7202df456146 23 const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA001;
rgrover1 0:28f095301cb2 24
rgrover1 6:18d8750f39ee 25 ButtonService(BLE &_ble, bool buttonPressedInitial) :
rgrover1 0:28f095301cb2 26 ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
rgrover1 0:28f095301cb2 27 {
rgrover1 0:28f095301cb2 28 GattCharacteristic *charTable[] = {&buttonState};
rgrover1 0:28f095301cb2 29 GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
rgrover1 6:18d8750f39ee 30 ble.gattServer().addService(buttonService);
rgrover1 0:28f095301cb2 31 }
rgrover1 0:28f095301cb2 32
nkosarek 14:700ba072d1a0 33 //void updateButtonState(uint8_t newState) {
nkosarek 14:700ba072d1a0 34 void updateButtonState(uint8_t *newState) {
nkosarek 14:700ba072d1a0 35 //ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(uint8_t));
nkosarek 14:700ba072d1a0 36 ble.gattServer().write(buttonState.getValueHandle(), newState, sizeof(uint8_t)*16);
rgrover1 0:28f095301cb2 37 }
rgrover1 0:28f095301cb2 38
rgrover1 0:28f095301cb2 39 private:
rgrover1 6:18d8750f39ee 40 BLE &ble;
rgrover1 0:28f095301cb2 41 ReadOnlyGattCharacteristic<bool> buttonState;
rgrover1 0:28f095301cb2 42 };
rgrover1 0:28f095301cb2 43
rgrover1 0:28f095301cb2 44 #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */