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

Committer:
tobyspark
Date:
Sun Oct 28 17:21:19 2012 +0000
Revision:
28:67269c2d042b
Parent:
27:27851d3d2bba
Child:
31:01845a2347ff
Included .ini file; More sprintf to snprintf safety fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 11:0783cfbeb746 1 #include "mbed.h"
tobyspark 13:3796bde6ba8f 2 #include <string>
tobyspark 13:3796bde6ba8f 3 #include <vector>
tobyspark 13:3796bde6ba8f 4
tobyspark 13:3796bde6ba8f 5 extern "C"
tobyspark 13:3796bde6ba8f 6 {
tobyspark 13:3796bde6ba8f 7 #include "iniparser.h"
tobyspark 13:3796bde6ba8f 8 }
tobyspark 11:0783cfbeb746 9
tobyspark 11:0783cfbeb746 10 class SPKSettings {
tobyspark 11:0783cfbeb746 11 public:
tobyspark 11:0783cfbeb746 12 SPKSettings()
tobyspark 11:0783cfbeb746 13 {
tobyspark 16:52484666b323 14 loadDefaults();
tobyspark 16:52484666b323 15 }
tobyspark 16:52484666b323 16
tobyspark 16:52484666b323 17 void loadDefaults()
tobyspark 16:52484666b323 18 {
tobyspark 16:52484666b323 19 //// KEYS
tobyspark 16:52484666b323 20
tobyspark 27:27851d3d2bba 21 keyerParamNames.clear();
tobyspark 27:27851d3d2bba 22 keyerParamSets.clear();
tobyspark 27:27851d3d2bba 23
tobyspark 16:52484666b323 24 // Parameter Set: minY, maxY, minU, maxU, minV, maxV
tobyspark 16:52484666b323 25 int paramSet1[6] = {0, 18, 128, 129, 128, 129};
tobyspark 16:52484666b323 26 keyerParamNames.push_back("Lumakey");
tobyspark 11:0783cfbeb746 27 keyerParamSets.push_back(paramSet1);
tobyspark 11:0783cfbeb746 28
tobyspark 16:52484666b323 29 int paramSet2[6] = {30, 35, 237, 242, 114, 121};
tobyspark 16:52484666b323 30 keyerParamNames.push_back("Chromakey - Blue");
tobyspark 11:0783cfbeb746 31 keyerParamSets.push_back(paramSet2);
tobyspark 16:52484666b323 32
tobyspark 16:52484666b323 33 //// RESOLUTIONS
tobyspark 16:52484666b323 34
tobyspark 27:27851d3d2bba 35 resolutionNames.clear();
tobyspark 27:27851d3d2bba 36 resolutionIndexes.clear();
tobyspark 27:27851d3d2bba 37 resolutionEDIDIndexes.clear();
tobyspark 27:27851d3d2bba 38
tobyspark 16:52484666b323 39 resolutionNames.push_back(kTV1ResolutionDescriptionVGA);
tobyspark 16:52484666b323 40 resolutionIndexes.push_back(kTV1ResolutionVGA);
tobyspark 16:52484666b323 41 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 42
tobyspark 16:52484666b323 43 resolutionNames.push_back(kTV1ResolutionDescriptionSVGA);
tobyspark 16:52484666b323 44 resolutionIndexes.push_back(kTV1ResolutionSVGA);
tobyspark 16:52484666b323 45 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 46
tobyspark 16:52484666b323 47 resolutionNames.push_back(kTV1ResolutionDescriptionXGAp60);
tobyspark 16:52484666b323 48 resolutionIndexes.push_back(kTV1ResolutionXGAp60);
tobyspark 16:52484666b323 49 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 50
tobyspark 16:52484666b323 51 resolutionNames.push_back(kTV1ResolutionDescriptionWSXGAPLUSp60);
tobyspark 16:52484666b323 52 resolutionIndexes.push_back(kTV1ResolutionWSXGAPLUSp60);
tobyspark 16:52484666b323 53 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 54
tobyspark 16:52484666b323 55 resolutionNames.push_back(kTV1ResolutionDescriptionWUXGAp60);
tobyspark 16:52484666b323 56 resolutionIndexes.push_back(kTV1ResolutionWUXGAp60);
tobyspark 16:52484666b323 57 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 58
tobyspark 16:52484666b323 59 resolutionNames.push_back(kTV1ResolutionDescription720p60);
tobyspark 16:52484666b323 60 resolutionIndexes.push_back(kTV1Resolution720p60);
tobyspark 16:52484666b323 61 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 62
tobyspark 16:52484666b323 63 resolutionNames.push_back(kTV1ResolutionDescription1080p60);
tobyspark 16:52484666b323 64 resolutionIndexes.push_back(kTV1Resolution1080p60);
tobyspark 16:52484666b323 65 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 66
tobyspark 16:52484666b323 67 resolutionNames.push_back(kTV1ResolutionDescriptionDualHeadSVGAp60);
tobyspark 16:52484666b323 68 resolutionIndexes.push_back(kTV1ResolutionDualHeadSVGAp60);
tobyspark 16:52484666b323 69 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 70
tobyspark 16:52484666b323 71 resolutionNames.push_back(kTV1ResolutionDescriptionDualHeadXGAp60);
tobyspark 16:52484666b323 72 resolutionIndexes.push_back(kTV1ResolutionDualHeadXGAp60);
tobyspark 16:52484666b323 73 resolutionEDIDIndexes.push_back(5);
tobyspark 16:52484666b323 74
tobyspark 16:52484666b323 75 resolutionNames.push_back(kTV1ResolutionDescriptionTripleHeadVGAp60);
tobyspark 16:52484666b323 76 resolutionIndexes.push_back(kTV1ResolutionTripleHeadVGAp60);
tobyspark 16:52484666b323 77 resolutionEDIDIndexes.push_back(5);
tobyspark 11:0783cfbeb746 78 }
tobyspark 11:0783cfbeb746 79
tobyspark 13:3796bde6ba8f 80 string keyerParamName (int index)
tobyspark 11:0783cfbeb746 81 {
tobyspark 11:0783cfbeb746 82 // TODO: Bounds check and return out of bounds name
tobyspark 11:0783cfbeb746 83 return keyerParamNames[index];
tobyspark 11:0783cfbeb746 84 }
tobyspark 11:0783cfbeb746 85
tobyspark 11:0783cfbeb746 86 int* keyerParamSet(int index)
tobyspark 11:0783cfbeb746 87 {
tobyspark 11:0783cfbeb746 88 return keyerParamSets[index];
tobyspark 11:0783cfbeb746 89 }
tobyspark 11:0783cfbeb746 90
tobyspark 11:0783cfbeb746 91 int keyerSetCount()
tobyspark 11:0783cfbeb746 92 {
tobyspark 11:0783cfbeb746 93 return keyerParamSets.size();
tobyspark 11:0783cfbeb746 94 }
tobyspark 11:0783cfbeb746 95
tobyspark 16:52484666b323 96 string resolutionName (int index)
tobyspark 16:52484666b323 97 {
tobyspark 16:52484666b323 98 // TODO: Bounds check and return out of bounds name
tobyspark 16:52484666b323 99 return resolutionNames[index];
tobyspark 16:52484666b323 100 }
tobyspark 16:52484666b323 101
tobyspark 16:52484666b323 102 int32_t resolutionIndex(int index)
tobyspark 16:52484666b323 103 {
tobyspark 16:52484666b323 104 return resolutionIndexes[index];
tobyspark 16:52484666b323 105 }
tobyspark 16:52484666b323 106
tobyspark 16:52484666b323 107 int32_t resolutionEDIDIndex(int index)
tobyspark 16:52484666b323 108 {
tobyspark 16:52484666b323 109 return resolutionEDIDIndexes[index];
tobyspark 16:52484666b323 110 }
tobyspark 16:52484666b323 111
tobyspark 16:52484666b323 112 int resolutionsCount()
tobyspark 16:52484666b323 113 {
tobyspark 16:52484666b323 114 return resolutionNames.size();
tobyspark 16:52484666b323 115 }
tobyspark 16:52484666b323 116
tobyspark 13:3796bde6ba8f 117 bool load(string filename)
tobyspark 11:0783cfbeb746 118 {
tobyspark 11:0783cfbeb746 119 bool success = false;
tobyspark 13:3796bde6ba8f 120
tobyspark 13:3796bde6ba8f 121 local = new LocalFileSystem("local");
tobyspark 13:3796bde6ba8f 122 string filePath("/local/");
tobyspark 13:3796bde6ba8f 123 filePath += filename;
tobyspark 13:3796bde6ba8f 124
tobyspark 13:3796bde6ba8f 125 dictionary* settings = iniparser_load(filePath.c_str());
tobyspark 13:3796bde6ba8f 126
tobyspark 13:3796bde6ba8f 127 // KEYER
tobyspark 13:3796bde6ba8f 128 {
tobyspark 13:3796bde6ba8f 129 int counter = 1;
tobyspark 13:3796bde6ba8f 130
tobyspark 13:3796bde6ba8f 131 bool keyParamReadOK = true;
tobyspark 13:3796bde6ba8f 132 bool keyParamCleared = false;
tobyspark 13:3796bde6ba8f 133
tobyspark 28:67269c2d042b 134 char* const failString = "Failed to read";
tobyspark 28:67269c2d042b 135 const int failInt = -1;
tobyspark 28:67269c2d042b 136 const int stringLength = 11;
tobyspark 13:3796bde6ba8f 137
tobyspark 13:3796bde6ba8f 138 // Loop through [Key1,2,...,99] sections
tobyspark 13:3796bde6ba8f 139 while(keyParamReadOK)
tobyspark 13:3796bde6ba8f 140 {
tobyspark 13:3796bde6ba8f 141 int paramSet[6];
tobyspark 13:3796bde6ba8f 142 char* paramName;
tobyspark 13:3796bde6ba8f 143
tobyspark 28:67269c2d042b 144 char key[stringLength];
tobyspark 11:0783cfbeb746 145
tobyspark 28:67269c2d042b 146 snprintf(key, stringLength, "Key%i:Name", counter);
tobyspark 13:3796bde6ba8f 147 paramName = iniparser_getstring(settings, key, failString);
tobyspark 13:3796bde6ba8f 148 keyParamReadOK = keyParamReadOK && strcmp(paramName, failString);
tobyspark 13:3796bde6ba8f 149
tobyspark 28:67269c2d042b 150 snprintf(key, stringLength, "Key%i:MinY", counter);
tobyspark 13:3796bde6ba8f 151 paramSet[0] = iniparser_getint(settings, key, failInt);
tobyspark 13:3796bde6ba8f 152 keyParamReadOK = keyParamReadOK && (paramSet[0] != failInt);
tobyspark 13:3796bde6ba8f 153
tobyspark 28:67269c2d042b 154 snprintf(key, stringLength, "Key%i:MaxY", counter);
tobyspark 13:3796bde6ba8f 155 paramSet[1] = iniparser_getint(settings, key, failInt);
tobyspark 13:3796bde6ba8f 156 keyParamReadOK = keyParamReadOK && (paramSet[1] != failInt);
tobyspark 13:3796bde6ba8f 157
tobyspark 28:67269c2d042b 158 snprintf(key, stringLength, "Key%i:MinU", counter);
tobyspark 13:3796bde6ba8f 159 paramSet[2] = iniparser_getint(settings, key, failInt);
tobyspark 13:3796bde6ba8f 160 keyParamReadOK = keyParamReadOK && (paramSet[2] != failInt);
tobyspark 13:3796bde6ba8f 161
tobyspark 28:67269c2d042b 162 snprintf(key, stringLength, "Key%i:MaxU", counter);
tobyspark 13:3796bde6ba8f 163 paramSet[3] = iniparser_getint(settings, key, failInt);
tobyspark 13:3796bde6ba8f 164 keyParamReadOK = keyParamReadOK && (paramSet[3] != failInt);
tobyspark 13:3796bde6ba8f 165
tobyspark 28:67269c2d042b 166 snprintf(key, stringLength, "Key%i:MinV", counter);
tobyspark 13:3796bde6ba8f 167 paramSet[4] = iniparser_getint(settings, key, failInt);
tobyspark 13:3796bde6ba8f 168 keyParamReadOK = keyParamReadOK && (paramSet[4] != failInt);
tobyspark 13:3796bde6ba8f 169
tobyspark 28:67269c2d042b 170 snprintf(key, stringLength, "Key%i:MaxV", counter);
tobyspark 13:3796bde6ba8f 171 paramSet[5] = iniparser_getint(settings, key, failInt);
tobyspark 13:3796bde6ba8f 172 keyParamReadOK = keyParamReadOK && (paramSet[5] != failInt);
tobyspark 13:3796bde6ba8f 173
tobyspark 13:3796bde6ba8f 174 // If all parameters have been read successfully
tobyspark 13:3796bde6ba8f 175 if (keyParamReadOK)
tobyspark 13:3796bde6ba8f 176 {
tobyspark 13:3796bde6ba8f 177
tobyspark 13:3796bde6ba8f 178 // If this is the first time through, clear old values
tobyspark 13:3796bde6ba8f 179 if (!keyParamCleared)
tobyspark 13:3796bde6ba8f 180 {
tobyspark 13:3796bde6ba8f 181 keyerParamNames.clear();
tobyspark 13:3796bde6ba8f 182 keyerParamSets.clear();
tobyspark 13:3796bde6ba8f 183 keyParamCleared = true;
tobyspark 13:3796bde6ba8f 184 }
tobyspark 13:3796bde6ba8f 185
tobyspark 13:3796bde6ba8f 186 // Apply settings
tobyspark 13:3796bde6ba8f 187 keyerParamNames.push_back(paramName);
tobyspark 13:3796bde6ba8f 188 keyerParamSets.push_back(paramSet);
tobyspark 13:3796bde6ba8f 189
tobyspark 13:3796bde6ba8f 190 // We've successfully read a keyer param set, so should return true;
tobyspark 13:3796bde6ba8f 191 success = true;
tobyspark 13:3796bde6ba8f 192 }
tobyspark 13:3796bde6ba8f 193
tobyspark 13:3796bde6ba8f 194 counter++;
tobyspark 13:3796bde6ba8f 195 }
tobyspark 13:3796bde6ba8f 196 }
tobyspark 13:3796bde6ba8f 197
tobyspark 16:52484666b323 198 // RESOLUTIONS
tobyspark 16:52484666b323 199 {
tobyspark 16:52484666b323 200 int counter = 1;
tobyspark 16:52484666b323 201
tobyspark 16:52484666b323 202 bool resolutionReadOK = true;
tobyspark 16:52484666b323 203 bool resolutionCleared = false;
tobyspark 16:52484666b323 204
tobyspark 28:67269c2d042b 205 char* const failString = "Failed to read";
tobyspark 28:67269c2d042b 206 const int failInt = -1;
tobyspark 28:67269c2d042b 207 const int stringLength = 25;
tobyspark 16:52484666b323 208
tobyspark 16:52484666b323 209 // Loop through [Key1,2,...,99] sections
tobyspark 16:52484666b323 210 while(resolutionReadOK)
tobyspark 16:52484666b323 211 {
tobyspark 16:52484666b323 212 char* resolutionName;
tobyspark 16:52484666b323 213 int resolutionIndex;
tobyspark 16:52484666b323 214 int resolutionEDIDIndex;
tobyspark 16:52484666b323 215
tobyspark 28:67269c2d042b 216 char key[stringLength];
tobyspark 16:52484666b323 217
tobyspark 28:67269c2d042b 218 snprintf(key, stringLength, "Resolution%i:Name", counter);
tobyspark 16:52484666b323 219 resolutionName = iniparser_getstring(settings, key, failString);
tobyspark 16:52484666b323 220 resolutionReadOK = resolutionReadOK && strcmp(resolutionName, failString);
tobyspark 16:52484666b323 221
tobyspark 28:67269c2d042b 222 snprintf(key, stringLength, "Resolution%i:Number", counter);
tobyspark 16:52484666b323 223 resolutionIndex = iniparser_getint(settings, key, failInt);
tobyspark 16:52484666b323 224 resolutionReadOK = resolutionReadOK && (resolutionIndex != failInt);
tobyspark 16:52484666b323 225
tobyspark 28:67269c2d042b 226 snprintf(key, stringLength, "Resolution%i:EDIDNumber", counter);
tobyspark 16:52484666b323 227 resolutionEDIDIndex = iniparser_getint(settings, key, failInt);
tobyspark 16:52484666b323 228 resolutionReadOK = resolutionReadOK && (resolutionEDIDIndex != failInt);
tobyspark 16:52484666b323 229
tobyspark 16:52484666b323 230 // If all parameters have been read successfully
tobyspark 16:52484666b323 231 if (resolutionReadOK)
tobyspark 16:52484666b323 232 {
tobyspark 16:52484666b323 233 // If this is the first time through, clear old values
tobyspark 16:52484666b323 234 if (!resolutionCleared)
tobyspark 16:52484666b323 235 {
tobyspark 16:52484666b323 236 resolutionNames.clear();
tobyspark 16:52484666b323 237 resolutionIndexes.clear();
tobyspark 16:52484666b323 238 resolutionEDIDIndexes.clear();
tobyspark 16:52484666b323 239 resolutionCleared = true;
tobyspark 16:52484666b323 240 }
tobyspark 16:52484666b323 241
tobyspark 16:52484666b323 242 // Apply settings
tobyspark 16:52484666b323 243 resolutionNames.push_back(resolutionName);
tobyspark 16:52484666b323 244 resolutionIndexes.push_back(resolutionIndex);
tobyspark 16:52484666b323 245 resolutionEDIDIndexes.push_back(resolutionEDIDIndex);
tobyspark 16:52484666b323 246
tobyspark 16:52484666b323 247 // We've successfully read a resolution, so should return true;
tobyspark 16:52484666b323 248 success = true;
tobyspark 16:52484666b323 249 }
tobyspark 16:52484666b323 250
tobyspark 16:52484666b323 251 counter++;
tobyspark 16:52484666b323 252 }
tobyspark 16:52484666b323 253 }
tobyspark 16:52484666b323 254
tobyspark 13:3796bde6ba8f 255 iniparser_freedict(settings);
tobyspark 13:3796bde6ba8f 256
tobyspark 13:3796bde6ba8f 257 delete local;
tobyspark 11:0783cfbeb746 258
tobyspark 11:0783cfbeb746 259 return success;
tobyspark 11:0783cfbeb746 260 }
tobyspark 11:0783cfbeb746 261
tobyspark 11:0783cfbeb746 262 protected:
tobyspark 11:0783cfbeb746 263 LocalFileSystem *local;
tobyspark 16:52484666b323 264 vector<int*> keyerParamSets;
tobyspark 16:52484666b323 265 vector<string> keyerParamNames;
tobyspark 16:52484666b323 266 vector<string> resolutionNames;
tobyspark 16:52484666b323 267 vector<int32_t> resolutionIndexes;
tobyspark 16:52484666b323 268 vector<int32_t> resolutionEDIDIndexes;
tobyspark 16:52484666b323 269 };