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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spk_settings.h Source File

spk_settings.h

00001 #include "mbed.h"
00002 #include "ipaddr.h"
00003 #include <string>
00004 #include <vector>
00005 
00006 extern "C" 
00007 {
00008 #include "iniparser.h"
00009 }
00010 
00011 class SPKSettings {
00012 public:
00013     enum keyerParameterType {minY = 0, maxY, minU, maxU, minV, maxV};
00014 
00015     int editingKeyerSetIndex;
00016     
00017     struct {
00018         bool DHCP;
00019         IpAddr controllerAddress;
00020         int controllerPort;
00021         IpAddr controllerSubnetMask;
00022         IpAddr controllerGateway;
00023         IpAddr controllerDNS;
00024         
00025         IpAddr sendAddress;
00026         int sendPort;
00027     } osc;
00028     
00029     struct {
00030         IpAddr controllerAddress;
00031         IpAddr broadcastAddress;
00032         int universe;
00033     } artNet;
00034     
00035     struct {
00036         int inChannelXFade;
00037         int inChannelFadeUp;
00038         int outChannelXFade;
00039         int outChannelFadeUp;
00040     } dmx;
00041     
00042     SPKSettings()
00043     {
00044         editingKeyerSetIndex = -1;
00045         loadDefaults();
00046     }
00047     
00048     void loadDefaults()
00049     {
00050         // NETWORK
00051         
00052         osc.DHCP = false;
00053         osc.controllerAddress = IpAddr(10,0,0,2);
00054         osc.controllerPort = 10000;
00055         osc.controllerSubnetMask = IpAddr(255,255,255,0);
00056         osc.controllerGateway = IpAddr(10,0,0,1);
00057         osc.controllerDNS = IpAddr(10,0,0,1);
00058         
00059         osc.sendAddress = IpAddr(255,255,255,255);
00060         osc.sendPort = 10000;
00061         
00062         artNet.controllerAddress = IpAddr(2,0,0,100);
00063         artNet.broadcastAddress = IpAddr(2,255,255,255);
00064         artNet.universe = 0;
00065         
00066         dmx.inChannelXFade = 0;
00067         dmx.inChannelFadeUp = 1;
00068         dmx.outChannelXFade = 0;
00069         dmx.outChannelFadeUp = 1;
00070     
00071         //// KEYS
00072         
00073         keyerParamNames.clear();
00074         keyerParamSets.clear();
00075         vector<int> paramSet(6);
00076         
00077         paramSet[minY] = 0;
00078         paramSet[maxY] = 18;
00079         paramSet[minU] = 128;
00080         paramSet[maxU] = 129;
00081         paramSet[minV] = 128;
00082         paramSet[maxV] = 129;
00083         keyerParamSets.push_back(paramSet);
00084         keyerParamNames.push_back("Key - Current");
00085         
00086         paramSet[minY] = 0;
00087         paramSet[maxY] = 18;
00088         paramSet[minU] = 128;
00089         paramSet[maxU] = 129;
00090         paramSet[minV] = 128;
00091         paramSet[maxV] = 129;
00092         keyerParamSets.push_back(paramSet);
00093         keyerParamNames.push_back("Lumakey");
00094         
00095         paramSet[minY] = 30;
00096         paramSet[maxY] = 35;
00097         paramSet[minU] = 237;
00098         paramSet[maxU] = 242;
00099         paramSet[minV] = 114;
00100         paramSet[maxV] = 121;
00101         keyerParamSets.push_back(paramSet);
00102         keyerParamNames.push_back("Chromakey - Blue");
00103         
00104         //// RESOLUTIONS
00105         
00106         resolutionNames.clear();
00107         resolutionIndexes.clear();
00108         resolutionEDIDIndexes.clear();
00109         
00110         resolutionNames.push_back(kTV1ResolutionDescriptionVGA);
00111         resolutionIndexes.push_back(kTV1ResolutionVGA);
00112         resolutionEDIDIndexes.push_back(6);
00113     
00114         resolutionNames.push_back(kTV1ResolutionDescriptionSVGA);
00115         resolutionIndexes.push_back(kTV1ResolutionSVGA);
00116         resolutionEDIDIndexes.push_back(6);
00117         
00118         resolutionNames.push_back(kTV1ResolutionDescriptionXGAp60);
00119         resolutionIndexes.push_back(kTV1ResolutionXGAp60);
00120         resolutionEDIDIndexes.push_back(6);
00121         
00122         resolutionNames.push_back(kTV1ResolutionDescriptionWSXGAPLUSp60);
00123         resolutionIndexes.push_back(kTV1ResolutionWSXGAPLUSp60);
00124         resolutionEDIDIndexes.push_back(6);
00125         
00126         resolutionNames.push_back(kTV1ResolutionDescriptionWUXGAp60);
00127         resolutionIndexes.push_back(kTV1ResolutionWUXGAp60);
00128         resolutionEDIDIndexes.push_back(6);
00129         
00130         resolutionNames.push_back(kTV1ResolutionDescription720p60);
00131         resolutionIndexes.push_back(kTV1Resolution720p60);
00132         resolutionEDIDIndexes.push_back(5);
00133         
00134         resolutionNames.push_back(kTV1ResolutionDescription1080p60);
00135         resolutionIndexes.push_back(kTV1Resolution1080p60);
00136         resolutionEDIDIndexes.push_back(5);
00137         
00138         resolutionNames.push_back(kTV1ResolutionDescriptionDualHeadSVGAp60);
00139         resolutionIndexes.push_back(kTV1ResolutionDualHeadSVGAp60);
00140         resolutionEDIDIndexes.push_back(4);
00141         
00142         resolutionNames.push_back(kTV1ResolutionDescriptionDualHeadXGAp60);
00143         resolutionIndexes.push_back(kTV1ResolutionDualHeadXGAp60);
00144         resolutionEDIDIndexes.push_back(4);
00145         
00146         resolutionNames.push_back(kTV1ResolutionDescriptionTripleHeadVGAp60);
00147         resolutionIndexes.push_back(kTV1ResolutionTripleHeadVGAp60);
00148         resolutionEDIDIndexes.push_back(4);   
00149     }
00150     
00151     string keyerParamName (int index)
00152     {
00153         // TODO: Bounds check and return out of bounds name
00154         return keyerParamNames[index];
00155     }
00156      
00157     vector<int>        keyerParamSet(int index)
00158     {
00159         return keyerParamSets[index];
00160     }
00161     
00162     int         keyerSetCount()
00163     {
00164         return keyerParamSets.size();
00165     }
00166     
00167     int editingKeyerSetValue(keyerParameterType parameter)
00168     {
00169         int value = -1;
00170         if (editingKeyerSetIndex >= 0 && editingKeyerSetIndex < keyerSetCount())
00171         {
00172             value = keyerParamSets[editingKeyerSetIndex][parameter];
00173         }
00174         return value;
00175     }
00176     
00177     void setEditingKeyerSetValue(keyerParameterType parameter, int value)
00178     {
00179         if (editingKeyerSetIndex >= 0 && editingKeyerSetIndex < keyerSetCount())
00180         {
00181             keyerParamSets[editingKeyerSetIndex][parameter] = value;
00182         }
00183     }
00184     
00185     string resolutionName (int index)
00186     {
00187         // TODO: Bounds check and return out of bounds name
00188         return resolutionNames[index];
00189     }
00190      
00191     int32_t     resolutionIndex(int index)
00192     {
00193         return resolutionIndexes[index];
00194     }
00195     
00196     int32_t     resolutionEDIDIndex(int index)
00197     {
00198         return resolutionEDIDIndexes[index];
00199     }
00200     
00201     int         resolutionsCount()
00202     {
00203         return resolutionNames.size();
00204     }
00205     
00206     bool        load(string filename)
00207     {
00208         bool success = false;
00209 
00210         local = new LocalFileSystem("local");
00211         string filePath("/local/");
00212         filePath += filename;
00213 
00214         char* const failString = "Failed to read";
00215         const int failInt = -1;
00216 
00217         dictionary* settings = iniparser_load(filePath.c_str());
00218         
00219         // NETWORK
00220         {
00221             bool netReadOK = true;
00222         
00223             int DHCP = iniparser_getboolean(settings, "OSC:DHCP", failInt);
00224             netReadOK = netReadOK && DHCP != failInt;
00225             
00226             IpAddr controllerAddress = ipAddrWithString(iniparser_getstring(settings, "OSC:ControllerAddress", failString));
00227             netReadOK = netReadOK && !controllerAddress.isNull();
00228             
00229             int controllerPort = iniparser_getint(settings, "OSC:ControllerPort", failInt);
00230             netReadOK = netReadOK && controllerPort != failInt;
00231             
00232             IpAddr controllerSubnetMask = ipAddrWithString(iniparser_getstring(settings, "OSC:ControllerSubnetMask", failString));
00233             netReadOK = netReadOK && !controllerSubnetMask.isNull();
00234             
00235             IpAddr controllerGateway = ipAddrWithString(iniparser_getstring(settings, "OSC:ControllerGateway", failString));
00236             netReadOK = netReadOK && !controllerGateway.isNull();
00237             
00238             IpAddr controllerDNS = ipAddrWithString(iniparser_getstring(settings, "OSC:ControllerDNS", failString));
00239             netReadOK = netReadOK && !controllerDNS.isNull();
00240         
00241             IpAddr sendAddress = ipAddrWithString(iniparser_getstring(settings, "OSC:SendAddress", failString));
00242             netReadOK = netReadOK && !sendAddress.isNull();
00243             
00244             int sendPort = iniparser_getint(settings, "OSC:SendPort", failInt);
00245             netReadOK = netReadOK && sendPort != failInt;
00246          
00247             IpAddr artNetControllerAddress = ipAddrWithString(iniparser_getstring(settings, "ArtNet:ControllerAddress", failString));
00248             netReadOK = netReadOK && !artNetControllerAddress.isNull();
00249             
00250             IpAddr artNetBroadcastAddress = ipAddrWithString(iniparser_getstring(settings, "ArtNet:BroadcastAddress", failString));
00251             netReadOK = netReadOK && !artNetBroadcastAddress.isNull();
00252             
00253             int universe = iniparser_getint(settings, "ArtNet:Universe", failInt);
00254             netReadOK = netReadOK && universe != failInt;
00255             
00256             int inChannelXFade = iniparser_getint(settings, "DMX:InChannelXFade", failInt);
00257             netReadOK = netReadOK && inChannelXFade != failInt;
00258             
00259             int inChannelFadeUp = iniparser_getint(settings, "DMX:InChannelFadeUp", failInt);
00260             netReadOK = netReadOK && inChannelFadeUp != failInt;
00261             
00262             int outChannelXFade = iniparser_getint(settings, "DMX:OutChannelXFade", failInt);
00263             netReadOK = netReadOK && outChannelXFade != failInt;
00264             
00265             int outChannelFadeUp = iniparser_getint(settings, "DMX:OutChannelFadeUp", failInt);
00266             netReadOK = netReadOK && outChannelFadeUp != failInt;
00267             
00268             if (netReadOK)
00269             {
00270                 osc.DHCP = DHCP;
00271                 osc.controllerAddress = controllerAddress;
00272                 osc.controllerPort = controllerPort;
00273                 osc.controllerSubnetMask = controllerSubnetMask;
00274                 osc.controllerGateway = controllerGateway;
00275                 osc.controllerDNS = controllerDNS;
00276         
00277                 osc.sendAddress = sendAddress;
00278                 osc.sendPort = sendPort;
00279     
00280                 artNet.controllerAddress = artNetControllerAddress;
00281                 artNet.broadcastAddress = artNetBroadcastAddress;
00282                 artNet.universe = universe;
00283         
00284                 dmx.inChannelXFade = inChannelXFade;
00285                 dmx.inChannelFadeUp = inChannelFadeUp;
00286                 dmx.outChannelXFade = outChannelXFade;
00287                 dmx.outChannelFadeUp = outChannelFadeUp;
00288                 
00289                 success = true;
00290             }
00291         }
00292             
00293         // KEYER
00294         {
00295             int counter = 1;
00296             
00297             bool keyParamReadOK = true;
00298             bool keyParamCleared = false;
00299 
00300             const int stringLength = 11;
00301             
00302             // Loop through [Key1,2,...,99] sections
00303             while(keyParamReadOK)
00304             {
00305                 vector<int> paramSet(6);
00306                 char*       paramName;
00307                 
00308                 char key[stringLength];
00309         
00310                 snprintf(key, stringLength, "Key%i:Name", counter);
00311                 paramName = iniparser_getstring(settings, key, failString);
00312                 keyParamReadOK = keyParamReadOK && strcmp(paramName, failString);
00313                        
00314                 snprintf(key, stringLength, "Key%i:MinY", counter);
00315                 paramSet[minY] = iniparser_getint(settings, key, failInt);
00316                 keyParamReadOK = keyParamReadOK && (paramSet[minY] != failInt);
00317 
00318                 snprintf(key, stringLength, "Key%i:MaxY", counter);
00319                 paramSet[maxY] = iniparser_getint(settings, key, failInt);
00320                 keyParamReadOK = keyParamReadOK && (paramSet[maxY] != failInt);
00321                 
00322                 snprintf(key, stringLength, "Key%i:MinU", counter);
00323                 paramSet[minU] = iniparser_getint(settings, key, failInt);
00324                 keyParamReadOK = keyParamReadOK && (paramSet[minU] != failInt);
00325                 
00326                 snprintf(key, stringLength, "Key%i:MaxU", counter);
00327                 paramSet[maxU] = iniparser_getint(settings, key, failInt);
00328                 keyParamReadOK = keyParamReadOK && (paramSet[maxU] != failInt);
00329                 
00330                 snprintf(key, stringLength, "Key%i:MinV", counter);
00331                 paramSet[minV] = iniparser_getint(settings, key, failInt);
00332                 keyParamReadOK = keyParamReadOK && (paramSet[minV] != failInt);
00333                 
00334                 snprintf(key, stringLength, "Key%i:MaxV", counter);
00335                 paramSet[maxV] = iniparser_getint(settings, key, failInt);
00336                 keyParamReadOK = keyParamReadOK && (paramSet[maxV] != failInt);
00337                 
00338                 // If all parameters have been read successfully
00339                 if (keyParamReadOK)
00340                 {
00341 
00342                     // If this is the first time through, clear old values
00343                     if (!keyParamCleared)
00344                     {
00345                         keyerParamNames.clear();
00346                         keyerParamSets.clear();
00347                         keyParamCleared = true;
00348                         
00349                         vector<int> paramSet(6);
00350                         paramSet[minY] = 0;
00351                         paramSet[maxY] = 18;
00352                         paramSet[minU] = 128;
00353                         paramSet[maxU] = 129;
00354                         paramSet[minV] = 128;
00355                         paramSet[maxV] = 129;
00356                         keyerParamSets.push_back(paramSet);
00357                         keyerParamNames.push_back("Key - Current");
00358                     }
00359                 
00360                     // Apply settings
00361                     keyerParamNames.push_back(paramName);
00362                     keyerParamSets.push_back(paramSet);
00363                     
00364                     // We've successfully read a keyer param set, so should return true;
00365                     success = true;  
00366                 }
00367                 
00368                 counter++;
00369             }
00370         }        
00371 
00372         // RESOLUTIONS
00373         {
00374             int counter = 1;
00375             
00376             bool resolutionReadOK = true;
00377             bool resolutionCleared = false;
00378             
00379             const int stringLength = 25;
00380             
00381             // Loop through [Key1,2,...,99] sections
00382             while(resolutionReadOK)
00383             {
00384                 char*   resolutionName;
00385                 int     resolutionIndex;
00386                 int     resolutionEDIDIndex;
00387                 
00388                 char key[stringLength];
00389         
00390                 snprintf(key, stringLength, "Resolution%i:Name", counter);
00391                 resolutionName = iniparser_getstring(settings, key, failString);
00392                 resolutionReadOK = resolutionReadOK && strcmp(resolutionName, failString);
00393                        
00394                 snprintf(key, stringLength, "Resolution%i:Number", counter);
00395                 resolutionIndex = iniparser_getint(settings, key, failInt);
00396                 resolutionReadOK = resolutionReadOK && (resolutionIndex != failInt);
00397 
00398                 snprintf(key, stringLength, "Resolution%i:EDIDNumber", counter);
00399                 resolutionEDIDIndex = iniparser_getint(settings, key, failInt);
00400                 resolutionReadOK = resolutionReadOK && (resolutionEDIDIndex != failInt);
00401                 
00402                 // If all parameters have been read successfully
00403                 if (resolutionReadOK)
00404                 {
00405                     // If this is the first time through, clear old values
00406                     if (!resolutionCleared)
00407                     {
00408                         resolutionNames.clear();
00409                         resolutionIndexes.clear();
00410                         resolutionEDIDIndexes.clear();
00411                         resolutionCleared = true;
00412                     }
00413                 
00414                     // Apply settings
00415                     resolutionNames.push_back(resolutionName);
00416                     resolutionIndexes.push_back(resolutionIndex);
00417                     resolutionEDIDIndexes.push_back(resolutionEDIDIndex);
00418                     
00419                     // We've successfully read a resolution, so should return true;
00420                     success = true;
00421                 }
00422                 
00423                 counter++;
00424             }
00425         }
00426 
00427         iniparser_freedict(settings);
00428         
00429         delete local;
00430         
00431         return success;
00432     }
00433     
00434 protected:
00435     LocalFileSystem *local;
00436     vector< vector<int> >   keyerParamSets;
00437     vector<string>          keyerParamNames;
00438     vector<string>          resolutionNames;
00439     vector<int32_t>         resolutionIndexes;
00440     vector<int32_t>         resolutionEDIDIndexes;
00441     
00442     IpAddr ipAddrWithString(const char* ipAsString)
00443     {
00444         int ip0, ip1, ip2, ip3;
00445         
00446         int parsedNum = sscanf(ipAsString, "%u.%u.%u.%u", &ip0, &ip1, &ip2, &ip3);
00447         
00448         if (parsedNum == 4)
00449         {
00450             return IpAddr(ip0, ip1, ip2, ip3);
00451         }
00452         
00453         return IpAddr();    
00454     }
00455 };