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:
Wed Aug 20 09:49:41 2014 +0000
Parent:
0:8d7583961274
Child:
2:e400fd4f501b
Commit message:
Initial version - fixed threshold, 10ms sampling, samples characteristic is a 20 byte array

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Aug 11 11:17:56 2014 +0000
+++ b/main.cpp	Wed Aug 20 09:49:41 2014 +0000
@@ -1,17 +1,8 @@
 /**
- * Copyright 2014 Nordic Semiconductor
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
+Scoring Device - for generic game scoring
+Using Puck BLE MBED library from Nordic
+Copyright (C) Nodule.io 2014
+
  */
 
 #define LOG_LEVEL_INFO
@@ -19,26 +10,70 @@
 
 Puck* puck = &Puck::getPuck();
 
-// Sample Gatt characteristic and service UUIDs
-const UUID SAMPLE_GATT_SERVICE = stringToUUID("bftj sample     ");
-const UUID SAMPLE_GATT_CHARACTERISTIC = stringToUUID("bftj sample char");
+// Gatt characteristic and service UUIDs
+const UUID SCORING_GATT_SERVICE =           stringToUUID("nodule.scoring  ");
+const UUID SAMPLES_GATT_CHARACTERISTIC =    stringToUUID("nodule.samples  ");
+
+const int SAMPLES_LEN = 20;
+uint8_t SAMPLES_BUF[SAMPLES_LEN];
+const int SAMPLE_THRESHOLD = 800;
+
+// Setup ADC
+AnalogIn ain(P0_1);
 
-int main(void) {
-    // Add the Gatt characteristic
-    int characteristicValueLength = 1;
+// Timer to avoid repeat sampling
+Timer antiRepeatTimer;
+int lastSampleTime = 0;
+const int MIN_MS_BETWEEN_SAMPLES = 2000;
+
+int main(void) 
+{
+    
+    // Set baud rate
+    logger.baud(115200);
+    
+    // Add the Gatt characteristic for samples
     puck->addCharacteristic(
-            SAMPLE_GATT_SERVICE,
-            SAMPLE_GATT_CHARACTERISTIC,
-            characteristicValueLength,
+            SCORING_GATT_SERVICE,
+            SAMPLES_GATT_CHARACTERISTIC,
+            SAMPLES_LEN,
             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
 
     // Initialize the puck
-    puck->init(0xFEED);
+    puck->init(0xCD01);
+    
+    // Start timer
+    antiRepeatTimer.start();
 
-    // Set the initial value of the characteristic
-    uint8_t new_value = 42;
-    puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, characteristicValueLength);
-
-    // Let the puck do it's thing
-    while(puck->drive());
-}
\ No newline at end of file
+    // Wait for something to be found
+    while(puck->drive())
+    {
+        int curTimerVal = antiRepeatTimer.read_ms();
+        if ((lastSampleTime < curTimerVal) || (curTimerVal - lastSampleTime > MIN_MS_BETWEEN_SAMPLES))
+        {
+            // Check threshold
+            unsigned short val = ain.read_u16();
+            if(val > SAMPLE_THRESHOLD)
+            {
+                for (int i = 0; i < SAMPLES_LEN; i++) 
+                {
+                    SAMPLES_BUF[i] = ain.read_u16() - 760;
+                    wait_ms(10);
+                }
+                    
+                // Set the value of the characteristic
+                puck->updateCharacteristicValue(SAMPLES_GATT_CHARACTERISTIC, SAMPLES_BUF, SAMPLES_LEN);
+                
+                // Display readings
+                for (int j = 0; j < SAMPLES_LEN; j++)
+                {
+                    LOG_INFO("%d ", SAMPLES_BUF[j]);
+                }
+                LOG_INFO("\n");
+                
+                // Set timer to disallow repeated readings
+                lastSampleTime = curTimerVal;
+            }
+        }                
+    }
+}
--- a/mbed.bld	Mon Aug 11 11:17:56 2014 +0000
+++ b/mbed.bld	Wed Aug 20 09:49:41 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file