Kod new
Dependencies: BLE_API MMA8452Q mbed nRF51822
Service.h@0:6bd1a61571d0, 2016-04-07 (annotated)
- Committer:
- Radoj
- Date:
- Thu Apr 07 16:44:08 2016 +0000
- Revision:
- 0:6bd1a61571d0
- Child:
- 2:e78a5ce9f1d7
code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Radoj | 0:6bd1a61571d0 | 1 | /* mbed Microcontroller Library |
Radoj | 0:6bd1a61571d0 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Radoj | 0:6bd1a61571d0 | 3 | * |
Radoj | 0:6bd1a61571d0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Radoj | 0:6bd1a61571d0 | 5 | * you may not use this file except in compliance with the License. |
Radoj | 0:6bd1a61571d0 | 6 | * You may obtain a copy of the License at |
Radoj | 0:6bd1a61571d0 | 7 | * |
Radoj | 0:6bd1a61571d0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Radoj | 0:6bd1a61571d0 | 9 | * |
Radoj | 0:6bd1a61571d0 | 10 | * Unless required by applicable law or agreed to in writing, software |
Radoj | 0:6bd1a61571d0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Radoj | 0:6bd1a61571d0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Radoj | 0:6bd1a61571d0 | 13 | * See the License for the specific language governing permissions and |
Radoj | 0:6bd1a61571d0 | 14 | * limitations under the License. |
Radoj | 0:6bd1a61571d0 | 15 | */ |
Radoj | 0:6bd1a61571d0 | 16 | |
Radoj | 0:6bd1a61571d0 | 17 | #ifndef __BLE_SERVICE_H__ |
Radoj | 0:6bd1a61571d0 | 18 | #define __BLE_SERVICE_H__ |
Radoj | 0:6bd1a61571d0 | 19 | |
Radoj | 0:6bd1a61571d0 | 20 | class Service { |
Radoj | 0:6bd1a61571d0 | 21 | public: |
Radoj | 0:6bd1a61571d0 | 22 | const static uint16_t SERVICE_UUID = 0x0010; |
Radoj | 0:6bd1a61571d0 | 23 | const static uint16_t X_CHARACTERISTIC_UUID = 0x0011; |
Radoj | 0:6bd1a61571d0 | 24 | const static uint16_t Y_CHARACTERISTIC_UUID = 0x0012; |
Radoj | 0:6bd1a61571d0 | 25 | const static uint16_t Z_CHARACTERISTIC_UUID = 0x0013; |
Radoj | 0:6bd1a61571d0 | 26 | const static uint16_t ALL_CHARACTERISTIC_UUID = 0x0014; |
Radoj | 0:6bd1a61571d0 | 27 | |
Radoj | 0:6bd1a61571d0 | 28 | Service(BLE &_ble) : |
Radoj | 0:6bd1a61571d0 | 29 | ble(_ble), xState(X_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),yState(Y_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),zState(Z_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),allState(ALL_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
Radoj | 0:6bd1a61571d0 | 30 | { |
Radoj | 0:6bd1a61571d0 | 31 | GattCharacteristic *charTable[] = {&xState,&yState, &zState, &allState}; |
Radoj | 0:6bd1a61571d0 | 32 | GattService Service(Service::SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
Radoj | 0:6bd1a61571d0 | 33 | ble.gattServer().addService(Service); |
Radoj | 0:6bd1a61571d0 | 34 | } |
Radoj | 0:6bd1a61571d0 | 35 | |
Radoj | 0:6bd1a61571d0 | 36 | void updateXState(float newState) { |
Radoj | 0:6bd1a61571d0 | 37 | printf("\n%f\r\n",newState); |
Radoj | 0:6bd1a61571d0 | 38 | ble.gattServer().write(xState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
Radoj | 0:6bd1a61571d0 | 39 | } |
Radoj | 0:6bd1a61571d0 | 40 | |
Radoj | 0:6bd1a61571d0 | 41 | void updateYState(float newState) { |
Radoj | 0:6bd1a61571d0 | 42 | ble.gattServer().write(yState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
Radoj | 0:6bd1a61571d0 | 43 | } |
Radoj | 0:6bd1a61571d0 | 44 | |
Radoj | 0:6bd1a61571d0 | 45 | void updateZState(float newState) { |
Radoj | 0:6bd1a61571d0 | 46 | ble.gattServer().write(zState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
Radoj | 0:6bd1a61571d0 | 47 | } |
Radoj | 0:6bd1a61571d0 | 48 | |
Radoj | 0:6bd1a61571d0 | 49 | void updateALLState(float newState) { |
Radoj | 0:6bd1a61571d0 | 50 | ble.gattServer().write(allState.getValueHandle(), (uint8_t *)&newState, sizeof(float)); |
Radoj | 0:6bd1a61571d0 | 51 | } |
Radoj | 0:6bd1a61571d0 | 52 | |
Radoj | 0:6bd1a61571d0 | 53 | private: |
Radoj | 0:6bd1a61571d0 | 54 | BLE &ble; |
Radoj | 0:6bd1a61571d0 | 55 | ReadOnlyGattCharacteristic<float> xState; |
Radoj | 0:6bd1a61571d0 | 56 | ReadOnlyGattCharacteristic<float> yState; |
Radoj | 0:6bd1a61571d0 | 57 | ReadOnlyGattCharacteristic<float> zState; |
Radoj | 0:6bd1a61571d0 | 58 | ReadOnlyGattCharacteristic<float> allState; |
Radoj | 0:6bd1a61571d0 | 59 | }; |
Radoj | 0:6bd1a61571d0 | 60 | |
Radoj | 0:6bd1a61571d0 | 61 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |