working version of song control with initialization from sd card

Dependencies:   MFRC522 NRF2401P SDFileSystem SPI_TFT_ILI9341 TFT_fonts mbed

Fork of Song_Control by Malcolm McCulloch

Revision:
0:c0f34d23943d
Child:
1:c2232b1eaf31
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 23 00:14:37 2016 +0000
@@ -0,0 +1,97 @@
+/**
+* This is a multi-purpose mbed. Duiring initialisation it reads the config file and then configures the mbed appropriately.
+* L Locker
+* H main Hub
+* B Battery
+*/
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "utils.h"
+#include "locker.h"
+#define debug 
+
+// Defines the type of mbed
+char type;
+unsigned int version = 1453505344; // Linux epoch time
+unsigned int sdVersion;
+int id;
+
+// Sd card
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
+
+
+/**
+* Reads config file and configures the mbed
+*/
+void initialise()
+{
+    char * name = "/sd/config.ini";
+    FILE *fp;
+
+    // Initialise the SD card
+    spiSD();
+    sd.large_frames(false);
+    sd.mount();
+    wait(0.1);
+#ifdef debug
+    printf("  SD MOUNTED Card type: %d  Capacity: %.1fMB\n\r", sd.card_type(),(sd.disk_sectors() * 512) / 1048576.0);
+#endif
+
+
+    //Configuration
+#ifdef debug
+    printf("Reading config file...\n\r");
+#endif
+    fp = fopen(name, "r");
+    if (fp == NULL) {
+        writeError ("Config file cannot be read");
+    }
+    if (fscanf (fp,"%c %*c %*s",&type )!=1) writeError("Config: cannot read type");
+    if (fscanf (fp,"%d %*c %*s",&sdVersion )!=1) writeError("Config: cannot read version");
+    if (fscanf (fp,"%d %*c %*s",&id )!=1) writeError("Config: cannot read id");
+#ifdef debug
+    printf("  Type:%c, Version %u, ID %d\n\r",type,sdVersion,id);
+#endif
+    switch (type){
+    case('B'): { // Battery
+            //initialiseBattery(fp);
+            break;
+        }
+    case('H'): { // Hub
+            //initialiseHub(fp);
+            break;
+        }
+    case('L'): { // Locker
+            initialiseLocker(fp);
+            break;
+        }
+    default:{
+    writeError ("Type declared in config not available.");
+    }
+        
+    }
+    fclose (fp);
+}
+
+/**
+* main loop. Set up timers and interupts then wait
+*/
+int main()
+{
+    struct tm * timeInf = localtime(&version);
+    printf("\n\r SOLAR NANO GRID CONTROLLER. Version %04d-%02d-%02d %02d:%02d \n\r", timeInf->tm_year+1900,timeInf->tm_mon+1,timeInf->tm_mday,timeInf->tm_hour, timeInf->tm_sec);
+    //
+    // Read config and initialise
+    //
+#ifdef debug
+    printf("\n\rInitialise \n\r");
+#endif
+    initialise();
+#ifdef debug
+    printf("\n\r> START LOOP\n\r");
+#endif
+    while (true) {
+        // do slower routines
+
+    }
+}
\ No newline at end of file