Using the MBED BLE library and Nordic Puck library this is a simple scoring application using Bluetooth LE. It monitors three analog inputs and triggers on reception of a pulse on any one recording data for a short period on all three. This is then published via BLE characteristics. It's a demonstrator for a new UI dev toolkit that is under development.

Dependencies:   Puck mbed

Fork of Example_Puck_BLE by Nordic Semiconductor

Files at this revision

API Documentation at this revision

Comitter:
Bobty
Date:
Sat Aug 23 20:44:36 2014 +0000
Parent:
6:81494b318e55
Child:
8:87a3708dca9c
Commit message:
Works now with Timeout instead of Ticker. But odd result is that when sample interval is 50ms get 30 puckDrive loops per sec but when reduced to 10ms get 117 loops - the two things should be independent!

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Aug 23 20:04:36 2014 +0000
+++ b/main.cpp	Sat Aug 23 20:44:36 2014 +0000
@@ -20,10 +20,10 @@
 const int NUM_SAMPLE_CHANNELS = 1;
 
 // Sample interval (uS)
-uint32_t sampleIntervalUs = 50000;
+uint32_t sampleIntervalUs = 10000;
 
 // Interrupt driven ticker to do the sampling
-Ticker sampleTicker;
+Timeout sampleTimeout;
 
 // Sample Channels
 SampleChannel sampleChannels[] =
@@ -39,12 +39,14 @@
 int lastSampleTime = 0;
 const int MIN_MS_BETWEEN_SAMPLES = 2000;
 
-// Function called in interrupt driven ticker to handle sampling
+// Function called in interrupt driven timeout to handle sampling
 static volatile int serviceCount = 0;
 void SampleService()
 {
     serviceCount++;
     
+    sampleTimeout.attach_us(&SampleService, sampleIntervalUs);
+
     return;
     
     // service all channel's state machines
@@ -160,12 +162,14 @@
     // Start timer
     intervalTimer.start();
     
-    // Start ticker to service the sampling
-    sampleTicker.attach_us(&SampleService, sampleIntervalUs);
+    // Start timeout to service the sampling
+    sampleTimeout.attach_us(&SampleService, sampleIntervalUs);
 
     // Wait for something to be found
     unsigned int lastPuckDriveTime = 0;
     unsigned int driveLoops = 0;
+    unsigned int lastDriveLoops = 0;
+    unsigned int lastServiceCount = 0;
     while(true)
     {
         // Service the puck
@@ -173,10 +177,14 @@
         driveLoops++;
         
         // Handle 1 second updates
-        if ((intervalTimer.read_ms() - lastPuckDriveTime >= 1000) || (intervalTimer.read_ms() < lastPuckDriveTime))
+        unsigned int nowTime = intervalTimer.read_ms();
+        if ((nowTime - lastPuckDriveTime >= 1000) || (nowTime < lastPuckDriveTime))
         {
+            unsigned int elapsed = nowTime - lastPuckDriveTime;
+            LOG_INFO("%u E%u C%u DC%u TC%u DTC%u L%u DL%u\n", nowTime, elapsed, serviceCount, serviceCount-lastServiceCount, nowTime/serviceCount, elapsed/(serviceCount-lastServiceCount), driveLoops, driveLoops-lastDriveLoops);
             lastPuckDriveTime = intervalTimer.read_ms();
-            LOG_INFO("%u T%u L%u\n", intervalTimer.read_ms(), serviceCount, driveLoops);
+            lastDriveLoops = driveLoops;
+            lastServiceCount = serviceCount;
         }
         
         continue;