Service and app to control Relay over BLE.

Dependencies:   BLE_API mbed nRF51822

Committer:
abhishekkumardwivedi
Date:
Mon Mar 23 19:47:19 2015 +0000
Revision:
0:ab978b3b579a
Service and app to control Relay remotely over BLE.

Who changed what in which revision?

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