BLE Feedbakc Service

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Committer:
ReneM92
Date:
Fri Jun 12 09:07:19 2015 +0000
Revision:
65:5a78321ef3d3
Parent:
64:4ced7a1586b0
Kicking MrFeedback out

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:87a7fc231fae 1 /* mbed Microcontroller Library
ktownsend 0:87a7fc231fae 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 0:87a7fc231fae 3 *
ktownsend 0:87a7fc231fae 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 0:87a7fc231fae 5 * you may not use this file except in compliance with the License.
ktownsend 0:87a7fc231fae 6 * You may obtain a copy of the License at
ktownsend 0:87a7fc231fae 7 *
ktownsend 0:87a7fc231fae 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 0:87a7fc231fae 9 *
ktownsend 0:87a7fc231fae 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 0:87a7fc231fae 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 0:87a7fc231fae 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 0:87a7fc231fae 13 * See the License for the specific language governing permissions and
ktownsend 0:87a7fc231fae 14 * limitations under the License.
ktownsend 0:87a7fc231fae 15 */
ktownsend 0:87a7fc231fae 16
ktownsend 0:87a7fc231fae 17 #include "mbed.h"
Rohit Grover 10:2436164b692e 18 #include "BLEDevice.h"
ReneM92 63:3c5ca3832415 19 #include "ble_feedback.h"
ReneM92 63:3c5ca3832415 20
ktownsend 0:87a7fc231fae 21
rgrover1 52:6bbf62943106 22 /* Enable the following if you need to throttle the connection interval. This has
rgrover1 52:6bbf62943106 23 * the effect of reducing energy consumption after a connection is made;
rgrover1 52:6bbf62943106 24 * particularly for applications where the central may want a fast connection
rgrover1 52:6bbf62943106 25 * interval.*/
rgrover1 52:6bbf62943106 26 #define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0
rgrover1 52:6bbf62943106 27
ReneM92 64:4ced7a1586b0 28 //BLEDevice ble;
rgrover1 47:430545f41113 29 DigitalOut led1(LED1);
ReneM92 63:3c5ca3832415 30 Serial pc(USBTX, USBRX); // tx, rx
ktownsend 0:87a7fc231fae 31
rgrover1 39:6390604f904c 32 static volatile bool triggerSensorPolling = false;
Rohit Grover 36:ea2a1b4f51c1 33
ReneM92 64:4ced7a1586b0 34 /*void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
ktownsend 0:87a7fc231fae 35 {
rgrover1 46:ee7c55907f36 36 ble.startAdvertising(); // restart advertising
ReneM92 64:4ced7a1586b0 37 }*/
ReneM92 64:4ced7a1586b0 38 /*
Rohit Grover 11:1d9aafee4984 39 void periodicCallback(void)
Rohit Grover 11:1d9aafee4984 40 {
rgrover1 47:430545f41113 41 led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
rgrover1 47:430545f41113 42
rgrover1 39:6390604f904c 43 /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
rgrover1 39:6390604f904c 44 * heavy-weight sensor polling from the main thread. */
ReneM92 64:4ced7a1586b0 45 //triggerSensorPolling = true;
ReneM92 64:4ced7a1586b0 46 //}
Rohit Grover 11:1d9aafee4984 47
ktownsend 0:87a7fc231fae 48 int main(void)
ktownsend 0:87a7fc231fae 49 {
ReneM92 64:4ced7a1586b0 50 //led1 = 1;
ReneM92 64:4ced7a1586b0 51 //Ticker ticker;
ReneM92 64:4ced7a1586b0 52 //ticker.attach(periodicCallback, 1); // blink LED every second
ktownsend 0:87a7fc231fae 53
ReneM92 64:4ced7a1586b0 54 //ble.onDisconnection(disconnectionCallback);
ktownsend 0:87a7fc231fae 55
rgrover1 45:98c5a34b07a4 56 /* Setup primary service. */
ReneM92 65:5a78321ef3d3 57 uint8_t battery = 100;
ReneM92 65:5a78321ef3d3 58 FeedbackService* FService = new FeedbackService();
Rohit Grover 3:24e2b056d229 59
mbedAustin 55:3a7d497a3e03 60 // infinite loop
ReneM92 65:5a78321ef3d3 61 while (1) {
ReneM92 64:4ced7a1586b0 62 // check for trigger from periodicCallback()
ReneM92 65:5a78321ef3d3 63 if ( FService->isConnected() && FService->newValue()) {
Rohit Grover 36:ea2a1b4f51c1 64 triggerSensorPolling = false;
Rohit Grover 36:ea2a1b4f51c1 65
ReneM92 63:3c5ca3832415 66 battery--;
mbedAustin 55:3a7d497a3e03 67
ReneM92 63:3c5ca3832415 68 if (battery == 0) {
ReneM92 63:3c5ca3832415 69 battery = 100;
Rohit Grover 36:ea2a1b4f51c1 70 }
ReneM92 65:5a78321ef3d3 71 pc.printf("\n\r geschreven %d \n\r", FService->getTest());
ReneM92 65:5a78321ef3d3 72 FService->updateBatteryValue(battery);
Rohit Grover 36:ea2a1b4f51c1 73 } else {
ReneM92 65:5a78321ef3d3 74 //ble.waitForEvent(); // low power wait for event
Rohit Grover 36:ea2a1b4f51c1 75 }
ReneM92 65:5a78321ef3d3 76 }
ktownsend 0:87a7fc231fae 77 }