my ble test

Dependencies:   BLE_API mbed nRF51822

Committer:
hu_xgbn
Date:
Sat Sep 24 23:02:03 2016 +0000
Revision:
0:1d3fde478296
first setup;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hu_xgbn 0:1d3fde478296 1 /* mbed Microcontroller Library
hu_xgbn 0:1d3fde478296 2 * Copyright (c) 2006-2013 ARM Limited
hu_xgbn 0:1d3fde478296 3 *
hu_xgbn 0:1d3fde478296 4 * Licensed under the Apache License, Version 2.0 (the "License");
hu_xgbn 0:1d3fde478296 5 * you may not use this file except in compliance with the License.
hu_xgbn 0:1d3fde478296 6 * You may obtain a copy of the License at
hu_xgbn 0:1d3fde478296 7 *
hu_xgbn 0:1d3fde478296 8 * http://www.apache.org/licenses/LICENSE-2.0
hu_xgbn 0:1d3fde478296 9 *
hu_xgbn 0:1d3fde478296 10 * Unless required by applicable law or agreed to in writing, software
hu_xgbn 0:1d3fde478296 11 * distributed under the License is distributed on an "AS IS" BASIS,
hu_xgbn 0:1d3fde478296 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
hu_xgbn 0:1d3fde478296 13 * See the License for the specific language governing permissions and
hu_xgbn 0:1d3fde478296 14 * limitations under the License.
hu_xgbn 0:1d3fde478296 15 */
hu_xgbn 0:1d3fde478296 16
hu_xgbn 0:1d3fde478296 17 #ifndef __BLE_LED_SERVICE_H__
hu_xgbn 0:1d3fde478296 18 #define __BLE_LED_SERVICE_H__
hu_xgbn 0:1d3fde478296 19
hu_xgbn 0:1d3fde478296 20 class LEDService {
hu_xgbn 0:1d3fde478296 21 public:
hu_xgbn 0:1d3fde478296 22 const static uint16_t LED_SERVICE_UUID = 0xA000;
hu_xgbn 0:1d3fde478296 23 const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001;
hu_xgbn 0:1d3fde478296 24
hu_xgbn 0:1d3fde478296 25 LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) :
hu_xgbn 0:1d3fde478296 26 ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic)
hu_xgbn 0:1d3fde478296 27 {
hu_xgbn 0:1d3fde478296 28 GattCharacteristic *charTable[] = {&ledState};
hu_xgbn 0:1d3fde478296 29 GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
hu_xgbn 0:1d3fde478296 30 ble.addService(ledService);
hu_xgbn 0:1d3fde478296 31 }
hu_xgbn 0:1d3fde478296 32
hu_xgbn 0:1d3fde478296 33 GattAttribute::Handle_t getValueHandle() const {
hu_xgbn 0:1d3fde478296 34 return ledState.getValueHandle();
hu_xgbn 0:1d3fde478296 35 }
hu_xgbn 0:1d3fde478296 36
hu_xgbn 0:1d3fde478296 37 private:
hu_xgbn 0:1d3fde478296 38 BLEDevice &ble;
hu_xgbn 0:1d3fde478296 39 ReadWriteGattCharacteristic<bool> ledState;
hu_xgbn 0:1d3fde478296 40 };
hu_xgbn 0:1d3fde478296 41
hu_xgbn 0:1d3fde478296 42 #endif /* #ifndef __BLE_LED_SERVICE_H__ */