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 Dec 02 16:13:31 2012 +0000
Revision:
43:328d851c429a
Parent:
41:00d1cd3b2af2
Code to save keyer parameter changes back to .ini. However iniparser hangs on reading the ini despite this part of save code being identical to load code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 8:d46cc49f0f37 1 /* *SPARK D-FUSER
tobyspark 8:d46cc49f0f37 2 * A project by Toby Harris
tobyspark 8:d46cc49f0f37 3 *
tobyspark 8:d46cc49f0f37 4 * 'DJ' controller styke RS232 Control for TV-One products
tobyspark 8:d46cc49f0f37 5 * Good for 1T-C2-750, others will need some extra work
tobyspark 8:d46cc49f0f37 6 *
tobyspark 8:d46cc49f0f37 7 * www.sparkav.co.uk/dvimixer
tobyspark 8:d46cc49f0f37 8 */
tobyspark 0:87aab40d5806 9
tobyspark 8:d46cc49f0f37 10 /* Copyright (c) 2011 Toby Harris, MIT License
tobyspark 8:d46cc49f0f37 11 *
tobyspark 8:d46cc49f0f37 12 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tobyspark 8:d46cc49f0f37 13 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tobyspark 8:d46cc49f0f37 14 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tobyspark 8:d46cc49f0f37 15 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tobyspark 8:d46cc49f0f37 16 * furnished to do so, subject to the following conditions:
tobyspark 8:d46cc49f0f37 17 *
tobyspark 8:d46cc49f0f37 18 * The above copyright notice and this permission notice shall be included in all copies or
tobyspark 8:d46cc49f0f37 19 * substantial portions of the Software.
tobyspark 8:d46cc49f0f37 20 *
tobyspark 8:d46cc49f0f37 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tobyspark 8:d46cc49f0f37 22 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tobyspark 8:d46cc49f0f37 23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tobyspark 8:d46cc49f0f37 24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tobyspark 8:d46cc49f0f37 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tobyspark 8:d46cc49f0f37 26 */
tobyspark 8:d46cc49f0f37 27
tobyspark 8:d46cc49f0f37 28 /* ROADMAP / HISTORY
tobyspark 8:d46cc49f0f37 29 * v10 - Port to mBed, keying redux - Apr'11
tobyspark 8:d46cc49f0f37 30 * v11 - Sign callbacks, code clean-up - Apr'11
tobyspark 8:d46cc49f0f37 31 * v12 - TVOne header split into two: defines and mbed class. v002 header updates pulled down. Removed sign callbacks, rewrite of debug and signing. - Apr'11
tobyspark 8:d46cc49f0f37 32 * v13 - Menu system for Resolution + Keying implemented, it writing to debug, it sending TVOne commands - Apr'11
tobyspark 8:d46cc49f0f37 33 * v14 - Fixes for new PCB - Oct'11
tobyspark 8:d46cc49f0f37 34 * v15 - TBZ PCB, OLED - Mar'12
tobyspark 8:d46cc49f0f37 35 * v16 - Comms menu, OSC, ArtNet - April'12
tobyspark 8:d46cc49f0f37 36 * v17 - RJ45 - May'12
tobyspark 8:d46cc49f0f37 37 * v18 - DMX - July'12
tobyspark 13:3796bde6ba8f 38 * v19 - TVOne mixing comms further optimised - August'12
tobyspark 30:873979018850 39 * v20 - Keying values and resolutions load from USB mass storage - September'12
tobyspark 30:873979018850 40 * v21 - Mixing behaviour upgrade: blend-additive as continuum, test cards on startup if no valid source - October'12
tobyspark 35:d5d9f0838f99 41 * v22 - EDID passthrough override and EDID upload from USB mass storage
tobyspark 36:8b5c75c8bc23 42 * v23 - Set keying values from controller, requires a guided, step-through process for user
tobyspark 36:8b5c75c8bc23 43 * vxx - TODO: Writes back to .ini on USB mass storage: keyer updates, comms, hdcp, edid internal/passthrough, ...?
tobyspark 8:d46cc49f0f37 44 * vxx - TODO: EDID creation from resolution
tobyspark 8:d46cc49f0f37 45 */
tobyspark 8:d46cc49f0f37 46
tobyspark 0:87aab40d5806 47 #include "mbed.h"
tobyspark 0:87aab40d5806 48
tobyspark 0:87aab40d5806 49 #include "spk_tvone_mbed.h"
tobyspark 0:87aab40d5806 50 #include "spk_utils.h"
tobyspark 0:87aab40d5806 51 #include "spk_mRotaryEncoder.h"
tobyspark 0:87aab40d5806 52 #include "spk_oled_ssd1305.h"
tobyspark 2:50043054e4f7 53 #include "spk_oled_gfx.h"
tobyspark 11:0783cfbeb746 54 #include "spk_settings.h"
tobyspark 1:f9fca21102e0 55 #include "EthernetNetIf.h"
tobyspark 1:f9fca21102e0 56 #include "mbedOSC.h"
tobyspark 3:033d2b7768f3 57 #include "DmxArtNet.h"
tobyspark 5:f8b285ca41ba 58 #include "DMX.h"
tobyspark 17:fc68d40b8b1f 59 #include "filter.h"
tobyspark 0:87aab40d5806 60
tobyspark 41:00d1cd3b2af2 61 #define kSPKDFSoftwareVersion "24"
tobyspark 13:3796bde6ba8f 62
tobyspark 5:f8b285ca41ba 63 // MBED PINS
tobyspark 5:f8b285ca41ba 64
tobyspark 5:f8b285ca41ba 65 #define kMBED_AIN_XFADE p20
tobyspark 5:f8b285ca41ba 66 #define kMBED_AIN_FADEUP p19
tobyspark 5:f8b285ca41ba 67 #define kMBED_DIN_TAP_L p24
tobyspark 5:f8b285ca41ba 68 #define kMBED_DIN_TAP_R p23
tobyspark 5:f8b285ca41ba 69 #define kMBED_ENC_SW p15
tobyspark 5:f8b285ca41ba 70 #define kMBED_ENC_A p16
tobyspark 5:f8b285ca41ba 71 #define kMBED_ENC_B p17
tobyspark 5:f8b285ca41ba 72
tobyspark 5:f8b285ca41ba 73 #define kMBED_RS232_TTLTX p13
tobyspark 5:f8b285ca41ba 74 #define kMBED_RS232_TTLRX p14
tobyspark 5:f8b285ca41ba 75
tobyspark 5:f8b285ca41ba 76 #define kMBED_OLED_MOSI p5
tobyspark 5:f8b285ca41ba 77 #define kMBED_OLED_SCK p7
tobyspark 5:f8b285ca41ba 78 #define kMBED_OLED_CS p8
tobyspark 5:f8b285ca41ba 79 #define kMBED_OLED_RES p9
tobyspark 5:f8b285ca41ba 80 #define kMBED_OLED_DC p10
tobyspark 5:f8b285ca41ba 81
tobyspark 5:f8b285ca41ba 82 #define kMBED_DIN_ETHLO_DMXHI p30
tobyspark 5:f8b285ca41ba 83 #define kMBED_DOUT_RS485_TXHI_RXLO p29
tobyspark 5:f8b285ca41ba 84 #define kMBED_RS485_TTLTX p28
tobyspark 5:f8b285ca41ba 85 #define kMBED_RS485_TTLRX p27
tobyspark 5:f8b285ca41ba 86
tobyspark 5:f8b285ca41ba 87 // DISPLAY
tobyspark 5:f8b285ca41ba 88
tobyspark 1:f9fca21102e0 89 #define kMenuLine1 3
tobyspark 1:f9fca21102e0 90 #define kMenuLine2 4
tobyspark 1:f9fca21102e0 91 #define kCommsStatusLine 6
tobyspark 1:f9fca21102e0 92 #define kTVOneStatusLine 7
tobyspark 1:f9fca21102e0 93
tobyspark 5:f8b285ca41ba 94 // NETWORKING
tobyspark 5:f8b285ca41ba 95
tobyspark 1:f9fca21102e0 96 #define kOSCMbedPort 10000
tobyspark 1:f9fca21102e0 97 #define kOSCMbedIPAddress 10,0,0,2
tobyspark 1:f9fca21102e0 98 #define kOSCMbedSubnetMask 255,255,255,0
tobyspark 1:f9fca21102e0 99 #define kOSCMbedGateway 10,0,0,1
tobyspark 1:f9fca21102e0 100 #define kOSCMbedDNS 10,0,0,1
tobyspark 0:87aab40d5806 101
tobyspark 3:033d2b7768f3 102 #define kArtNetBindIPAddress 2,0,0,100
tobyspark 3:033d2b7768f3 103 #define kArtNetBroadcastAddress 2,255,255,255
tobyspark 3:033d2b7768f3 104
tobyspark 5:f8b285ca41ba 105 #define kDMXInChannelXFade 0
tobyspark 5:f8b285ca41ba 106 #define kDMXInChannelFadeUp 1
tobyspark 5:f8b285ca41ba 107 #define kDMXOutChannelXFade 0
tobyspark 5:f8b285ca41ba 108 #define kDMXOutChannelFadeUp 1
tobyspark 5:f8b285ca41ba 109
tobyspark 13:3796bde6ba8f 110 // 8.3 format filename only, no subdirs
tobyspark 13:3796bde6ba8f 111 #define kSPKDFSettingsFilename "SPKDF.ini"
tobyspark 11:0783cfbeb746 112
tobyspark 26:0299f8760715 113 #define kStringBufferLength 30
tobyspark 26:0299f8760715 114
tobyspark 0:87aab40d5806 115 //// DEBUG
tobyspark 0:87aab40d5806 116
tobyspark 0:87aab40d5806 117 // Comment out one or the other...
tobyspark 41:00d1cd3b2af2 118 //Serial *debug = new Serial(USBTX, USBRX); // For debugging via USB serial
tobyspark 37:744bef2e8be8 119 Serial *debug = NULL; // For release (no debugging)
tobyspark 0:87aab40d5806 120
tobyspark 15:4b394c64b461 121 //// SOFT RESET
tobyspark 15:4b394c64b461 122
tobyspark 15:4b394c64b461 123 extern "C" void mbed_reset();
tobyspark 15:4b394c64b461 124
tobyspark 0:87aab40d5806 125 //// mBED PIN ASSIGNMENTS
tobyspark 0:87aab40d5806 126
tobyspark 0:87aab40d5806 127 // Inputs
tobyspark 5:f8b285ca41ba 128 AnalogIn xFadeAIN(kMBED_AIN_XFADE);
tobyspark 5:f8b285ca41ba 129 AnalogIn fadeUpAIN(kMBED_AIN_FADEUP);
tobyspark 5:f8b285ca41ba 130 DigitalIn tapLeftDIN(kMBED_DIN_TAP_L);
tobyspark 5:f8b285ca41ba 131 DigitalIn tapRightDIN(kMBED_DIN_TAP_R);
tobyspark 17:fc68d40b8b1f 132 medianFilter xFadeFilter(9);
tobyspark 17:fc68d40b8b1f 133 medianFilter fadeUpFilter(9);
tobyspark 0:87aab40d5806 134
tobyspark 5:f8b285ca41ba 135 SPKRotaryEncoder menuEnc(kMBED_ENC_A, kMBED_ENC_B, kMBED_ENC_SW);
tobyspark 5:f8b285ca41ba 136
tobyspark 5:f8b285ca41ba 137 DigitalIn rj45ModeDIN(kMBED_DIN_ETHLO_DMXHI);
tobyspark 0:87aab40d5806 138
tobyspark 0:87aab40d5806 139 // Outputs
tobyspark 0:87aab40d5806 140 PwmOut fadeAPO(LED1);
tobyspark 0:87aab40d5806 141 PwmOut fadeBPO(LED2);
tobyspark 0:87aab40d5806 142
tobyspark 5:f8b285ca41ba 143 DigitalOut dmxDirectionDOUT(kMBED_DOUT_RS485_TXHI_RXLO);
tobyspark 5:f8b285ca41ba 144
tobyspark 0:87aab40d5806 145 // SPKTVOne(PinName txPin, PinName rxPin, PinName signWritePin, PinName signErrorPin, Serial *debugSerial)
tobyspark 5:f8b285ca41ba 146 SPKTVOne tvOne(kMBED_RS232_TTLTX, kMBED_RS232_TTLRX, LED3, LED4, debug);
tobyspark 0:87aab40d5806 147
tobyspark 0:87aab40d5806 148 // SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL);
tobyspark 5:f8b285ca41ba 149 SPKDisplay screen(kMBED_OLED_MOSI, kMBED_OLED_SCK, kMBED_OLED_CS, kMBED_OLED_DC, kMBED_OLED_RES, debug);
tobyspark 0:87aab40d5806 150
tobyspark 11:0783cfbeb746 151 // Saved Settings
tobyspark 11:0783cfbeb746 152 SPKSettings settings;
tobyspark 11:0783cfbeb746 153
tobyspark 0:87aab40d5806 154 // Menu
tobyspark 0:87aab40d5806 155 SPKMenu *selectedMenu;
tobyspark 23:909928cafb95 156 SPKMenu mainMenu;
tobyspark 23:909928cafb95 157 SPKMenu resolutionMenu;
tobyspark 12:c270870bdd23 158
tobyspark 24:49c6624119ae 159 SPKMenu mixModeMenu;
tobyspark 36:8b5c75c8bc23 160 SPKMenu mixModeAdditiveMenu;
tobyspark 36:8b5c75c8bc23 161 SPKMenu mixModeKeyerMenuUpdate;
tobyspark 36:8b5c75c8bc23 162 SPKMenu mixModeKeyerMenuMinY;
tobyspark 36:8b5c75c8bc23 163 SPKMenu mixModeKeyerMenuMaxY;
tobyspark 36:8b5c75c8bc23 164 SPKMenu mixModeKeyerMenuMinU;
tobyspark 36:8b5c75c8bc23 165 SPKMenu mixModeKeyerMenuMaxU;
tobyspark 36:8b5c75c8bc23 166 SPKMenu mixModeKeyerMenuMinV;
tobyspark 36:8b5c75c8bc23 167 SPKMenu mixModeKeyerMenuMaxV;
tobyspark 36:8b5c75c8bc23 168 enum { mixBlend, mixAdditive, mixKey };
tobyspark 36:8b5c75c8bc23 169 int mixKeyStartIndex = 1; // need this hard coded as mixBlend and mixAdditive are now combined into the same menu item
tobyspark 30:873979018850 170 int mixMode = mixBlend; // Start with safe mix mode, and test to get out of it. Safe mode will work with inputs missing and without hold frames.
tobyspark 29:95a7efe30527 171 float fadeCurve = 0.0f; // 0 = "X", ie. as per blend, 1 = "/\", ie. as per additive <-- pictograms!
tobyspark 22:90054fe6d86c 172
tobyspark 23:909928cafb95 173 SPKMenu commsMenu;
tobyspark 5:f8b285ca41ba 174 enum { commsNone, commsOSC, commsArtNet, commsDMXIn, commsDMXOut};
tobyspark 5:f8b285ca41ba 175 int commsMode = commsNone;
tobyspark 22:90054fe6d86c 176
tobyspark 23:909928cafb95 177 SPKMenu advancedMenu;
tobyspark 41:00d1cd3b2af2 178 enum { advancedHDCPOn, advancedHDCPOff, advancedEDIDPassthrough, advancedEDIDInternal, advancedTestSources, advancedConformProcessor, advancedConformUploadProcessor, advancedLoadDefaults, advancedSetResolutions };
tobyspark 1:f9fca21102e0 179
tobyspark 5:f8b285ca41ba 180 // RJ45 Comms
tobyspark 5:f8b285ca41ba 181 enum { rj45Ethernet = 0, rj45DMX = 1}; // These values from circuit
tobyspark 5:f8b285ca41ba 182 int rj45Mode = -1;
tobyspark 1:f9fca21102e0 183 EthernetNetIf *ethernet = NULL;
tobyspark 1:f9fca21102e0 184 OSCClass *osc = NULL;
tobyspark 33:e6672a9bd571 185 OSCMessage sendMessage;
tobyspark 33:e6672a9bd571 186 OSCMessage receiveMessage;
tobyspark 3:033d2b7768f3 187 DmxArtNet *artNet = NULL;
tobyspark 5:f8b285ca41ba 188 DMX *dmx = NULL;
tobyspark 0:87aab40d5806 189
tobyspark 3:033d2b7768f3 190 // Fade logic constants
tobyspark 0:87aab40d5806 191 const float xFadeTolerance = 0.05;
tobyspark 0:87aab40d5806 192 const float fadeUpTolerance = 0.05;
tobyspark 0:87aab40d5806 193
tobyspark 0:87aab40d5806 194 // A&B Fade as resolved percent
tobyspark 0:87aab40d5806 195 int fadeAPercent = 0;
tobyspark 0:87aab40d5806 196 int fadeBPercent = 0;
tobyspark 17:fc68d40b8b1f 197 int oldFadeAPercent = 0;
tobyspark 17:fc68d40b8b1f 198 int oldFadeBPercent = 0;
tobyspark 0:87aab40d5806 199
tobyspark 0:87aab40d5806 200 // Tap button states
tobyspark 5:f8b285ca41ba 201 bool tapLeftWasFirstPressed = false;
tobyspark 0:87aab40d5806 202
tobyspark 0:87aab40d5806 203 // Key mode parameters
tobyspark 0:87aab40d5806 204 int keyerParamsSet = -1; // last keyParams index uploaded to unit
tobyspark 0:87aab40d5806 205
tobyspark 30:873979018850 206 // TVOne input sources stable flag
tobyspark 34:69dfe64e7e6b 207 bool tvOneRGB1Stable = false;
tobyspark 34:69dfe64e7e6b 208 bool tvOneRGB2Stable = false;
tobyspark 30:873979018850 209
tobyspark 31:01845a2347ff 210 // TVOne behaviour flags
tobyspark 31:01845a2347ff 211 bool tvOneHDCPOn = false;
tobyspark 34:69dfe64e7e6b 212 bool tvOneEDIDPassthrough = false;
tobyspark 31:01845a2347ff 213 const int32_t EDIDPassthroughSlot = 7;
tobyspark 31:01845a2347ff 214
tobyspark 34:69dfe64e7e6b 215
tobyspark 33:e6672a9bd571 216 void processOSCIn(float &xFade, float &fadeUp) {
tobyspark 25:3b519ef70341 217 string statusMessage;
tobyspark 3:033d2b7768f3 218
tobyspark 33:e6672a9bd571 219 if (!strcmp( receiveMessage.getTopAddress() , "dvimxr" ))
tobyspark 3:033d2b7768f3 220 {
tobyspark 25:3b519ef70341 221 statusMessage = "OSC: /dvimxr";
tobyspark 33:e6672a9bd571 222 if (!strcmp( receiveMessage.getSubAddress() , "xFade" ))
tobyspark 25:3b519ef70341 223 {
tobyspark 33:e6672a9bd571 224 if (receiveMessage.getArgNum() == 1)
tobyspark 33:e6672a9bd571 225 if (receiveMessage.getTypeTag(0) == 'f')
tobyspark 25:3b519ef70341 226 {
tobyspark 33:e6672a9bd571 227 xFade = receiveMessage.getArgFloat(0);
tobyspark 25:3b519ef70341 228 char buffer[15];
tobyspark 26:0299f8760715 229 snprintf(buffer, kStringBufferLength, "/xFade %1.2f", xFade);
tobyspark 25:3b519ef70341 230 statusMessage += buffer;
tobyspark 25:3b519ef70341 231 }
tobyspark 25:3b519ef70341 232 }
tobyspark 33:e6672a9bd571 233 else if (!strcmp( receiveMessage.getSubAddress() , "fadeUp" ))
tobyspark 25:3b519ef70341 234 {
tobyspark 33:e6672a9bd571 235 if (receiveMessage.getArgNum() == 1)
tobyspark 33:e6672a9bd571 236 if (receiveMessage.getTypeTag(0) == 'f')
tobyspark 3:033d2b7768f3 237 {
tobyspark 33:e6672a9bd571 238 fadeUp = receiveMessage.getArgFloat(0);
tobyspark 25:3b519ef70341 239 char buffer[15];
tobyspark 26:0299f8760715 240 snprintf(buffer, kStringBufferLength, "/fadeUp %1.2f", fadeUp);
tobyspark 25:3b519ef70341 241 statusMessage += buffer;
tobyspark 3:033d2b7768f3 242 }
tobyspark 25:3b519ef70341 243 }
tobyspark 25:3b519ef70341 244 else
tobyspark 25:3b519ef70341 245 {
tobyspark 33:e6672a9bd571 246 statusMessage += receiveMessage.getSubAddress();
tobyspark 25:3b519ef70341 247 statusMessage += " - Ignoring";
tobyspark 25:3b519ef70341 248 }
tobyspark 3:033d2b7768f3 249 }
tobyspark 3:033d2b7768f3 250 else
tobyspark 3:033d2b7768f3 251 {
tobyspark 25:3b519ef70341 252 statusMessage = "OSC: ";
tobyspark 33:e6672a9bd571 253 statusMessage += receiveMessage.getTopAddress();
tobyspark 25:3b519ef70341 254 statusMessage += " - Ignoring";
tobyspark 3:033d2b7768f3 255 }
tobyspark 3:033d2b7768f3 256
tobyspark 3:033d2b7768f3 257 screen.clearBufferRow(kCommsStatusLine);
tobyspark 25:3b519ef70341 258 screen.textToBuffer(statusMessage, kCommsStatusLine);
tobyspark 33:e6672a9bd571 259
tobyspark 25:3b519ef70341 260 if (debug) debug->printf("%s \r\n", statusMessage.c_str());
tobyspark 3:033d2b7768f3 261
tobyspark 3:033d2b7768f3 262 }
tobyspark 3:033d2b7768f3 263
tobyspark 33:e6672a9bd571 264 void processOSCOut(float &xFade, float &fadeUp)
tobyspark 33:e6672a9bd571 265 {
tobyspark 33:e6672a9bd571 266 char statusMessageBuffer[kStringBufferLength];
tobyspark 33:e6672a9bd571 267
tobyspark 33:e6672a9bd571 268 sendMessage.setAddress("dvimxr", "xFadeFadeUp");
tobyspark 33:e6672a9bd571 269 sendMessage.setArgs("ff", &xFade, &fadeUp);
tobyspark 33:e6672a9bd571 270 osc->sendOsc(&sendMessage);
tobyspark 33:e6672a9bd571 271
tobyspark 33:e6672a9bd571 272 screen.clearBufferRow(kCommsStatusLine);
tobyspark 33:e6672a9bd571 273 snprintf(statusMessageBuffer, kStringBufferLength, "OSC Out: xF %.2f fUp %.2f", xFade, fadeUp);
tobyspark 33:e6672a9bd571 274 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 275
tobyspark 33:e6672a9bd571 276 if (debug) debug->printf(statusMessageBuffer);
tobyspark 33:e6672a9bd571 277 }
tobyspark 33:e6672a9bd571 278
tobyspark 33:e6672a9bd571 279 void processArtNetIn(float &xFade, float &fadeUp)
tobyspark 8:d46cc49f0f37 280 {
tobyspark 3:033d2b7768f3 281 screen.clearBufferRow(kCommsStatusLine);
tobyspark 3:033d2b7768f3 282 screen.textToBuffer("ArtNet activity", kCommsStatusLine);
tobyspark 33:e6672a9bd571 283
tobyspark 3:033d2b7768f3 284 if (debug) debug->printf("ArtNet activity");
tobyspark 3:033d2b7768f3 285 }
tobyspark 0:87aab40d5806 286
tobyspark 33:e6672a9bd571 287 void processArtNetOut(float &xFade, float &fadeUp)
tobyspark 33:e6672a9bd571 288 {
tobyspark 33:e6672a9bd571 289 char statusMessageBuffer[kStringBufferLength];
tobyspark 33:e6672a9bd571 290
tobyspark 33:e6672a9bd571 291 int xFadeDMX = xFade*255;
tobyspark 33:e6672a9bd571 292 int fadeUpDMX = fadeUp*255;
tobyspark 33:e6672a9bd571 293
tobyspark 33:e6672a9bd571 294 // Universe 0, Channel 0 = xFade, Channel 1 = fadeUp
tobyspark 33:e6672a9bd571 295 char dmxData[2] = {xFadeDMX, fadeUpDMX};
tobyspark 33:e6672a9bd571 296 artNet->Send_ArtDmx(0, 0, dmxData, 2);
tobyspark 33:e6672a9bd571 297
tobyspark 33:e6672a9bd571 298 screen.clearBufferRow(kCommsStatusLine);
tobyspark 33:e6672a9bd571 299 snprintf(statusMessageBuffer, kStringBufferLength, "A'Net Out: xF%3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 33:e6672a9bd571 300 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 301
tobyspark 33:e6672a9bd571 302 if (debug) debug->printf(statusMessageBuffer);
tobyspark 33:e6672a9bd571 303 }
tobyspark 33:e6672a9bd571 304
tobyspark 8:d46cc49f0f37 305 void processDMXIn(float &xFade, float &fadeUp)
tobyspark 8:d46cc49f0f37 306 {
tobyspark 26:0299f8760715 307 char statusMessageBuffer[kStringBufferLength];
tobyspark 5:f8b285ca41ba 308
tobyspark 5:f8b285ca41ba 309 int xFadeDMX = dmx->get(kDMXInChannelXFade);
tobyspark 7:e6717468c18d 310 int fadeUpDMX = dmx->get(kDMXInChannelFadeUp);
tobyspark 5:f8b285ca41ba 311
tobyspark 5:f8b285ca41ba 312 xFade = (float)xFadeDMX/255;
tobyspark 5:f8b285ca41ba 313 fadeUp = (float)fadeUpDMX/255;
tobyspark 5:f8b285ca41ba 314
tobyspark 5:f8b285ca41ba 315 screen.clearBufferRow(kCommsStatusLine);
tobyspark 26:0299f8760715 316 snprintf(statusMessageBuffer, kStringBufferLength, "DMX In: xF %3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 25:3b519ef70341 317 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 318
tobyspark 25:3b519ef70341 319 if (debug) debug->printf(statusMessageBuffer);
tobyspark 5:f8b285ca41ba 320 }
tobyspark 5:f8b285ca41ba 321
tobyspark 8:d46cc49f0f37 322 void processDMXOut(float &xFade, float &fadeUp)
tobyspark 8:d46cc49f0f37 323 {
tobyspark 26:0299f8760715 324 char statusMessageBuffer[kStringBufferLength];
tobyspark 5:f8b285ca41ba 325
tobyspark 5:f8b285ca41ba 326 int xFadeDMX = xFade*255;
tobyspark 5:f8b285ca41ba 327 int fadeUpDMX = fadeUp*255;
tobyspark 5:f8b285ca41ba 328
tobyspark 5:f8b285ca41ba 329 dmx->put(kDMXOutChannelXFade, xFadeDMX);
tobyspark 5:f8b285ca41ba 330 dmx->put(kDMXOutChannelFadeUp, fadeUpDMX);
tobyspark 5:f8b285ca41ba 331
tobyspark 5:f8b285ca41ba 332 screen.clearBufferRow(kCommsStatusLine);
tobyspark 26:0299f8760715 333 snprintf(statusMessageBuffer, kStringBufferLength, "DMX Out: xF %3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 25:3b519ef70341 334 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 335
tobyspark 25:3b519ef70341 336 if (debug) debug->printf(statusMessageBuffer);
tobyspark 5:f8b285ca41ba 337 }
tobyspark 0:87aab40d5806 338
tobyspark 8:d46cc49f0f37 339 inline float fadeCalc (const float AIN, const float tolerance)
tobyspark 8:d46cc49f0f37 340 {
tobyspark 0:87aab40d5806 341 float pos ;
tobyspark 0:87aab40d5806 342 if (AIN < tolerance) pos = 0;
tobyspark 0:87aab40d5806 343 else if (AIN > 1.0 - tolerance) pos = 1;
tobyspark 0:87aab40d5806 344 else pos = (AIN - tolerance) / (1 - 2*tolerance);
tobyspark 0:87aab40d5806 345 if (debug && false) debug->printf("fadeCalc in: %f out: %f \r\n", AIN, pos);
tobyspark 0:87aab40d5806 346 return pos;
tobyspark 0:87aab40d5806 347 }
tobyspark 0:87aab40d5806 348
tobyspark 34:69dfe64e7e6b 349 bool handleTVOneSources()
tobyspark 30:873979018850 350 {
tobyspark 30:873979018850 351 bool ok = true;
tobyspark 30:873979018850 352
tobyspark 30:873979018850 353 int32_t payload = 0;
tobyspark 30:873979018850 354
tobyspark 30:873979018850 355 ok = ok && tvOne.readCommand(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceSourceStable, payload);
tobyspark 34:69dfe64e7e6b 356 bool RGB1 = (payload == 1);
tobyspark 30:873979018850 357
tobyspark 30:873979018850 358 ok = ok && tvOne.readCommand(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceSourceStable, payload);
tobyspark 30:873979018850 359 bool RGB2 = (payload == 1);
tobyspark 30:873979018850 360
tobyspark 34:69dfe64e7e6b 361 ok = ok && tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, payload);
tobyspark 34:69dfe64e7e6b 362 int sourceA = payload;
tobyspark 34:69dfe64e7e6b 363
tobyspark 34:69dfe64e7e6b 364 ok = ok && tvOne.readCommand(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, payload);
tobyspark 34:69dfe64e7e6b 365 int sourceB = payload;
tobyspark 34:69dfe64e7e6b 366
tobyspark 34:69dfe64e7e6b 367 if (debug) debug->printf("HandleTVOneSources: RGB1: %i, RGB2: %i, sourceA: %#x, sourceB: %#i \r\n", RGB1, RGB2, sourceA, sourceB);
tobyspark 34:69dfe64e7e6b 368
tobyspark 30:873979018850 369 string tvOneDetectString;
tobyspark 30:873979018850 370 if (!ok)
tobyspark 30:873979018850 371 {
tobyspark 30:873979018850 372 tvOneDetectString = "TVOne: link failed";
tobyspark 30:873979018850 373 }
tobyspark 30:873979018850 374 else if (!RGB1 || !RGB2)
tobyspark 30:873979018850 375 {
tobyspark 30:873979018850 376 if (!RGB1 && !RGB2) tvOneDetectString = "TVOne: no sources";
tobyspark 30:873979018850 377 else if (!RGB1) tvOneDetectString = "TVOne: no right source";
tobyspark 30:873979018850 378 else if (!RGB2) tvOneDetectString = "TVOne: no left source";
tobyspark 30:873979018850 379 }
tobyspark 30:873979018850 380 else
tobyspark 30:873979018850 381 {
tobyspark 30:873979018850 382 tvOneDetectString = "TVOne: OK";
tobyspark 30:873979018850 383 }
tobyspark 30:873979018850 384
tobyspark 34:69dfe64e7e6b 385 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 34:69dfe64e7e6b 386 screen.textToBuffer(tvOneDetectString, kTVOneStatusLine);
tobyspark 34:69dfe64e7e6b 387
tobyspark 34:69dfe64e7e6b 388 // Assign appropriate source depending on whether DVI input is good
tobyspark 34:69dfe64e7e6b 389 // If that assign command completes ok, and the DVI input is good, finally flag the unit has had a live source
tobyspark 34:69dfe64e7e6b 390 // Note any further losses on this input will be handled by the unit holding the last frame, so we don't need to switch back to SIS.
tobyspark 34:69dfe64e7e6b 391 if (ok && !tvOneRGB1Stable)
tobyspark 30:873979018850 392 {
tobyspark 34:69dfe64e7e6b 393 if (RGB1 && (sourceB != kTV1SourceRGB1)) ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB1);
tobyspark 34:69dfe64e7e6b 394 if (!RGB1 && (sourceB != kTV1SourceSIS2)) ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceSIS2); // Wierd: Can't set to SIS1 sometimes.
tobyspark 34:69dfe64e7e6b 395 if (ok && RGB1) tvOneRGB1Stable = true;
tobyspark 30:873979018850 396 }
tobyspark 34:69dfe64e7e6b 397 if (ok && !tvOneRGB2Stable)
tobyspark 34:69dfe64e7e6b 398 {
tobyspark 34:69dfe64e7e6b 399 if (RGB2 && (sourceA != kTV1SourceRGB2)) ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB2);
tobyspark 34:69dfe64e7e6b 400 if (!RGB2 && (sourceA != kTV1SourceSIS2)) ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceSIS2);
tobyspark 34:69dfe64e7e6b 401 if (ok && RGB2) tvOneRGB2Stable = true;
tobyspark 34:69dfe64e7e6b 402 }
tobyspark 30:873979018850 403
tobyspark 30:873979018850 404 return ok;
tobyspark 30:873979018850 405 }
tobyspark 30:873979018850 406
tobyspark 8:d46cc49f0f37 407 bool setKeyParamsTo(int index)
tobyspark 8:d46cc49f0f37 408 {
tobyspark 0:87aab40d5806 409 // Only spend the time uploading six parameters if we need to
tobyspark 0:87aab40d5806 410 // Might want to bounds check here
tobyspark 0:87aab40d5806 411
tobyspark 9:f83eadd8917a 412 bool ok;
tobyspark 0:87aab40d5806 413
tobyspark 0:87aab40d5806 414 if (index != keyerParamsSet)
tobyspark 0:87aab40d5806 415 {
tobyspark 31:01845a2347ff 416 ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, settings.keyerParamSet(index)[SPKSettings::minY]);
tobyspark 31:01845a2347ff 417 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, settings.keyerParamSet(index)[SPKSettings::maxY]);
tobyspark 31:01845a2347ff 418 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, settings.keyerParamSet(index)[SPKSettings::minU]);
tobyspark 31:01845a2347ff 419 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, settings.keyerParamSet(index)[SPKSettings::maxU]);
tobyspark 31:01845a2347ff 420 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, settings.keyerParamSet(index)[SPKSettings::minV]);
tobyspark 31:01845a2347ff 421 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, settings.keyerParamSet(index)[SPKSettings::maxV]);
tobyspark 0:87aab40d5806 422
tobyspark 0:87aab40d5806 423 keyerParamsSet = index;
tobyspark 9:f83eadd8917a 424 }
tobyspark 9:f83eadd8917a 425 else
tobyspark 9:f83eadd8917a 426 {
tobyspark 9:f83eadd8917a 427 ok = true;
tobyspark 9:f83eadd8917a 428 }
tobyspark 0:87aab40d5806 429
tobyspark 0:87aab40d5806 430 return ok;
tobyspark 0:87aab40d5806 431 }
tobyspark 0:87aab40d5806 432
tobyspark 24:49c6624119ae 433 void actionMixMode()
tobyspark 24:49c6624119ae 434 {
tobyspark 31:01845a2347ff 435 if (debug) debug->printf("Changing mix mode \r\n");
tobyspark 31:01845a2347ff 436
tobyspark 24:49c6624119ae 437 bool ok = true;
tobyspark 25:3b519ef70341 438 string sentOK;
tobyspark 26:0299f8760715 439 char sentMSGBuffer[kStringBufferLength];
tobyspark 24:49c6624119ae 440
tobyspark 24:49c6624119ae 441 // Set Keyer
tobyspark 39:7d9a5eef93c9 442 if (mixMode < mixKey)
tobyspark 24:49c6624119ae 443 {
tobyspark 31:01845a2347ff 444 // Set Keyer Off. Quicker to set and fail than to test for on and then turn off
tobyspark 35:d5d9f0838f99 445 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, false);
tobyspark 31:01845a2347ff 446
tobyspark 31:01845a2347ff 447 if (mixMode == mixBlend)
tobyspark 24:49c6624119ae 448 {
tobyspark 31:01845a2347ff 449 // Turn off Additive Mixing on output
tobyspark 31:01845a2347ff 450 ok = tvOne.command(0, kTV1WindowIDA, 0x298, 0);
tobyspark 31:01845a2347ff 451 snprintf(sentMSGBuffer, kStringBufferLength, "Blend");
tobyspark 24:49c6624119ae 452 }
tobyspark 31:01845a2347ff 453 if (mixMode == mixAdditive)
tobyspark 31:01845a2347ff 454 {
tobyspark 31:01845a2347ff 455 // First set B to what you'd expect for additive; it may be left at 100 if optimised blend mixing was previous mixmode.
tobyspark 31:01845a2347ff 456 ok = tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent);
tobyspark 31:01845a2347ff 457 // Then turn on Additive Mixing
tobyspark 31:01845a2347ff 458 ok = ok && tvOne.command(0, kTV1WindowIDA, 0x298, 1);
tobyspark 31:01845a2347ff 459 snprintf(sentMSGBuffer, kStringBufferLength, "Additive");
tobyspark 31:01845a2347ff 460 }
tobyspark 24:49c6624119ae 461 }
tobyspark 24:49c6624119ae 462 else
tobyspark 24:49c6624119ae 463 {
tobyspark 39:7d9a5eef93c9 464 int index = mixModeMenu.selectedIndex() - mixKeyStartIndex;
tobyspark 25:3b519ef70341 465
tobyspark 24:49c6624119ae 466 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, true);
tobyspark 24:49c6624119ae 467 ok = ok && setKeyParamsTo(index);
tobyspark 25:3b519ef70341 468
tobyspark 26:0299f8760715 469 snprintf(sentMSGBuffer, kStringBufferLength, "Keyer On with %i", index);
tobyspark 24:49c6624119ae 470 }
tobyspark 24:49c6624119ae 471
tobyspark 24:49c6624119ae 472 if (ok) sentOK = "Sent:";
tobyspark 24:49c6624119ae 473 else sentOK = "Send Error:";
tobyspark 24:49c6624119ae 474
tobyspark 24:49c6624119ae 475 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 25:3b519ef70341 476 screen.textToBuffer(sentOK + sentMSGBuffer, kTVOneStatusLine);
tobyspark 24:49c6624119ae 477 }
tobyspark 24:49c6624119ae 478
tobyspark 24:49c6624119ae 479
tobyspark 17:fc68d40b8b1f 480 bool conformProcessor()
tobyspark 17:fc68d40b8b1f 481 {
tobyspark 17:fc68d40b8b1f 482 bool ok = true;
tobyspark 17:fc68d40b8b1f 483
tobyspark 17:fc68d40b8b1f 484 int32_t on = 1;
tobyspark 17:fc68d40b8b1f 485 int32_t off = 0;
tobyspark 20:8b92d7922c48 486
tobyspark 20:8b92d7922c48 487 // Independent output
tobyspark 30:873979018850 488 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionMode, 2);
tobyspark 20:8b92d7922c48 489 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputEnable, on);
tobyspark 20:8b92d7922c48 490 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsLockMethod, off);
tobyspark 17:fc68d40b8b1f 491
tobyspark 17:fc68d40b8b1f 492 // Make sure our windows exist
tobyspark 17:fc68d40b8b1f 493 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsEnable, on);
tobyspark 17:fc68d40b8b1f 494 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsEnable, on);
tobyspark 18:ebe5da639a6a 495 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsLayerPriority, 0);
tobyspark 18:ebe5da639a6a 496 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsLayerPriority, 1);
tobyspark 17:fc68d40b8b1f 497
tobyspark 17:fc68d40b8b1f 498 // Assign inputs to windows, so that left on the crossfader is left on the processor viewed from front
tobyspark 17:fc68d40b8b1f 499 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB2);
tobyspark 17:fc68d40b8b1f 500 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB1);
tobyspark 17:fc68d40b8b1f 501
tobyspark 17:fc68d40b8b1f 502 // Set scaling to fit source within output, maintaining aspect ratio
tobyspark 17:fc68d40b8b1f 503 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustWindowsZoomLevel, 100);
tobyspark 17:fc68d40b8b1f 504 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDB, kTV1FunctionAdjustWindowsZoomLevel, 100);
tobyspark 17:fc68d40b8b1f 505 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustWindowsShrinkEnable, off);
tobyspark 17:fc68d40b8b1f 506 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDB, kTV1FunctionAdjustWindowsShrinkEnable, off);
tobyspark 17:fc68d40b8b1f 507 int32_t fit = 1;
tobyspark 17:fc68d40b8b1f 508 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, fit);
tobyspark 17:fc68d40b8b1f 509 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, fit);
tobyspark 38:2701101dcd56 510 int32_t oneToOne = 4;
tobyspark 38:2701101dcd56 511 ok = ok && tvOne.command(kTV1SourceSIS2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, oneToOne);
tobyspark 17:fc68d40b8b1f 512
tobyspark 17:fc68d40b8b1f 513 // On source loss, hold on the last frame received.
tobyspark 17:fc68d40b8b1f 514 int32_t freeze = 1;
tobyspark 17:fc68d40b8b1f 515 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze);
tobyspark 17:fc68d40b8b1f 516 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze);
tobyspark 17:fc68d40b8b1f 517
tobyspark 30:873979018850 518 // Set resolution and fade levels for maximum chance of being seen
tobyspark 31:01845a2347ff 519 int32_t slot = tvOneEDIDPassthrough ? EDIDPassthroughSlot : 5;
tobyspark 30:873979018850 520 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputResolution, kTV1ResolutionVGA);
tobyspark 31:01845a2347ff 521 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 31:01845a2347ff 522 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 30:873979018850 523 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, 100);
tobyspark 30:873979018850 524 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, 100);
tobyspark 30:873979018850 525
tobyspark 40:bfddeb2a7fcf 526 // Set evil, evil HDCP off
tobyspark 40:bfddeb2a7fcf 527 ok = ok && tvOne.setHDCPOn(false);
tobyspark 40:bfddeb2a7fcf 528
tobyspark 41:00d1cd3b2af2 529 // Save current state in preset one
tobyspark 41:00d1cd3b2af2 530 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionPreset, 1); // Set Preset 1
tobyspark 41:00d1cd3b2af2 531 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionPresetStore, 1); // Store
tobyspark 41:00d1cd3b2af2 532
tobyspark 41:00d1cd3b2af2 533 // Save current state for power on
tobyspark 41:00d1cd3b2af2 534 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 41:00d1cd3b2af2 535
tobyspark 41:00d1cd3b2af2 536 return ok;
tobyspark 41:00d1cd3b2af2 537 }
tobyspark 41:00d1cd3b2af2 538
tobyspark 41:00d1cd3b2af2 539 bool uploadToProcessor()
tobyspark 41:00d1cd3b2af2 540 {
tobyspark 41:00d1cd3b2af2 541 bool ok = true;
tobyspark 41:00d1cd3b2af2 542
tobyspark 41:00d1cd3b2af2 543 LocalFileSystem local("local");
tobyspark 41:00d1cd3b2af2 544 FILE *file;
tobyspark 41:00d1cd3b2af2 545
tobyspark 34:69dfe64e7e6b 546 // Upload Matrox EDID to mem4 (ie. index 3). Use this EDID slot when setting Matrox resolutions.
tobyspark 34:69dfe64e7e6b 547 {
tobyspark 41:00d1cd3b2af2 548 file = fopen("/local/matroxe.did", "r"); // 8.3, avoid .bin as mbed executable extension
tobyspark 35:d5d9f0838f99 549 if (file)
tobyspark 34:69dfe64e7e6b 550 {
tobyspark 41:00d1cd3b2af2 551 ok = ok && tvOne.uploadEDID(file, 3);
tobyspark 35:d5d9f0838f99 552 fclose(file);
tobyspark 34:69dfe64e7e6b 553 }
tobyspark 35:d5d9f0838f99 554 else
tobyspark 35:d5d9f0838f99 555 {
tobyspark 35:d5d9f0838f99 556 if (debug) debug->printf("Could not open Matrox EDID file 'matroxe.did'");
tobyspark 35:d5d9f0838f99 557 }
tobyspark 34:69dfe64e7e6b 558 }
tobyspark 41:00d1cd3b2af2 559
tobyspark 41:00d1cd3b2af2 560 // Upload Logo to SIS2. Use this (minimal) image when no sources are connected.
tobyspark 41:00d1cd3b2af2 561 {
tobyspark 41:00d1cd3b2af2 562 file = fopen("/local/spark.dat", "r"); // 8.3, avoid .bin as mbed executable extension
tobyspark 41:00d1cd3b2af2 563 if (file)
tobyspark 41:00d1cd3b2af2 564 {
tobyspark 41:00d1cd3b2af2 565 ok = ok && tvOne.uploadImage(file, 1);
tobyspark 41:00d1cd3b2af2 566 fclose(file);
tobyspark 41:00d1cd3b2af2 567 }
tobyspark 41:00d1cd3b2af2 568 else
tobyspark 41:00d1cd3b2af2 569 {
tobyspark 41:00d1cd3b2af2 570 if (debug) debug->printf("Could not open image file 'spark.dat'");
tobyspark 41:00d1cd3b2af2 571 }
tobyspark 41:00d1cd3b2af2 572 }
tobyspark 17:fc68d40b8b1f 573
tobyspark 17:fc68d40b8b1f 574 return ok;
tobyspark 17:fc68d40b8b1f 575 }
tobyspark 17:fc68d40b8b1f 576
tobyspark 27:27851d3d2bba 577 void setResolutionMenuItems()
tobyspark 27:27851d3d2bba 578 {
tobyspark 27:27851d3d2bba 579 resolutionMenu.clearMenuItems();
tobyspark 27:27851d3d2bba 580 for (int i=0; i < settings.resolutionsCount(); i++)
tobyspark 27:27851d3d2bba 581 {
tobyspark 27:27851d3d2bba 582 resolutionMenu.addMenuItem(SPKMenuItem(settings.resolutionName(i), settings.resolutionIndex(i), settings.resolutionEDIDIndex(i)));
tobyspark 27:27851d3d2bba 583 }
tobyspark 27:27851d3d2bba 584 resolutionMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 27:27851d3d2bba 585 }
tobyspark 27:27851d3d2bba 586
tobyspark 27:27851d3d2bba 587 void setMixModeMenuItems()
tobyspark 27:27851d3d2bba 588 {
tobyspark 27:27851d3d2bba 589 mixModeMenu.clearMenuItems();
tobyspark 29:95a7efe30527 590 mixModeMenu.addMenuItem(SPKMenuItem("Crossfade", &mixModeAdditiveMenu));
tobyspark 27:27851d3d2bba 591 for (int i=0; i < settings.keyerSetCount(); i++)
tobyspark 27:27851d3d2bba 592 {
tobyspark 36:8b5c75c8bc23 593 mixModeMenu.addMenuItem(SPKMenuItem(settings.keyerParamName(i), &mixModeKeyerMenuUpdate));
tobyspark 27:27851d3d2bba 594 }
tobyspark 27:27851d3d2bba 595 mixModeMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 27:27851d3d2bba 596 }
tobyspark 27:27851d3d2bba 597
tobyspark 27:27851d3d2bba 598 void setCommsMenuItems()
tobyspark 27:27851d3d2bba 599 {
tobyspark 27:27851d3d2bba 600 if (rj45Mode == rj45Ethernet)
tobyspark 27:27851d3d2bba 601 {
tobyspark 27:27851d3d2bba 602 commsMenu.title = "Network Mode [Ethernet]";
tobyspark 27:27851d3d2bba 603 commsMenu.clearMenuItems();
tobyspark 27:27851d3d2bba 604 commsMenu.addMenuItem(SPKMenuItem("None", commsNone));
tobyspark 27:27851d3d2bba 605 commsMenu.addMenuItem(SPKMenuItem("OSC", commsOSC));
tobyspark 27:27851d3d2bba 606 commsMenu.addMenuItem(SPKMenuItem("ArtNet", commsArtNet));
tobyspark 27:27851d3d2bba 607 commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 33:e6672a9bd571 608 commsMenu = 0;
tobyspark 27:27851d3d2bba 609 }
tobyspark 27:27851d3d2bba 610 else if (rj45Mode == rj45DMX)
tobyspark 27:27851d3d2bba 611 {
tobyspark 27:27851d3d2bba 612 commsMenu.title = "Network Mode [DMX]";
tobyspark 27:27851d3d2bba 613 commsMenu.clearMenuItems();
tobyspark 27:27851d3d2bba 614 commsMenu.addMenuItem(SPKMenuItem("None", commsNone));
tobyspark 27:27851d3d2bba 615 commsMenu.addMenuItem(SPKMenuItem("DMX In", commsDMXIn));
tobyspark 27:27851d3d2bba 616 commsMenu.addMenuItem(SPKMenuItem("DMX Out", commsDMXOut));
tobyspark 27:27851d3d2bba 617 commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 33:e6672a9bd571 618 commsMenu = 0;
tobyspark 27:27851d3d2bba 619 }
tobyspark 27:27851d3d2bba 620 }
tobyspark 27:27851d3d2bba 621
tobyspark 0:87aab40d5806 622 int main()
tobyspark 0:87aab40d5806 623 {
tobyspark 0:87aab40d5806 624 if (debug)
tobyspark 0:87aab40d5806 625 {
tobyspark 0:87aab40d5806 626 debug->printf("\r\n\r\n");
tobyspark 0:87aab40d5806 627 debug->printf("*spark d-fuser -----------\r\n");
tobyspark 0:87aab40d5806 628 debug->printf(" debug channel\r\n");
tobyspark 0:87aab40d5806 629 }
tobyspark 2:50043054e4f7 630
tobyspark 2:50043054e4f7 631 // Set display font
tobyspark 2:50043054e4f7 632 screen.fontStartCharacter = &characterBytesStartChar;
tobyspark 2:50043054e4f7 633 screen.fontEndCharacter = &characterBytesEndChar;
tobyspark 2:50043054e4f7 634 screen.fontCharacters = characterBytes;
tobyspark 2:50043054e4f7 635
tobyspark 0:87aab40d5806 636 // Splash screen
tobyspark 30:873979018850 637 string softwareLine = "SW ";
tobyspark 30:873979018850 638 softwareLine += kSPKDFSoftwareVersion;
tobyspark 2:50043054e4f7 639 screen.imageToBuffer(spkDisplayLogo);
tobyspark 0:87aab40d5806 640 screen.textToBuffer("SPK:D-Fuser",0);
tobyspark 30:873979018850 641 screen.textToBuffer(softwareLine,1);
tobyspark 5:f8b285ca41ba 642 screen.sendBuffer();
tobyspark 0:87aab40d5806 643
tobyspark 11:0783cfbeb746 644 // Load saved settings
tobyspark 16:52484666b323 645 bool settingsAreCustom = false;
tobyspark 16:52484666b323 646 settingsAreCustom = settings.load(kSPKDFSettingsFilename);
tobyspark 30:873979018850 647 if (settingsAreCustom)
tobyspark 30:873979018850 648 {
tobyspark 30:873979018850 649 softwareLine += "; ini OK";
tobyspark 30:873979018850 650 screen.textToBuffer(softwareLine, 1);
tobyspark 30:873979018850 651 }
tobyspark 30:873979018850 652
tobyspark 0:87aab40d5806 653 // Set menu structure
tobyspark 0:87aab40d5806 654 mixModeMenu.title = "Mix Mode";
tobyspark 27:27851d3d2bba 655 setMixModeMenuItems();
tobyspark 24:49c6624119ae 656
tobyspark 29:95a7efe30527 657 mixModeAdditiveMenu.title = "Crossfade";
tobyspark 30:873979018850 658 mixModeAdditiveMenu.addMenuItem(SPKMenuItem("[title overridden]", &mixModeMenu, true));
tobyspark 36:8b5c75c8bc23 659
tobyspark 36:8b5c75c8bc23 660 mixModeKeyerMenuUpdate.title = "Update Keyer Settings?";
tobyspark 36:8b5c75c8bc23 661 mixModeKeyerMenuUpdate.addMenuItem(SPKMenuItem("[title overridden]", &mixModeKeyerMenuMaxY, true));
tobyspark 36:8b5c75c8bc23 662
tobyspark 36:8b5c75c8bc23 663 mixModeKeyerMenuMaxY.title = "UP until lighter gone";
tobyspark 36:8b5c75c8bc23 664 mixModeKeyerMenuMaxY.addMenuItem(SPKMenuItem("[title overridden]", &mixModeKeyerMenuMinY, true));
tobyspark 36:8b5c75c8bc23 665
tobyspark 36:8b5c75c8bc23 666 mixModeKeyerMenuMinY.title = "UP to bring back darker";
tobyspark 36:8b5c75c8bc23 667 mixModeKeyerMenuMinY.addMenuItem(SPKMenuItem("[title overridden]", &mixModeKeyerMenuMaxU, true));
tobyspark 36:8b5c75c8bc23 668
tobyspark 36:8b5c75c8bc23 669 mixModeKeyerMenuMaxU.title = "UP until lighter gone";
tobyspark 36:8b5c75c8bc23 670 mixModeKeyerMenuMaxU.addMenuItem(SPKMenuItem("[title overridden]", &mixModeKeyerMenuMinU, true));
tobyspark 36:8b5c75c8bc23 671
tobyspark 36:8b5c75c8bc23 672 mixModeKeyerMenuMinU.title = "UP to bring back darker";
tobyspark 36:8b5c75c8bc23 673 mixModeKeyerMenuMinU.addMenuItem(SPKMenuItem("[title overridden]", &mixModeKeyerMenuMaxV, true));
tobyspark 36:8b5c75c8bc23 674
tobyspark 36:8b5c75c8bc23 675 mixModeKeyerMenuMaxV.title = "UP until lighter gone";
tobyspark 36:8b5c75c8bc23 676 mixModeKeyerMenuMaxV.addMenuItem(SPKMenuItem("[title overridden]", &mixModeKeyerMenuMinV, true));
tobyspark 36:8b5c75c8bc23 677
tobyspark 36:8b5c75c8bc23 678 mixModeKeyerMenuMinV.title = "UP to bring back darker";
tobyspark 36:8b5c75c8bc23 679 mixModeKeyerMenuMinV.addMenuItem(SPKMenuItem("[title overridden]", &mixModeMenu, true));
tobyspark 36:8b5c75c8bc23 680
tobyspark 0:87aab40d5806 681
tobyspark 0:87aab40d5806 682 resolutionMenu.title = "Resolution";
tobyspark 27:27851d3d2bba 683 setResolutionMenuItems();
tobyspark 0:87aab40d5806 684
tobyspark 27:27851d3d2bba 685 commsMenu.title = "Network Mode";
tobyspark 27:27851d3d2bba 686 setCommsMenuItems();
tobyspark 23:909928cafb95 687
tobyspark 15:4b394c64b461 688 advancedMenu.title = "Troubleshooting";
tobyspark 23:909928cafb95 689 advancedMenu.addMenuItem(SPKMenuItem("HDCP Off", advancedHDCPOff));
tobyspark 23:909928cafb95 690 advancedMenu.addMenuItem(SPKMenuItem("HDCP On", advancedHDCPOn));
tobyspark 35:d5d9f0838f99 691 advancedMenu.addMenuItem(SPKMenuItem("EDID Passthrough", advancedEDIDPassthrough));
tobyspark 31:01845a2347ff 692 advancedMenu.addMenuItem(SPKMenuItem("EDID Internal", advancedEDIDInternal));
tobyspark 30:873979018850 693 advancedMenu.addMenuItem(SPKMenuItem("Test Processor Sources", advancedTestSources));
tobyspark 41:00d1cd3b2af2 694 advancedMenu.addMenuItem(SPKMenuItem("Revert Processor", advancedConformProcessor));
tobyspark 30:873979018850 695 if (settingsAreCustom) advancedMenu.addMenuItem(SPKMenuItem("Revert Controller", advancedLoadDefaults));
tobyspark 41:00d1cd3b2af2 696 advancedMenu.addMenuItem(SPKMenuItem("Conform Processor", advancedConformUploadProcessor));
tobyspark 24:49c6624119ae 697 advancedMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 23:909928cafb95 698
tobyspark 0:87aab40d5806 699 mainMenu.title = "Main Menu";
tobyspark 24:49c6624119ae 700 mainMenu.addMenuItem(SPKMenuItem(mixModeMenu.title, &mixModeMenu));
tobyspark 24:49c6624119ae 701 mainMenu.addMenuItem(SPKMenuItem(resolutionMenu.title, &resolutionMenu));
tobyspark 24:49c6624119ae 702 mainMenu.addMenuItem(SPKMenuItem(commsMenu.title, &commsMenu));
tobyspark 24:49c6624119ae 703 mainMenu.addMenuItem(SPKMenuItem(advancedMenu.title, &advancedMenu));
tobyspark 23:909928cafb95 704
tobyspark 0:87aab40d5806 705 selectedMenu = &mainMenu;
tobyspark 23:909928cafb95 706
tobyspark 0:87aab40d5806 707 // Misc I/O stuff
tobyspark 0:87aab40d5806 708
tobyspark 0:87aab40d5806 709 fadeAPO.period(0.001);
tobyspark 0:87aab40d5806 710 fadeBPO.period(0.001);
tobyspark 0:87aab40d5806 711
tobyspark 20:8b92d7922c48 712 // Test for TV One connectivity and determine unit type
tobyspark 30:873979018850 713 // TODO: Determine and fall back if not dfuser firmware?
tobyspark 30:873979018850 714 // TODO: Use software version to select resolution slots?
tobyspark 30:873979018850 715 // TODO: Use product / board type to select TVOne conform type?
tobyspark 21:f9d63cb7cedb 716 // kTV1FunctionReadSoftwareVersion
tobyspark 21:f9d63cb7cedb 717 // kTV1FunctionReadProductType
tobyspark 21:f9d63cb7cedb 718 // kTV1FunctionReadBoardType
tobyspark 21:f9d63cb7cedb 719
tobyspark 12:c270870bdd23 720 // Display menu and framing lines
tobyspark 0:87aab40d5806 721 screen.horizLineToBuffer(kMenuLine1*pixInPage - 1);
tobyspark 0:87aab40d5806 722 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 723 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 724 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 725 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 726 screen.horizLineToBuffer(kMenuLine2*pixInPage + pixInPage);
tobyspark 1:f9fca21102e0 727 screen.horizLineToBuffer(kCommsStatusLine*pixInPage - 1);
tobyspark 1:f9fca21102e0 728 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 34:69dfe64e7e6b 729 screen.textToBuffer("TVOne: OK", kTVOneStatusLine); // handleTVOneSources will update this
tobyspark 30:873979018850 730
tobyspark 30:873979018850 731 // If we do not have two solid sources, act on this as we rely on the window having a source for crossfade behaviour
tobyspark 30:873979018850 732 // Once we've had two solid inputs, don't check any more as we're ok as the unit is set to hold on last frame.
tobyspark 34:69dfe64e7e6b 733 bool ok = handleTVOneSources();
tobyspark 33:e6672a9bd571 734
tobyspark 33:e6672a9bd571 735 // Update display before starting mixer loop
tobyspark 33:e6672a9bd571 736 screen.sendBuffer();
tobyspark 33:e6672a9bd571 737
tobyspark 0:87aab40d5806 738 //// CONTROLS TEST
tobyspark 0:87aab40d5806 739
tobyspark 0:87aab40d5806 740 while (0) {
tobyspark 0:87aab40d5806 741 if (debug) debug->printf("xFade: %f, fadeOut: %f, tapLeft %i, tapRight: %i encPos: %i encChange:%i encHasPressed:%i \r\n" , xFadeAIN.read(), fadeUpAIN.read(), tapLeftDIN.read(), tapRightDIN.read(), menuEnc.getPos(), menuEnc.getChange(), menuEnc.hasPressed());
tobyspark 0:87aab40d5806 742 }
tobyspark 0:87aab40d5806 743
tobyspark 0:87aab40d5806 744 //// MIXER RUN
tobyspark 0:87aab40d5806 745
tobyspark 8:d46cc49f0f37 746 while (1)
tobyspark 8:d46cc49f0f37 747 {
tobyspark 35:d5d9f0838f99 748 bool updateMixMode = false;
tobyspark 35:d5d9f0838f99 749
tobyspark 1:f9fca21102e0 750 //// Task background things
tobyspark 33:e6672a9bd571 751 if ((osc || artNet) && rj45Mode == rj45Ethernet)
tobyspark 5:f8b285ca41ba 752 {
tobyspark 5:f8b285ca41ba 753 Net::poll();
tobyspark 5:f8b285ca41ba 754 }
tobyspark 5:f8b285ca41ba 755
tobyspark 5:f8b285ca41ba 756 //// RJ45 SWITCH
tobyspark 5:f8b285ca41ba 757
tobyspark 5:f8b285ca41ba 758 if (rj45ModeDIN != rj45Mode)
tobyspark 1:f9fca21102e0 759 {
tobyspark 23:909928cafb95 760 if (debug) debug->printf("Handling RJ45 mode change\r\n");
tobyspark 27:27851d3d2bba 761
tobyspark 5:f8b285ca41ba 762 // update state
tobyspark 5:f8b285ca41ba 763 rj45Mode = rj45ModeDIN;
tobyspark 27:27851d3d2bba 764
tobyspark 27:27851d3d2bba 765 setCommsMenuItems();
tobyspark 5:f8b285ca41ba 766
tobyspark 5:f8b285ca41ba 767 // cancel old comms
tobyspark 5:f8b285ca41ba 768 commsMode = commsNone;
tobyspark 5:f8b285ca41ba 769 commsMenu = commsMode;
tobyspark 5:f8b285ca41ba 770
tobyspark 5:f8b285ca41ba 771 // refresh display
tobyspark 23:909928cafb95 772 if (selectedMenu == &commsMenu)
tobyspark 23:909928cafb95 773 {
tobyspark 33:e6672a9bd571 774 screen.clearBufferRow(kMenuLine1);
tobyspark 33:e6672a9bd571 775 screen.clearBufferRow(kMenuLine2);
tobyspark 23:909928cafb95 776 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 23:909928cafb95 777 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 23:909928cafb95 778 }
tobyspark 5:f8b285ca41ba 779 if (rj45Mode == rj45Ethernet) screen.textToBuffer("RJ45: Ethernet Engaged", kCommsStatusLine);
tobyspark 5:f8b285ca41ba 780 if (rj45Mode == rj45DMX) screen.textToBuffer("RJ45: DMX Engaged", kCommsStatusLine);
tobyspark 1:f9fca21102e0 781 }
tobyspark 1:f9fca21102e0 782
tobyspark 0:87aab40d5806 783 //// MENU
tobyspark 0:87aab40d5806 784
tobyspark 0:87aab40d5806 785 int menuChange = menuEnc.getChange();
tobyspark 0:87aab40d5806 786
tobyspark 0:87aab40d5806 787 // Update GUI
tobyspark 0:87aab40d5806 788 if (menuChange != 0)
tobyspark 0:87aab40d5806 789 {
tobyspark 24:49c6624119ae 790 if (selectedMenu->selectedItem().handlingControls)
tobyspark 24:49c6624119ae 791 {
tobyspark 24:49c6624119ae 792 if (selectedMenu == &mixModeAdditiveMenu)
tobyspark 24:49c6624119ae 793 {
tobyspark 24:49c6624119ae 794 fadeCurve += menuChange * 0.05;
tobyspark 24:49c6624119ae 795 if (fadeCurve > 1.0f) fadeCurve = 1.0f;
tobyspark 24:49c6624119ae 796 if (fadeCurve < 0.0f) fadeCurve = 0.0f;
tobyspark 29:95a7efe30527 797
tobyspark 31:01845a2347ff 798 int newMixMode = (fadeCurve > 0.0f) ? mixAdditive: mixBlend;
tobyspark 31:01845a2347ff 799
tobyspark 31:01845a2347ff 800 if (newMixMode != mixMode)
tobyspark 31:01845a2347ff 801 {
tobyspark 31:01845a2347ff 802 mixMode = newMixMode;
tobyspark 35:d5d9f0838f99 803 updateMixMode = true;
tobyspark 31:01845a2347ff 804 }
tobyspark 29:95a7efe30527 805
tobyspark 24:49c6624119ae 806 screen.clearBufferRow(kMenuLine2);
tobyspark 29:95a7efe30527 807 screen.textToBuffer("Blend [ ----- ] Add", kMenuLine2);
tobyspark 29:95a7efe30527 808 screen.characterToBuffer('X', 38 + fadeCurve*20.0f, kMenuLine2);
tobyspark 24:49c6624119ae 809
tobyspark 31:01845a2347ff 810 if (debug) debug->printf("Fade curve changed by %i to %f \r\n", menuChange, fadeCurve);
tobyspark 24:49c6624119ae 811 }
tobyspark 36:8b5c75c8bc23 812 else if (selectedMenu == &mixModeKeyerMenuUpdate)
tobyspark 36:8b5c75c8bc23 813 {
tobyspark 36:8b5c75c8bc23 814 if (menuChange < 0)
tobyspark 36:8b5c75c8bc23 815 {
tobyspark 36:8b5c75c8bc23 816 settings.editingKeyerSetIndex = mixModeMenu.selectedIndex() - mixKeyStartIndex;
tobyspark 36:8b5c75c8bc23 817 screen.textToBuffer("[Yes/ ]", kMenuLine2);
tobyspark 36:8b5c75c8bc23 818 }
tobyspark 36:8b5c75c8bc23 819 else
tobyspark 36:8b5c75c8bc23 820 {
tobyspark 36:8b5c75c8bc23 821 settings.editingKeyerSetIndex = -1;
tobyspark 36:8b5c75c8bc23 822 screen.textToBuffer("[ /No]", kMenuLine2);
tobyspark 36:8b5c75c8bc23 823 }
tobyspark 36:8b5c75c8bc23 824 }
tobyspark 36:8b5c75c8bc23 825 else if (selectedMenu == &mixModeKeyerMenuMinY)
tobyspark 36:8b5c75c8bc23 826 {
tobyspark 36:8b5c75c8bc23 827 int value = settings.editingKeyerSetValue(SPKSettings::minY);
tobyspark 36:8b5c75c8bc23 828 value += menuChange;
tobyspark 36:8b5c75c8bc23 829 if (value < 0) value = 0;
tobyspark 36:8b5c75c8bc23 830 if (value > settings.editingKeyerSetValue(SPKSettings::maxY)) value = settings.editingKeyerSetValue(SPKSettings::maxY);
tobyspark 36:8b5c75c8bc23 831 settings.setEditingKeyerSetValue(SPKSettings::minY, value);
tobyspark 36:8b5c75c8bc23 832
tobyspark 36:8b5c75c8bc23 833 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 834
tobyspark 36:8b5c75c8bc23 835 char paramLine[kStringBufferLength];
tobyspark 37:744bef2e8be8 836 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][ / ][ / ]", value,
tobyspark 37:744bef2e8be8 837 settings.editingKeyerSetValue(SPKSettings::maxY));
tobyspark 36:8b5c75c8bc23 838 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 839
tobyspark 36:8b5c75c8bc23 840 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, value);
tobyspark 36:8b5c75c8bc23 841 }
tobyspark 36:8b5c75c8bc23 842 else if (selectedMenu == &mixModeKeyerMenuMaxY)
tobyspark 36:8b5c75c8bc23 843 {
tobyspark 36:8b5c75c8bc23 844 int value = settings.editingKeyerSetValue(SPKSettings::maxY);
tobyspark 36:8b5c75c8bc23 845 value += menuChange;
tobyspark 36:8b5c75c8bc23 846 if (value < 0) value = 0;
tobyspark 36:8b5c75c8bc23 847 if (value > 255) value = 255;
tobyspark 36:8b5c75c8bc23 848 settings.setEditingKeyerSetValue(SPKSettings::maxY, value);
tobyspark 36:8b5c75c8bc23 849
tobyspark 36:8b5c75c8bc23 850 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 851
tobyspark 36:8b5c75c8bc23 852 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 853 snprintf(paramLine, kStringBufferLength, "[ /%3i][ / ][ / ]", value);
tobyspark 36:8b5c75c8bc23 854 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 855
tobyspark 36:8b5c75c8bc23 856 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, value);
tobyspark 36:8b5c75c8bc23 857 }
tobyspark 36:8b5c75c8bc23 858 else if (selectedMenu == &mixModeKeyerMenuMinU)
tobyspark 36:8b5c75c8bc23 859 {
tobyspark 36:8b5c75c8bc23 860 int value = settings.editingKeyerSetValue(SPKSettings::minU);
tobyspark 36:8b5c75c8bc23 861 value += menuChange;
tobyspark 36:8b5c75c8bc23 862 if (value > settings.editingKeyerSetValue(SPKSettings::maxU)) value = settings.editingKeyerSetValue(SPKSettings::maxU);
tobyspark 36:8b5c75c8bc23 863 if (value > 255) value = 255;
tobyspark 36:8b5c75c8bc23 864 settings.setEditingKeyerSetValue(SPKSettings::minU, value);
tobyspark 36:8b5c75c8bc23 865
tobyspark 36:8b5c75c8bc23 866 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 867
tobyspark 36:8b5c75c8bc23 868 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 869 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 870 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 37:744bef2e8be8 871 value,
tobyspark 37:744bef2e8be8 872 settings.editingKeyerSetValue(SPKSettings::maxU));
tobyspark 36:8b5c75c8bc23 873 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 874
tobyspark 36:8b5c75c8bc23 875 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, value);
tobyspark 36:8b5c75c8bc23 876 }
tobyspark 36:8b5c75c8bc23 877 else if (selectedMenu == &mixModeKeyerMenuMaxU)
tobyspark 36:8b5c75c8bc23 878 {
tobyspark 36:8b5c75c8bc23 879 int value = settings.editingKeyerSetValue(SPKSettings::maxU);
tobyspark 36:8b5c75c8bc23 880 value += menuChange;
tobyspark 36:8b5c75c8bc23 881 if (value < 0) value = 0;
tobyspark 36:8b5c75c8bc23 882 if (value > 255) value = 255;
tobyspark 36:8b5c75c8bc23 883 settings.setEditingKeyerSetValue(SPKSettings::maxU, value);
tobyspark 36:8b5c75c8bc23 884
tobyspark 36:8b5c75c8bc23 885 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 886
tobyspark 36:8b5c75c8bc23 887 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 888 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][ /%3i][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 889 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 890 value);
tobyspark 36:8b5c75c8bc23 891 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 892
tobyspark 36:8b5c75c8bc23 893 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, value);
tobyspark 36:8b5c75c8bc23 894 }
tobyspark 36:8b5c75c8bc23 895 else if (selectedMenu == &mixModeKeyerMenuMinV)
tobyspark 36:8b5c75c8bc23 896 {
tobyspark 36:8b5c75c8bc23 897 int value = settings.editingKeyerSetValue(SPKSettings::minV);
tobyspark 36:8b5c75c8bc23 898 value += menuChange;
tobyspark 36:8b5c75c8bc23 899 if (value > settings.editingKeyerSetValue(SPKSettings::maxV)) value = settings.editingKeyerSetValue(SPKSettings::maxV);
tobyspark 36:8b5c75c8bc23 900 if (value > 255) value = 255;
tobyspark 36:8b5c75c8bc23 901 settings.setEditingKeyerSetValue(SPKSettings::minV, value);
tobyspark 36:8b5c75c8bc23 902
tobyspark 36:8b5c75c8bc23 903 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 904
tobyspark 36:8b5c75c8bc23 905 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 906 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][%3i/%3i]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 907 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 908 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 37:744bef2e8be8 909 settings.editingKeyerSetValue(SPKSettings::maxU),
tobyspark 37:744bef2e8be8 910 value,
tobyspark 37:744bef2e8be8 911 settings.editingKeyerSetValue(SPKSettings::maxV));
tobyspark 36:8b5c75c8bc23 912 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 913
tobyspark 36:8b5c75c8bc23 914 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, value);
tobyspark 36:8b5c75c8bc23 915 }
tobyspark 36:8b5c75c8bc23 916 else if (selectedMenu == &mixModeKeyerMenuMaxV)
tobyspark 36:8b5c75c8bc23 917 {
tobyspark 36:8b5c75c8bc23 918 int value = settings.editingKeyerSetValue(SPKSettings::maxV);
tobyspark 36:8b5c75c8bc23 919 value += menuChange;
tobyspark 36:8b5c75c8bc23 920 if (value < 0) value = 0;
tobyspark 36:8b5c75c8bc23 921 if (value > 255) value = 255;
tobyspark 36:8b5c75c8bc23 922 settings.setEditingKeyerSetValue(SPKSettings::maxV, value);
tobyspark 36:8b5c75c8bc23 923
tobyspark 36:8b5c75c8bc23 924 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 925
tobyspark 36:8b5c75c8bc23 926 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 927 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][ /%3i]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 928 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 929 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 36:8b5c75c8bc23 930 settings.editingKeyerSetValue(SPKSettings::maxU),
tobyspark 36:8b5c75c8bc23 931 value);
tobyspark 36:8b5c75c8bc23 932 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 933
tobyspark 43:328d851c429a 934 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, value);
tobyspark 36:8b5c75c8bc23 935 }
tobyspark 24:49c6624119ae 936 }
tobyspark 24:49c6624119ae 937 else
tobyspark 24:49c6624119ae 938 {
tobyspark 24:49c6624119ae 939 if (debug) debug->printf("Menu changed by %i\r\n", menuChange);
tobyspark 24:49c6624119ae 940
tobyspark 24:49c6624119ae 941 *selectedMenu = selectedMenu->selectedIndex() + menuChange;
tobyspark 24:49c6624119ae 942
tobyspark 24:49c6624119ae 943 // update OLED line 2 here
tobyspark 24:49c6624119ae 944 screen.clearBufferRow(kMenuLine2);
tobyspark 24:49c6624119ae 945 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 24:49c6624119ae 946
tobyspark 24:49c6624119ae 947 if (debug) debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 24:49c6624119ae 948 }
tobyspark 0:87aab40d5806 949 }
tobyspark 0:87aab40d5806 950
tobyspark 0:87aab40d5806 951 // Action menu item
tobyspark 0:87aab40d5806 952 if (menuEnc.hasPressed())
tobyspark 0:87aab40d5806 953 {
tobyspark 0:87aab40d5806 954 if (debug) debug->printf("Action Menu Item!\r\n");
tobyspark 21:f9d63cb7cedb 955
tobyspark 0:87aab40d5806 956 // Are we changing menus?
tobyspark 23:909928cafb95 957 if (selectedMenu->selectedItem().type == SPKMenuItem::changesToMenu)
tobyspark 0:87aab40d5806 958 {
tobyspark 31:01845a2347ff 959 // If we're exiting the menu, we should set its selected index back to the menu's beginning...
tobyspark 31:01845a2347ff 960 SPKMenu* menuToReset = selectedMenu->selectedItem().payload.menu == &mainMenu? selectedMenu : NULL;
tobyspark 31:01845a2347ff 961
tobyspark 31:01845a2347ff 962 // point selected menu pointer to the new menu pointer
tobyspark 23:909928cafb95 963 selectedMenu = selectedMenu->selectedItem().payload.menu;
tobyspark 0:87aab40d5806 964
tobyspark 31:01845a2347ff 965 // ...doing this, of course, after we've used the value
tobyspark 31:01845a2347ff 966 if (menuToReset) *menuToReset = 0;
tobyspark 31:01845a2347ff 967
tobyspark 0:87aab40d5806 968 // update OLED lines 1&2
tobyspark 0:87aab40d5806 969 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 970 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 971 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 972 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 973
tobyspark 0:87aab40d5806 974 if (debug)
tobyspark 0:87aab40d5806 975 {
tobyspark 0:87aab40d5806 976 debug->printf("\r\n");
tobyspark 0:87aab40d5806 977 debug->printf("%s \r\n", selectedMenu->title.c_str());
tobyspark 0:87aab40d5806 978 debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 0:87aab40d5806 979 }
tobyspark 24:49c6624119ae 980
tobyspark 24:49c6624119ae 981 // Are we changing menus that should have a command attached?
tobyspark 24:49c6624119ae 982 if (selectedMenu == &mixModeAdditiveMenu)
tobyspark 24:49c6624119ae 983 {
tobyspark 29:95a7efe30527 984 screen.clearBufferRow(kMenuLine2);
tobyspark 29:95a7efe30527 985 screen.textToBuffer("Blend [ ----- ] Add", kMenuLine2);
tobyspark 29:95a7efe30527 986 screen.characterToBuffer('X', 38 + fadeCurve*20.0f, kMenuLine2);
tobyspark 29:95a7efe30527 987
tobyspark 29:95a7efe30527 988 mixMode = fadeCurve > 0 ? mixAdditive : mixBlend;
tobyspark 35:d5d9f0838f99 989 updateMixMode = true;
tobyspark 24:49c6624119ae 990 }
tobyspark 36:8b5c75c8bc23 991 else if (selectedMenu == &mixModeKeyerMenuUpdate)
tobyspark 36:8b5c75c8bc23 992 {
tobyspark 36:8b5c75c8bc23 993 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 994 if (settings.editingKeyerSetIndex == mixModeMenu.selectedIndex() - mixKeyStartIndex)
tobyspark 36:8b5c75c8bc23 995 screen.textToBuffer("[Yes/ ]", kMenuLine2);
tobyspark 36:8b5c75c8bc23 996 else
tobyspark 36:8b5c75c8bc23 997 screen.textToBuffer("[ /No]", kMenuLine2);
tobyspark 36:8b5c75c8bc23 998
tobyspark 36:8b5c75c8bc23 999 mixMode = mixKey;
tobyspark 36:8b5c75c8bc23 1000 updateMixMode = true;
tobyspark 36:8b5c75c8bc23 1001 }
tobyspark 36:8b5c75c8bc23 1002 else if (selectedMenu == &mixModeKeyerMenuMinY)
tobyspark 36:8b5c75c8bc23 1003 {
tobyspark 36:8b5c75c8bc23 1004 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 1005 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1006 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][ / ][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 1007 settings.editingKeyerSetValue(SPKSettings::maxY));
tobyspark 36:8b5c75c8bc23 1008 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 1009 }
tobyspark 36:8b5c75c8bc23 1010 else if (selectedMenu == &mixModeKeyerMenuMaxY)
tobyspark 36:8b5c75c8bc23 1011 {
tobyspark 36:8b5c75c8bc23 1012 // First, check outcome of menu that got us here: mixModeKeyerMenuUpdate
tobyspark 36:8b5c75c8bc23 1013 if (settings.editingKeyerSetIndex == -1)
tobyspark 36:8b5c75c8bc23 1014 {
tobyspark 36:8b5c75c8bc23 1015 selectedMenu = &mixModeMenu;
tobyspark 36:8b5c75c8bc23 1016
tobyspark 36:8b5c75c8bc23 1017 // update OLED lines 1&2
tobyspark 36:8b5c75c8bc23 1018 screen.clearBufferRow(kMenuLine1);
tobyspark 36:8b5c75c8bc23 1019 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1020 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 36:8b5c75c8bc23 1021 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 36:8b5c75c8bc23 1022 }
tobyspark 36:8b5c75c8bc23 1023 else
tobyspark 36:8b5c75c8bc23 1024 {
tobyspark 36:8b5c75c8bc23 1025 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 1026 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1027 snprintf(paramLine, kStringBufferLength, "[ /%3i][ / ][ / ]", settings.editingKeyerSetValue(SPKSettings::maxY));
tobyspark 36:8b5c75c8bc23 1028 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 1029 }
tobyspark 36:8b5c75c8bc23 1030 }
tobyspark 36:8b5c75c8bc23 1031 else if (selectedMenu == &mixModeKeyerMenuMinU)
tobyspark 36:8b5c75c8bc23 1032 {
tobyspark 36:8b5c75c8bc23 1033 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 1034 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1035 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 1036 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 1037 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 36:8b5c75c8bc23 1038 settings.editingKeyerSetValue(SPKSettings::maxU));
tobyspark 36:8b5c75c8bc23 1039 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 1040 }
tobyspark 36:8b5c75c8bc23 1041 else if (selectedMenu == &mixModeKeyerMenuMaxU)
tobyspark 36:8b5c75c8bc23 1042 {
tobyspark 36:8b5c75c8bc23 1043 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 1044 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1045 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][ /%3i][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 1046 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 1047 settings.editingKeyerSetValue(SPKSettings::maxU));
tobyspark 36:8b5c75c8bc23 1048 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 1049 }
tobyspark 36:8b5c75c8bc23 1050 else if (selectedMenu == &mixModeKeyerMenuMinV)
tobyspark 36:8b5c75c8bc23 1051 {
tobyspark 36:8b5c75c8bc23 1052 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 1053 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1054 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][%3i/%3i]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 1055 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 1056 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 36:8b5c75c8bc23 1057 settings.editingKeyerSetValue(SPKSettings::maxU),
tobyspark 36:8b5c75c8bc23 1058 settings.editingKeyerSetValue(SPKSettings::minV),
tobyspark 36:8b5c75c8bc23 1059 settings.editingKeyerSetValue(SPKSettings::maxV));
tobyspark 36:8b5c75c8bc23 1060 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 1061 }
tobyspark 36:8b5c75c8bc23 1062 else if (selectedMenu == &mixModeKeyerMenuMaxV)
tobyspark 36:8b5c75c8bc23 1063 {
tobyspark 36:8b5c75c8bc23 1064 char paramLine[kStringBufferLength];
tobyspark 36:8b5c75c8bc23 1065 screen.clearBufferRow(kMenuLine2);
tobyspark 36:8b5c75c8bc23 1066 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][ /%3i]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 36:8b5c75c8bc23 1067 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 36:8b5c75c8bc23 1068 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 36:8b5c75c8bc23 1069 settings.editingKeyerSetValue(SPKSettings::maxU),
tobyspark 36:8b5c75c8bc23 1070 settings.editingKeyerSetValue(SPKSettings::maxV));
tobyspark 36:8b5c75c8bc23 1071 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 36:8b5c75c8bc23 1072 }
tobyspark 43:328d851c429a 1073 else if (selectedMenu == &mixModeMenu)
tobyspark 43:328d851c429a 1074 {
tobyspark 43:328d851c429a 1075 // We should save the keyer parameter set if it was updated
tobyspark 43:328d851c429a 1076 if (settings.editingKeyerSetIndex != -1)
tobyspark 43:328d851c429a 1077 {
tobyspark 43:328d851c429a 1078 settings.saveEditingKeyerSet(kSPKDFSettingsFilename);
tobyspark 43:328d851c429a 1079 }
tobyspark 43:328d851c429a 1080 }
tobyspark 0:87aab40d5806 1081 }
tobyspark 0:87aab40d5806 1082 // With that out of the way, we should be actioning a specific menu's payload?
tobyspark 0:87aab40d5806 1083 else if (selectedMenu == &resolutionMenu)
tobyspark 0:87aab40d5806 1084 {
tobyspark 9:f83eadd8917a 1085 bool ok = true;
tobyspark 0:87aab40d5806 1086
tobyspark 23:909928cafb95 1087 ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputResolution, resolutionMenu.selectedItem().payload.command[0]);
tobyspark 31:01845a2347ff 1088
tobyspark 31:01845a2347ff 1089 int32_t slot = tvOneEDIDPassthrough ? EDIDPassthroughSlot : resolutionMenu.selectedItem().payload.command[1];
tobyspark 31:01845a2347ff 1090
tobyspark 31:01845a2347ff 1091 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 31:01845a2347ff 1092 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 0:87aab40d5806 1093
tobyspark 35:d5d9f0838f99 1094 // Save new resolution and EDID into TV One unit for power-on. Cycling TV One power sometimes needed for EDID. Pffft.
tobyspark 35:d5d9f0838f99 1095 if (ok) ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 35:d5d9f0838f99 1096
tobyspark 25:3b519ef70341 1097 string sentOK;
tobyspark 0:87aab40d5806 1098 if (ok) sentOK = "Sent: ";
tobyspark 0:87aab40d5806 1099 else sentOK = "Send Error: ";
tobyspark 0:87aab40d5806 1100
tobyspark 26:0299f8760715 1101 char sentMSGBuffer[kStringBufferLength];
tobyspark 26:0299f8760715 1102 snprintf(sentMSGBuffer, kStringBufferLength,"Res %i, EDID %i", resolutionMenu.selectedItem().payload.command[0], resolutionMenu.selectedItem().payload.command[1]);
tobyspark 0:87aab40d5806 1103
tobyspark 1:f9fca21102e0 1104 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 25:3b519ef70341 1105 screen.textToBuffer(sentOK + sentMSGBuffer, kTVOneStatusLine);
tobyspark 0:87aab40d5806 1106
tobyspark 0:87aab40d5806 1107 if (debug) { debug->printf("Changing resolution"); }
tobyspark 0:87aab40d5806 1108 }
tobyspark 1:f9fca21102e0 1109 else if (selectedMenu == &commsMenu)
tobyspark 1:f9fca21102e0 1110 {
tobyspark 26:0299f8760715 1111 string commsTypeString = "Network:";
tobyspark 26:0299f8760715 1112 char commsStatusBuffer[kStringBufferLength] = "--";
tobyspark 1:f9fca21102e0 1113
tobyspark 1:f9fca21102e0 1114 // Tear down any existing comms
tobyspark 1:f9fca21102e0 1115 // This is the action of commsNone
tobyspark 1:f9fca21102e0 1116 // And also clears the way for other comms actions
tobyspark 26:0299f8760715 1117 commsMode = commsNone;
tobyspark 5:f8b285ca41ba 1118 if (osc) {delete osc; osc = NULL;}
tobyspark 5:f8b285ca41ba 1119 if (ethernet) {delete ethernet; ethernet = NULL;}
tobyspark 33:e6672a9bd571 1120 if (artNet)
tobyspark 33:e6672a9bd571 1121 {
tobyspark 33:e6672a9bd571 1122 artNet->ArtPollReply.NumPorts = 0;
tobyspark 33:e6672a9bd571 1123 strcpy(artNet->ArtPollReply.NodeReport, "Shutdown");
tobyspark 33:e6672a9bd571 1124 artNet->SendArtPollReply();
tobyspark 33:e6672a9bd571 1125 artNet->Done();
tobyspark 33:e6672a9bd571 1126 delete artNet;
tobyspark 33:e6672a9bd571 1127 artNet = NULL;
tobyspark 33:e6672a9bd571 1128 }
tobyspark 5:f8b285ca41ba 1129 if (dmx) {delete dmx; dmx = NULL;}
tobyspark 5:f8b285ca41ba 1130
tobyspark 5:f8b285ca41ba 1131 // Ensure we can't change to comms modes the hardware isn't switched to
tobyspark 23:909928cafb95 1132 if (rj45Mode == rj45DMX && (commsMenu.selectedItem().payload.command[0] == commsOSC || commsMenu.selectedItem().payload.command[0] == commsArtNet))
tobyspark 1:f9fca21102e0 1133 {
tobyspark 5:f8b285ca41ba 1134 commsTypeString = "RJ45 not in Ethernet mode";
tobyspark 5:f8b285ca41ba 1135 }
tobyspark 23:909928cafb95 1136 else if (rj45Mode == rj45Ethernet && (commsMenu.selectedItem().payload.command[0] == commsDMXIn || commsMenu.selectedItem().payload.command[0] == commsDMXOut))
tobyspark 5:f8b285ca41ba 1137 {
tobyspark 5:f8b285ca41ba 1138 commsTypeString = "RJ45 not in DMX mode";
tobyspark 5:f8b285ca41ba 1139 }
tobyspark 5:f8b285ca41ba 1140 // Action!
tobyspark 23:909928cafb95 1141 else if (commsMenu.selectedItem().payload.command[0] == commsOSC)
tobyspark 5:f8b285ca41ba 1142 {
tobyspark 5:f8b285ca41ba 1143 commsMode = commsOSC;
tobyspark 5:f8b285ca41ba 1144 commsTypeString = "OSC: ";
tobyspark 1:f9fca21102e0 1145
tobyspark 1:f9fca21102e0 1146 ethernet = new EthernetNetIf(
tobyspark 1:f9fca21102e0 1147 IpAddr(kOSCMbedIPAddress),
tobyspark 1:f9fca21102e0 1148 IpAddr(kOSCMbedSubnetMask),
tobyspark 1:f9fca21102e0 1149 IpAddr(kOSCMbedGateway),
tobyspark 1:f9fca21102e0 1150 IpAddr(kOSCMbedDNS)
tobyspark 1:f9fca21102e0 1151 );
tobyspark 3:033d2b7768f3 1152
tobyspark 1:f9fca21102e0 1153 EthernetErr ethError = ethernet->setup();
tobyspark 1:f9fca21102e0 1154 if(ethError)
tobyspark 1:f9fca21102e0 1155 {
tobyspark 1:f9fca21102e0 1156 if (debug) debug->printf("Ethernet setup error, %d", ethError);
tobyspark 26:0299f8760715 1157 snprintf(commsStatusBuffer, kStringBufferLength, "Ethernet setup failed");
tobyspark 5:f8b285ca41ba 1158 commsMenu = commsNone;
tobyspark 1:f9fca21102e0 1159 // break out of here. this setup should be a function that returns a boolean
tobyspark 1:f9fca21102e0 1160 }
tobyspark 1:f9fca21102e0 1161
tobyspark 1:f9fca21102e0 1162 osc = new OSCClass();
tobyspark 33:e6672a9bd571 1163 osc->setReceiveMessage(&receiveMessage);
tobyspark 1:f9fca21102e0 1164 osc->begin(kOSCMbedPort);
tobyspark 1:f9fca21102e0 1165
tobyspark 26:0299f8760715 1166 snprintf(commsStatusBuffer, kStringBufferLength, "Listening on %i", kOSCMbedPort);
tobyspark 1:f9fca21102e0 1167 }
tobyspark 23:909928cafb95 1168 else if (commsMenu.selectedItem().payload.command[0] == commsArtNet)
tobyspark 1:f9fca21102e0 1169 {
tobyspark 5:f8b285ca41ba 1170 commsMode = commsArtNet;
tobyspark 5:f8b285ca41ba 1171 commsTypeString = "ArtNet: ";
tobyspark 3:033d2b7768f3 1172
tobyspark 3:033d2b7768f3 1173 artNet = new DmxArtNet();
tobyspark 1:f9fca21102e0 1174
tobyspark 3:033d2b7768f3 1175 artNet->BindIpAddress = IpAddr(kArtNetBindIPAddress);
tobyspark 3:033d2b7768f3 1176 artNet->BCastAddress = IpAddr(kArtNetBroadcastAddress);
tobyspark 3:033d2b7768f3 1177
tobyspark 3:033d2b7768f3 1178 artNet->InitArtPollReplyDefaults();
tobyspark 3:033d2b7768f3 1179
tobyspark 33:e6672a9bd571 1180 artNet->ArtPollReply.PortType[0] = 128; // Bit 7 = Set is this channel can output data from the Art-Net Network.
tobyspark 33:e6672a9bd571 1181 artNet->ArtPollReply.GoodOutput[0] = 128; // Bit 7 = Set – Data is being transmitted.
tobyspark 33:e6672a9bd571 1182 artNet->ArtPollReply.PortType[2] = 64; // Bit 6 = Set if this channel can input onto the Art-NetNetwork.
tobyspark 33:e6672a9bd571 1183 artNet->ArtPollReply.GoodInput[2] = 128; // Bit 7 = Set – Data received.
tobyspark 3:033d2b7768f3 1184
tobyspark 3:033d2b7768f3 1185 artNet->Init();
tobyspark 3:033d2b7768f3 1186 artNet->SendArtPollReply(); // announce to art-net nodes
tobyspark 3:033d2b7768f3 1187
tobyspark 26:0299f8760715 1188 snprintf(commsStatusBuffer, kStringBufferLength, "Listening");
tobyspark 1:f9fca21102e0 1189 }
tobyspark 23:909928cafb95 1190 else if (commsMenu.selectedItem().payload.command[0] == commsDMXIn)
tobyspark 1:f9fca21102e0 1191 {
tobyspark 5:f8b285ca41ba 1192 commsMode = commsDMXIn;
tobyspark 5:f8b285ca41ba 1193 commsTypeString = "DMX In: ";
tobyspark 1:f9fca21102e0 1194
tobyspark 5:f8b285ca41ba 1195 dmxDirectionDOUT = 0;
tobyspark 5:f8b285ca41ba 1196
tobyspark 5:f8b285ca41ba 1197 dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX);
tobyspark 1:f9fca21102e0 1198 }
tobyspark 23:909928cafb95 1199 else if (commsMenu.selectedItem().payload.command[0] == commsDMXOut)
tobyspark 5:f8b285ca41ba 1200 {
tobyspark 5:f8b285ca41ba 1201 commsMode = commsDMXOut;
tobyspark 5:f8b285ca41ba 1202 commsTypeString = "DMX Out: ";
tobyspark 5:f8b285ca41ba 1203
tobyspark 5:f8b285ca41ba 1204 dmxDirectionDOUT = 1;
tobyspark 5:f8b285ca41ba 1205
tobyspark 5:f8b285ca41ba 1206 dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX);
tobyspark 5:f8b285ca41ba 1207 }
tobyspark 5:f8b285ca41ba 1208
tobyspark 1:f9fca21102e0 1209 screen.clearBufferRow(kCommsStatusLine);
tobyspark 25:3b519ef70341 1210 screen.textToBuffer(commsTypeString + commsStatusBuffer, kCommsStatusLine);
tobyspark 1:f9fca21102e0 1211 }
tobyspark 12:c270870bdd23 1212 else if (selectedMenu == &advancedMenu)
tobyspark 12:c270870bdd23 1213 {
tobyspark 23:909928cafb95 1214 if (advancedMenu.selectedItem().payload.command[0] == advancedHDCPOff)
tobyspark 12:c270870bdd23 1215 {
tobyspark 31:01845a2347ff 1216 bool ok;
tobyspark 12:c270870bdd23 1217
tobyspark 15:4b394c64b461 1218 ok = tvOne.setHDCPOn(false);
tobyspark 12:c270870bdd23 1219
tobyspark 12:c270870bdd23 1220 std::string sendOK = ok ? "Sent: HDCP Off" : "Send Error: HDCP Off";
tobyspark 12:c270870bdd23 1221
tobyspark 12:c270870bdd23 1222 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 12:c270870bdd23 1223 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 12:c270870bdd23 1224 }
tobyspark 23:909928cafb95 1225 else if (advancedMenu.selectedItem().payload.command[0] == advancedHDCPOn)
tobyspark 15:4b394c64b461 1226 {
tobyspark 31:01845a2347ff 1227 bool ok;
tobyspark 15:4b394c64b461 1228
tobyspark 15:4b394c64b461 1229 ok = tvOne.setHDCPOn(true);
tobyspark 15:4b394c64b461 1230
tobyspark 15:4b394c64b461 1231 std::string sendOK = ok ? "Sent: HDCP On" : "Send Error: HDCP On";
tobyspark 15:4b394c64b461 1232
tobyspark 15:4b394c64b461 1233 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 15:4b394c64b461 1234 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 15:4b394c64b461 1235 }
tobyspark 31:01845a2347ff 1236 else if (advancedMenu.selectedItem().payload.command[0] == advancedEDIDPassthrough)
tobyspark 31:01845a2347ff 1237 {
tobyspark 31:01845a2347ff 1238 tvOneEDIDPassthrough = true;
tobyspark 31:01845a2347ff 1239
tobyspark 31:01845a2347ff 1240 bool ok = true;
tobyspark 31:01845a2347ff 1241
tobyspark 31:01845a2347ff 1242 int32_t slot = tvOneEDIDPassthrough ? EDIDPassthroughSlot : resolutionMenu.selectedItem().payload.command[1];
tobyspark 31:01845a2347ff 1243
tobyspark 31:01845a2347ff 1244 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 31:01845a2347ff 1245 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 31:01845a2347ff 1246
tobyspark 31:01845a2347ff 1247 std::string sendOK = ok ? "Sent: EDID. Next:conform?" : "Send Error: EDID";
tobyspark 31:01845a2347ff 1248
tobyspark 31:01845a2347ff 1249 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 31:01845a2347ff 1250 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 31:01845a2347ff 1251 }
tobyspark 31:01845a2347ff 1252 else if (advancedMenu.selectedItem().payload.command[0] == advancedEDIDInternal)
tobyspark 31:01845a2347ff 1253 {
tobyspark 31:01845a2347ff 1254 tvOneEDIDPassthrough = false;
tobyspark 31:01845a2347ff 1255
tobyspark 31:01845a2347ff 1256 bool ok = true;
tobyspark 31:01845a2347ff 1257
tobyspark 31:01845a2347ff 1258 int32_t slot = tvOneEDIDPassthrough ? EDIDPassthroughSlot : resolutionMenu.selectedItem().payload.command[1];
tobyspark 31:01845a2347ff 1259
tobyspark 31:01845a2347ff 1260 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 31:01845a2347ff 1261 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, slot);
tobyspark 31:01845a2347ff 1262
tobyspark 31:01845a2347ff 1263 std::string sendOK = ok ? "Sent: EDID. Next:conform?" : "Send Error: EDID";
tobyspark 31:01845a2347ff 1264
tobyspark 31:01845a2347ff 1265 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 31:01845a2347ff 1266 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 31:01845a2347ff 1267 }
tobyspark 30:873979018850 1268 else if (advancedMenu.selectedItem().payload.command[0] == advancedTestSources)
tobyspark 34:69dfe64e7e6b 1269 {
tobyspark 34:69dfe64e7e6b 1270 tvOneRGB1Stable = false;
tobyspark 34:69dfe64e7e6b 1271 tvOneRGB2Stable = false;
tobyspark 34:69dfe64e7e6b 1272 handleTVOneSources();
tobyspark 29:95a7efe30527 1273 }
tobyspark 23:909928cafb95 1274 else if (advancedMenu.selectedItem().payload.command[0] == advancedConformProcessor)
tobyspark 17:fc68d40b8b1f 1275 {
tobyspark 20:8b92d7922c48 1276 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1277 screen.textToBuffer("Reverting...", kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1278 screen.sendBuffer();
tobyspark 41:00d1cd3b2af2 1279
tobyspark 41:00d1cd3b2af2 1280 bool ok = conformProcessor();
tobyspark 41:00d1cd3b2af2 1281
tobyspark 41:00d1cd3b2af2 1282 std::string sendOK = ok ? "Reverting success" : "Send Error: Revert";
tobyspark 41:00d1cd3b2af2 1283
tobyspark 41:00d1cd3b2af2 1284 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1285 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1286 }
tobyspark 41:00d1cd3b2af2 1287 else if (advancedMenu.selectedItem().payload.command[0] == advancedConformUploadProcessor)
tobyspark 41:00d1cd3b2af2 1288 {
tobyspark 41:00d1cd3b2af2 1289 bool ok = true;
tobyspark 41:00d1cd3b2af2 1290
tobyspark 41:00d1cd3b2af2 1291 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1292 screen.textToBuffer("Uploading...", kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1293 screen.sendBuffer();
tobyspark 41:00d1cd3b2af2 1294
tobyspark 41:00d1cd3b2af2 1295 ok = ok && uploadToProcessor();
tobyspark 41:00d1cd3b2af2 1296
tobyspark 41:00d1cd3b2af2 1297 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 20:8b92d7922c48 1298 screen.textToBuffer("Conforming...", kTVOneStatusLine);
tobyspark 20:8b92d7922c48 1299 screen.sendBuffer();
tobyspark 20:8b92d7922c48 1300
tobyspark 41:00d1cd3b2af2 1301 ok = ok && conformProcessor();
tobyspark 17:fc68d40b8b1f 1302
tobyspark 17:fc68d40b8b1f 1303 std::string sendOK = ok ? "Conform success" : "Send Error: Conform";
tobyspark 17:fc68d40b8b1f 1304
tobyspark 17:fc68d40b8b1f 1305 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 17:fc68d40b8b1f 1306 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 17:fc68d40b8b1f 1307 }
tobyspark 23:909928cafb95 1308 else if (advancedMenu.selectedItem().payload.command[0] == advancedLoadDefaults)
tobyspark 16:52484666b323 1309 {
tobyspark 16:52484666b323 1310 settings.loadDefaults();
tobyspark 27:27851d3d2bba 1311 setMixModeMenuItems();
tobyspark 27:27851d3d2bba 1312 setResolutionMenuItems();
tobyspark 16:52484666b323 1313
tobyspark 16:52484666b323 1314 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 16:52484666b323 1315 screen.textToBuffer("Controller reverted", kTVOneStatusLine);
tobyspark 16:52484666b323 1316 }
tobyspark 23:909928cafb95 1317 else if (advancedMenu.selectedItem().payload.command[0] == advancedSetResolutions)
tobyspark 21:f9d63cb7cedb 1318 {
tobyspark 21:f9d63cb7cedb 1319 bool ok;
tobyspark 21:f9d63cb7cedb 1320 ok = tvOne.setCustomResolutions();
tobyspark 21:f9d63cb7cedb 1321
tobyspark 21:f9d63cb7cedb 1322 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 21:f9d63cb7cedb 1323 screen.textToBuffer(ok ? "Resolutions set" : "Res' could not be set", kTVOneStatusLine);
tobyspark 21:f9d63cb7cedb 1324 }
tobyspark 12:c270870bdd23 1325 }
tobyspark 0:87aab40d5806 1326 else
tobyspark 0:87aab40d5806 1327 {
tobyspark 0:87aab40d5806 1328 if (debug) { debug->printf("Warning: No action identified"); }
tobyspark 0:87aab40d5806 1329 }
tobyspark 0:87aab40d5806 1330 }
tobyspark 0:87aab40d5806 1331
tobyspark 34:69dfe64e7e6b 1332 // Send any updates to the display
tobyspark 34:69dfe64e7e6b 1333 screen.sendBuffer();
tobyspark 0:87aab40d5806 1334
tobyspark 5:f8b285ca41ba 1335 //// MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIXMIX MIX MIXMIX MIX MIX MIX MIX MIXMIX MIX MIX
tobyspark 0:87aab40d5806 1336
tobyspark 0:87aab40d5806 1337 bool updateFade = false;
tobyspark 3:033d2b7768f3 1338 float xFade = 0;
tobyspark 3:033d2b7768f3 1339 float fadeUp = 1;
tobyspark 3:033d2b7768f3 1340
tobyspark 3:033d2b7768f3 1341 //// TASK: Process control surface
tobyspark 3:033d2b7768f3 1342
tobyspark 0:87aab40d5806 1343 // Get new states of tap buttons, remembering at end of loop() assign these current values to the previous variables
tobyspark 5:f8b285ca41ba 1344 const bool tapLeft = !tapLeftDIN;
tobyspark 5:f8b285ca41ba 1345 const bool tapRight = !tapRightDIN;
tobyspark 0:87aab40d5806 1346
tobyspark 17:fc68d40b8b1f 1347 // We're taking a further median of the AINs on top of mbed libs v29.
tobyspark 17:fc68d40b8b1f 1348 // This takes some values from last passes and most from now. With debug off, seem to need median size > 5
tobyspark 17:fc68d40b8b1f 1349 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1350 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1351 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1352 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1353 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1354 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1355 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1356 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1357 const float xFadeAINCached = xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1358 const float fadeUpAINCached = fadeUpFilter.process(fadeUpAIN.read());
tobyspark 0:87aab40d5806 1359
tobyspark 0:87aab40d5806 1360 // When a tap is depressed, we can ignore any move of the crossfader but not fade to black
tobyspark 0:87aab40d5806 1361 if (tapLeft || tapRight)
tobyspark 0:87aab40d5806 1362 {
tobyspark 5:f8b285ca41ba 1363 // If both are pressed, take to the one that is new, ie. not the first pressed.
tobyspark 0:87aab40d5806 1364 if (tapLeft && tapRight)
tobyspark 0:87aab40d5806 1365 {
tobyspark 5:f8b285ca41ba 1366 xFade = tapLeftWasFirstPressed ? 1 : 0;
tobyspark 0:87aab40d5806 1367 }
tobyspark 5:f8b285ca41ba 1368 // If just one is pressed, take to that and remember which is pressed
tobyspark 5:f8b285ca41ba 1369 else if (tapLeft)
tobyspark 5:f8b285ca41ba 1370 {
tobyspark 5:f8b285ca41ba 1371 xFade = 0;
tobyspark 5:f8b285ca41ba 1372 tapLeftWasFirstPressed = 1;
tobyspark 5:f8b285ca41ba 1373 }
tobyspark 5:f8b285ca41ba 1374 else if (tapRight)
tobyspark 5:f8b285ca41ba 1375 {
tobyspark 5:f8b285ca41ba 1376 xFade = 1;
tobyspark 5:f8b285ca41ba 1377 tapLeftWasFirstPressed = 0;
tobyspark 5:f8b285ca41ba 1378 }
tobyspark 5:f8b285ca41ba 1379 }
tobyspark 18:ebe5da639a6a 1380 else xFade = 1.0 - fadeCalc(xFadeAINCached, xFadeTolerance);
tobyspark 0:87aab40d5806 1381
tobyspark 0:87aab40d5806 1382 fadeUp = 1.0 - fadeCalc(fadeUpAINCached, fadeUpTolerance);
tobyspark 0:87aab40d5806 1383
tobyspark 33:e6672a9bd571 1384 //// TASK: Process Network Comms In, ie. modify TVOne state
tobyspark 5:f8b285ca41ba 1385 if (commsMode == commsOSC)
tobyspark 3:033d2b7768f3 1386 {
tobyspark 3:033d2b7768f3 1387 if (osc->newMessage)
tobyspark 3:033d2b7768f3 1388 {
tobyspark 3:033d2b7768f3 1389 osc->newMessage = false; // fixme!
tobyspark 33:e6672a9bd571 1390 processOSCIn(xFade, fadeUp);
tobyspark 3:033d2b7768f3 1391 }
tobyspark 3:033d2b7768f3 1392 }
tobyspark 3:033d2b7768f3 1393
tobyspark 5:f8b285ca41ba 1394 if (commsMode == commsArtNet)
tobyspark 3:033d2b7768f3 1395 {
tobyspark 33:e6672a9bd571 1396 if (artNet->Work()) processArtNetIn(xFade, fadeUp);
tobyspark 3:033d2b7768f3 1397 }
tobyspark 3:033d2b7768f3 1398
tobyspark 5:f8b285ca41ba 1399 if (commsMode == commsDMXIn)
tobyspark 5:f8b285ca41ba 1400 {
tobyspark 5:f8b285ca41ba 1401 processDMXIn(xFade, fadeUp);
tobyspark 5:f8b285ca41ba 1402 }
tobyspark 5:f8b285ca41ba 1403
tobyspark 5:f8b285ca41ba 1404 if (commsMode == commsDMXOut)
tobyspark 5:f8b285ca41ba 1405 {
tobyspark 5:f8b285ca41ba 1406 processDMXOut(xFade, fadeUp);
tobyspark 5:f8b285ca41ba 1407 }
tobyspark 0:87aab40d5806 1408
tobyspark 0:87aab40d5806 1409 // Calculate new A&B fade percents
tobyspark 0:87aab40d5806 1410 int newFadeAPercent = 0;
tobyspark 0:87aab40d5806 1411 int newFadeBPercent = 0;
tobyspark 0:87aab40d5806 1412
tobyspark 30:873979018850 1413 if (mixMode == mixBlend)
tobyspark 11:0783cfbeb746 1414 {
tobyspark 30:873979018850 1415 if (fadeUp < 1.0)
tobyspark 30:873979018850 1416 {
tobyspark 30:873979018850 1417 // we need to set fade level of both windows as there is no way AFAIK to implement fade to black as a further window on top of A&B
tobyspark 30:873979018850 1418 newFadeAPercent = (1.0-xFade) * fadeUp * 100.0;
tobyspark 30:873979018850 1419 newFadeBPercent = xFade * fadeUp * 100.0;
tobyspark 30:873979018850 1420 }
tobyspark 30:873979018850 1421 else
tobyspark 30:873979018850 1422 {
tobyspark 30:873979018850 1423 // we can optimise and just fade A in and out over a fully up B, doubling the rate of fadeA commands sent.
tobyspark 30:873979018850 1424 newFadeAPercent = (1.0-xFade) * 100.0;
tobyspark 30:873979018850 1425 newFadeBPercent = 100.0;
tobyspark 30:873979018850 1426 }
tobyspark 11:0783cfbeb746 1427 }
tobyspark 15:4b394c64b461 1428 else if (mixMode == mixAdditive)
tobyspark 11:0783cfbeb746 1429 {
tobyspark 22:90054fe6d86c 1430 // we need to set fade level of both windows according to the fade curve profile
tobyspark 22:90054fe6d86c 1431 float newFadeA = (1.0-xFade) * (1.0 + fadeCurve);
tobyspark 22:90054fe6d86c 1432 float newFadeB = xFade * (1 + fadeCurve);
tobyspark 22:90054fe6d86c 1433 if (newFadeA > 1.0) newFadeA = 1.0;
tobyspark 22:90054fe6d86c 1434 if (newFadeB > 1.0) newFadeB = 1.0;
tobyspark 22:90054fe6d86c 1435
tobyspark 22:90054fe6d86c 1436 newFadeAPercent = newFadeA * fadeUp * 100.0;
tobyspark 22:90054fe6d86c 1437 newFadeBPercent = newFadeB * fadeUp * 100.0;
tobyspark 11:0783cfbeb746 1438 }
tobyspark 36:8b5c75c8bc23 1439 else if (mixMode >= mixKeyStartIndex)
tobyspark 11:0783cfbeb746 1440 {
tobyspark 0:87aab40d5806 1441 newFadeAPercent = (1.0-xFade) * fadeUp * 100.0;
tobyspark 0:87aab40d5806 1442 newFadeBPercent = fadeUp * 100.0;
tobyspark 0:87aab40d5806 1443 }
tobyspark 0:87aab40d5806 1444
tobyspark 17:fc68d40b8b1f 1445 //// TASK: Send to TVOne if percents have changed
tobyspark 17:fc68d40b8b1f 1446
tobyspark 17:fc68d40b8b1f 1447 // No amount of median filtering is stopping flipflopping between two adjacent percents, so...
tobyspark 17:fc68d40b8b1f 1448 bool fadeAPercentHasChanged;
tobyspark 17:fc68d40b8b1f 1449 bool fadeBPercentHasChanged;
tobyspark 17:fc68d40b8b1f 1450 if (oldFadeAPercent == newFadeAPercent && (newFadeAPercent == fadeAPercent - 1 || newFadeAPercent == fadeAPercent + 1))
tobyspark 17:fc68d40b8b1f 1451 fadeAPercentHasChanged = false;
tobyspark 17:fc68d40b8b1f 1452 else
tobyspark 17:fc68d40b8b1f 1453 fadeAPercentHasChanged = newFadeAPercent != fadeAPercent;
tobyspark 17:fc68d40b8b1f 1454 if (oldFadeBPercent == newFadeBPercent && (newFadeBPercent == fadeBPercent - 1 || newFadeBPercent == fadeBPercent + 1))
tobyspark 17:fc68d40b8b1f 1455 fadeBPercentHasChanged = false;
tobyspark 17:fc68d40b8b1f 1456 else
tobyspark 17:fc68d40b8b1f 1457 fadeBPercentHasChanged = newFadeBPercent != fadeBPercent;
tobyspark 17:fc68d40b8b1f 1458
tobyspark 35:d5d9f0838f99 1459 // If changing mixMode from additive, we want to do this before updating fade values
tobyspark 35:d5d9f0838f99 1460 if (updateMixMode && mixMode != mixAdditive) actionMixMode();
tobyspark 35:d5d9f0838f99 1461
tobyspark 9:f83eadd8917a 1462 // We want to send the higher first, otherwise black flashes can happen on taps
tobyspark 17:fc68d40b8b1f 1463 if (fadeAPercentHasChanged && newFadeAPercent >= newFadeBPercent)
tobyspark 8:d46cc49f0f37 1464 {
tobyspark 17:fc68d40b8b1f 1465 oldFadeAPercent = fadeAPercent;
tobyspark 0:87aab40d5806 1466 fadeAPercent = newFadeAPercent;
tobyspark 0:87aab40d5806 1467 updateFade = true;
tobyspark 0:87aab40d5806 1468
tobyspark 0:87aab40d5806 1469 fadeAPO = fadeAPercent / 100.0;
tobyspark 0:87aab40d5806 1470 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent);
tobyspark 0:87aab40d5806 1471 }
tobyspark 17:fc68d40b8b1f 1472 if (fadeBPercentHasChanged)
tobyspark 8:d46cc49f0f37 1473 {
tobyspark 17:fc68d40b8b1f 1474 oldFadeBPercent = fadeBPercent;
tobyspark 0:87aab40d5806 1475 fadeBPercent = newFadeBPercent;
tobyspark 0:87aab40d5806 1476 updateFade = true;
tobyspark 0:87aab40d5806 1477
tobyspark 0:87aab40d5806 1478 fadeBPO = fadeBPercent / 100.0;
tobyspark 0:87aab40d5806 1479 tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent);
tobyspark 0:87aab40d5806 1480 }
tobyspark 17:fc68d40b8b1f 1481 if (fadeAPercentHasChanged && newFadeAPercent < newFadeBPercent)
tobyspark 9:f83eadd8917a 1482 {
tobyspark 17:fc68d40b8b1f 1483 oldFadeAPercent = fadeAPercent;
tobyspark 9:f83eadd8917a 1484 fadeAPercent = newFadeAPercent;
tobyspark 9:f83eadd8917a 1485 updateFade = true;
tobyspark 9:f83eadd8917a 1486
tobyspark 9:f83eadd8917a 1487 fadeAPO = fadeAPercent / 100.0;
tobyspark 9:f83eadd8917a 1488 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent);
tobyspark 9:f83eadd8917a 1489 }
tobyspark 8:d46cc49f0f37 1490 if (updateFade && debug)
tobyspark 8:d46cc49f0f37 1491 {
tobyspark 0:87aab40d5806 1492 //debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAIN.read(), fadeUpAIN.read());
tobyspark 0:87aab40d5806 1493 debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAINCached, fadeUpAINCached);
tobyspark 0:87aab40d5806 1494 debug->printf("xFade = %3f fadeUp = %3f fadeA% = %i fadeB% = %i \r\n", xFade, fadeUp, fadeAPercent, fadeBPercent);
tobyspark 18:ebe5da639a6a 1495 debug->printf("\r\n");
tobyspark 0:87aab40d5806 1496 }
tobyspark 30:873979018850 1497
tobyspark 35:d5d9f0838f99 1498 // If changing mixMode to additive, we want to do this before updating fade values
tobyspark 35:d5d9f0838f99 1499 if (updateMixMode && mixMode == mixAdditive) actionMixMode();
tobyspark 35:d5d9f0838f99 1500
tobyspark 33:e6672a9bd571 1501 //// TASK: Process Network Comms Out, ie. send out any fade updates
tobyspark 33:e6672a9bd571 1502 if (commsMode == commsOSC && updateFade)
tobyspark 33:e6672a9bd571 1503 {
tobyspark 33:e6672a9bd571 1504 processOSCOut(xFade, fadeUp);
tobyspark 33:e6672a9bd571 1505 }
tobyspark 33:e6672a9bd571 1506
tobyspark 33:e6672a9bd571 1507 if (commsMode == commsArtNet && updateFade)
tobyspark 33:e6672a9bd571 1508 {
tobyspark 33:e6672a9bd571 1509 processArtNetOut(xFade, fadeUp);
tobyspark 33:e6672a9bd571 1510 }
tobyspark 33:e6672a9bd571 1511
tobyspark 33:e6672a9bd571 1512 if (commsMode == commsDMXOut && updateFade)
tobyspark 33:e6672a9bd571 1513 {
tobyspark 33:e6672a9bd571 1514 processDMXOut(xFade, fadeUp);
tobyspark 33:e6672a9bd571 1515 }
tobyspark 33:e6672a9bd571 1516
tobyspark 34:69dfe64e7e6b 1517 // Housekeeping
tobyspark 34:69dfe64e7e6b 1518 if (tvOne.millisSinceLastCommandSent() > 1500)
tobyspark 30:873979018850 1519 {
tobyspark 34:69dfe64e7e6b 1520 // We should check up on any source that hasn't ever been stable
tobyspark 30:873979018850 1521 if (!tvOneRGB1Stable || !tvOneRGB2Stable) handleTVOneSources();
tobyspark 30:873979018850 1522 }
tobyspark 0:87aab40d5806 1523 }
tobyspark 30:873979018850 1524 }