
To get and handle event on getting motion event from PIR
Dependencies: BLE_API mbed nRF51822
PIRService.h@0:c165b9e652d8, 2015-05-20 (annotated)
- Committer:
- abhishekkumardwivedi
- Date:
- Wed May 20 12:06:18 2015 +0000
- Revision:
- 0:c165b9e652d8
To control device on getting motion event from PIR.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abhishekkumardwivedi | 0:c165b9e652d8 | 1 | /* mbed Microcontroller Library |
abhishekkumardwivedi | 0:c165b9e652d8 | 2 | * Copyright (c) 2006-2013 ARM Limited |
abhishekkumardwivedi | 0:c165b9e652d8 | 3 | * |
abhishekkumardwivedi | 0:c165b9e652d8 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
abhishekkumardwivedi | 0:c165b9e652d8 | 5 | * you may not use this file except in compliance with the License. |
abhishekkumardwivedi | 0:c165b9e652d8 | 6 | * You may obtain a copy of the License at |
abhishekkumardwivedi | 0:c165b9e652d8 | 7 | * |
abhishekkumardwivedi | 0:c165b9e652d8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
abhishekkumardwivedi | 0:c165b9e652d8 | 9 | * |
abhishekkumardwivedi | 0:c165b9e652d8 | 10 | * Unless required by applicable law or agreed to in writing, software |
abhishekkumardwivedi | 0:c165b9e652d8 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
abhishekkumardwivedi | 0:c165b9e652d8 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
abhishekkumardwivedi | 0:c165b9e652d8 | 13 | * See the License for the specific language governing permissions and |
abhishekkumardwivedi | 0:c165b9e652d8 | 14 | * limitations under the License. |
abhishekkumardwivedi | 0:c165b9e652d8 | 15 | */ |
abhishekkumardwivedi | 0:c165b9e652d8 | 16 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 17 | #ifndef __BLE_PIR_SERVICE_H__ |
abhishekkumardwivedi | 0:c165b9e652d8 | 18 | #define __BLE_PIR_SERVICE_H__ |
abhishekkumardwivedi | 0:c165b9e652d8 | 19 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 20 | class PIRService |
abhishekkumardwivedi | 0:c165b9e652d8 | 21 | { |
abhishekkumardwivedi | 0:c165b9e652d8 | 22 | public: |
abhishekkumardwivedi | 0:c165b9e652d8 | 23 | const static uint16_t PIR_SERVICE_UUID = 0xA000; |
abhishekkumardwivedi | 0:c165b9e652d8 | 24 | const static uint16_t PIR_STATE_CHARACTERISTIC_UUID = 0xA001; |
abhishekkumardwivedi | 0:c165b9e652d8 | 25 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 26 | PIRService(BLEDevice &_ble, bool initialValueForPIRCharacteristic) : |
abhishekkumardwivedi | 0:c165b9e652d8 | 27 | ble(_ble), pirStateCharacteristic(PIR_STATE_CHARACTERISTIC_UUID, &initialValueForPIRCharacteristic) { |
abhishekkumardwivedi | 0:c165b9e652d8 | 28 | GattCharacteristic *charTable[] = {&pirStateCharacteristic}; |
abhishekkumardwivedi | 0:c165b9e652d8 | 29 | GattService pirService(PIR_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
abhishekkumardwivedi | 0:c165b9e652d8 | 30 | ble.addService(pirService); |
abhishekkumardwivedi | 0:c165b9e652d8 | 31 | } |
abhishekkumardwivedi | 0:c165b9e652d8 | 32 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 33 | GattAttribute::Handle_t getValueHandle() const { |
abhishekkumardwivedi | 0:c165b9e652d8 | 34 | return pirStateCharacteristic.getValueHandle(); |
abhishekkumardwivedi | 0:c165b9e652d8 | 35 | } |
abhishekkumardwivedi | 0:c165b9e652d8 | 36 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 37 | void UpdateMotionStatus(bool status) { |
abhishekkumardwivedi | 0:c165b9e652d8 | 38 | ble.updateCharacteristicValue(pirStateCharacteristic.getValueHandle(), (uint8_t *)&status, sizeof(bool)); |
abhishekkumardwivedi | 0:c165b9e652d8 | 39 | } |
abhishekkumardwivedi | 0:c165b9e652d8 | 40 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 41 | private: |
abhishekkumardwivedi | 0:c165b9e652d8 | 42 | BLEDevice &ble; |
abhishekkumardwivedi | 0:c165b9e652d8 | 43 | ReadOnlyGattCharacteristic<bool> pirStateCharacteristic; |
abhishekkumardwivedi | 0:c165b9e652d8 | 44 | }; |
abhishekkumardwivedi | 0:c165b9e652d8 | 45 | |
abhishekkumardwivedi | 0:c165b9e652d8 | 46 | #endif /* #ifndef __BLE_PIR_SERVICE_H__ */ |