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