Self test boot program for testing icarus sensors

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_UARTConsole by Bluetooth Low Energy

Revision:
8:e9ae7a01d866
Parent:
7:438b55fe8576
Child:
9:ed3636e1873f
--- a/main.cpp	Mon Jan 26 13:57:26 2015 +0000
+++ b/main.cpp	Tue Jan 27 09:29:17 2015 +0000
@@ -23,60 +23,71 @@
 //Icarus libraries
 #include "RNGSensor.h"
 
-#define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
+#define DEBUG 1 /* Set this if you need debug messages on the console;
                                * it will have an impact on code-size and power consumption. */
-#define DEBUG_BUFFER 100
-#if NEED_CONSOLE_OUTPUT
-#define DEBUG(...)  do { if (uart) {snprintf(debugBuffer, DEBUG_BUFFER , __VA_ARGS__); uart->write(debugBuffer, strlen(debugBuffer));} } while (0)
+
+#if DEBUG
+#define LOG_BUFFER 100
+#define LOG(...)  do { if (uart) {snprintf(debugBuffer, LOG_BUFFER , __VA_ARGS__); uart->write(debugBuffer, strlen(debugBuffer));} } while (0)
 #else
-#define DEBUG(...) /* nothing */
-#endif /* #if NEED_CONSOLE_OUTPUT */
-
-
-
+#define LOG_BUFFER 0
+#define LOG(...) /* nothing */
+#endif /* #if DEBUG */
 
 
 BLEDevice  ble;
-DigitalOut led1(LED1);
 UARTService *uart;
 RNGSensor sensor;
 
-char debugBuffer[DEBUG_BUFFER];
+DigitalOut led(p5); 
+DigitalOut motor(p6); 
+
+DigitalIn button(p16,PullDown);
+
+char debugBuffer[LOG_BUFFER];
 int sensorErrors[10];
 
 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
-    DEBUG("Disconnected!\n\r");
-    DEBUG("Restarting the advertising process\n\r");
+    LOG("Disconnected!\n\r");
+    LOG("Restarting the advertising process\n\r");
     ble.startAdvertising();
 }
 
-void periodicCallback(void)
-{
-    led1 = !led1;
-    DEBUG("ping\r\n");
-}
+
 int testSensors(void)
 {
     int errorCount = sensor.verifyIntegrity(sensorErrors);
     if (errorCount>0){
         for (int i=0;i<errorCount;i++){
-            DEBUG("ERROR: Sensor %s failed with error code: %d",sensor.getSimpleName(),sensorErrors[i]);
+            LOG("ERROR: Sensor %s failed with error code: %d",sensor.getSimpleName(),sensorErrors[i]);
         }
     } else {
-        DEBUG("Sensor %s validated!\n\r",sensor.getSimpleName());     
+        LOG("Sensor %s validated!\n\r",sensor.getSimpleName());     
     }
     return errorCount;   
 }
 
+void periodicCallback(void)
+{
+    led=!led;
+         if(button){
+            motor=1;
+        } else {
+            motor =0;
+        }
+//    testSensors();
+    LOG("ping\r\n");
+}
+
 int main(void)
 {
-    led1 = 1;
+    led=1;
     Ticker ticker;
     ticker.attach(periodicCallback, 1);
 
-    DEBUG("Initialising the nRF51822\n\r");
+    LOG("Initialising the nRF51822\n\r");
     ble.init();
     ble.onDisconnection(disconnectionCallback);
     
@@ -96,4 +107,4 @@
     while (true) {
         ble.waitForEvent();
     }
-}
+}
\ No newline at end of file