Rene Miedema / Mbed 2 deprecated BLE_Feedback

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Committer:
ReneM92
Date:
Fri Jun 12 08:23:05 2015 +0000
Revision:
63:3c5ca3832415
Parent:
56:83623419d5e4
Child:
64:4ced7a1586b0
MrFeedback going 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
Rohit Grover 10:2436164b692e 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
rgrover1 41:9cef0129da5f 34 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
ktownsend 0:87a7fc231fae 35 {
rgrover1 46:ee7c55907f36 36 ble.startAdvertising(); // restart advertising
rgrover1 7:daab8ba5139e 37 }
Rohit Grover 3:24e2b056d229 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. */
rgrover1 39:6390604f904c 45 triggerSensorPolling = true;
Rohit Grover 11:1d9aafee4984 46 }
Rohit Grover 11:1d9aafee4984 47
ktownsend 0:87a7fc231fae 48 int main(void)
ktownsend 0:87a7fc231fae 49 {
rgrover1 47:430545f41113 50 led1 = 1;
Rohit Grover 11:1d9aafee4984 51 Ticker ticker;
mbedAustin 55:3a7d497a3e03 52 ticker.attach(periodicCallback, 1); // blink LED every second
ktownsend 0:87a7fc231fae 53
rgrover1 7:daab8ba5139e 54 ble.onDisconnection(disconnectionCallback);
ktownsend 0:87a7fc231fae 55
rgrover1 45:98c5a34b07a4 56 /* Setup primary service. */
ReneM92 63:3c5ca3832415 57 uint8_t battery = 100;
ReneM92 63:3c5ca3832415 58 FeedbackService FService(ble);
Rohit Grover 3:24e2b056d229 59
mbedAustin 55:3a7d497a3e03 60 // infinite loop
mbedAustin 55:3a7d497a3e03 61 while (1) {
mbedAustin 55:3a7d497a3e03 62 // check for trigger from periodicCallback()
rgrover1 50:477004d54431 63 if (triggerSensorPolling && ble.getGapState().connected) {
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 63:3c5ca3832415 71 pc.printf("\n\r geschreven %d \n\r", FService.getTest());
ReneM92 63:3c5ca3832415 72 FService.updateBatteryValue(battery);
Rohit Grover 36:ea2a1b4f51c1 73 } else {
mbedAustin 55:3a7d497a3e03 74 ble.waitForEvent(); // low power wait for event
Rohit Grover 36:ea2a1b4f51c1 75 }
ktownsend 0:87a7fc231fae 76 }
ktownsend 0:87a7fc231fae 77 }