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@13:3796bde6ba8f, 2012-09-17 (annotated)
- Committer:
- tobyspark
- Date:
- Mon Sep 17 00:34:51 2012 +0000
- Revision:
- 13:3796bde6ba8f
- Parent:
- 11:0783cfbeb746
- Child:
- 16:52484666b323
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.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tobyspark | 11:0783cfbeb746 | 1 | // Parameter Set: minY, maxY, minU, maxU, minV, maxV |
tobyspark | 11:0783cfbeb746 | 2 | #define kKeyerParam1Name "Lumakey" |
tobyspark | 11:0783cfbeb746 | 3 | #define kKeyerParam1Set 0, 18, 128, 129, 128, 129 |
tobyspark | 11:0783cfbeb746 | 4 | #define kKeyerParam2Name "Chromakey - Blue" |
tobyspark | 11:0783cfbeb746 | 5 | #define kKeyerParam2Set 30, 35, 237, 242, 114, 121 |
tobyspark | 11:0783cfbeb746 | 6 | |
tobyspark | 11:0783cfbeb746 | 7 | #include "mbed.h" |
tobyspark | 13:3796bde6ba8f | 8 | #include <string> |
tobyspark | 13:3796bde6ba8f | 9 | #include <vector> |
tobyspark | 13:3796bde6ba8f | 10 | |
tobyspark | 13:3796bde6ba8f | 11 | // CRAZY: When this file is used in a test program, doesn't need the extern to compile, and works perfectly. |
tobyspark | 13:3796bde6ba8f | 12 | // When this file is used in SPK-DVIMXR, requires the extern to compile and crashes on iniparser_load |
tobyspark | 13:3796bde6ba8f | 13 | extern "C" |
tobyspark | 13:3796bde6ba8f | 14 | { |
tobyspark | 13:3796bde6ba8f | 15 | #include "iniparser.h" |
tobyspark | 13:3796bde6ba8f | 16 | } |
tobyspark | 11:0783cfbeb746 | 17 | |
tobyspark | 11:0783cfbeb746 | 18 | class SPKSettings { |
tobyspark | 11:0783cfbeb746 | 19 | public: |
tobyspark | 11:0783cfbeb746 | 20 | SPKSettings() |
tobyspark | 11:0783cfbeb746 | 21 | { |
tobyspark | 11:0783cfbeb746 | 22 | int paramSet1[6] = {kKeyerParam1Set}; |
tobyspark | 11:0783cfbeb746 | 23 | keyerParamNames.push_back(kKeyerParam1Name); |
tobyspark | 11:0783cfbeb746 | 24 | keyerParamSets.push_back(paramSet1); |
tobyspark | 11:0783cfbeb746 | 25 | |
tobyspark | 11:0783cfbeb746 | 26 | int paramSet2[6] = {kKeyerParam2Set}; |
tobyspark | 11:0783cfbeb746 | 27 | keyerParamNames.push_back(kKeyerParam2Name); |
tobyspark | 11:0783cfbeb746 | 28 | keyerParamSets.push_back(paramSet2); |
tobyspark | 11:0783cfbeb746 | 29 | } |
tobyspark | 11:0783cfbeb746 | 30 | |
tobyspark | 13:3796bde6ba8f | 31 | string keyerParamName (int index) |
tobyspark | 11:0783cfbeb746 | 32 | { |
tobyspark | 11:0783cfbeb746 | 33 | // TODO: Bounds check and return out of bounds name |
tobyspark | 11:0783cfbeb746 | 34 | return keyerParamNames[index]; |
tobyspark | 11:0783cfbeb746 | 35 | } |
tobyspark | 11:0783cfbeb746 | 36 | |
tobyspark | 11:0783cfbeb746 | 37 | int* keyerParamSet(int index) |
tobyspark | 11:0783cfbeb746 | 38 | { |
tobyspark | 11:0783cfbeb746 | 39 | return keyerParamSets[index]; |
tobyspark | 11:0783cfbeb746 | 40 | } |
tobyspark | 11:0783cfbeb746 | 41 | |
tobyspark | 11:0783cfbeb746 | 42 | int keyerSetCount() |
tobyspark | 11:0783cfbeb746 | 43 | { |
tobyspark | 11:0783cfbeb746 | 44 | return keyerParamSets.size(); |
tobyspark | 11:0783cfbeb746 | 45 | } |
tobyspark | 11:0783cfbeb746 | 46 | |
tobyspark | 13:3796bde6ba8f | 47 | bool load(string filename) |
tobyspark | 11:0783cfbeb746 | 48 | { |
tobyspark | 11:0783cfbeb746 | 49 | bool success = false; |
tobyspark | 13:3796bde6ba8f | 50 | |
tobyspark | 13:3796bde6ba8f | 51 | local = new LocalFileSystem("local"); |
tobyspark | 13:3796bde6ba8f | 52 | string filePath("/local/"); |
tobyspark | 13:3796bde6ba8f | 53 | filePath += filename; |
tobyspark | 13:3796bde6ba8f | 54 | |
tobyspark | 13:3796bde6ba8f | 55 | dictionary* settings = iniparser_load(filePath.c_str()); |
tobyspark | 13:3796bde6ba8f | 56 | |
tobyspark | 13:3796bde6ba8f | 57 | // KEYER |
tobyspark | 13:3796bde6ba8f | 58 | { |
tobyspark | 13:3796bde6ba8f | 59 | int counter = 1; |
tobyspark | 13:3796bde6ba8f | 60 | |
tobyspark | 13:3796bde6ba8f | 61 | bool keyParamReadOK = true; |
tobyspark | 13:3796bde6ba8f | 62 | bool keyParamCleared = false; |
tobyspark | 13:3796bde6ba8f | 63 | |
tobyspark | 13:3796bde6ba8f | 64 | char* failString = "Failed to read"; |
tobyspark | 13:3796bde6ba8f | 65 | int failInt = -1; |
tobyspark | 13:3796bde6ba8f | 66 | |
tobyspark | 13:3796bde6ba8f | 67 | // Loop through [Key1,2,...,99] sections |
tobyspark | 13:3796bde6ba8f | 68 | while(keyParamReadOK) |
tobyspark | 13:3796bde6ba8f | 69 | { |
tobyspark | 13:3796bde6ba8f | 70 | int paramSet[6]; |
tobyspark | 13:3796bde6ba8f | 71 | char* paramName; |
tobyspark | 13:3796bde6ba8f | 72 | |
tobyspark | 13:3796bde6ba8f | 73 | char key[11]; |
tobyspark | 11:0783cfbeb746 | 74 | |
tobyspark | 13:3796bde6ba8f | 75 | sprintf(key, "Key%i:Name", counter); |
tobyspark | 13:3796bde6ba8f | 76 | paramName = iniparser_getstring(settings, key, failString); |
tobyspark | 13:3796bde6ba8f | 77 | keyParamReadOK = keyParamReadOK && strcmp(paramName, failString); |
tobyspark | 13:3796bde6ba8f | 78 | |
tobyspark | 13:3796bde6ba8f | 79 | sprintf(key, "Key%i:MinY", counter); |
tobyspark | 13:3796bde6ba8f | 80 | paramSet[0] = iniparser_getint(settings, key, failInt); |
tobyspark | 13:3796bde6ba8f | 81 | keyParamReadOK = keyParamReadOK && (paramSet[0] != failInt); |
tobyspark | 13:3796bde6ba8f | 82 | |
tobyspark | 13:3796bde6ba8f | 83 | sprintf(key, "Key%i:MaxY", counter); |
tobyspark | 13:3796bde6ba8f | 84 | paramSet[1] = iniparser_getint(settings, key, failInt); |
tobyspark | 13:3796bde6ba8f | 85 | keyParamReadOK = keyParamReadOK && (paramSet[1] != failInt); |
tobyspark | 13:3796bde6ba8f | 86 | |
tobyspark | 13:3796bde6ba8f | 87 | sprintf(key, "Key%i:MinU", counter); |
tobyspark | 13:3796bde6ba8f | 88 | paramSet[2] = iniparser_getint(settings, key, failInt); |
tobyspark | 13:3796bde6ba8f | 89 | keyParamReadOK = keyParamReadOK && (paramSet[2] != failInt); |
tobyspark | 13:3796bde6ba8f | 90 | |
tobyspark | 13:3796bde6ba8f | 91 | sprintf(key, "Key%i:MaxU", counter); |
tobyspark | 13:3796bde6ba8f | 92 | paramSet[3] = iniparser_getint(settings, key, failInt); |
tobyspark | 13:3796bde6ba8f | 93 | keyParamReadOK = keyParamReadOK && (paramSet[3] != failInt); |
tobyspark | 13:3796bde6ba8f | 94 | |
tobyspark | 13:3796bde6ba8f | 95 | sprintf(key, "Key%i:MinV", counter); |
tobyspark | 13:3796bde6ba8f | 96 | paramSet[4] = iniparser_getint(settings, key, failInt); |
tobyspark | 13:3796bde6ba8f | 97 | keyParamReadOK = keyParamReadOK && (paramSet[4] != failInt); |
tobyspark | 13:3796bde6ba8f | 98 | |
tobyspark | 13:3796bde6ba8f | 99 | sprintf(key, "Key%i:MaxV", counter); |
tobyspark | 13:3796bde6ba8f | 100 | paramSet[5] = iniparser_getint(settings, key, failInt); |
tobyspark | 13:3796bde6ba8f | 101 | keyParamReadOK = keyParamReadOK && (paramSet[5] != failInt); |
tobyspark | 13:3796bde6ba8f | 102 | |
tobyspark | 13:3796bde6ba8f | 103 | // If all parameters have been read successfully |
tobyspark | 13:3796bde6ba8f | 104 | if (keyParamReadOK) |
tobyspark | 13:3796bde6ba8f | 105 | { |
tobyspark | 13:3796bde6ba8f | 106 | |
tobyspark | 13:3796bde6ba8f | 107 | // If this is the first time through, clear old values |
tobyspark | 13:3796bde6ba8f | 108 | if (!keyParamCleared) |
tobyspark | 13:3796bde6ba8f | 109 | { |
tobyspark | 13:3796bde6ba8f | 110 | keyerParamNames.clear(); |
tobyspark | 13:3796bde6ba8f | 111 | keyerParamSets.clear(); |
tobyspark | 13:3796bde6ba8f | 112 | keyParamCleared = true; |
tobyspark | 13:3796bde6ba8f | 113 | } |
tobyspark | 13:3796bde6ba8f | 114 | |
tobyspark | 13:3796bde6ba8f | 115 | // Apply settings |
tobyspark | 13:3796bde6ba8f | 116 | keyerParamNames.push_back(paramName); |
tobyspark | 13:3796bde6ba8f | 117 | keyerParamSets.push_back(paramSet); |
tobyspark | 13:3796bde6ba8f | 118 | |
tobyspark | 13:3796bde6ba8f | 119 | // We've successfully read a keyer param set, so should return true; |
tobyspark | 13:3796bde6ba8f | 120 | success = true; |
tobyspark | 13:3796bde6ba8f | 121 | } |
tobyspark | 13:3796bde6ba8f | 122 | |
tobyspark | 13:3796bde6ba8f | 123 | counter++; |
tobyspark | 13:3796bde6ba8f | 124 | } |
tobyspark | 13:3796bde6ba8f | 125 | } |
tobyspark | 13:3796bde6ba8f | 126 | |
tobyspark | 13:3796bde6ba8f | 127 | iniparser_freedict(settings); |
tobyspark | 13:3796bde6ba8f | 128 | |
tobyspark | 13:3796bde6ba8f | 129 | delete local; |
tobyspark | 11:0783cfbeb746 | 130 | |
tobyspark | 11:0783cfbeb746 | 131 | return success; |
tobyspark | 11:0783cfbeb746 | 132 | } |
tobyspark | 11:0783cfbeb746 | 133 | |
tobyspark | 11:0783cfbeb746 | 134 | protected: |
tobyspark | 11:0783cfbeb746 | 135 | LocalFileSystem *local; |
tobyspark | 13:3796bde6ba8f | 136 | vector<int*> keyerParamSets; |
tobyspark | 13:3796bde6ba8f | 137 | vector<string> keyerParamNames; |
tobyspark | 11:0783cfbeb746 | 138 | }; |