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:
Fri Jul 26 12:46:58 2013 +0000
Revision:
61:f0a42bfca816
Parent:
51:98cc27390484
Child:
68:c26478f42ca4
Mix Mode Menu UX + Keying redux. ; ; Saving back to .ini hasn't worked out, so having active key settings saved in processor and read back in on load. Presets from ini now "activate" their values.

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