The codebase to run the *spark d-fuser controller www.sparkav.co.uk/dvimixer

Dependencies:   SPK-TVOne DMX DmxArtNet NetServicesMin OSC PinDetect mRotaryEncoder iniparser mbed spk_oled_ssd1305 filter

Files at this revision

API Documentation at this revision

Comitter:
tobyspark
Date:
Mon Sep 17 00:34:51 2012 +0000
Parent:
12:c270870bdd23
Child:
14:00d3ba738f21
Commit message:
SPK-Setting using iniparser library; ...but it crashes on using it, despite the class being tested good when in test program. see note in load method.

Changed in this revision

ConfigFile.lib Show diff for this revision Revisions of this file
iniparser.lib 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
spk_settings.h Show annotated file Show diff for this revision Revisions of this file
--- a/ConfigFile.lib	Tue Aug 28 15:41:51 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/pbrier/code/ConfigFile/#8c8cf4615b32
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iniparser.lib	Mon Sep 17 00:34:51 2012 +0000
@@ -0,0 +1,1 @@
+iniparser#1a9f9f36242e
--- a/main.cpp	Tue Aug 28 15:41:51 2012 +0000
+++ b/main.cpp	Mon Sep 17 00:34:51 2012 +0000
@@ -35,6 +35,7 @@
  * v16 - Comms menu, OSC, ArtNet - April'12
  * v17 - RJ45 - May'12
  * v18 - DMX - July'12
+ * v19 - TVOne mixing comms further optimised - August'12
  * vxx - TODO: Keying values load from USB mass storage
  * vxx - TODO: Set keying values from controller, requires a guided, step-through process for user
  * vxx - TODO: Defaults load/save from USB mass storage
@@ -57,6 +58,8 @@
 
 #include <sstream>
 
+#define kSPKDFSoftwareVersion "beta.19"
+
 // MBED PINS
 
 #define kMBED_AIN_XFADE     p20
@@ -104,7 +107,8 @@
 #define kDMXOutChannelXFade 0
 #define kDMXOutChannelFadeUp 1
 
-#define kSPKDFSettingsFilename "SPKDF-Settings.txt"
+// 8.3 format filename only, no subdirs
+#define kSPKDFSettingsFilename "SPKDF.ini"
 
 //// DEBUG
 
@@ -310,12 +314,16 @@
     // Splash screen
     screen.imageToBuffer(spkDisplayLogo);
     screen.textToBuffer("SPK:D-Fuser",0);
-    screen.textToBuffer("SW beta.18",1);
+    screen.textToBuffer(string("SW ") + kSPKDFSoftwareVersion,1);
     screen.sendBuffer();
     
     // Load saved settings
-    settings.load(kSPKDFSettingsFilename);
-    
+/* CRAZY, see note in spk_settings.h   
+    if (settings.load(kSPKDFSettingsFilename)) 
+    {screen.textToBuffer("Settings Read",2); screen.sendBuffer();}
+    else 
+    {screen.textToBuffer("Settings NOT Read",2); screen.sendBuffer();}
+*/    
     // Set menu structure
     mixModeMenu.title = "Mix Mode";
     mixModeMenu.addMenuItem("Blend", blend, 0);
--- a/spk_settings.h	Tue Aug 28 15:41:51 2012 +0000
+++ b/spk_settings.h	Mon Sep 17 00:34:51 2012 +0000
@@ -5,6 +5,15 @@
 #define kKeyerParam2Set     30, 35, 237, 242, 114, 121
 
 #include "mbed.h"
+#include <string>
+#include <vector>
+
+// CRAZY: When this file is used in a test program, doesn't need the extern to compile, and works perfectly.
+// When this file is used in SPK-DVIMXR, requires the extern to compile and crashes on iniparser_load
+extern "C" 
+{
+#include "iniparser.h"
+}
 
 class SPKSettings {
 public:
@@ -19,7 +28,7 @@
         keyerParamSets.push_back(paramSet2);
     }
     
-    std::string keyerParamName (int index)
+    string keyerParamName (int index)
     {
         // TODO: Bounds check and return out of bounds name
         return keyerParamNames[index];
@@ -35,17 +44,95 @@
         return keyerParamSets.size();
     }
     
-    bool        load(std::string filename)
+    bool        load(string filename)
     {
         bool success = false;
+
+        local = new LocalFileSystem("local");
+        string filePath("/local/");
+        filePath += filename;
+
+        dictionary* settings = iniparser_load(filePath.c_str());
+            
+        // KEYER
+        {
+            int counter = 1;
+            
+            bool keyParamReadOK = true;
+            bool keyParamCleared = false;
+            
+            char* failString = "Failed to read";
+            int failInt = -1;
+            
+            // Loop through [Key1,2,...,99] sections
+            while(keyParamReadOK)
+            {
+                int     paramSet[6];
+                char*   paramName;
+                
+                char key[11];
         
-        // TODO!
+                sprintf(key, "Key%i:Name", counter);
+                paramName = iniparser_getstring(settings, key, failString);
+                keyParamReadOK = keyParamReadOK && strcmp(paramName, failString);
+                       
+                sprintf(key, "Key%i:MinY", counter);
+                paramSet[0] = iniparser_getint(settings, key, failInt);
+                keyParamReadOK = keyParamReadOK && (paramSet[0] != failInt);
+
+                sprintf(key, "Key%i:MaxY", counter);
+                paramSet[1] = iniparser_getint(settings, key, failInt);
+                keyParamReadOK = keyParamReadOK && (paramSet[1] != failInt);
+                
+                sprintf(key, "Key%i:MinU", counter);
+                paramSet[2] = iniparser_getint(settings, key, failInt);
+                keyParamReadOK = keyParamReadOK && (paramSet[2] != failInt);
+                
+                sprintf(key, "Key%i:MaxU", counter);
+                paramSet[3] = iniparser_getint(settings, key, failInt);
+                keyParamReadOK = keyParamReadOK && (paramSet[3] != failInt);
+                
+                sprintf(key, "Key%i:MinV", counter);
+                paramSet[4] = iniparser_getint(settings, key, failInt);
+                keyParamReadOK = keyParamReadOK && (paramSet[4] != failInt);
+                
+                sprintf(key, "Key%i:MaxV", counter);
+                paramSet[5] = iniparser_getint(settings, key, failInt);
+                keyParamReadOK = keyParamReadOK && (paramSet[5] != failInt);
+                
+                // If all parameters have been read successfully
+                if (keyParamReadOK)
+                {
+
+                    // If this is the first time through, clear old values
+                    if (!keyParamCleared)
+                    {
+                        keyerParamNames.clear();
+                        keyerParamSets.clear();
+                        keyParamCleared = true;
+                    }
+                
+                    // Apply settings
+                    keyerParamNames.push_back(paramName);
+                    keyerParamSets.push_back(paramSet);
+                    
+                    // We've successfully read a keyer param set, so should return true;
+                    success = true;
+                }
+                
+                counter++;
+            }
+        }        
+
+        iniparser_freedict(settings);
+        
+        delete local;
         
         return success;
     }
     
 protected:
     LocalFileSystem *local;
-    std::vector<int*> keyerParamSets;
-    std::vector<std::string> keyerParamNames;
+    vector<int*> keyerParamSets;
+    vector<string> keyerParamNames;
 };