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

Files at this revision

API Documentation at this revision

Comitter:
epgmdm
Date:
Sun Jan 24 16:15:53 2016 +0000
Parent:
0:c0f34d23943d
Child:
2:d1eae91343a9
Commit message:
Basic structure has Hub,Locker,Battery and Test

Changed in this revision

battery.cpp Show annotated file Show diff for this revision Revisions of this file
battery.h Show annotated file Show diff for this revision Revisions of this file
hub.cpp Show annotated file Show diff for this revision Revisions of this file
hub.h Show annotated file Show diff for this revision Revisions of this file
locker.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
test.cpp Show annotated file Show diff for this revision Revisions of this file
test.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/battery.cpp	Sun Jan 24 16:15:53 2016 +0000
@@ -0,0 +1,43 @@
+/**
+* All the code associated to run the mbed as a battery.
+* Link with locker
+*/
+#include "mbed.h"
+#include "utils.h"
+#define debug 
+
+// Flags
+// Variables
+// tx nRF2401
+
+long long addrLocker=0xBBBBBBBBBB;
+extern int channel;
+
+// Initializaton
+/**
+* Initialise for a battery
+* fp is the config file if additonal information is needed.
+*/
+void initialiseBattery(FILE *fp){
+#ifdef debug
+    printf("Initialise Battery\n\r");
+#endif
+
+    // Read in hub address and channel
+    if (fscanf (fp,"%x %*c %*s",&channel )!=1) writeError("Battery config: cannot read channel");
+    if (fscanf (fp,"%llx %*c %*s",&addrLocker )!=1) writeError("Battery config: cannot read address");
+
+#ifdef debug
+    printf("  Channel:%x,  Address %llx \n\r",channel, addrLocker);
+#endif
+
+
+}
+// Interupt routines
+
+
+// Loop through slow routines
+
+void loopBattery(){
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/battery.h	Sun Jan 24 16:15:53 2016 +0000
@@ -0,0 +1,5 @@
+/**
+* All the code associated to run the mbed as a battery
+*/
+void initialiseBattery(FILE *fp);
+void loopBattery();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hub.cpp	Sun Jan 24 16:15:53 2016 +0000
@@ -0,0 +1,43 @@
+/**
+* All the code associated to run the mbed as a hub.
+* Link with locker
+*/
+#include "mbed.h"
+#include "utils.h"
+#define debug 
+
+// Flags
+// Variables
+// tx nRF2401
+
+long long addrLcker=0xBBBBBBBBBB;
+extern int channel;
+
+// Initializaton
+/**
+* Initialise for a locker
+* fp is the config file if additonal information is needed.
+*/
+void initialiseHub(FILE *fp){
+#ifdef debug
+    printf("Initialise Hub\n\r");
+#endif
+
+    // Read in hub address and channel
+    if (fscanf (fp,"%x %*c %*s",&channel )!=1) writeError("Hub config: cannot read channel");
+    if (fscanf (fp,"%llx %*c %*s",&addrLcker )!=1) writeError("Hub config: cannot read hub address");
+
+#ifdef debug
+    printf("  Channel:%x, Hub Address %llx \n\r",channel, addrLcker);
+#endif
+
+
+}
+// Interupt routines
+
+
+// Loop through slow routines
+
+void loopHub(){
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hub.h	Sun Jan 24 16:15:53 2016 +0000
@@ -0,0 +1,5 @@
+/**
+* All the code associated to run the mbed as a hub.
+*/
+void initialiseHub(FILE *fp);
+void loopHub();
\ No newline at end of file
--- a/locker.cpp	Sat Jan 23 00:14:37 2016 +0000
+++ b/locker.cpp	Sun Jan 24 16:15:53 2016 +0000
@@ -12,7 +12,7 @@
 // tx nRF2401
 
 long long addrHub=0xBBBBBBBBBB;
-int channel = 76;
+extern int channel;
 
 // Initializaton
 /**
--- a/main.cpp	Sat Jan 23 00:14:37 2016 +0000
+++ b/main.cpp	Sun Jan 24 16:15:53 2016 +0000
@@ -7,14 +7,18 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
 #include "utils.h"
+#include "battery.h"
+#include "hub.h"
 #include "locker.h"
+#include "test.h"
 #define debug 
 
-// Defines the type of mbed
-char type;
+// Defines the role of mbed
+char role;
 unsigned int version = 1453505344; // Linux epoch time
 unsigned int sdVersion;
 int id;
+int channel;
 
 // Sd card
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
@@ -34,7 +38,7 @@
     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);
+    printf("  SD MOUNTED Card role: %d  Capacity: %.1fMB\n\r", sd.card_type(),(sd.disk_sectors() * 512) / 1048576.0);
 #endif
 
 
@@ -46,15 +50,15 @@
     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,"%c %*c %*s",&role )!=1) writeError("Config: cannot read role");
     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);
+    printf("  Type:%c, Version %u, ID %d\n\r",role,sdVersion,id);
 #endif
-    switch (type){
+    switch (role){
     case('B'): { // Battery
-            //initialiseBattery(fp);
+            initialiseBattery(fp);
             break;
         }
     case('H'): { // Hub
@@ -65,6 +69,10 @@
             initialiseLocker(fp);
             break;
         }
+    case('T'): { // Test
+            initialiseTest(fp);
+            break;
+        }
     default:{
     writeError ("Type declared in config not available.");
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test.cpp	Sun Jan 24 16:15:53 2016 +0000
@@ -0,0 +1,43 @@
+/**
+* All the code associated to run the mbed as a Test
+* 
+*/
+#include "mbed.h"
+#include "utils.h"
+#define debug 
+
+// Flags
+// Variables
+// tx nRF2401
+
+long long addr=0xBBBBBBBBBB;
+extern int channel;
+
+// Initializaton
+/**
+* Initialise for a locker
+* fp is the config file if additonal information is needed.
+*/
+void initialiseTest(FILE *fp){
+#ifdef debug
+    printf("Initialise Test\n\r");
+#endif
+
+    // Read in hub address and channel
+    if (fscanf (fp,"%x %*c %*s",&channel )!=1) writeError("Test config: cannot read channel");
+    if (fscanf (fp,"%llx %*c %*s",&addr )!=1) writeError("Test config: cannot read address");
+
+#ifdef debug
+    printf("  Channel:%x,  Address %llx \n\r",channel, addr);
+#endif
+
+
+}
+// Interupt routines
+
+
+// Loop through slow routines
+
+void loopTest(){
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test.h	Sun Jan 24 16:15:53 2016 +0000
@@ -0,0 +1,5 @@
+/**
+* All the code associated to run the mbed as a Test
+*/
+void initialiseTest(FILE *fp);
+void loopTest();
\ No newline at end of file