EMIR - Ekvitermní mikroprocesorová regulace https://code.google.com/p/emir/ https://code.google.com/p/emir/wiki/DesignV3

Dependencies:   ConfigFile DS1307 OneWire SDFileSystem USBDeviceLite mbed-rtos mbed

Revision:
5:5c8e97742751
Parent:
4:9065e9ccb078
--- a/src/main.cpp	Wed May 07 07:03:18 2014 +0000
+++ b/src/main.cpp	Wed May 28 13:58:06 2014 +0000
@@ -1,12 +1,9 @@
 #include "mbed.h"
+#include "mbed_debug.h"
 #include "rtos.h"
-#include "SDFileSystem.h"
 #include "sensor.h"
 #include "comm.h"
-
-Serial pc(MBED_UARTUSB);
-
-SDFileSystem sd(MBED_SPI0, "sd");
+#include "sd.h"
 
 DigitalOut ledR(LED_RED, 1);
 DigitalOut ledG(LED_GREEN, 1);
@@ -27,38 +24,36 @@
 
 int main(void)
 {
-    pc.printf("EMIRv2 compiled " __DATE__ " " __TIME__ "\n");
+    debug("\n\n\nEMIRv2 compiled " __DATE__ " " __TIME__ "\n");
     
-    pc.printf("Starting threads... ");
+    debug("Initializing SD... ");
+    sd_init();
+
+    debug("Starting threads... ");
     Thread sensor(sensor_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
     Thread comm(comm_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
-    pc.printf("done\n");
-
-    FILE *fp = fopen("/sd/sdtest2.txt", "w");
-    if (fp == NULL) {
-        pc.printf("Could not open file for write\n");
-    } else {
-        pc.printf("Writing... ");
-        fprintf(fp, "Hello fun SD Card World!\nOK!\n");
-        pc.printf("closing... ");
-        fclose(fp); 
-    }
-    pc.printf("done\n");
+    debug("done\n");
 
     OUT1 = 1;
     OUT2 = 1;
     OUT3 = 1;
     OUT4 = 1;
-    wait(1.0);
+    wait(0.5);
     OUT1 = 0;
     OUT2 = 0;
     OUT3 = 0;
     OUT4 = 0;
 
+    int i = 0;
     while (1) 
     {
         ledG = !ledG;
-        Thread::wait(200);
+        Thread::wait(100);
+        
+        if (i++ >= 100) {
+            write_config();
+            i = 0;
+        }
     }
 
 }