test uploading

Dependencies:   BLE_API mbed nRF51822

Committer:
ReneM92
Date:
Mon Jun 08 13:08:15 2015 +0000
Revision:
1:3a1494d478bd
Parent:
0:ac8f3df14a42
testing ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ReneM92 0:ac8f3df14a42 1 /* mbed Microcontroller Library
ReneM92 0:ac8f3df14a42 2 * Copyright (c) 2006-2013 ARM Limited
ReneM92 0:ac8f3df14a42 3 *
ReneM92 0:ac8f3df14a42 4 * Licensed under the Apache License, Version 2.0 (the "License");
ReneM92 0:ac8f3df14a42 5 * you may not use this file except in compliance with the License.
ReneM92 0:ac8f3df14a42 6 * You may obtain a copy of the License at
ReneM92 0:ac8f3df14a42 7 *
ReneM92 0:ac8f3df14a42 8 * http://www.apache.org/licenses/LICENSE-2.0
ReneM92 0:ac8f3df14a42 9 *
ReneM92 0:ac8f3df14a42 10 * Unless required by applicable law or agreed to in writing, software
ReneM92 0:ac8f3df14a42 11 * distributed under the License is distributed on an "AS IS" BASIS,
ReneM92 0:ac8f3df14a42 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ReneM92 0:ac8f3df14a42 13 * See the License for the specific language governing permissions and
ReneM92 0:ac8f3df14a42 14 * limitations under the License.
ReneM92 0:ac8f3df14a42 15 */
ReneM92 0:ac8f3df14a42 16
ReneM92 0:ac8f3df14a42 17 #include "mbed.h"
ReneM92 0:ac8f3df14a42 18 #include "BLEDevice.h"
ReneM92 0:ac8f3df14a42 19 #include "ble_meter.h"
ReneM92 0:ac8f3df14a42 20
ReneM92 0:ac8f3df14a42 21 /* Enable the following if you need to throttle the connection interval. This has
ReneM92 0:ac8f3df14a42 22 * the effect of reducing energy consumption after a connection is made;
ReneM92 0:ac8f3df14a42 23 * particularly for applications where the central may want a fast connection
ReneM92 0:ac8f3df14a42 24 * interval.*/
ReneM92 0:ac8f3df14a42 25 #define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 1
ReneM92 0:ac8f3df14a42 26
ReneM92 0:ac8f3df14a42 27 Serial pc(USBTX, USBRX); // tx, rx
ReneM92 0:ac8f3df14a42 28 BLEDevice ble;
ReneM92 0:ac8f3df14a42 29 DigitalOut led1(LED1);
ReneM92 0:ac8f3df14a42 30
ReneM92 0:ac8f3df14a42 31 static volatile bool triggerSensorPolling = false;
ReneM92 0:ac8f3df14a42 32
ReneM92 0:ac8f3df14a42 33 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
ReneM92 0:ac8f3df14a42 34 {
ReneM92 0:ac8f3df14a42 35 ble.startAdvertising(); // restart advertising
ReneM92 0:ac8f3df14a42 36 }
ReneM92 0:ac8f3df14a42 37
ReneM92 0:ac8f3df14a42 38 void periodicCallback()
ReneM92 0:ac8f3df14a42 39 {
ReneM92 0:ac8f3df14a42 40
ReneM92 0:ac8f3df14a42 41 led1 = !led1;
ReneM92 0:ac8f3df14a42 42
ReneM92 0:ac8f3df14a42 43 // kijken hoe snel ble is
ReneM92 0:ac8f3df14a42 44
ReneM92 0:ac8f3df14a42 45 triggerSensorPolling = true;
ReneM92 0:ac8f3df14a42 46 }
ReneM92 0:ac8f3df14a42 47
ReneM92 0:ac8f3df14a42 48 void batteryCallback(){
ReneM92 0:ac8f3df14a42 49
ReneM92 0:ac8f3df14a42 50 }
ReneM92 0:ac8f3df14a42 51 int main(void)
ReneM92 0:ac8f3df14a42 52 {
ReneM92 0:ac8f3df14a42 53 led1 = 1;
ReneM92 0:ac8f3df14a42 54 Ticker ticker;
ReneM92 0:ac8f3df14a42 55 ticker.attach(periodicCallback,1); // blink LED every second
ReneM92 0:ac8f3df14a42 56
ReneM92 0:ac8f3df14a42 57 ble.onDisconnection(disconnectionCallback);
ReneM92 0:ac8f3df14a42 58
ReneM92 0:ac8f3df14a42 59 /* Setup primary service. */
ReneM92 0:ac8f3df14a42 60 uint16_t hoek = 250;
ReneM92 0:ac8f3df14a42 61 uint16_t acc = 0;
ReneM92 0:ac8f3df14a42 62 uint16_t gyro = 300;
ReneM92 0:ac8f3df14a42 63 GonioService G_Service(ble, hoek,acc,gyro);
ReneM92 0:ac8f3df14a42 64
ReneM92 0:ac8f3df14a42 65 // infinite loop
ReneM92 0:ac8f3df14a42 66 while (1) {
ReneM92 0:ac8f3df14a42 67 // check for trigger from periodicCallback()
ReneM92 0:ac8f3df14a42 68 if (triggerSensorPolling && ble.getGapState().connected) {
ReneM92 0:ac8f3df14a42 69 triggerSensorPolling = false;
ReneM92 0:ac8f3df14a42 70
ReneM92 0:ac8f3df14a42 71 // Do blocking calls or whatever is necessary for sensor polling.
ReneM92 0:ac8f3df14a42 72 // In our case, we simply update the HRM measurement.
ReneM92 0:ac8f3df14a42 73 hoek++;
ReneM92 0:ac8f3df14a42 74 acc++;
ReneM92 0:ac8f3df14a42 75 gyro++;
ReneM92 0:ac8f3df14a42 76
ReneM92 0:ac8f3df14a42 77 // 100 <= HRM bps <=175
ReneM92 0:ac8f3df14a42 78 if (hoek == 350) {
ReneM92 0:ac8f3df14a42 79 hoek = 250;
ReneM92 0:ac8f3df14a42 80 acc = 0;
ReneM92 0:ac8f3df14a42 81 gyro = 300;
ReneM92 0:ac8f3df14a42 82 }
ReneM92 0:ac8f3df14a42 83
ReneM92 0:ac8f3df14a42 84 // update bps
ReneM92 0:ac8f3df14a42 85 //pc.printf("\n\r gelezen waarde: %d", G_Service.getWriteValue());
ReneM92 0:ac8f3df14a42 86 G_Service.updateGonio(hoek,acc,gyro); // deze testen in de periodic callback
ReneM92 0:ac8f3df14a42 87 } else {
ReneM92 0:ac8f3df14a42 88 ble.waitForEvent(); // low power wait for event
ReneM92 0:ac8f3df14a42 89 }
ReneM92 0:ac8f3df14a42 90 }
ReneM92 0:ac8f3df14a42 91 }