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 May 12 23:50:33 2013 +0000
Revision:
58:54347f2c3184
Parent:
57:14d37904c889
Child:
59:bb17773d0051
Network In works with hands-on controls. Mix will only be controlled by network if messages received, and while no messages are being received moving the hands-on controls will pick control back from network.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 47:ff6b98459548 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 49:16309f39cead 42 * v23 - Set keying values from controller
tobyspark 44:723e65413ebe 43 * v24 - Conform uploads SIS image; now once firmware is loaded controller is all that is required
tobyspark 49:16309f39cead 44 * v25 - UX work
tobyspark 58:54347f2c3184 45 * v26 - Tweaks: Network in works with hands-on controls, EDID Change message, Fit/Fill
tobyspark 36:8b5c75c8bc23 46 * vxx - TODO: Writes back to .ini on USB mass storage: keyer updates, comms, hdcp, edid internal/passthrough, ...?
tobyspark 8:d46cc49f0f37 47 * vxx - TODO: EDID creation from resolution
tobyspark 8:d46cc49f0f37 48 */
tobyspark 8:d46cc49f0f37 49
tobyspark 0:87aab40d5806 50 #include "mbed.h"
tobyspark 0:87aab40d5806 51
tobyspark 0:87aab40d5806 52 #include "spk_tvone_mbed.h"
tobyspark 0:87aab40d5806 53 #include "spk_utils.h"
tobyspark 0:87aab40d5806 54 #include "spk_mRotaryEncoder.h"
tobyspark 0:87aab40d5806 55 #include "spk_oled_ssd1305.h"
tobyspark 2:50043054e4f7 56 #include "spk_oled_gfx.h"
tobyspark 11:0783cfbeb746 57 #include "spk_settings.h"
tobyspark 1:f9fca21102e0 58 #include "EthernetNetIf.h"
tobyspark 1:f9fca21102e0 59 #include "mbedOSC.h"
tobyspark 3:033d2b7768f3 60 #include "DmxArtNet.h"
tobyspark 5:f8b285ca41ba 61 #include "DMX.h"
tobyspark 17:fc68d40b8b1f 62 #include "filter.h"
tobyspark 0:87aab40d5806 63
tobyspark 55:35a295d36d23 64 #define kSPKDFSoftwareVersion "26beta"
tobyspark 13:3796bde6ba8f 65
tobyspark 5:f8b285ca41ba 66 // MBED PINS
tobyspark 5:f8b285ca41ba 67
tobyspark 5:f8b285ca41ba 68 #define kMBED_AIN_XFADE p20
tobyspark 5:f8b285ca41ba 69 #define kMBED_AIN_FADEUP p19
tobyspark 5:f8b285ca41ba 70 #define kMBED_DIN_TAP_L p24
tobyspark 5:f8b285ca41ba 71 #define kMBED_DIN_TAP_R p23
tobyspark 5:f8b285ca41ba 72 #define kMBED_ENC_SW p15
tobyspark 5:f8b285ca41ba 73 #define kMBED_ENC_A p16
tobyspark 5:f8b285ca41ba 74 #define kMBED_ENC_B p17
tobyspark 5:f8b285ca41ba 75
tobyspark 5:f8b285ca41ba 76 #define kMBED_RS232_TTLTX p13
tobyspark 5:f8b285ca41ba 77 #define kMBED_RS232_TTLRX p14
tobyspark 5:f8b285ca41ba 78
tobyspark 5:f8b285ca41ba 79 #define kMBED_OLED_MOSI p5
tobyspark 5:f8b285ca41ba 80 #define kMBED_OLED_SCK p7
tobyspark 5:f8b285ca41ba 81 #define kMBED_OLED_CS p8
tobyspark 5:f8b285ca41ba 82 #define kMBED_OLED_RES p9
tobyspark 5:f8b285ca41ba 83 #define kMBED_OLED_DC p10
tobyspark 5:f8b285ca41ba 84
tobyspark 5:f8b285ca41ba 85 #define kMBED_DIN_ETHLO_DMXHI p30
tobyspark 5:f8b285ca41ba 86 #define kMBED_DOUT_RS485_TXHI_RXLO p29
tobyspark 5:f8b285ca41ba 87 #define kMBED_RS485_TTLTX p28
tobyspark 5:f8b285ca41ba 88 #define kMBED_RS485_TTLRX p27
tobyspark 5:f8b285ca41ba 89
tobyspark 5:f8b285ca41ba 90 // DISPLAY
tobyspark 5:f8b285ca41ba 91
tobyspark 1:f9fca21102e0 92 #define kMenuLine1 3
tobyspark 1:f9fca21102e0 93 #define kMenuLine2 4
tobyspark 1:f9fca21102e0 94 #define kCommsStatusLine 6
tobyspark 1:f9fca21102e0 95 #define kTVOneStatusLine 7
tobyspark 48:c0fedfa8c525 96 #define kTVOneStatusMessageHoldTime 5
tobyspark 1:f9fca21102e0 97
tobyspark 5:f8b285ca41ba 98 // NETWORKING
tobyspark 5:f8b285ca41ba 99
tobyspark 1:f9fca21102e0 100 #define kOSCMbedPort 10000
tobyspark 1:f9fca21102e0 101 #define kOSCMbedIPAddress 10,0,0,2
tobyspark 1:f9fca21102e0 102 #define kOSCMbedSubnetMask 255,255,255,0
tobyspark 1:f9fca21102e0 103 #define kOSCMbedGateway 10,0,0,1
tobyspark 1:f9fca21102e0 104 #define kOSCMbedDNS 10,0,0,1
tobyspark 0:87aab40d5806 105
tobyspark 54:e8606eaa47a3 106 #define kOSCDestIPAddress 10,0,0,1
tobyspark 54:e8606eaa47a3 107 #define kOSCDestPort 12000
tobyspark 54:e8606eaa47a3 108
tobyspark 3:033d2b7768f3 109 #define kArtNetBindIPAddress 2,0,0,100
tobyspark 3:033d2b7768f3 110 #define kArtNetBroadcastAddress 2,255,255,255
tobyspark 3:033d2b7768f3 111
tobyspark 5:f8b285ca41ba 112 #define kDMXInChannelXFade 0
tobyspark 5:f8b285ca41ba 113 #define kDMXInChannelFadeUp 1
tobyspark 5:f8b285ca41ba 114 #define kDMXOutChannelXFade 0
tobyspark 5:f8b285ca41ba 115 #define kDMXOutChannelFadeUp 1
tobyspark 5:f8b285ca41ba 116
tobyspark 13:3796bde6ba8f 117 // 8.3 format filename only, no subdirs
tobyspark 13:3796bde6ba8f 118 #define kSPKDFSettingsFilename "SPKDF.ini"
tobyspark 11:0783cfbeb746 119
tobyspark 26:0299f8760715 120 #define kStringBufferLength 30
tobyspark 26:0299f8760715 121
tobyspark 0:87aab40d5806 122 //// DEBUG
tobyspark 0:87aab40d5806 123
tobyspark 0:87aab40d5806 124 // Comment out one or the other...
tobyspark 56:d6f77bd54e10 125 //Serial *debug = new Serial(USBTX, USBRX); // For debugging via USB serial
tobyspark 56:d6f77bd54e10 126 Serial *debug = NULL; // For release (no debugging)
tobyspark 0:87aab40d5806 127
tobyspark 15:4b394c64b461 128 //// SOFT RESET
tobyspark 15:4b394c64b461 129
tobyspark 15:4b394c64b461 130 extern "C" void mbed_reset();
tobyspark 15:4b394c64b461 131
tobyspark 0:87aab40d5806 132 //// mBED PIN ASSIGNMENTS
tobyspark 0:87aab40d5806 133
tobyspark 0:87aab40d5806 134 // Inputs
tobyspark 5:f8b285ca41ba 135 AnalogIn xFadeAIN(kMBED_AIN_XFADE);
tobyspark 5:f8b285ca41ba 136 AnalogIn fadeUpAIN(kMBED_AIN_FADEUP);
tobyspark 5:f8b285ca41ba 137 DigitalIn tapLeftDIN(kMBED_DIN_TAP_L);
tobyspark 5:f8b285ca41ba 138 DigitalIn tapRightDIN(kMBED_DIN_TAP_R);
tobyspark 17:fc68d40b8b1f 139 medianFilter xFadeFilter(9);
tobyspark 17:fc68d40b8b1f 140 medianFilter fadeUpFilter(9);
tobyspark 0:87aab40d5806 141
tobyspark 5:f8b285ca41ba 142 SPKRotaryEncoder menuEnc(kMBED_ENC_A, kMBED_ENC_B, kMBED_ENC_SW);
tobyspark 5:f8b285ca41ba 143
tobyspark 5:f8b285ca41ba 144 DigitalIn rj45ModeDIN(kMBED_DIN_ETHLO_DMXHI);
tobyspark 0:87aab40d5806 145
tobyspark 0:87aab40d5806 146 // Outputs
tobyspark 0:87aab40d5806 147 PwmOut fadeAPO(LED1);
tobyspark 0:87aab40d5806 148 PwmOut fadeBPO(LED2);
tobyspark 0:87aab40d5806 149
tobyspark 5:f8b285ca41ba 150 DigitalOut dmxDirectionDOUT(kMBED_DOUT_RS485_TXHI_RXLO);
tobyspark 5:f8b285ca41ba 151
tobyspark 0:87aab40d5806 152 // SPKTVOne(PinName txPin, PinName rxPin, PinName signWritePin, PinName signErrorPin, Serial *debugSerial)
tobyspark 5:f8b285ca41ba 153 SPKTVOne tvOne(kMBED_RS232_TTLTX, kMBED_RS232_TTLRX, LED3, LED4, debug);
tobyspark 0:87aab40d5806 154
tobyspark 0:87aab40d5806 155 // SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL);
tobyspark 5:f8b285ca41ba 156 SPKDisplay screen(kMBED_OLED_MOSI, kMBED_OLED_SCK, kMBED_OLED_CS, kMBED_OLED_DC, kMBED_OLED_RES, debug);
tobyspark 48:c0fedfa8c525 157 SPKMessageHold tvOneStatusMessage;
tobyspark 0:87aab40d5806 158
tobyspark 11:0783cfbeb746 159 // Saved Settings
tobyspark 11:0783cfbeb746 160 SPKSettings settings;
tobyspark 11:0783cfbeb746 161
tobyspark 0:87aab40d5806 162 // Menu
tobyspark 0:87aab40d5806 163 SPKMenu *selectedMenu;
tobyspark 23:909928cafb95 164 SPKMenu mainMenu;
tobyspark 23:909928cafb95 165 SPKMenu resolutionMenu;
tobyspark 12:c270870bdd23 166
tobyspark 24:49c6624119ae 167 SPKMenu mixModeMenu;
tobyspark 36:8b5c75c8bc23 168 SPKMenu mixModeAdditiveMenu;
tobyspark 49:16309f39cead 169 SPKMenu mixModeUpdateKeyMenu;
tobyspark 36:8b5c75c8bc23 170 enum { mixBlend, mixAdditive, mixKey };
tobyspark 36:8b5c75c8bc23 171 int mixKeyStartIndex = 1; // need this hard coded as mixBlend and mixAdditive are now combined into the same menu item
tobyspark 30:873979018850 172 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 49:16309f39cead 173 int mixModeOld = mixMode;
tobyspark 29:95a7efe30527 174 float fadeCurve = 0.0f; // 0 = "X", ie. as per blend, 1 = "/\", ie. as per additive <-- pictograms!
tobyspark 22:90054fe6d86c 175
tobyspark 23:909928cafb95 176 SPKMenu commsMenu;
tobyspark 5:f8b285ca41ba 177 enum { commsNone, commsOSC, commsArtNet, commsDMXIn, commsDMXOut};
tobyspark 5:f8b285ca41ba 178 int commsMode = commsNone;
tobyspark 22:90054fe6d86c 179
tobyspark 51:98cc27390484 180 SPKMenu troubleshootingMenu;
tobyspark 51:98cc27390484 181 SPKMenu troubleshootingMenuHDCP;
tobyspark 51:98cc27390484 182 SPKMenu troubleshootingMenuEDID;
tobyspark 55:35a295d36d23 183 SPKMenu troubleshootingMenuAspect;
tobyspark 51:98cc27390484 184 SPKMenu troubleshootingMenuReset;
tobyspark 51:98cc27390484 185
tobyspark 23:909928cafb95 186 SPKMenu advancedMenu;
tobyspark 51:98cc27390484 187 enum { advancedConformUploadProcessor, advancedSetResolutions };
tobyspark 1:f9fca21102e0 188
tobyspark 5:f8b285ca41ba 189 // RJ45 Comms
tobyspark 5:f8b285ca41ba 190 enum { rj45Ethernet = 0, rj45DMX = 1}; // These values from circuit
tobyspark 5:f8b285ca41ba 191 int rj45Mode = -1;
tobyspark 1:f9fca21102e0 192 EthernetNetIf *ethernet = NULL;
tobyspark 1:f9fca21102e0 193 OSCClass *osc = NULL;
tobyspark 33:e6672a9bd571 194 OSCMessage sendMessage;
tobyspark 33:e6672a9bd571 195 OSCMessage receiveMessage;
tobyspark 3:033d2b7768f3 196 DmxArtNet *artNet = NULL;
tobyspark 5:f8b285ca41ba 197 DMX *dmx = NULL;
tobyspark 0:87aab40d5806 198
tobyspark 3:033d2b7768f3 199 // Fade logic constants
tobyspark 0:87aab40d5806 200 const float xFadeTolerance = 0.05;
tobyspark 0:87aab40d5806 201 const float fadeUpTolerance = 0.05;
tobyspark 0:87aab40d5806 202
tobyspark 0:87aab40d5806 203 // A&B Fade as resolved percent
tobyspark 0:87aab40d5806 204 int fadeAPercent = 0;
tobyspark 0:87aab40d5806 205 int fadeBPercent = 0;
tobyspark 17:fc68d40b8b1f 206 int oldFadeAPercent = 0;
tobyspark 17:fc68d40b8b1f 207 int oldFadeBPercent = 0;
tobyspark 0:87aab40d5806 208
tobyspark 0:87aab40d5806 209 // Tap button states
tobyspark 5:f8b285ca41ba 210 bool tapLeftWasFirstPressed = false;
tobyspark 0:87aab40d5806 211
tobyspark 58:54347f2c3184 212 // Comms In fade state
tobyspark 58:54347f2c3184 213 float commsXFade = 0;
tobyspark 58:54347f2c3184 214 float commsFadeUp = 0;
tobyspark 58:54347f2c3184 215 float oldXFade = 0;
tobyspark 58:54347f2c3184 216 float oldFadeUp = 0;
tobyspark 58:54347f2c3184 217 bool commsInActive = false;
tobyspark 58:54347f2c3184 218
tobyspark 0:87aab40d5806 219 // Key mode parameters
tobyspark 0:87aab40d5806 220 int keyerParamsSet = -1; // last keyParams index uploaded to unit
tobyspark 0:87aab40d5806 221
tobyspark 30:873979018850 222 // TVOne input sources stable flag
tobyspark 34:69dfe64e7e6b 223 bool tvOneRGB1Stable = false;
tobyspark 34:69dfe64e7e6b 224 bool tvOneRGB2Stable = false;
tobyspark 30:873979018850 225
tobyspark 31:01845a2347ff 226 // TVOne behaviour flags
tobyspark 31:01845a2347ff 227 bool tvOneHDCPOn = false;
tobyspark 34:69dfe64e7e6b 228 bool tvOneEDIDPassthrough = false;
tobyspark 31:01845a2347ff 229 const int32_t EDIDPassthroughSlot = 7;
tobyspark 55:35a295d36d23 230 enum { tvOneAspectFit = 1, tvOneAspectHFill = 2, tvOneAspectVFill = 3, tvOneAspect1to1 = 4 };
tobyspark 55:35a295d36d23 231 int tvOneAspectHandling = tvOneAspectFit;
tobyspark 34:69dfe64e7e6b 232
tobyspark 58:54347f2c3184 233 bool processOSCIn()
tobyspark 58:54347f2c3184 234 {
tobyspark 58:54347f2c3184 235 bool updateFade = false;
tobyspark 58:54347f2c3184 236
tobyspark 58:54347f2c3184 237 if (osc->newMessage)
tobyspark 3:033d2b7768f3 238 {
tobyspark 58:54347f2c3184 239 osc->newMessage = false; // fixme!
tobyspark 58:54347f2c3184 240
tobyspark 58:54347f2c3184 241 string statusMessage;
tobyspark 58:54347f2c3184 242
tobyspark 58:54347f2c3184 243 if (!strcmp( receiveMessage.getTopAddress() , "dvimxr" ))
tobyspark 25:3b519ef70341 244 {
tobyspark 58:54347f2c3184 245 statusMessage = "OSC: /dvimxr";
tobyspark 58:54347f2c3184 246 if (!strcmp( receiveMessage.getSubAddress() , "xFade" ))
tobyspark 58:54347f2c3184 247 {
tobyspark 58:54347f2c3184 248 if (receiveMessage.getArgNum() == 1)
tobyspark 58:54347f2c3184 249 if (receiveMessage.getTypeTag(0) == 'f')
tobyspark 58:54347f2c3184 250 {
tobyspark 58:54347f2c3184 251 commsXFade = receiveMessage.getArgFloat(0);
tobyspark 58:54347f2c3184 252 updateFade = true;
tobyspark 58:54347f2c3184 253
tobyspark 58:54347f2c3184 254 char buffer[15];
tobyspark 58:54347f2c3184 255 snprintf(buffer, 15, "/xFade %1.2f", commsXFade);
tobyspark 58:54347f2c3184 256 statusMessage += buffer;
tobyspark 58:54347f2c3184 257 }
tobyspark 58:54347f2c3184 258 }
tobyspark 58:54347f2c3184 259 else if (!strcmp( receiveMessage.getSubAddress() , "fadeUp" ))
tobyspark 58:54347f2c3184 260 {
tobyspark 58:54347f2c3184 261 if (receiveMessage.getArgNum() == 1)
tobyspark 58:54347f2c3184 262 if (receiveMessage.getTypeTag(0) == 'f')
tobyspark 58:54347f2c3184 263 {
tobyspark 58:54347f2c3184 264 commsFadeUp = receiveMessage.getArgFloat(0);
tobyspark 58:54347f2c3184 265 updateFade = true;
tobyspark 58:54347f2c3184 266
tobyspark 58:54347f2c3184 267 char buffer[15];
tobyspark 58:54347f2c3184 268 snprintf(buffer, 15, "/fadeUp %1.2f", commsFadeUp);
tobyspark 58:54347f2c3184 269 statusMessage += buffer;
tobyspark 58:54347f2c3184 270 }
tobyspark 58:54347f2c3184 271 }
tobyspark 58:54347f2c3184 272 else
tobyspark 58:54347f2c3184 273 {
tobyspark 58:54347f2c3184 274 statusMessage += receiveMessage.getSubAddress();
tobyspark 58:54347f2c3184 275 statusMessage += " - Ignoring";
tobyspark 58:54347f2c3184 276 }
tobyspark 25:3b519ef70341 277 }
tobyspark 58:54347f2c3184 278 else
tobyspark 25:3b519ef70341 279 {
tobyspark 58:54347f2c3184 280 statusMessage = "OSC: ";
tobyspark 58:54347f2c3184 281 statusMessage += receiveMessage.getTopAddress();
tobyspark 25:3b519ef70341 282 statusMessage += " - Ignoring";
tobyspark 25:3b519ef70341 283 }
tobyspark 58:54347f2c3184 284
tobyspark 58:54347f2c3184 285 screen.clearBufferRow(kCommsStatusLine);
tobyspark 58:54347f2c3184 286 screen.textToBuffer(statusMessage, kCommsStatusLine);
tobyspark 58:54347f2c3184 287
tobyspark 58:54347f2c3184 288 if (debug) debug->printf("%s \r\n", statusMessage.c_str());
tobyspark 3:033d2b7768f3 289 }
tobyspark 3:033d2b7768f3 290
tobyspark 58:54347f2c3184 291 return updateFade;
tobyspark 3:033d2b7768f3 292 }
tobyspark 3:033d2b7768f3 293
tobyspark 58:54347f2c3184 294 void processOSCOut(const float &xFade, const float &fadeUp)
tobyspark 33:e6672a9bd571 295 {
tobyspark 33:e6672a9bd571 296 sendMessage.setAddress("dvimxr", "xFadeFadeUp");
tobyspark 33:e6672a9bd571 297 sendMessage.setArgs("ff", &xFade, &fadeUp);
tobyspark 33:e6672a9bd571 298 osc->sendOsc(&sendMessage);
tobyspark 33:e6672a9bd571 299
tobyspark 58:54347f2c3184 300 char statusMessageBuffer[kStringBufferLength];
tobyspark 58:54347f2c3184 301 snprintf(statusMessageBuffer, kStringBufferLength, "OSC Out: xF %.2f fUp %.2f", xFade, fadeUp);
tobyspark 33:e6672a9bd571 302 screen.clearBufferRow(kCommsStatusLine);
tobyspark 33:e6672a9bd571 303 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 304
tobyspark 33:e6672a9bd571 305 if (debug) debug->printf(statusMessageBuffer);
tobyspark 33:e6672a9bd571 306 }
tobyspark 33:e6672a9bd571 307
tobyspark 58:54347f2c3184 308 bool processArtNetIn()
tobyspark 8:d46cc49f0f37 309 {
tobyspark 58:54347f2c3184 310 if (artNet->Work())
tobyspark 58:54347f2c3184 311 {
tobyspark 58:54347f2c3184 312 int xFadeDMX = artNet->DmxIn[0][0];
tobyspark 58:54347f2c3184 313 int fadeUpDMX = artNet->DmxIn[0][1];
tobyspark 58:54347f2c3184 314
tobyspark 58:54347f2c3184 315 commsXFade = (float)xFadeDMX/255;
tobyspark 58:54347f2c3184 316 commsFadeUp = (float)fadeUpDMX/255;
tobyspark 58:54347f2c3184 317
tobyspark 58:54347f2c3184 318 char statusMessageBuffer[kStringBufferLength];
tobyspark 58:54347f2c3184 319 snprintf(statusMessageBuffer, kStringBufferLength, "A'Net In: xF%3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 58:54347f2c3184 320 screen.clearBufferRow(kCommsStatusLine);
tobyspark 58:54347f2c3184 321 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 58:54347f2c3184 322
tobyspark 58:54347f2c3184 323 if (debug) debug->printf("ArtNet activity");
tobyspark 58:54347f2c3184 324
tobyspark 58:54347f2c3184 325 return true;
tobyspark 58:54347f2c3184 326 }
tobyspark 58:54347f2c3184 327
tobyspark 58:54347f2c3184 328 return false;
tobyspark 3:033d2b7768f3 329 }
tobyspark 0:87aab40d5806 330
tobyspark 58:54347f2c3184 331 void processArtNetOut(const float &xFade, const float &fadeUp)
tobyspark 33:e6672a9bd571 332 {
tobyspark 33:e6672a9bd571 333 int xFadeDMX = xFade*255;
tobyspark 33:e6672a9bd571 334 int fadeUpDMX = fadeUp*255;
tobyspark 33:e6672a9bd571 335
tobyspark 33:e6672a9bd571 336 // Universe 0, Channel 0 = xFade, Channel 1 = fadeUp
tobyspark 33:e6672a9bd571 337 char dmxData[2] = {xFadeDMX, fadeUpDMX};
tobyspark 33:e6672a9bd571 338 artNet->Send_ArtDmx(0, 0, dmxData, 2);
tobyspark 33:e6672a9bd571 339
tobyspark 58:54347f2c3184 340 char statusMessageBuffer[kStringBufferLength];
tobyspark 58:54347f2c3184 341 snprintf(statusMessageBuffer, kStringBufferLength, "A'Net Out: xF%3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 33:e6672a9bd571 342 screen.clearBufferRow(kCommsStatusLine);
tobyspark 33:e6672a9bd571 343 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 344
tobyspark 33:e6672a9bd571 345 if (debug) debug->printf(statusMessageBuffer);
tobyspark 33:e6672a9bd571 346 }
tobyspark 33:e6672a9bd571 347
tobyspark 58:54347f2c3184 348 bool processDMXIn()
tobyspark 8:d46cc49f0f37 349 {
tobyspark 5:f8b285ca41ba 350 int xFadeDMX = dmx->get(kDMXInChannelXFade);
tobyspark 7:e6717468c18d 351 int fadeUpDMX = dmx->get(kDMXInChannelFadeUp);
tobyspark 5:f8b285ca41ba 352
tobyspark 58:54347f2c3184 353 if (((float)xFadeDMX/255 != commsXFade) && ((float)fadeUpDMX/255 != commsFadeUp))
tobyspark 58:54347f2c3184 354 {
tobyspark 58:54347f2c3184 355 commsXFade = (float)xFadeDMX/255;
tobyspark 58:54347f2c3184 356 commsFadeUp = (float)fadeUpDMX/255;
tobyspark 58:54347f2c3184 357
tobyspark 58:54347f2c3184 358 char statusMessageBuffer[kStringBufferLength];
tobyspark 58:54347f2c3184 359 snprintf(statusMessageBuffer, kStringBufferLength, "DMX In: xF %3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 58:54347f2c3184 360 screen.clearBufferRow(kCommsStatusLine);
tobyspark 58:54347f2c3184 361 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 58:54347f2c3184 362
tobyspark 58:54347f2c3184 363 if (debug) debug->printf(statusMessageBuffer);
tobyspark 58:54347f2c3184 364
tobyspark 58:54347f2c3184 365 return true;
tobyspark 58:54347f2c3184 366 }
tobyspark 58:54347f2c3184 367
tobyspark 58:54347f2c3184 368 return false;
tobyspark 5:f8b285ca41ba 369 }
tobyspark 5:f8b285ca41ba 370
tobyspark 58:54347f2c3184 371 void processDMXOut(const float &xFade, const float &fadeUp)
tobyspark 8:d46cc49f0f37 372 {
tobyspark 51:98cc27390484 373 int xFadeDMX = xFade*255;
tobyspark 51:98cc27390484 374 int fadeUpDMX = fadeUp*255;
tobyspark 5:f8b285ca41ba 375
tobyspark 5:f8b285ca41ba 376 dmx->put(kDMXOutChannelXFade, xFadeDMX);
tobyspark 5:f8b285ca41ba 377 dmx->put(kDMXOutChannelFadeUp, fadeUpDMX);
tobyspark 5:f8b285ca41ba 378
tobyspark 58:54347f2c3184 379 char statusMessageBuffer[kStringBufferLength];
tobyspark 58:54347f2c3184 380 snprintf(statusMessageBuffer, kStringBufferLength, "DMX Out: xF %3i fUp %3i", xFadeDMX, fadeUpDMX);
tobyspark 5:f8b285ca41ba 381 screen.clearBufferRow(kCommsStatusLine);
tobyspark 25:3b519ef70341 382 screen.textToBuffer(statusMessageBuffer, kCommsStatusLine);
tobyspark 33:e6672a9bd571 383
tobyspark 25:3b519ef70341 384 if (debug) debug->printf(statusMessageBuffer);
tobyspark 5:f8b285ca41ba 385 }
tobyspark 0:87aab40d5806 386
tobyspark 8:d46cc49f0f37 387 inline float fadeCalc (const float AIN, const float tolerance)
tobyspark 8:d46cc49f0f37 388 {
tobyspark 0:87aab40d5806 389 float pos ;
tobyspark 0:87aab40d5806 390 if (AIN < tolerance) pos = 0;
tobyspark 0:87aab40d5806 391 else if (AIN > 1.0 - tolerance) pos = 1;
tobyspark 0:87aab40d5806 392 else pos = (AIN - tolerance) / (1 - 2*tolerance);
tobyspark 0:87aab40d5806 393 if (debug && false) debug->printf("fadeCalc in: %f out: %f \r\n", AIN, pos);
tobyspark 0:87aab40d5806 394 return pos;
tobyspark 0:87aab40d5806 395 }
tobyspark 0:87aab40d5806 396
tobyspark 34:69dfe64e7e6b 397 bool handleTVOneSources()
tobyspark 30:873979018850 398 {
tobyspark 49:16309f39cead 399 static int notOKCounter = 0;
tobyspark 49:16309f39cead 400
tobyspark 30:873979018850 401 bool ok = true;
tobyspark 30:873979018850 402
tobyspark 30:873979018850 403 int32_t payload = 0;
tobyspark 30:873979018850 404
tobyspark 30:873979018850 405 ok = ok && tvOne.readCommand(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceSourceStable, payload);
tobyspark 34:69dfe64e7e6b 406 bool RGB1 = (payload == 1);
tobyspark 30:873979018850 407
tobyspark 30:873979018850 408 ok = ok && tvOne.readCommand(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceSourceStable, payload);
tobyspark 30:873979018850 409 bool RGB2 = (payload == 1);
tobyspark 30:873979018850 410
tobyspark 34:69dfe64e7e6b 411 ok = ok && tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, payload);
tobyspark 34:69dfe64e7e6b 412 int sourceA = payload;
tobyspark 34:69dfe64e7e6b 413
tobyspark 34:69dfe64e7e6b 414 ok = ok && tvOne.readCommand(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, payload);
tobyspark 34:69dfe64e7e6b 415 int sourceB = payload;
tobyspark 34:69dfe64e7e6b 416
tobyspark 44:723e65413ebe 417 if (debug) debug->printf("HandleTVOneSources: RGB1: %i, RGB2: %i, sourceA: %#x, sourceB: %#x \r\n", RGB1, RGB2, sourceA, sourceB);
tobyspark 45:cf8c2400be5c 418
tobyspark 45:cf8c2400be5c 419 string tvOneDetectString = "TVOne: ";
tobyspark 45:cf8c2400be5c 420
tobyspark 45:cf8c2400be5c 421 if (ok)
tobyspark 30:873979018850 422 {
tobyspark 45:cf8c2400be5c 423 string right = RGB1 ? "Live" : (tvOneRGB1Stable ? "Hold" : "Logo");
tobyspark 45:cf8c2400be5c 424 string left = RGB2 ? "Live" : (tvOneRGB2Stable ? "Hold" : "Logo");
tobyspark 45:cf8c2400be5c 425
tobyspark 45:cf8c2400be5c 426 tvOneDetectString += "L: ";
tobyspark 45:cf8c2400be5c 427 tvOneDetectString += left;
tobyspark 45:cf8c2400be5c 428 tvOneDetectString += " R: ";
tobyspark 45:cf8c2400be5c 429 tvOneDetectString += right;
tobyspark 30:873979018850 430 }
tobyspark 49:16309f39cead 431
tobyspark 48:c0fedfa8c525 432 tvOneStatusMessage.addMessage(tvOneDetectString, 0);
tobyspark 34:69dfe64e7e6b 433
tobyspark 34:69dfe64e7e6b 434 // Assign appropriate source depending on whether DVI input is good
tobyspark 34:69dfe64e7e6b 435 // If that assign command completes ok, and the DVI input is good, finally flag the unit has had a live source
tobyspark 34:69dfe64e7e6b 436 // 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 437 if (ok && !tvOneRGB1Stable)
tobyspark 30:873979018850 438 {
tobyspark 34:69dfe64e7e6b 439 if (RGB1 && (sourceB != kTV1SourceRGB1)) ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB1);
tobyspark 34:69dfe64e7e6b 440 if (!RGB1 && (sourceB != kTV1SourceSIS2)) ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceSIS2); // Wierd: Can't set to SIS1 sometimes.
tobyspark 34:69dfe64e7e6b 441 if (ok && RGB1) tvOneRGB1Stable = true;
tobyspark 30:873979018850 442 }
tobyspark 34:69dfe64e7e6b 443 if (ok && !tvOneRGB2Stable)
tobyspark 34:69dfe64e7e6b 444 {
tobyspark 34:69dfe64e7e6b 445 if (RGB2 && (sourceA != kTV1SourceRGB2)) ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB2);
tobyspark 34:69dfe64e7e6b 446 if (!RGB2 && (sourceA != kTV1SourceSIS2)) ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceSIS2);
tobyspark 34:69dfe64e7e6b 447 if (ok && RGB2) tvOneRGB2Stable = true;
tobyspark 34:69dfe64e7e6b 448 }
tobyspark 48:c0fedfa8c525 449
tobyspark 49:16309f39cead 450 // It seems there is an occasional RS232 choke around power-on of the processor.
tobyspark 49:16309f39cead 451 // Hard to reproduce, doubly so when in debug mode, this may fix.
tobyspark 49:16309f39cead 452 if (ok)
tobyspark 49:16309f39cead 453 {
tobyspark 49:16309f39cead 454 notOKCounter = 0;
tobyspark 49:16309f39cead 455 tvOne.resetCommandPeriods();
tobyspark 49:16309f39cead 456 }
tobyspark 51:98cc27390484 457 else
tobyspark 49:16309f39cead 458 {
tobyspark 51:98cc27390484 459 notOKCounter++;
tobyspark 51:98cc27390484 460 if (notOKCounter == 5)
tobyspark 51:98cc27390484 461 {
tobyspark 51:98cc27390484 462 tvOne.increaseCommandPeriods(200);
tobyspark 51:98cc27390484 463 }
tobyspark 51:98cc27390484 464 if (notOKCounter == 6)
tobyspark 51:98cc27390484 465 {
tobyspark 51:98cc27390484 466 tvOne.resetCommandPeriods();
tobyspark 51:98cc27390484 467 }
tobyspark 51:98cc27390484 468 if (notOKCounter % 15 == 0)
tobyspark 51:98cc27390484 469 {
tobyspark 51:98cc27390484 470 tvOneStatusMessage.addMessage("TVOne: Resetting link", 2.0f);
tobyspark 51:98cc27390484 471 screen.textToBuffer(tvOneStatusMessage.message(), kTVOneStatusLine);
tobyspark 51:98cc27390484 472 screen.sendBuffer();
tobyspark 51:98cc27390484 473
tobyspark 52:98f557fe93a3 474 tvOne.increaseCommandPeriods(1500);
tobyspark 51:98cc27390484 475 }
tobyspark 51:98cc27390484 476 if (notOKCounter % 15 == 1)
tobyspark 51:98cc27390484 477 {
tobyspark 51:98cc27390484 478 tvOne.resetCommandPeriods();
tobyspark 51:98cc27390484 479 }
tobyspark 49:16309f39cead 480 }
tobyspark 49:16309f39cead 481
tobyspark 51:98cc27390484 482 return ok;
tobyspark 30:873979018850 483 }
tobyspark 30:873979018850 484
tobyspark 8:d46cc49f0f37 485 bool setKeyParamsTo(int index)
tobyspark 8:d46cc49f0f37 486 {
tobyspark 0:87aab40d5806 487 // Only spend the time uploading six parameters if we need to
tobyspark 0:87aab40d5806 488 // Might want to bounds check here
tobyspark 0:87aab40d5806 489
tobyspark 9:f83eadd8917a 490 bool ok;
tobyspark 0:87aab40d5806 491
tobyspark 0:87aab40d5806 492 if (index != keyerParamsSet)
tobyspark 0:87aab40d5806 493 {
tobyspark 31:01845a2347ff 494 ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, settings.keyerParamSet(index)[SPKSettings::minY]);
tobyspark 31:01845a2347ff 495 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, settings.keyerParamSet(index)[SPKSettings::maxY]);
tobyspark 31:01845a2347ff 496 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, settings.keyerParamSet(index)[SPKSettings::minU]);
tobyspark 31:01845a2347ff 497 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, settings.keyerParamSet(index)[SPKSettings::maxU]);
tobyspark 31:01845a2347ff 498 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, settings.keyerParamSet(index)[SPKSettings::minV]);
tobyspark 31:01845a2347ff 499 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, settings.keyerParamSet(index)[SPKSettings::maxV]);
tobyspark 0:87aab40d5806 500
tobyspark 0:87aab40d5806 501 keyerParamsSet = index;
tobyspark 9:f83eadd8917a 502 }
tobyspark 9:f83eadd8917a 503 else
tobyspark 9:f83eadd8917a 504 {
tobyspark 9:f83eadd8917a 505 ok = true;
tobyspark 9:f83eadd8917a 506 }
tobyspark 0:87aab40d5806 507
tobyspark 0:87aab40d5806 508 return ok;
tobyspark 0:87aab40d5806 509 }
tobyspark 0:87aab40d5806 510
tobyspark 24:49c6624119ae 511 void actionMixMode()
tobyspark 24:49c6624119ae 512 {
tobyspark 31:01845a2347ff 513 if (debug) debug->printf("Changing mix mode \r\n");
tobyspark 31:01845a2347ff 514
tobyspark 24:49c6624119ae 515 bool ok = true;
tobyspark 25:3b519ef70341 516 string sentOK;
tobyspark 26:0299f8760715 517 char sentMSGBuffer[kStringBufferLength];
tobyspark 24:49c6624119ae 518
tobyspark 24:49c6624119ae 519 // Set Keyer
tobyspark 39:7d9a5eef93c9 520 if (mixMode < mixKey)
tobyspark 24:49c6624119ae 521 {
tobyspark 31:01845a2347ff 522 // Set Keyer Off. Quicker to set and fail than to test for on and then turn off
tobyspark 35:d5d9f0838f99 523 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, false);
tobyspark 31:01845a2347ff 524
tobyspark 31:01845a2347ff 525 if (mixMode == mixBlend)
tobyspark 24:49c6624119ae 526 {
tobyspark 31:01845a2347ff 527 // Turn off Additive Mixing on output
tobyspark 52:98f557fe93a3 528 if (tvOne.getProcessorType().version == 423)
tobyspark 52:98f557fe93a3 529 {
tobyspark 52:98f557fe93a3 530 ok = tvOne.command(0, kTV1WindowIDA, 0x298, 0);
tobyspark 52:98f557fe93a3 531 }
tobyspark 31:01845a2347ff 532 snprintf(sentMSGBuffer, kStringBufferLength, "Blend");
tobyspark 24:49c6624119ae 533 }
tobyspark 31:01845a2347ff 534 if (mixMode == mixAdditive)
tobyspark 31:01845a2347ff 535 {
tobyspark 31:01845a2347ff 536 // 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 537 ok = tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent);
tobyspark 31:01845a2347ff 538 // Then turn on Additive Mixing
tobyspark 52:98f557fe93a3 539 if (tvOne.getProcessorType().version == 423)
tobyspark 52:98f557fe93a3 540 {
tobyspark 52:98f557fe93a3 541 ok = ok && tvOne.command(0, kTV1WindowIDA, 0x298, 1);
tobyspark 52:98f557fe93a3 542 }
tobyspark 31:01845a2347ff 543 snprintf(sentMSGBuffer, kStringBufferLength, "Additive");
tobyspark 31:01845a2347ff 544 }
tobyspark 24:49c6624119ae 545 }
tobyspark 24:49c6624119ae 546 else
tobyspark 24:49c6624119ae 547 {
tobyspark 39:7d9a5eef93c9 548 int index = mixModeMenu.selectedIndex() - mixKeyStartIndex;
tobyspark 49:16309f39cead 549
tobyspark 49:16309f39cead 550 // Turn off Additive Mixing on output
tobyspark 52:98f557fe93a3 551 if (tvOne.getProcessorType().version == 423)
tobyspark 52:98f557fe93a3 552 {
tobyspark 52:98f557fe93a3 553 ok = tvOne.command(0, kTV1WindowIDA, 0x298, 0);
tobyspark 52:98f557fe93a3 554 }
tobyspark 49:16309f39cead 555 // Turn on Keyer
tobyspark 49:16309f39cead 556 ok = ok && setKeyParamsTo(index);
tobyspark 24:49c6624119ae 557 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, true);
tobyspark 49:16309f39cead 558
tobyspark 26:0299f8760715 559 snprintf(sentMSGBuffer, kStringBufferLength, "Keyer On with %i", index);
tobyspark 24:49c6624119ae 560 }
tobyspark 49:16309f39cead 561
tobyspark 49:16309f39cead 562 mixModeOld = mixMode;
tobyspark 24:49c6624119ae 563
tobyspark 24:49c6624119ae 564 if (ok) sentOK = "Sent:";
tobyspark 24:49c6624119ae 565 else sentOK = "Send Error:";
tobyspark 24:49c6624119ae 566
tobyspark 48:c0fedfa8c525 567 tvOneStatusMessage.addMessage(sentOK + sentMSGBuffer, kTVOneStatusMessageHoldTime);
tobyspark 24:49c6624119ae 568 }
tobyspark 24:49c6624119ae 569
tobyspark 49:16309f39cead 570 bool checkTVOneMixStatus()
tobyspark 49:16309f39cead 571 {
tobyspark 49:16309f39cead 572 bool ok = true;
tobyspark 49:16309f39cead 573
tobyspark 49:16309f39cead 574 int32_t payload;
tobyspark 49:16309f39cead 575
tobyspark 49:16309f39cead 576 // Mix Mode
tobyspark 49:16309f39cead 577 bool mixModeNeedsAction = false;
tobyspark 49:16309f39cead 578 bool additiveOn = false, keyerOn = false;
tobyspark 49:16309f39cead 579
tobyspark 49:16309f39cead 580 if (mixMode == mixBlend) { additiveOn = false; keyerOn = false;}
tobyspark 49:16309f39cead 581 if (mixMode == mixAdditive) { additiveOn = true; keyerOn = false;}
tobyspark 49:16309f39cead 582 if (mixMode >= mixKey) { additiveOn = false; keyerOn = true; }
tobyspark 49:16309f39cead 583
tobyspark 52:98f557fe93a3 584 if (tvOne.getProcessorType().version == 423)
tobyspark 52:98f557fe93a3 585 {
tobyspark 52:98f557fe93a3 586 payload = -1;
tobyspark 52:98f557fe93a3 587 ok = ok && tvOne.readCommand(0, kTV1WindowIDA, 0x298, payload);
tobyspark 52:98f557fe93a3 588 if (payload != additiveOn) mixModeNeedsAction = true;
tobyspark 52:98f557fe93a3 589 }
tobyspark 52:98f557fe93a3 590
tobyspark 49:16309f39cead 591 payload = -1;
tobyspark 49:16309f39cead 592 ok = ok && tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, payload);
tobyspark 49:16309f39cead 593 if (payload != keyerOn) mixModeNeedsAction = true;
tobyspark 49:16309f39cead 594
tobyspark 49:16309f39cead 595 if (ok && mixModeNeedsAction)
tobyspark 49:16309f39cead 596 {
tobyspark 49:16309f39cead 597 if (debug) debug->printf("Check TVOne Mix Status requiring mixMode action. mixMode: %i \r\n", mixMode);
tobyspark 49:16309f39cead 598 actionMixMode();
tobyspark 49:16309f39cead 599 }
tobyspark 49:16309f39cead 600
tobyspark 49:16309f39cead 601 // Check Fade
tobyspark 49:16309f39cead 602 payload = -1;
tobyspark 49:16309f39cead 603 ok = ok && tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, payload);
tobyspark 49:16309f39cead 604 if (ok && (payload != fadeAPercent))
tobyspark 49:16309f39cead 605 {
tobyspark 49:16309f39cead 606 if (debug) debug->printf("Check TVOne Mix Status requiring fadeA action");
tobyspark 49:16309f39cead 607 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent);
tobyspark 49:16309f39cead 608 }
tobyspark 49:16309f39cead 609
tobyspark 49:16309f39cead 610 payload = -1;
tobyspark 49:16309f39cead 611 ok = ok && tvOne.readCommand(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, payload);
tobyspark 49:16309f39cead 612 if (ok && (payload != fadeBPercent))
tobyspark 49:16309f39cead 613 {
tobyspark 49:16309f39cead 614 if (debug) debug->printf("Check TVOne Mix Status requiring fadeB action");
tobyspark 49:16309f39cead 615 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent);
tobyspark 49:16309f39cead 616 }
tobyspark 49:16309f39cead 617
tobyspark 49:16309f39cead 618 return ok;
tobyspark 49:16309f39cead 619 }
tobyspark 24:49c6624119ae 620
tobyspark 17:fc68d40b8b1f 621 bool conformProcessor()
tobyspark 17:fc68d40b8b1f 622 {
tobyspark 44:723e65413ebe 623 bool ok;
tobyspark 17:fc68d40b8b1f 624
tobyspark 17:fc68d40b8b1f 625 int32_t on = 1;
tobyspark 17:fc68d40b8b1f 626 int32_t off = 0;
tobyspark 17:fc68d40b8b1f 627
tobyspark 44:723e65413ebe 628 for (int i=0; i < 3; i++)
tobyspark 44:723e65413ebe 629 {
tobyspark 44:723e65413ebe 630 // Independent output
tobyspark 44:723e65413ebe 631 ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionMode, 2);
tobyspark 44:723e65413ebe 632 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputEnable, on);
tobyspark 44:723e65413ebe 633 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsLockMethod, off);
tobyspark 44:723e65413ebe 634
tobyspark 44:723e65413ebe 635 // Make sure our windows exist
tobyspark 44:723e65413ebe 636 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsEnable, on);
tobyspark 44:723e65413ebe 637 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsEnable, on);
tobyspark 44:723e65413ebe 638 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsLayerPriority, 0);
tobyspark 44:723e65413ebe 639 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsLayerPriority, 1);
tobyspark 44:723e65413ebe 640
tobyspark 44:723e65413ebe 641 // Assign inputs to windows, so that left on the crossfader is left on the processor viewed from front
tobyspark 44:723e65413ebe 642 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB2);
tobyspark 44:723e65413ebe 643 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB1);
tobyspark 44:723e65413ebe 644
tobyspark 44:723e65413ebe 645 // Set scaling to fit source within output, maintaining aspect ratio
tobyspark 44:723e65413ebe 646 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsZoomLevel, 100);
tobyspark 44:723e65413ebe 647 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsZoomLevel, 100);
tobyspark 44:723e65413ebe 648 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsShrinkEnable, off);
tobyspark 44:723e65413ebe 649 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsShrinkEnable, off);
tobyspark 56:d6f77bd54e10 650 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, tvOneAspectFit);
tobyspark 56:d6f77bd54e10 651 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, tvOneAspectFit);
tobyspark 56:d6f77bd54e10 652 ok = ok && tvOne.command(kTV1SourceSIS1, kTV1WindowIDA, kTV1FunctionAdjustSourceTestCard, 1);
tobyspark 56:d6f77bd54e10 653 ok = ok && tvOne.command(kTV1SourceSIS1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, tvOneAspect1to1);
tobyspark 44:723e65413ebe 654 ok = ok && tvOne.command(kTV1SourceSIS2, kTV1WindowIDA, kTV1FunctionAdjustSourceTestCard, 1);
tobyspark 56:d6f77bd54e10 655 ok = ok && tvOne.command(kTV1SourceSIS2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, tvOneAspect1to1);
tobyspark 44:723e65413ebe 656
tobyspark 44:723e65413ebe 657 // On source loss, hold on the last frame received.
tobyspark 44:723e65413ebe 658 int32_t freeze = 1;
tobyspark 44:723e65413ebe 659 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze);
tobyspark 44:723e65413ebe 660 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze);
tobyspark 44:723e65413ebe 661
tobyspark 44:723e65413ebe 662 // Set resolution and fade levels for maximum chance of being seen
tobyspark 56:d6f77bd54e10 663 ok = ok && tvOne.setResolution(kTV1ResolutionVGA, 5);
tobyspark 48:c0fedfa8c525 664 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, 50);
tobyspark 44:723e65413ebe 665 ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, 100);
tobyspark 44:723e65413ebe 666
tobyspark 44:723e65413ebe 667 // Set evil, evil HDCP off
tobyspark 44:723e65413ebe 668 ok = ok && tvOne.setHDCPOn(false);
tobyspark 30:873979018850 669
tobyspark 44:723e65413ebe 670 if (ok) break;
tobyspark 44:723e65413ebe 671 else tvOne.increaseCommandPeriods(500);
tobyspark 44:723e65413ebe 672 }
tobyspark 40:bfddeb2a7fcf 673
tobyspark 44:723e65413ebe 674 if (ok)
tobyspark 44:723e65413ebe 675 {
tobyspark 44:723e65413ebe 676 // Save current state in preset one
tobyspark 44:723e65413ebe 677 tvOne.command(0, kTV1WindowIDA, kTV1FunctionPreset, 1); // Set Preset 1
tobyspark 44:723e65413ebe 678 tvOne.command(0, kTV1WindowIDA, kTV1FunctionPresetStore, 1); // Store
tobyspark 44:723e65413ebe 679
tobyspark 44:723e65413ebe 680 // Save current state for power on
tobyspark 44:723e65413ebe 681 tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 44:723e65413ebe 682 }
tobyspark 41:00d1cd3b2af2 683
tobyspark 44:723e65413ebe 684 tvOne.resetCommandPeriods();
tobyspark 41:00d1cd3b2af2 685
tobyspark 41:00d1cd3b2af2 686 return ok;
tobyspark 41:00d1cd3b2af2 687 }
tobyspark 41:00d1cd3b2af2 688
tobyspark 41:00d1cd3b2af2 689 bool uploadToProcessor()
tobyspark 41:00d1cd3b2af2 690 {
tobyspark 41:00d1cd3b2af2 691 bool ok = true;
tobyspark 41:00d1cd3b2af2 692
tobyspark 41:00d1cd3b2af2 693 LocalFileSystem local("local");
tobyspark 41:00d1cd3b2af2 694 FILE *file;
tobyspark 41:00d1cd3b2af2 695
tobyspark 34:69dfe64e7e6b 696 // Upload Matrox EDID to mem4 (ie. index 3). Use this EDID slot when setting Matrox resolutions.
tobyspark 44:723e65413ebe 697 if (tvOne.getProcessorType().version < 415)
tobyspark 44:723e65413ebe 698 {
tobyspark 44:723e65413ebe 699 if (debug) debug->printf("Skipping EDID upload as unsupported on detected TV One firmware\r\n");
tobyspark 44:723e65413ebe 700 }
tobyspark 44:723e65413ebe 701 else
tobyspark 34:69dfe64e7e6b 702 {
tobyspark 41:00d1cd3b2af2 703 file = fopen("/local/matroxe.did", "r"); // 8.3, avoid .bin as mbed executable extension
tobyspark 35:d5d9f0838f99 704 if (file)
tobyspark 34:69dfe64e7e6b 705 {
tobyspark 41:00d1cd3b2af2 706 ok = ok && tvOne.uploadEDID(file, 3);
tobyspark 35:d5d9f0838f99 707 fclose(file);
tobyspark 34:69dfe64e7e6b 708 }
tobyspark 35:d5d9f0838f99 709 else
tobyspark 35:d5d9f0838f99 710 {
tobyspark 44:723e65413ebe 711 if (debug) debug->printf("Could not open Matrox EDID file 'matroxe.did'\r\n");
tobyspark 35:d5d9f0838f99 712 }
tobyspark 34:69dfe64e7e6b 713 }
tobyspark 41:00d1cd3b2af2 714
tobyspark 41:00d1cd3b2af2 715 // Upload Logo to SIS2. Use this (minimal) image when no sources are connected.
tobyspark 41:00d1cd3b2af2 716 {
tobyspark 41:00d1cd3b2af2 717 file = fopen("/local/spark.dat", "r"); // 8.3, avoid .bin as mbed executable extension
tobyspark 41:00d1cd3b2af2 718 if (file)
tobyspark 41:00d1cd3b2af2 719 {
tobyspark 52:98f557fe93a3 720 ok = ok && tvOne.uploadImage(file, 0);
tobyspark 41:00d1cd3b2af2 721 fclose(file);
tobyspark 41:00d1cd3b2af2 722 }
tobyspark 41:00d1cd3b2af2 723 else
tobyspark 41:00d1cd3b2af2 724 {
tobyspark 41:00d1cd3b2af2 725 if (debug) debug->printf("Could not open image file 'spark.dat'");
tobyspark 41:00d1cd3b2af2 726 }
tobyspark 41:00d1cd3b2af2 727 }
tobyspark 17:fc68d40b8b1f 728
tobyspark 17:fc68d40b8b1f 729 return ok;
tobyspark 17:fc68d40b8b1f 730 }
tobyspark 17:fc68d40b8b1f 731
tobyspark 27:27851d3d2bba 732 void setResolutionMenuItems()
tobyspark 27:27851d3d2bba 733 {
tobyspark 27:27851d3d2bba 734 resolutionMenu.clearMenuItems();
tobyspark 27:27851d3d2bba 735 for (int i=0; i < settings.resolutionsCount(); i++)
tobyspark 27:27851d3d2bba 736 {
tobyspark 27:27851d3d2bba 737 resolutionMenu.addMenuItem(SPKMenuItem(settings.resolutionName(i), settings.resolutionIndex(i), settings.resolutionEDIDIndex(i)));
tobyspark 27:27851d3d2bba 738 }
tobyspark 27:27851d3d2bba 739 resolutionMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 27:27851d3d2bba 740 }
tobyspark 27:27851d3d2bba 741
tobyspark 27:27851d3d2bba 742 void setMixModeMenuItems()
tobyspark 27:27851d3d2bba 743 {
tobyspark 27:27851d3d2bba 744 mixModeMenu.clearMenuItems();
tobyspark 44:723e65413ebe 745
tobyspark 46:491229c97336 746 if (tvOne.getProcessorType().version == 423 || tvOne.getProcessorType().version == -1)
tobyspark 44:723e65413ebe 747 {
tobyspark 44:723e65413ebe 748 mixModeMenu.addMenuItem(SPKMenuItem("Crossfade", &mixModeAdditiveMenu));
tobyspark 44:723e65413ebe 749 }
tobyspark 44:723e65413ebe 750 else
tobyspark 44:723e65413ebe 751 {
tobyspark 44:723e65413ebe 752 mixModeMenu.addMenuItem(SPKMenuItem("Blend", mixBlend));
tobyspark 44:723e65413ebe 753 }
tobyspark 44:723e65413ebe 754
tobyspark 27:27851d3d2bba 755 for (int i=0; i < settings.keyerSetCount(); i++)
tobyspark 27:27851d3d2bba 756 {
tobyspark 49:16309f39cead 757 mixModeMenu.addMenuItem(SPKMenuItem(settings.keyerParamName(i), mixKeyStartIndex + i));
tobyspark 27:27851d3d2bba 758 }
tobyspark 27:27851d3d2bba 759 mixModeMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 27:27851d3d2bba 760 }
tobyspark 27:27851d3d2bba 761
tobyspark 27:27851d3d2bba 762 void setCommsMenuItems()
tobyspark 27:27851d3d2bba 763 {
tobyspark 27:27851d3d2bba 764 if (rj45Mode == rj45Ethernet)
tobyspark 27:27851d3d2bba 765 {
tobyspark 27:27851d3d2bba 766 commsMenu.title = "Network Mode [Ethernet]";
tobyspark 27:27851d3d2bba 767 commsMenu.clearMenuItems();
tobyspark 27:27851d3d2bba 768 commsMenu.addMenuItem(SPKMenuItem("None", commsNone));
tobyspark 27:27851d3d2bba 769 commsMenu.addMenuItem(SPKMenuItem("OSC", commsOSC));
tobyspark 27:27851d3d2bba 770 commsMenu.addMenuItem(SPKMenuItem("ArtNet", commsArtNet));
tobyspark 27:27851d3d2bba 771 commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 33:e6672a9bd571 772 commsMenu = 0;
tobyspark 27:27851d3d2bba 773 }
tobyspark 27:27851d3d2bba 774 else if (rj45Mode == rj45DMX)
tobyspark 27:27851d3d2bba 775 {
tobyspark 27:27851d3d2bba 776 commsMenu.title = "Network Mode [DMX]";
tobyspark 27:27851d3d2bba 777 commsMenu.clearMenuItems();
tobyspark 27:27851d3d2bba 778 commsMenu.addMenuItem(SPKMenuItem("None", commsNone));
tobyspark 27:27851d3d2bba 779 commsMenu.addMenuItem(SPKMenuItem("DMX In", commsDMXIn));
tobyspark 27:27851d3d2bba 780 commsMenu.addMenuItem(SPKMenuItem("DMX Out", commsDMXOut));
tobyspark 27:27851d3d2bba 781 commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 33:e6672a9bd571 782 commsMenu = 0;
tobyspark 27:27851d3d2bba 783 }
tobyspark 27:27851d3d2bba 784 }
tobyspark 27:27851d3d2bba 785
tobyspark 49:16309f39cead 786 void mixModeAdditiveMenuHandler(int change, bool action)
tobyspark 49:16309f39cead 787 {
tobyspark 49:16309f39cead 788 fadeCurve += change * 0.05f;
tobyspark 49:16309f39cead 789 if (fadeCurve > 1.0f) fadeCurve = 1.0f;
tobyspark 49:16309f39cead 790 if (fadeCurve < 0.0f) fadeCurve = 0.0f;
tobyspark 49:16309f39cead 791
tobyspark 49:16309f39cead 792 mixMode = (fadeCurve > 0.001f) ? mixAdditive: mixBlend;
tobyspark 49:16309f39cead 793
tobyspark 49:16309f39cead 794 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 795 screen.textToBuffer("Blend [ ----- ] Add", kMenuLine2);
tobyspark 49:16309f39cead 796 screen.characterToBuffer('X', 38 + fadeCurve*20.0f, kMenuLine2);
tobyspark 49:16309f39cead 797
tobyspark 49:16309f39cead 798 if (debug) debug->printf("Fade curve changed by %i to %f \r\n", change, fadeCurve);
tobyspark 49:16309f39cead 799
tobyspark 49:16309f39cead 800 if (action)
tobyspark 49:16309f39cead 801 {
tobyspark 49:16309f39cead 802 selectedMenu = &mixModeMenu;
tobyspark 49:16309f39cead 803
tobyspark 49:16309f39cead 804 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 805 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 806 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 49:16309f39cead 807 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 49:16309f39cead 808 }
tobyspark 49:16309f39cead 809 }
tobyspark 49:16309f39cead 810
tobyspark 51:98cc27390484 811 void troubleshootingMenuHDCPHandler(int change, bool action)
tobyspark 49:16309f39cead 812 {
tobyspark 49:16309f39cead 813 static int currentHDCP;
tobyspark 53:0993424e1529 814 static int state = 0;
tobyspark 49:16309f39cead 815
tobyspark 49:16309f39cead 816 if (change == 0 && !action)
tobyspark 49:16309f39cead 817 {
tobyspark 49:16309f39cead 818 // We check the control not the status, as status depends on connection etc.
tobyspark 49:16309f39cead 819
tobyspark 49:16309f39cead 820 int32_t payloadOutput = -1;
tobyspark 49:16309f39cead 821 tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsHDCPRequired, payloadOutput);
tobyspark 49:16309f39cead 822
tobyspark 49:16309f39cead 823 int32_t payload1 = -1;
tobyspark 49:16309f39cead 824 tvOne.readCommand(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceHDCPAdvertize, payload1);
tobyspark 49:16309f39cead 825
tobyspark 49:16309f39cead 826 int32_t payload2 = -1;
tobyspark 49:16309f39cead 827 tvOne.readCommand(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceHDCPAdvertize, payload2);
tobyspark 49:16309f39cead 828
tobyspark 49:16309f39cead 829 if ((payloadOutput == payload1) && (payload1 == payload2) && (payload2 == 0))
tobyspark 49:16309f39cead 830 {
tobyspark 49:16309f39cead 831 currentHDCP = 0; // Change to on
tobyspark 49:16309f39cead 832 }
tobyspark 49:16309f39cead 833 else if ((payloadOutput == payload1) && (payload1 == payload2) && (payload2 == 1))
tobyspark 49:16309f39cead 834 {
tobyspark 49:16309f39cead 835 currentHDCP = 1; // Change to off
tobyspark 49:16309f39cead 836 }
tobyspark 49:16309f39cead 837 else
tobyspark 49:16309f39cead 838 {
tobyspark 49:16309f39cead 839 currentHDCP = -1; // Change to off
tobyspark 49:16309f39cead 840 }
tobyspark 49:16309f39cead 841
tobyspark 49:16309f39cead 842 if (debug) debug->printf("HDCP detected O: %i 1: %i 2: %i", payloadOutput, payload1, payload2);
tobyspark 49:16309f39cead 843 }
tobyspark 49:16309f39cead 844
tobyspark 49:16309f39cead 845 state += change;
tobyspark 53:0993424e1529 846 if (state > 1) state = 1;
tobyspark 53:0993424e1529 847 if (state < 0) state = 0;
tobyspark 49:16309f39cead 848
tobyspark 49:16309f39cead 849 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 850 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 851
tobyspark 49:16309f39cead 852 const char* current = currentHDCP == -1 ? "Mixed" : ( currentHDCP == 1 ? "On" : "Off");
tobyspark 49:16309f39cead 853
tobyspark 53:0993424e1529 854 if (state == 0) snprintf(paramLine, kStringBufferLength, "%s. Set: [%s/ ]?", current, currentHDCP == 0 ? "On " : "Off" );
tobyspark 49:16309f39cead 855 else snprintf(paramLine, kStringBufferLength, "%s. Set: [ /Cancel]?", current);
tobyspark 49:16309f39cead 856 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 857
tobyspark 49:16309f39cead 858 if (action)
tobyspark 49:16309f39cead 859 {
tobyspark 53:0993424e1529 860 if (state == 0)
tobyspark 49:16309f39cead 861 {
tobyspark 49:16309f39cead 862 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 49:16309f39cead 863 screen.textToBuffer("Setting HDCP...", kTVOneStatusLine);
tobyspark 49:16309f39cead 864 screen.sendBuffer();
tobyspark 49:16309f39cead 865
tobyspark 49:16309f39cead 866 // Do the action
tobyspark 49:16309f39cead 867 bool ok = tvOne.setHDCPOn(currentHDCP == 0);
tobyspark 49:16309f39cead 868
tobyspark 49:16309f39cead 869 if (ok) tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 49:16309f39cead 870
tobyspark 49:16309f39cead 871 std::string sendOK = ok ? "Sent: HDCP " : "Send Error: HDCP ";
tobyspark 49:16309f39cead 872 sendOK += currentHDCP == 0 ? "On" : "Off";
tobyspark 49:16309f39cead 873
tobyspark 49:16309f39cead 874 tvOneStatusMessage.addMessage(sendOK, kTVOneStatusMessageHoldTime);
tobyspark 49:16309f39cead 875 }
tobyspark 49:16309f39cead 876
tobyspark 49:16309f39cead 877 // Get back to menu
tobyspark 51:98cc27390484 878 selectedMenu = &troubleshootingMenu;
tobyspark 49:16309f39cead 879
tobyspark 49:16309f39cead 880 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 881 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 882 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 49:16309f39cead 883 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 49:16309f39cead 884 }
tobyspark 49:16309f39cead 885 }
tobyspark 49:16309f39cead 886
tobyspark 51:98cc27390484 887 void troubleshootingMenuEDIDHandler(int change, bool action)
tobyspark 49:16309f39cead 888 {
tobyspark 49:16309f39cead 889 static int currentEDIDPassthrough;
tobyspark 57:14d37904c889 890 static int currentEDID;
tobyspark 53:0993424e1529 891 static int state = 0;
tobyspark 57:14d37904c889 892
tobyspark 49:16309f39cead 893 if (change == 0 && !action)
tobyspark 49:16309f39cead 894 {
tobyspark 57:14d37904c889 895 currentEDID = tvOne.getEDID();
tobyspark 49:16309f39cead 896
tobyspark 57:14d37904c889 897 if (currentEDID == -1) currentEDIDPassthrough = -1;
tobyspark 57:14d37904c889 898 else currentEDIDPassthrough = (currentEDID == EDIDPassthroughSlot) ? 1 : 0;
tobyspark 49:16309f39cead 899 }
tobyspark 49:16309f39cead 900
tobyspark 49:16309f39cead 901 state += change;
tobyspark 53:0993424e1529 902 if (state > 1) state = 1;
tobyspark 53:0993424e1529 903 if (state < 0) state = 0;
tobyspark 49:16309f39cead 904
tobyspark 49:16309f39cead 905 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 906 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 907
tobyspark 51:98cc27390484 908 const char* current = currentEDIDPassthrough == -1 ? "Mixed" : ( currentEDIDPassthrough == 1 ? "Thru" : "Internal");
tobyspark 49:16309f39cead 909
tobyspark 53:0993424e1529 910 if (state == 0) snprintf(paramLine, kStringBufferLength, "%s. Set: [%s/ ]?", current, currentEDIDPassthrough == 0 ? "Thru" : "Int");
tobyspark 49:16309f39cead 911 else snprintf(paramLine, kStringBufferLength, "%s. Set: [ /Cancel]?", current);
tobyspark 49:16309f39cead 912 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 913
tobyspark 49:16309f39cead 914 if (action)
tobyspark 49:16309f39cead 915 {
tobyspark 53:0993424e1529 916 if (state == 0)
tobyspark 49:16309f39cead 917 {
tobyspark 49:16309f39cead 918 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 49:16309f39cead 919 screen.textToBuffer("Setting EDID...", kTVOneStatusLine);
tobyspark 49:16309f39cead 920 screen.sendBuffer();
tobyspark 49:16309f39cead 921
tobyspark 49:16309f39cead 922 // Do the action
tobyspark 49:16309f39cead 923 tvOneEDIDPassthrough = currentEDIDPassthrough == 0;
tobyspark 49:16309f39cead 924
tobyspark 49:16309f39cead 925 bool ok = true;
tobyspark 57:14d37904c889 926 std::string message;
tobyspark 49:16309f39cead 927
tobyspark 57:14d37904c889 928 int newEDID = tvOneEDIDPassthrough ? EDIDPassthroughSlot : resolutionMenu.selectedItem().payload.command[1];
tobyspark 57:14d37904c889 929
tobyspark 57:14d37904c889 930 if (newEDID != currentEDID)
tobyspark 57:14d37904c889 931 {
tobyspark 57:14d37904c889 932 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, newEDID);
tobyspark 57:14d37904c889 933 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, newEDID);
tobyspark 57:14d37904c889 934 if (ok) message = "Sent: EDID";
tobyspark 57:14d37904c889 935 else message = "Send Error: EDID";
tobyspark 57:14d37904c889 936 }
tobyspark 57:14d37904c889 937 else message = "EDID already set";
tobyspark 49:16309f39cead 938
tobyspark 49:16309f39cead 939 if (ok) tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 49:16309f39cead 940
tobyspark 57:14d37904c889 941 tvOneStatusMessage.addMessage(message, kTVOneStatusMessageHoldTime);
tobyspark 49:16309f39cead 942
tobyspark 57:14d37904c889 943 // This is WHACK. Can't believe it's both needed and officially in the 1T-C2-750 manual
tobyspark 57:14d37904c889 944 if ((newEDID != currentEDID) && ok) tvOneStatusMessage.addMessage("EDID: Processor Off+On?", kTVOneStatusMessageHoldTime);
tobyspark 49:16309f39cead 945 }
tobyspark 49:16309f39cead 946
tobyspark 49:16309f39cead 947 // Get back to menu
tobyspark 51:98cc27390484 948 selectedMenu = &troubleshootingMenu;
tobyspark 49:16309f39cead 949
tobyspark 49:16309f39cead 950 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 951 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 952 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 49:16309f39cead 953 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 49:16309f39cead 954 }
tobyspark 49:16309f39cead 955 }
tobyspark 49:16309f39cead 956
tobyspark 55:35a295d36d23 957 void troubleshootingMenuAspectHandler(int change, bool action)
tobyspark 55:35a295d36d23 958 {
tobyspark 55:35a295d36d23 959 static int state = 0;
tobyspark 55:35a295d36d23 960
tobyspark 55:35a295d36d23 961 if (change == 0 && !action)
tobyspark 55:35a295d36d23 962 {
tobyspark 55:35a295d36d23 963 int32_t payload1 = -1;
tobyspark 55:35a295d36d23 964 tvOne.readCommand(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, payload1);
tobyspark 55:35a295d36d23 965
tobyspark 55:35a295d36d23 966 int32_t payload2 = -1;
tobyspark 55:35a295d36d23 967 tvOne.readCommand(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, payload2);
tobyspark 55:35a295d36d23 968
tobyspark 55:35a295d36d23 969 if ((payload1 == payload2) && (payload2 == tvOneAspectFit))
tobyspark 55:35a295d36d23 970 {
tobyspark 55:35a295d36d23 971 state = 0;
tobyspark 55:35a295d36d23 972 }
tobyspark 55:35a295d36d23 973 else if ((payload1 == payload2) && (payload2 == tvOneAspectHFill))
tobyspark 55:35a295d36d23 974 {
tobyspark 55:35a295d36d23 975 state = 1;
tobyspark 55:35a295d36d23 976 }
tobyspark 55:35a295d36d23 977 else if ((payload1 == payload2) && (payload2 == tvOneAspectVFill))
tobyspark 55:35a295d36d23 978 {
tobyspark 55:35a295d36d23 979 state = 1;
tobyspark 55:35a295d36d23 980 }
tobyspark 55:35a295d36d23 981 else if ((payload1 == payload2) && (payload2 == tvOneAspect1to1))
tobyspark 55:35a295d36d23 982 {
tobyspark 55:35a295d36d23 983 state = 2;
tobyspark 55:35a295d36d23 984 }
tobyspark 55:35a295d36d23 985 else
tobyspark 55:35a295d36d23 986 {
tobyspark 55:35a295d36d23 987 state = 0;
tobyspark 55:35a295d36d23 988 }
tobyspark 55:35a295d36d23 989 }
tobyspark 55:35a295d36d23 990
tobyspark 55:35a295d36d23 991 state += change;
tobyspark 55:35a295d36d23 992 if (state > 3) state = 3;
tobyspark 55:35a295d36d23 993 if (state < 0) state = 0;
tobyspark 55:35a295d36d23 994
tobyspark 55:35a295d36d23 995 screen.clearBufferRow(kMenuLine2);
tobyspark 55:35a295d36d23 996 switch (state)
tobyspark 55:35a295d36d23 997 {
tobyspark 55:35a295d36d23 998 case 0: screen.textToBuffer("Set: [Fit/ / / ]", kMenuLine2); break;
tobyspark 55:35a295d36d23 999 case 1: screen.textToBuffer("Set: [ /Fill/ / ]", kMenuLine2); break;
tobyspark 55:35a295d36d23 1000 case 2: screen.textToBuffer("Set: [ / /1:1/ ]", kMenuLine2); break;
tobyspark 55:35a295d36d23 1001 case 3: screen.textToBuffer("Set: [ / / /Cancel]", kMenuLine2); break;
tobyspark 55:35a295d36d23 1002 }
tobyspark 55:35a295d36d23 1003
tobyspark 55:35a295d36d23 1004 if (action)
tobyspark 55:35a295d36d23 1005 {
tobyspark 55:35a295d36d23 1006 if (state != 3)
tobyspark 55:35a295d36d23 1007 {
tobyspark 55:35a295d36d23 1008 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 55:35a295d36d23 1009 screen.textToBuffer("Setting Aspect...", kTVOneStatusLine);
tobyspark 55:35a295d36d23 1010 screen.sendBuffer();
tobyspark 55:35a295d36d23 1011
tobyspark 55:35a295d36d23 1012 // Do the action
tobyspark 55:35a295d36d23 1013 switch (state)
tobyspark 55:35a295d36d23 1014 {
tobyspark 55:35a295d36d23 1015 case 0: tvOneAspectHandling = tvOneAspectFit; break;
tobyspark 55:35a295d36d23 1016 case 1: tvOneAspectHandling = tvOneAspectHFill; break;
tobyspark 55:35a295d36d23 1017 case 2: tvOneAspectHandling = tvOneAspect1to1; break;
tobyspark 55:35a295d36d23 1018 }
tobyspark 55:35a295d36d23 1019
tobyspark 55:35a295d36d23 1020 bool ok = true;
tobyspark 55:35a295d36d23 1021
tobyspark 55:35a295d36d23 1022 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, tvOneAspectHandling);
tobyspark 55:35a295d36d23 1023 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, tvOneAspectHandling);
tobyspark 55:35a295d36d23 1024
tobyspark 55:35a295d36d23 1025 if (ok) tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 55:35a295d36d23 1026
tobyspark 55:35a295d36d23 1027 std::string sendOK = ok ? "Sent: " : "Send Error: ";
tobyspark 55:35a295d36d23 1028 switch (tvOneAspectHandling)
tobyspark 55:35a295d36d23 1029 {
tobyspark 55:35a295d36d23 1030 case tvOneAspectFit: sendOK += "Aspect Fit "; break;
tobyspark 55:35a295d36d23 1031 case tvOneAspectHFill: sendOK += "Aspect Fill"; break;
tobyspark 55:35a295d36d23 1032 case tvOneAspectVFill: sendOK += "Aspect Fill"; break;
tobyspark 55:35a295d36d23 1033 case tvOneAspect1to1: sendOK += "Aspect 1:1"; break;
tobyspark 55:35a295d36d23 1034 }
tobyspark 55:35a295d36d23 1035 tvOneStatusMessage.addMessage(sendOK, kTVOneStatusMessageHoldTime);
tobyspark 55:35a295d36d23 1036 }
tobyspark 55:35a295d36d23 1037
tobyspark 55:35a295d36d23 1038 // Get back to menu
tobyspark 55:35a295d36d23 1039 selectedMenu = &troubleshootingMenu;
tobyspark 55:35a295d36d23 1040
tobyspark 55:35a295d36d23 1041 screen.clearBufferRow(kMenuLine1);
tobyspark 55:35a295d36d23 1042 screen.clearBufferRow(kMenuLine2);
tobyspark 55:35a295d36d23 1043 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 55:35a295d36d23 1044 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 55:35a295d36d23 1045 }
tobyspark 55:35a295d36d23 1046 }
tobyspark 55:35a295d36d23 1047
tobyspark 49:16309f39cead 1048 void mixModeUpdateKeyMenuHandler(int menuChange, bool action)
tobyspark 49:16309f39cead 1049 {
tobyspark 49:16309f39cead 1050 static int actionCount = 0;
tobyspark 53:0993424e1529 1051 static int state = 0;
tobyspark 49:16309f39cead 1052
tobyspark 49:16309f39cead 1053 if (action) actionCount++;
tobyspark 49:16309f39cead 1054
tobyspark 49:16309f39cead 1055 if (actionCount == 0)
tobyspark 49:16309f39cead 1056 {
tobyspark 49:16309f39cead 1057 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1058 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1059 screen.textToBuffer("Edit current key?", kMenuLine1);
tobyspark 49:16309f39cead 1060
tobyspark 49:16309f39cead 1061 state += menuChange;
tobyspark 53:0993424e1529 1062 if (state > 2) state = 2;
tobyspark 53:0993424e1529 1063 if (state < 0) state = 0;
tobyspark 53:0993424e1529 1064
tobyspark 53:0993424e1529 1065 switch (state)
tobyspark 49:16309f39cead 1066 {
tobyspark 49:16309f39cead 1067 case 0: screen.textToBuffer("[Tweak/ / ]", kMenuLine2); break;
tobyspark 49:16309f39cead 1068 case 1: screen.textToBuffer("[ /Start Over/ ]", kMenuLine2); break;
tobyspark 49:16309f39cead 1069 case 2: screen.textToBuffer("[ / /Cancel]", kMenuLine2); break;
tobyspark 49:16309f39cead 1070 }
tobyspark 49:16309f39cead 1071 }
tobyspark 49:16309f39cead 1072 if (actionCount == 1)
tobyspark 49:16309f39cead 1073 {
tobyspark 49:16309f39cead 1074 if (state == 0)
tobyspark 49:16309f39cead 1075 {
tobyspark 49:16309f39cead 1076 settings.editingKeyerSetIndex = mixModeMenu.selectedIndex() - mixKeyStartIndex;
tobyspark 49:16309f39cead 1077 actionCount++;
tobyspark 49:16309f39cead 1078 }
tobyspark 49:16309f39cead 1079 else if (state == 1)
tobyspark 49:16309f39cead 1080 {
tobyspark 49:16309f39cead 1081 settings.editingKeyerSetIndex = mixModeMenu.selectedIndex() - mixKeyStartIndex;
tobyspark 49:16309f39cead 1082 settings.setEditingKeyerSetValue(SPKSettings::minY, 0);
tobyspark 49:16309f39cead 1083 settings.setEditingKeyerSetValue(SPKSettings::maxY, 255);
tobyspark 49:16309f39cead 1084 settings.setEditingKeyerSetValue(SPKSettings::minU, 0);
tobyspark 49:16309f39cead 1085 settings.setEditingKeyerSetValue(SPKSettings::maxU, 255);
tobyspark 49:16309f39cead 1086 settings.setEditingKeyerSetValue(SPKSettings::minV, 0);
tobyspark 49:16309f39cead 1087 settings.setEditingKeyerSetValue(SPKSettings::maxV, 255);
tobyspark 51:98cc27390484 1088 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, 0);
tobyspark 51:98cc27390484 1089 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, 255);
tobyspark 51:98cc27390484 1090 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, 0);
tobyspark 51:98cc27390484 1091 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, 255);
tobyspark 51:98cc27390484 1092 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, 0);
tobyspark 51:98cc27390484 1093 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, 255);
tobyspark 49:16309f39cead 1094 actionCount++;
tobyspark 49:16309f39cead 1095 state = 0;
tobyspark 49:16309f39cead 1096 }
tobyspark 49:16309f39cead 1097 else if (state == 2)
tobyspark 49:16309f39cead 1098 {
tobyspark 49:16309f39cead 1099 settings.editingKeyerSetIndex = -1;
tobyspark 49:16309f39cead 1100
tobyspark 49:16309f39cead 1101 // Get back to menu
tobyspark 49:16309f39cead 1102 actionCount = 0;
tobyspark 49:16309f39cead 1103 state = 0;
tobyspark 49:16309f39cead 1104 selectedMenu = &mixModeMenu;
tobyspark 49:16309f39cead 1105 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1106 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1107 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 49:16309f39cead 1108 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 49:16309f39cead 1109
tobyspark 49:16309f39cead 1110 return;
tobyspark 49:16309f39cead 1111 }
tobyspark 49:16309f39cead 1112 }
tobyspark 49:16309f39cead 1113 if (actionCount == 2)
tobyspark 49:16309f39cead 1114 {
tobyspark 49:16309f39cead 1115 int value = settings.editingKeyerSetValue(SPKSettings::maxY);
tobyspark 49:16309f39cead 1116 value += menuChange;
tobyspark 49:16309f39cead 1117 if (value < 0) value = 0;
tobyspark 49:16309f39cead 1118 if (value > 255) value = 255;
tobyspark 49:16309f39cead 1119 settings.setEditingKeyerSetValue(SPKSettings::maxY, value);
tobyspark 49:16309f39cead 1120
tobyspark 49:16309f39cead 1121 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1122 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1123 screen.textToBuffer("Down until unmasked", kMenuLine1);
tobyspark 49:16309f39cead 1124
tobyspark 49:16309f39cead 1125 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 1126 snprintf(paramLine, kStringBufferLength, "[ /%3i][ / ][ / ]", value);
tobyspark 49:16309f39cead 1127 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 1128
tobyspark 49:16309f39cead 1129 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, value);
tobyspark 49:16309f39cead 1130 }
tobyspark 49:16309f39cead 1131 else if (actionCount == 3)
tobyspark 49:16309f39cead 1132 {
tobyspark 49:16309f39cead 1133 int value = settings.editingKeyerSetValue(SPKSettings::minY);
tobyspark 49:16309f39cead 1134 value += menuChange;
tobyspark 49:16309f39cead 1135 if (value < 0) value = 0;
tobyspark 49:16309f39cead 1136 if (value > settings.editingKeyerSetValue(SPKSettings::maxY)) value = settings.editingKeyerSetValue(SPKSettings::maxY);
tobyspark 49:16309f39cead 1137 settings.setEditingKeyerSetValue(SPKSettings::minY, value);
tobyspark 49:16309f39cead 1138
tobyspark 49:16309f39cead 1139 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1140 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1141 screen.textToBuffer("Up until unmasked", kMenuLine1);
tobyspark 49:16309f39cead 1142
tobyspark 49:16309f39cead 1143 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 1144 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][ / ][ / ]", value,
tobyspark 49:16309f39cead 1145 settings.editingKeyerSetValue(SPKSettings::maxY));
tobyspark 49:16309f39cead 1146 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 1147
tobyspark 49:16309f39cead 1148 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, value);
tobyspark 49:16309f39cead 1149 }
tobyspark 49:16309f39cead 1150 else if (actionCount == 4)
tobyspark 49:16309f39cead 1151 {
tobyspark 49:16309f39cead 1152 int value = settings.editingKeyerSetValue(SPKSettings::maxU);
tobyspark 49:16309f39cead 1153 value += menuChange;
tobyspark 49:16309f39cead 1154 if (value < 0) value = 0;
tobyspark 49:16309f39cead 1155 if (value > 255) value = 255;
tobyspark 49:16309f39cead 1156 settings.setEditingKeyerSetValue(SPKSettings::maxU, value);
tobyspark 49:16309f39cead 1157
tobyspark 49:16309f39cead 1158 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1159 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1160 screen.textToBuffer("Down until unmasked", kMenuLine1);
tobyspark 49:16309f39cead 1161
tobyspark 49:16309f39cead 1162 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 1163 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][ /%3i][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 49:16309f39cead 1164 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 49:16309f39cead 1165 value);
tobyspark 49:16309f39cead 1166 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 1167
tobyspark 49:16309f39cead 1168 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, value);
tobyspark 49:16309f39cead 1169 }
tobyspark 49:16309f39cead 1170 else if (actionCount == 5)
tobyspark 49:16309f39cead 1171 {
tobyspark 49:16309f39cead 1172 int value = settings.editingKeyerSetValue(SPKSettings::minU);
tobyspark 49:16309f39cead 1173 value += menuChange;
tobyspark 49:16309f39cead 1174 if (value < 0) value = 0;
tobyspark 49:16309f39cead 1175 if (value > settings.editingKeyerSetValue(SPKSettings::maxU)) value = settings.editingKeyerSetValue(SPKSettings::maxU);
tobyspark 49:16309f39cead 1176 settings.setEditingKeyerSetValue(SPKSettings::minU, value);
tobyspark 49:16309f39cead 1177
tobyspark 49:16309f39cead 1178 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1179 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1180 screen.textToBuffer("Up until unmasked", kMenuLine1);
tobyspark 49:16309f39cead 1181
tobyspark 49:16309f39cead 1182 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 1183 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][ / ]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 49:16309f39cead 1184 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 49:16309f39cead 1185 value,
tobyspark 49:16309f39cead 1186 settings.editingKeyerSetValue(SPKSettings::maxU));
tobyspark 49:16309f39cead 1187 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 1188
tobyspark 49:16309f39cead 1189 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, value);
tobyspark 49:16309f39cead 1190 }
tobyspark 49:16309f39cead 1191 else if (actionCount == 6)
tobyspark 49:16309f39cead 1192 {
tobyspark 49:16309f39cead 1193 int value = settings.editingKeyerSetValue(SPKSettings::maxV);
tobyspark 49:16309f39cead 1194 value += menuChange;
tobyspark 49:16309f39cead 1195 if (value < 0) value = 0;
tobyspark 49:16309f39cead 1196 if (value > 255) value = 255;
tobyspark 49:16309f39cead 1197 settings.setEditingKeyerSetValue(SPKSettings::maxV, value);
tobyspark 49:16309f39cead 1198
tobyspark 49:16309f39cead 1199 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1200 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1201 screen.textToBuffer("Down until unmasked", kMenuLine1);
tobyspark 49:16309f39cead 1202
tobyspark 49:16309f39cead 1203 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 1204 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][ /%3i]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 49:16309f39cead 1205 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 49:16309f39cead 1206 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 49:16309f39cead 1207 settings.editingKeyerSetValue(SPKSettings::maxU),
tobyspark 49:16309f39cead 1208 value);
tobyspark 49:16309f39cead 1209 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 1210
tobyspark 49:16309f39cead 1211 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, value);
tobyspark 49:16309f39cead 1212 }
tobyspark 49:16309f39cead 1213 else if (actionCount == 7)
tobyspark 49:16309f39cead 1214 {
tobyspark 49:16309f39cead 1215 int value = settings.editingKeyerSetValue(SPKSettings::minV);
tobyspark 49:16309f39cead 1216 value += menuChange;
tobyspark 49:16309f39cead 1217 if (value < 0) value = 0;
tobyspark 49:16309f39cead 1218 if (value > settings.editingKeyerSetValue(SPKSettings::maxV)) value = settings.editingKeyerSetValue(SPKSettings::maxV);
tobyspark 49:16309f39cead 1219 settings.setEditingKeyerSetValue(SPKSettings::minV, value);
tobyspark 49:16309f39cead 1220
tobyspark 49:16309f39cead 1221 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1222 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1223 screen.textToBuffer("Up until unmasked", kMenuLine1);
tobyspark 49:16309f39cead 1224
tobyspark 49:16309f39cead 1225 char paramLine[kStringBufferLength];
tobyspark 49:16309f39cead 1226 snprintf(paramLine, kStringBufferLength, "[%3i/%3i][%3i/%3i][%3i/%3i]", settings.editingKeyerSetValue(SPKSettings::minY),
tobyspark 49:16309f39cead 1227 settings.editingKeyerSetValue(SPKSettings::maxY),
tobyspark 49:16309f39cead 1228 settings.editingKeyerSetValue(SPKSettings::minU),
tobyspark 49:16309f39cead 1229 settings.editingKeyerSetValue(SPKSettings::maxU),
tobyspark 49:16309f39cead 1230 value,
tobyspark 49:16309f39cead 1231 settings.editingKeyerSetValue(SPKSettings::maxV));
tobyspark 49:16309f39cead 1232 screen.textToBuffer(paramLine, kMenuLine2);
tobyspark 49:16309f39cead 1233
tobyspark 49:16309f39cead 1234 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, value);
tobyspark 49:16309f39cead 1235 }
tobyspark 49:16309f39cead 1236 else if (actionCount == 8)
tobyspark 49:16309f39cead 1237 {
tobyspark 51:98cc27390484 1238 // A save dialog would go here
tobyspark 49:16309f39cead 1239
tobyspark 49:16309f39cead 1240 // Get back to menu
tobyspark 49:16309f39cead 1241 actionCount = 0;
tobyspark 49:16309f39cead 1242 selectedMenu = &mixModeMenu;
tobyspark 49:16309f39cead 1243 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1244 screen.clearBufferRow(kMenuLine2);
tobyspark 49:16309f39cead 1245 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 49:16309f39cead 1246 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 49:16309f39cead 1247 }
tobyspark 49:16309f39cead 1248 }
tobyspark 49:16309f39cead 1249
tobyspark 51:98cc27390484 1250 void troubleshootingMenuResetHandler(int menuChange, bool action)
tobyspark 51:98cc27390484 1251 {
tobyspark 51:98cc27390484 1252 static int actionCount = 0;
tobyspark 53:0993424e1529 1253 static int state = 0;
tobyspark 51:98cc27390484 1254
tobyspark 51:98cc27390484 1255 if (action) actionCount++;
tobyspark 51:98cc27390484 1256
tobyspark 51:98cc27390484 1257 if (actionCount == 0)
tobyspark 51:98cc27390484 1258 {
tobyspark 51:98cc27390484 1259 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1260
tobyspark 51:98cc27390484 1261 state += menuChange;
tobyspark 53:0993424e1529 1262 if (state > 1) state = 1;
tobyspark 53:0993424e1529 1263 if (state < 0) state = 0;
tobyspark 53:0993424e1529 1264
tobyspark 53:0993424e1529 1265 switch (state)
tobyspark 51:98cc27390484 1266 {
tobyspark 51:98cc27390484 1267 case 0: screen.textToBuffer("1. Controller [Reset/ ]", kMenuLine2); break;
tobyspark 51:98cc27390484 1268 case 1: screen.textToBuffer("1. Controller [ /Skip]", kMenuLine2); break;
tobyspark 51:98cc27390484 1269 }
tobyspark 51:98cc27390484 1270 }
tobyspark 51:98cc27390484 1271 if (actionCount == 1)
tobyspark 51:98cc27390484 1272 {
tobyspark 51:98cc27390484 1273 if (state == 0)
tobyspark 51:98cc27390484 1274 {
tobyspark 51:98cc27390484 1275 tvOneRGB1Stable = false;
tobyspark 51:98cc27390484 1276 tvOneRGB2Stable = false;
tobyspark 51:98cc27390484 1277 handleTVOneSources();
tobyspark 51:98cc27390484 1278
tobyspark 51:98cc27390484 1279 settings.editingKeyerSetIndex = -1;
tobyspark 51:98cc27390484 1280 keyerParamsSet = -1;
tobyspark 51:98cc27390484 1281 bool ok = settings.load(kSPKDFSettingsFilename);
tobyspark 51:98cc27390484 1282 if (!ok) settings.loadDefaults();
tobyspark 51:98cc27390484 1283
tobyspark 51:98cc27390484 1284 setMixModeMenuItems();
tobyspark 51:98cc27390484 1285 setResolutionMenuItems();
tobyspark 51:98cc27390484 1286
tobyspark 52:98f557fe93a3 1287 tvOneStatusMessage.addMessage("Controller Reset", kTVOneStatusMessageHoldTime);
tobyspark 52:98f557fe93a3 1288
tobyspark 51:98cc27390484 1289 actionCount++;
tobyspark 51:98cc27390484 1290 }
tobyspark 51:98cc27390484 1291 else if (state == 1)
tobyspark 51:98cc27390484 1292 {
tobyspark 51:98cc27390484 1293 actionCount++;
tobyspark 51:98cc27390484 1294 }
tobyspark 51:98cc27390484 1295
tobyspark 51:98cc27390484 1296 state = 0;
tobyspark 51:98cc27390484 1297 }
tobyspark 51:98cc27390484 1298 if (actionCount == 2)
tobyspark 51:98cc27390484 1299 {
tobyspark 51:98cc27390484 1300 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1301
tobyspark 51:98cc27390484 1302 state += menuChange;
tobyspark 53:0993424e1529 1303 if (state > 1) state = 1;
tobyspark 53:0993424e1529 1304 if (state < 0) state = 0;
tobyspark 53:0993424e1529 1305 switch (state)
tobyspark 51:98cc27390484 1306 {
tobyspark 51:98cc27390484 1307 case 0: screen.textToBuffer("2. Processor [Reset/ ]", kMenuLine2); break;
tobyspark 51:98cc27390484 1308 case 1: screen.textToBuffer("2. Processor [ /Skip]", kMenuLine2); break;
tobyspark 51:98cc27390484 1309 }
tobyspark 51:98cc27390484 1310 }
tobyspark 51:98cc27390484 1311 if (actionCount == 3)
tobyspark 51:98cc27390484 1312 {
tobyspark 51:98cc27390484 1313 if (state == 0)
tobyspark 51:98cc27390484 1314 {
tobyspark 51:98cc27390484 1315 screen.clearBufferRow(kMenuLine2);
tobyspark 52:98f557fe93a3 1316 screen.textToBuffer("Find MENU+STANDBY [NEXT]", kMenuLine2);
tobyspark 51:98cc27390484 1317 }
tobyspark 51:98cc27390484 1318 else if (state == 1)
tobyspark 51:98cc27390484 1319 {
tobyspark 51:98cc27390484 1320 actionCount = actionCount + 3; // extra stage to skip
tobyspark 51:98cc27390484 1321 }
tobyspark 51:98cc27390484 1322
tobyspark 51:98cc27390484 1323 state = 0;
tobyspark 51:98cc27390484 1324 }
tobyspark 51:98cc27390484 1325 if (actionCount == 4)
tobyspark 51:98cc27390484 1326 {
tobyspark 51:98cc27390484 1327 Timer timer;
tobyspark 51:98cc27390484 1328 timer.start();
tobyspark 51:98cc27390484 1329
tobyspark 51:98cc27390484 1330 while (timer.read_ms() < 16000)
tobyspark 51:98cc27390484 1331 {
tobyspark 51:98cc27390484 1332 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1333 char messageBuffer[kStringBufferLength];
tobyspark 52:98f557fe93a3 1334 snprintf(messageBuffer, kStringBufferLength,"Hold buttons for [%i s]", 15 - (timer.read_ms() / 1000));
tobyspark 51:98cc27390484 1335 screen.textToBuffer(messageBuffer, kMenuLine2);
tobyspark 51:98cc27390484 1336 screen.sendBuffer();
tobyspark 51:98cc27390484 1337 }
tobyspark 51:98cc27390484 1338
tobyspark 51:98cc27390484 1339 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1340 screen.textToBuffer("Hold buttons for [NEXT]", kMenuLine2);
tobyspark 51:98cc27390484 1341 }
tobyspark 51:98cc27390484 1342 if (actionCount == 5)
tobyspark 51:98cc27390484 1343 {
tobyspark 51:98cc27390484 1344 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1345 screen.textToBuffer("Updating processor [---]", kMenuLine2);
tobyspark 51:98cc27390484 1346 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 51:98cc27390484 1347 screen.textToBuffer("Sending...", kTVOneStatusLine);
tobyspark 51:98cc27390484 1348 screen.sendBuffer();
tobyspark 51:98cc27390484 1349
tobyspark 51:98cc27390484 1350 bool ok = conformProcessor();
tobyspark 51:98cc27390484 1351
tobyspark 51:98cc27390484 1352 std::string sendOK = ok ? "TVOne: Reset success" : "Send Error: Reset";
tobyspark 51:98cc27390484 1353
tobyspark 51:98cc27390484 1354 tvOneStatusMessage.addMessage(sendOK, kTVOneStatusMessageHoldTime);
tobyspark 51:98cc27390484 1355
tobyspark 51:98cc27390484 1356 tvOneRGB1Stable = false;
tobyspark 51:98cc27390484 1357 tvOneRGB2Stable = false;
tobyspark 51:98cc27390484 1358 handleTVOneSources();
tobyspark 51:98cc27390484 1359
tobyspark 51:98cc27390484 1360 actionCount++;
tobyspark 51:98cc27390484 1361 }
tobyspark 51:98cc27390484 1362 if (actionCount == 6)
tobyspark 51:98cc27390484 1363 {
tobyspark 52:98f557fe93a3 1364 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1365 screen.textToBuffer("3. No more steps [DONE]", kMenuLine2);
tobyspark 51:98cc27390484 1366 }
tobyspark 51:98cc27390484 1367 if (actionCount == 7)
tobyspark 51:98cc27390484 1368 {
tobyspark 51:98cc27390484 1369 // Get back to menu
tobyspark 51:98cc27390484 1370 actionCount = 0;
tobyspark 51:98cc27390484 1371 selectedMenu = &troubleshootingMenu;
tobyspark 51:98cc27390484 1372 screen.clearBufferRow(kMenuLine1);
tobyspark 51:98cc27390484 1373 screen.clearBufferRow(kMenuLine2);
tobyspark 51:98cc27390484 1374 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 51:98cc27390484 1375 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 51:98cc27390484 1376 }
tobyspark 51:98cc27390484 1377 }
tobyspark 51:98cc27390484 1378
tobyspark 0:87aab40d5806 1379 int main()
tobyspark 0:87aab40d5806 1380 {
tobyspark 0:87aab40d5806 1381 if (debug)
tobyspark 0:87aab40d5806 1382 {
tobyspark 0:87aab40d5806 1383 debug->printf("\r\n\r\n");
tobyspark 0:87aab40d5806 1384 debug->printf("*spark d-fuser -----------\r\n");
tobyspark 0:87aab40d5806 1385 debug->printf(" debug channel\r\n");
tobyspark 0:87aab40d5806 1386 }
tobyspark 2:50043054e4f7 1387
tobyspark 2:50043054e4f7 1388 // Set display font
tobyspark 2:50043054e4f7 1389 screen.fontStartCharacter = &characterBytesStartChar;
tobyspark 2:50043054e4f7 1390 screen.fontEndCharacter = &characterBytesEndChar;
tobyspark 2:50043054e4f7 1391 screen.fontCharacters = characterBytes;
tobyspark 2:50043054e4f7 1392
tobyspark 0:87aab40d5806 1393 // Splash screen
tobyspark 30:873979018850 1394 string softwareLine = "SW ";
tobyspark 30:873979018850 1395 softwareLine += kSPKDFSoftwareVersion;
tobyspark 2:50043054e4f7 1396 screen.imageToBuffer(spkDisplayLogo);
tobyspark 0:87aab40d5806 1397 screen.textToBuffer("SPK:D-Fuser",0);
tobyspark 30:873979018850 1398 screen.textToBuffer(softwareLine,1);
tobyspark 5:f8b285ca41ba 1399 screen.sendBuffer();
tobyspark 0:87aab40d5806 1400
tobyspark 11:0783cfbeb746 1401 // Load saved settings
tobyspark 16:52484666b323 1402 bool settingsAreCustom = false;
tobyspark 16:52484666b323 1403 settingsAreCustom = settings.load(kSPKDFSettingsFilename);
tobyspark 30:873979018850 1404 if (settingsAreCustom)
tobyspark 30:873979018850 1405 {
tobyspark 30:873979018850 1406 softwareLine += "; ini OK";
tobyspark 30:873979018850 1407 screen.textToBuffer(softwareLine, 1);
tobyspark 30:873979018850 1408 }
tobyspark 30:873979018850 1409
tobyspark 0:87aab40d5806 1410 // Set menu structure
tobyspark 0:87aab40d5806 1411 mixModeMenu.title = "Mix Mode";
tobyspark 27:27851d3d2bba 1412 setMixModeMenuItems();
tobyspark 24:49c6624119ae 1413
tobyspark 29:95a7efe30527 1414 mixModeAdditiveMenu.title = "Crossfade";
tobyspark 49:16309f39cead 1415 mixModeAdditiveMenu.addMenuItem(SPKMenuItem(&mixModeAdditiveMenuHandler));
tobyspark 36:8b5c75c8bc23 1416
tobyspark 49:16309f39cead 1417 mixModeUpdateKeyMenu.title = "Update Keyer Settings?";
tobyspark 55:35a295d36d23 1418 mixModeUpdateKeyMenu.addMenuItem(SPKMenuItem(&mixModeUpdateKeyMenuHandler));
tobyspark 36:8b5c75c8bc23 1419
tobyspark 0:87aab40d5806 1420 resolutionMenu.title = "Resolution";
tobyspark 27:27851d3d2bba 1421 setResolutionMenuItems();
tobyspark 0:87aab40d5806 1422
tobyspark 27:27851d3d2bba 1423 commsMenu.title = "Network Mode";
tobyspark 27:27851d3d2bba 1424 setCommsMenuItems();
tobyspark 23:909928cafb95 1425
tobyspark 51:98cc27390484 1426 advancedMenu.title = "Advanced Commands";
tobyspark 51:98cc27390484 1427 advancedMenu.addMenuItem(SPKMenuItem("Processor full conform", advancedConformUploadProcessor));
tobyspark 51:98cc27390484 1428 advancedMenu.addMenuItem(SPKMenuItem("Back to Troubleshooting Menu", &troubleshootingMenu));
tobyspark 51:98cc27390484 1429
tobyspark 51:98cc27390484 1430 troubleshootingMenu.title = "Troubleshooting";
tobyspark 51:98cc27390484 1431 troubleshootingMenuHDCP.title = "HDCP - Can Block DVI";
tobyspark 51:98cc27390484 1432 troubleshootingMenuHDCP.addMenuItem(SPKMenuItem(&troubleshootingMenuHDCPHandler));
tobyspark 51:98cc27390484 1433 troubleshootingMenu.addMenuItem(SPKMenuItem(troubleshootingMenuHDCP.title, &troubleshootingMenuHDCP));
tobyspark 51:98cc27390484 1434 troubleshootingMenuEDID.title = "EDID - Advertises Res's";
tobyspark 55:35a295d36d23 1435 troubleshootingMenuEDID.addMenuItem(SPKMenuItem(&troubleshootingMenuEDIDHandler));
tobyspark 51:98cc27390484 1436 troubleshootingMenu.addMenuItem(SPKMenuItem(troubleshootingMenuEDID.title, &troubleshootingMenuEDID));
tobyspark 55:35a295d36d23 1437 troubleshootingMenuAspect.title = "Aspect - Mismatched Res";
tobyspark 55:35a295d36d23 1438 troubleshootingMenuAspect.addMenuItem(SPKMenuItem(&troubleshootingMenuAspectHandler));
tobyspark 55:35a295d36d23 1439 troubleshootingMenu.addMenuItem(SPKMenuItem(troubleshootingMenuAspect.title, &troubleshootingMenuAspect));
tobyspark 51:98cc27390484 1440 troubleshootingMenuReset.title = "Output - Mixing Wrong";
tobyspark 51:98cc27390484 1441 troubleshootingMenuReset.addMenuItem(SPKMenuItem(&troubleshootingMenuResetHandler));
tobyspark 51:98cc27390484 1442 troubleshootingMenu.addMenuItem(SPKMenuItem(troubleshootingMenuReset.title, &troubleshootingMenuReset));
tobyspark 51:98cc27390484 1443 troubleshootingMenu.addMenuItem(SPKMenuItem(advancedMenu.title, &advancedMenu));
tobyspark 51:98cc27390484 1444 troubleshootingMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu));
tobyspark 23:909928cafb95 1445
tobyspark 0:87aab40d5806 1446 mainMenu.title = "Main Menu";
tobyspark 24:49c6624119ae 1447 mainMenu.addMenuItem(SPKMenuItem(mixModeMenu.title, &mixModeMenu));
tobyspark 24:49c6624119ae 1448 mainMenu.addMenuItem(SPKMenuItem(resolutionMenu.title, &resolutionMenu));
tobyspark 24:49c6624119ae 1449 mainMenu.addMenuItem(SPKMenuItem(commsMenu.title, &commsMenu));
tobyspark 51:98cc27390484 1450 mainMenu.addMenuItem(SPKMenuItem(troubleshootingMenu.title, &troubleshootingMenu));
tobyspark 23:909928cafb95 1451
tobyspark 0:87aab40d5806 1452 selectedMenu = &mainMenu;
tobyspark 23:909928cafb95 1453
tobyspark 0:87aab40d5806 1454 // Misc I/O stuff
tobyspark 0:87aab40d5806 1455
tobyspark 0:87aab40d5806 1456 fadeAPO.period(0.001);
tobyspark 0:87aab40d5806 1457 fadeBPO.period(0.001);
tobyspark 48:c0fedfa8c525 1458
tobyspark 48:c0fedfa8c525 1459 // If we do not have two solid sources, act on this as we rely on the window having a source for crossfade behaviour
tobyspark 48:c0fedfa8c525 1460 // 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 49:16309f39cead 1461 handleTVOneSources();
tobyspark 49:16309f39cead 1462
tobyspark 49:16309f39cead 1463 // Processor can have been power-on saved with a keyer on, lets revert
tobyspark 49:16309f39cead 1464 actionMixMode();
tobyspark 0:87aab40d5806 1465
tobyspark 12:c270870bdd23 1466 // Display menu and framing lines
tobyspark 0:87aab40d5806 1467 screen.horizLineToBuffer(kMenuLine1*pixInPage - 1);
tobyspark 0:87aab40d5806 1468 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 1469 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 1470 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 1471 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 1472 screen.horizLineToBuffer(kMenuLine2*pixInPage + pixInPage);
tobyspark 1:f9fca21102e0 1473 screen.horizLineToBuffer(kCommsStatusLine*pixInPage - 1);
tobyspark 1:f9fca21102e0 1474 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 48:c0fedfa8c525 1475 screen.textToBuffer(tvOneStatusMessage.message(), kTVOneStatusLine);
tobyspark 33:e6672a9bd571 1476 screen.sendBuffer();
tobyspark 33:e6672a9bd571 1477
tobyspark 0:87aab40d5806 1478 //// CONTROLS TEST
tobyspark 0:87aab40d5806 1479
tobyspark 0:87aab40d5806 1480 while (0) {
tobyspark 0:87aab40d5806 1481 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 1482 }
tobyspark 0:87aab40d5806 1483
tobyspark 0:87aab40d5806 1484 //// MIXER RUN
tobyspark 0:87aab40d5806 1485
tobyspark 8:d46cc49f0f37 1486 while (1)
tobyspark 49:16309f39cead 1487 {
tobyspark 1:f9fca21102e0 1488 //// Task background things
tobyspark 33:e6672a9bd571 1489 if ((osc || artNet) && rj45Mode == rj45Ethernet)
tobyspark 5:f8b285ca41ba 1490 {
tobyspark 5:f8b285ca41ba 1491 Net::poll();
tobyspark 5:f8b285ca41ba 1492 }
tobyspark 5:f8b285ca41ba 1493
tobyspark 5:f8b285ca41ba 1494 //// RJ45 SWITCH
tobyspark 5:f8b285ca41ba 1495
tobyspark 5:f8b285ca41ba 1496 if (rj45ModeDIN != rj45Mode)
tobyspark 1:f9fca21102e0 1497 {
tobyspark 23:909928cafb95 1498 if (debug) debug->printf("Handling RJ45 mode change\r\n");
tobyspark 27:27851d3d2bba 1499
tobyspark 5:f8b285ca41ba 1500 // update state
tobyspark 5:f8b285ca41ba 1501 rj45Mode = rj45ModeDIN;
tobyspark 27:27851d3d2bba 1502
tobyspark 27:27851d3d2bba 1503 setCommsMenuItems();
tobyspark 5:f8b285ca41ba 1504
tobyspark 5:f8b285ca41ba 1505 // cancel old comms
tobyspark 5:f8b285ca41ba 1506 commsMode = commsNone;
tobyspark 5:f8b285ca41ba 1507 commsMenu = commsMode;
tobyspark 5:f8b285ca41ba 1508
tobyspark 5:f8b285ca41ba 1509 // refresh display
tobyspark 23:909928cafb95 1510 if (selectedMenu == &commsMenu)
tobyspark 23:909928cafb95 1511 {
tobyspark 33:e6672a9bd571 1512 screen.clearBufferRow(kMenuLine1);
tobyspark 33:e6672a9bd571 1513 screen.clearBufferRow(kMenuLine2);
tobyspark 23:909928cafb95 1514 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 23:909928cafb95 1515 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 23:909928cafb95 1516 }
tobyspark 5:f8b285ca41ba 1517 if (rj45Mode == rj45Ethernet) screen.textToBuffer("RJ45: Ethernet Engaged", kCommsStatusLine);
tobyspark 5:f8b285ca41ba 1518 if (rj45Mode == rj45DMX) screen.textToBuffer("RJ45: DMX Engaged", kCommsStatusLine);
tobyspark 1:f9fca21102e0 1519 }
tobyspark 1:f9fca21102e0 1520
tobyspark 0:87aab40d5806 1521 //// MENU
tobyspark 0:87aab40d5806 1522
tobyspark 0:87aab40d5806 1523 int menuChange = menuEnc.getChange();
tobyspark 0:87aab40d5806 1524
tobyspark 0:87aab40d5806 1525 // Update GUI
tobyspark 0:87aab40d5806 1526 if (menuChange != 0)
tobyspark 0:87aab40d5806 1527 {
tobyspark 49:16309f39cead 1528 if (selectedMenu->selectedItem().type == SPKMenuItem::hasHandler)
tobyspark 24:49c6624119ae 1529 {
tobyspark 49:16309f39cead 1530 selectedMenu->selectedItem().payload.handler(menuChange, false);
tobyspark 24:49c6624119ae 1531 }
tobyspark 24:49c6624119ae 1532 else
tobyspark 24:49c6624119ae 1533 {
tobyspark 24:49c6624119ae 1534 if (debug) debug->printf("Menu changed by %i\r\n", menuChange);
tobyspark 24:49c6624119ae 1535
tobyspark 24:49c6624119ae 1536 *selectedMenu = selectedMenu->selectedIndex() + menuChange;
tobyspark 24:49c6624119ae 1537
tobyspark 24:49c6624119ae 1538 // update OLED line 2 here
tobyspark 24:49c6624119ae 1539 screen.clearBufferRow(kMenuLine2);
tobyspark 24:49c6624119ae 1540 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 24:49c6624119ae 1541
tobyspark 24:49c6624119ae 1542 if (debug) debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 24:49c6624119ae 1543 }
tobyspark 0:87aab40d5806 1544 }
tobyspark 0:87aab40d5806 1545
tobyspark 0:87aab40d5806 1546 // Action menu item
tobyspark 0:87aab40d5806 1547 if (menuEnc.hasPressed())
tobyspark 0:87aab40d5806 1548 {
tobyspark 0:87aab40d5806 1549 if (debug) debug->printf("Action Menu Item!\r\n");
tobyspark 21:f9d63cb7cedb 1550
tobyspark 0:87aab40d5806 1551 // Are we changing menus?
tobyspark 23:909928cafb95 1552 if (selectedMenu->selectedItem().type == SPKMenuItem::changesToMenu)
tobyspark 0:87aab40d5806 1553 {
tobyspark 31:01845a2347ff 1554 // If we're exiting the menu, we should set its selected index back to the menu's beginning...
tobyspark 31:01845a2347ff 1555 SPKMenu* menuToReset = selectedMenu->selectedItem().payload.menu == &mainMenu? selectedMenu : NULL;
tobyspark 31:01845a2347ff 1556
tobyspark 31:01845a2347ff 1557 // point selected menu pointer to the new menu pointer
tobyspark 23:909928cafb95 1558 selectedMenu = selectedMenu->selectedItem().payload.menu;
tobyspark 0:87aab40d5806 1559
tobyspark 31:01845a2347ff 1560 // ...doing this, of course, after we've used the value
tobyspark 31:01845a2347ff 1561 if (menuToReset) *menuToReset = 0;
tobyspark 31:01845a2347ff 1562
tobyspark 0:87aab40d5806 1563 // update OLED lines 1&2
tobyspark 0:87aab40d5806 1564 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 1565 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 1566 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 1567 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 1568
tobyspark 49:16309f39cead 1569 if (selectedMenu->selectedItem().type == SPKMenuItem::hasHandler)
tobyspark 49:16309f39cead 1570 {
tobyspark 49:16309f39cead 1571 selectedMenu->selectedItem().payload.handler(0, false);
tobyspark 49:16309f39cead 1572 }
tobyspark 49:16309f39cead 1573
tobyspark 0:87aab40d5806 1574 if (debug)
tobyspark 0:87aab40d5806 1575 {
tobyspark 0:87aab40d5806 1576 debug->printf("\r\n");
tobyspark 0:87aab40d5806 1577 debug->printf("%s \r\n", selectedMenu->title.c_str());
tobyspark 0:87aab40d5806 1578 debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 0:87aab40d5806 1579 }
tobyspark 49:16309f39cead 1580 }
tobyspark 49:16309f39cead 1581 else if (selectedMenu->selectedItem().type == SPKMenuItem::hasHandler)
tobyspark 49:16309f39cead 1582 {
tobyspark 49:16309f39cead 1583 selectedMenu->selectedItem().payload.handler(0, true);
tobyspark 0:87aab40d5806 1584 }
tobyspark 0:87aab40d5806 1585 // With that out of the way, we should be actioning a specific menu's payload?
tobyspark 44:723e65413ebe 1586 else if (selectedMenu == &mixModeMenu)
tobyspark 44:723e65413ebe 1587 {
tobyspark 44:723e65413ebe 1588 mixMode = mixModeMenu.selectedItem().payload.command[0];
tobyspark 49:16309f39cead 1589
tobyspark 49:16309f39cead 1590 // the spanner in the works: mixBlend and mixAdditive are now both index 0 in the menu
tobyspark 49:16309f39cead 1591 if (mixMode >= mixKeyStartIndex)
tobyspark 49:16309f39cead 1592 {
tobyspark 49:16309f39cead 1593 // adjust for the two-into-one spanner
tobyspark 49:16309f39cead 1594 mixMode += 1;
tobyspark 49:16309f39cead 1595
tobyspark 49:16309f39cead 1596 // if its the second click on the keying mode, lets edit the parameters
tobyspark 49:16309f39cead 1597 if (mixMode == mixModeOld)
tobyspark 49:16309f39cead 1598 {
tobyspark 49:16309f39cead 1599 selectedMenu = &mixModeUpdateKeyMenu;
tobyspark 49:16309f39cead 1600
tobyspark 49:16309f39cead 1601 screen.clearBufferRow(kMenuLine1);
tobyspark 49:16309f39cead 1602 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 49:16309f39cead 1603
tobyspark 49:16309f39cead 1604 selectedMenu->selectedItem().payload.handler(0, false);
tobyspark 49:16309f39cead 1605 }
tobyspark 49:16309f39cead 1606 }
tobyspark 44:723e65413ebe 1607 }
tobyspark 0:87aab40d5806 1608 else if (selectedMenu == &resolutionMenu)
tobyspark 0:87aab40d5806 1609 {
tobyspark 49:16309f39cead 1610 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 49:16309f39cead 1611 screen.textToBuffer("Setting Resolution...", kTVOneStatusLine);
tobyspark 49:16309f39cead 1612 screen.sendBuffer();
tobyspark 49:16309f39cead 1613
tobyspark 44:723e65413ebe 1614 bool ok;
tobyspark 57:14d37904c889 1615 int oldEDID = tvOne.getEDID();
tobyspark 57:14d37904c889 1616 int newEDID = tvOneEDIDPassthrough ? EDIDPassthroughSlot : resolutionMenu.selectedItem().payload.command[1];
tobyspark 31:01845a2347ff 1617
tobyspark 57:14d37904c889 1618 ok = tvOne.setResolution(resolutionMenu.selectedItem().payload.command[0], newEDID);
tobyspark 0:87aab40d5806 1619
tobyspark 35:d5d9f0838f99 1620 // Save new resolution and EDID into TV One unit for power-on. Cycling TV One power sometimes needed for EDID. Pffft.
tobyspark 44:723e65413ebe 1621 if (ok) tvOne.command(0, kTV1WindowIDA, kTV1FunctionPowerOnPresetStore, 1);
tobyspark 35:d5d9f0838f99 1622
tobyspark 57:14d37904c889 1623 string message;
tobyspark 57:14d37904c889 1624 if (ok)
tobyspark 57:14d37904c889 1625 {
tobyspark 57:14d37904c889 1626 if (oldEDID == newEDID) message = "Sent: Resolution";
tobyspark 57:14d37904c889 1627 else message = "Sent: Resolution + EDID";
tobyspark 57:14d37904c889 1628 }
tobyspark 57:14d37904c889 1629 else message = "Send Error: Resolution";
tobyspark 57:14d37904c889 1630 tvOneStatusMessage.addMessage(message, kTVOneStatusMessageHoldTime);
tobyspark 0:87aab40d5806 1631
tobyspark 57:14d37904c889 1632 // This is WHACK. Can't believe it's both needed and officially in the 1T-C2-750 manual
tobyspark 57:14d37904c889 1633 if ((oldEDID != newEDID) && ok) tvOneStatusMessage.addMessage("EDID: Processor Off+On?", kTVOneStatusMessageHoldTime);
tobyspark 0:87aab40d5806 1634
tobyspark 0:87aab40d5806 1635 if (debug) { debug->printf("Changing resolution"); }
tobyspark 0:87aab40d5806 1636 }
tobyspark 1:f9fca21102e0 1637 else if (selectedMenu == &commsMenu)
tobyspark 1:f9fca21102e0 1638 {
tobyspark 26:0299f8760715 1639 string commsTypeString = "Network:";
tobyspark 26:0299f8760715 1640 char commsStatusBuffer[kStringBufferLength] = "--";
tobyspark 1:f9fca21102e0 1641
tobyspark 1:f9fca21102e0 1642 // Tear down any existing comms
tobyspark 1:f9fca21102e0 1643 // This is the action of commsNone
tobyspark 1:f9fca21102e0 1644 // And also clears the way for other comms actions
tobyspark 26:0299f8760715 1645 commsMode = commsNone;
tobyspark 5:f8b285ca41ba 1646 if (osc) {delete osc; osc = NULL;}
tobyspark 5:f8b285ca41ba 1647 if (ethernet) {delete ethernet; ethernet = NULL;}
tobyspark 33:e6672a9bd571 1648 if (artNet)
tobyspark 33:e6672a9bd571 1649 {
tobyspark 33:e6672a9bd571 1650 artNet->ArtPollReply.NumPorts = 0;
tobyspark 33:e6672a9bd571 1651 strcpy(artNet->ArtPollReply.NodeReport, "Shutdown");
tobyspark 33:e6672a9bd571 1652 artNet->SendArtPollReply();
tobyspark 33:e6672a9bd571 1653 artNet->Done();
tobyspark 33:e6672a9bd571 1654 delete artNet;
tobyspark 33:e6672a9bd571 1655 artNet = NULL;
tobyspark 33:e6672a9bd571 1656 }
tobyspark 5:f8b285ca41ba 1657 if (dmx) {delete dmx; dmx = NULL;}
tobyspark 5:f8b285ca41ba 1658
tobyspark 5:f8b285ca41ba 1659 // Ensure we can't change to comms modes the hardware isn't switched to
tobyspark 23:909928cafb95 1660 if (rj45Mode == rj45DMX && (commsMenu.selectedItem().payload.command[0] == commsOSC || commsMenu.selectedItem().payload.command[0] == commsArtNet))
tobyspark 1:f9fca21102e0 1661 {
tobyspark 5:f8b285ca41ba 1662 commsTypeString = "RJ45 not in Ethernet mode";
tobyspark 5:f8b285ca41ba 1663 }
tobyspark 23:909928cafb95 1664 else if (rj45Mode == rj45Ethernet && (commsMenu.selectedItem().payload.command[0] == commsDMXIn || commsMenu.selectedItem().payload.command[0] == commsDMXOut))
tobyspark 5:f8b285ca41ba 1665 {
tobyspark 5:f8b285ca41ba 1666 commsTypeString = "RJ45 not in DMX mode";
tobyspark 5:f8b285ca41ba 1667 }
tobyspark 5:f8b285ca41ba 1668 // Action!
tobyspark 23:909928cafb95 1669 else if (commsMenu.selectedItem().payload.command[0] == commsOSC)
tobyspark 5:f8b285ca41ba 1670 {
tobyspark 5:f8b285ca41ba 1671 commsMode = commsOSC;
tobyspark 5:f8b285ca41ba 1672 commsTypeString = "OSC: ";
tobyspark 1:f9fca21102e0 1673
tobyspark 1:f9fca21102e0 1674 ethernet = new EthernetNetIf(
tobyspark 1:f9fca21102e0 1675 IpAddr(kOSCMbedIPAddress),
tobyspark 1:f9fca21102e0 1676 IpAddr(kOSCMbedSubnetMask),
tobyspark 1:f9fca21102e0 1677 IpAddr(kOSCMbedGateway),
tobyspark 1:f9fca21102e0 1678 IpAddr(kOSCMbedDNS)
tobyspark 1:f9fca21102e0 1679 );
tobyspark 3:033d2b7768f3 1680
tobyspark 1:f9fca21102e0 1681 EthernetErr ethError = ethernet->setup();
tobyspark 1:f9fca21102e0 1682 if(ethError)
tobyspark 1:f9fca21102e0 1683 {
tobyspark 1:f9fca21102e0 1684 if (debug) debug->printf("Ethernet setup error, %d", ethError);
tobyspark 26:0299f8760715 1685 snprintf(commsStatusBuffer, kStringBufferLength, "Ethernet setup failed");
tobyspark 5:f8b285ca41ba 1686 commsMenu = commsNone;
tobyspark 1:f9fca21102e0 1687 // break out of here. this setup should be a function that returns a boolean
tobyspark 1:f9fca21102e0 1688 }
tobyspark 1:f9fca21102e0 1689
tobyspark 1:f9fca21102e0 1690 osc = new OSCClass();
tobyspark 33:e6672a9bd571 1691 osc->setReceiveMessage(&receiveMessage);
tobyspark 1:f9fca21102e0 1692 osc->begin(kOSCMbedPort);
tobyspark 1:f9fca21102e0 1693
tobyspark 54:e8606eaa47a3 1694 uint8_t destIP[] = { kOSCDestIPAddress };
tobyspark 54:e8606eaa47a3 1695 sendMessage.setIp( destIP );
tobyspark 54:e8606eaa47a3 1696 sendMessage.setPort( kOSCDestPort );
tobyspark 54:e8606eaa47a3 1697
tobyspark 26:0299f8760715 1698 snprintf(commsStatusBuffer, kStringBufferLength, "Listening on %i", kOSCMbedPort);
tobyspark 1:f9fca21102e0 1699 }
tobyspark 23:909928cafb95 1700 else if (commsMenu.selectedItem().payload.command[0] == commsArtNet)
tobyspark 1:f9fca21102e0 1701 {
tobyspark 5:f8b285ca41ba 1702 commsMode = commsArtNet;
tobyspark 5:f8b285ca41ba 1703 commsTypeString = "ArtNet: ";
tobyspark 3:033d2b7768f3 1704
tobyspark 3:033d2b7768f3 1705 artNet = new DmxArtNet();
tobyspark 1:f9fca21102e0 1706
tobyspark 3:033d2b7768f3 1707 artNet->BindIpAddress = IpAddr(kArtNetBindIPAddress);
tobyspark 3:033d2b7768f3 1708 artNet->BCastAddress = IpAddr(kArtNetBroadcastAddress);
tobyspark 3:033d2b7768f3 1709
tobyspark 3:033d2b7768f3 1710 artNet->InitArtPollReplyDefaults();
tobyspark 3:033d2b7768f3 1711
tobyspark 33:e6672a9bd571 1712 artNet->ArtPollReply.PortType[0] = 128; // Bit 7 = Set is this channel can output data from the Art-Net Network.
tobyspark 33:e6672a9bd571 1713 artNet->ArtPollReply.GoodOutput[0] = 128; // Bit 7 = Set – Data is being transmitted.
tobyspark 33:e6672a9bd571 1714 artNet->ArtPollReply.PortType[2] = 64; // Bit 6 = Set if this channel can input onto the Art-NetNetwork.
tobyspark 33:e6672a9bd571 1715 artNet->ArtPollReply.GoodInput[2] = 128; // Bit 7 = Set – Data received.
tobyspark 3:033d2b7768f3 1716
tobyspark 3:033d2b7768f3 1717 artNet->Init();
tobyspark 3:033d2b7768f3 1718 artNet->SendArtPollReply(); // announce to art-net nodes
tobyspark 3:033d2b7768f3 1719
tobyspark 26:0299f8760715 1720 snprintf(commsStatusBuffer, kStringBufferLength, "Listening");
tobyspark 1:f9fca21102e0 1721 }
tobyspark 23:909928cafb95 1722 else if (commsMenu.selectedItem().payload.command[0] == commsDMXIn)
tobyspark 1:f9fca21102e0 1723 {
tobyspark 5:f8b285ca41ba 1724 commsMode = commsDMXIn;
tobyspark 5:f8b285ca41ba 1725 commsTypeString = "DMX In: ";
tobyspark 1:f9fca21102e0 1726
tobyspark 5:f8b285ca41ba 1727 dmxDirectionDOUT = 0;
tobyspark 5:f8b285ca41ba 1728
tobyspark 5:f8b285ca41ba 1729 dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX);
tobyspark 1:f9fca21102e0 1730 }
tobyspark 23:909928cafb95 1731 else if (commsMenu.selectedItem().payload.command[0] == commsDMXOut)
tobyspark 5:f8b285ca41ba 1732 {
tobyspark 5:f8b285ca41ba 1733 commsMode = commsDMXOut;
tobyspark 5:f8b285ca41ba 1734 commsTypeString = "DMX Out: ";
tobyspark 5:f8b285ca41ba 1735
tobyspark 5:f8b285ca41ba 1736 dmxDirectionDOUT = 1;
tobyspark 5:f8b285ca41ba 1737
tobyspark 5:f8b285ca41ba 1738 dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX);
tobyspark 5:f8b285ca41ba 1739 }
tobyspark 5:f8b285ca41ba 1740
tobyspark 1:f9fca21102e0 1741 screen.clearBufferRow(kCommsStatusLine);
tobyspark 25:3b519ef70341 1742 screen.textToBuffer(commsTypeString + commsStatusBuffer, kCommsStatusLine);
tobyspark 1:f9fca21102e0 1743 }
tobyspark 12:c270870bdd23 1744 else if (selectedMenu == &advancedMenu)
tobyspark 12:c270870bdd23 1745 {
tobyspark 51:98cc27390484 1746 if (advancedMenu.selectedItem().payload.command[0] == advancedConformUploadProcessor)
tobyspark 41:00d1cd3b2af2 1747 {
tobyspark 41:00d1cd3b2af2 1748 bool ok = true;
tobyspark 41:00d1cd3b2af2 1749
tobyspark 41:00d1cd3b2af2 1750 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1751 screen.textToBuffer("Uploading...", kTVOneStatusLine);
tobyspark 41:00d1cd3b2af2 1752 screen.sendBuffer();
tobyspark 41:00d1cd3b2af2 1753
tobyspark 41:00d1cd3b2af2 1754 ok = ok && uploadToProcessor();
tobyspark 41:00d1cd3b2af2 1755
tobyspark 41:00d1cd3b2af2 1756 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 20:8b92d7922c48 1757 screen.textToBuffer("Conforming...", kTVOneStatusLine);
tobyspark 20:8b92d7922c48 1758 screen.sendBuffer();
tobyspark 20:8b92d7922c48 1759
tobyspark 41:00d1cd3b2af2 1760 ok = ok && conformProcessor();
tobyspark 17:fc68d40b8b1f 1761
tobyspark 17:fc68d40b8b1f 1762 std::string sendOK = ok ? "Conform success" : "Send Error: Conform";
tobyspark 17:fc68d40b8b1f 1763
tobyspark 48:c0fedfa8c525 1764 tvOneStatusMessage.addMessage(sendOK, kTVOneStatusMessageHoldTime);
tobyspark 17:fc68d40b8b1f 1765 }
tobyspark 51:98cc27390484 1766 // else if (advancedMenu.selectedItem().payload.command[0] == advancedSetResolutions)
tobyspark 51:98cc27390484 1767 // {
tobyspark 51:98cc27390484 1768 // bool ok;
tobyspark 51:98cc27390484 1769 // ok = tvOne.uploadCustomResolutions();
tobyspark 51:98cc27390484 1770 //
tobyspark 51:98cc27390484 1771 // tvOneStatusMessage.addMessage(ok ? "Resolutions set" : "Res' could not be set", kTVOneStatusMessageHoldTime);
tobyspark 51:98cc27390484 1772 // }
tobyspark 12:c270870bdd23 1773 }
tobyspark 0:87aab40d5806 1774 else
tobyspark 0:87aab40d5806 1775 {
tobyspark 0:87aab40d5806 1776 if (debug) { debug->printf("Warning: No action identified"); }
tobyspark 0:87aab40d5806 1777 }
tobyspark 0:87aab40d5806 1778 }
tobyspark 0:87aab40d5806 1779
tobyspark 34:69dfe64e7e6b 1780 // Send any updates to the display
tobyspark 48:c0fedfa8c525 1781 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 48:c0fedfa8c525 1782 screen.textToBuffer(tvOneStatusMessage.message(), kTVOneStatusLine);
tobyspark 34:69dfe64e7e6b 1783 screen.sendBuffer();
tobyspark 0:87aab40d5806 1784
tobyspark 5:f8b285ca41ba 1785 //// MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIXMIX MIX MIXMIX MIX MIX MIX MIX MIXMIX MIX MIX
tobyspark 0:87aab40d5806 1786
tobyspark 0:87aab40d5806 1787 bool updateFade = false;
tobyspark 3:033d2b7768f3 1788 float xFade = 0;
tobyspark 3:033d2b7768f3 1789 float fadeUp = 1;
tobyspark 3:033d2b7768f3 1790
tobyspark 3:033d2b7768f3 1791 //// TASK: Process control surface
tobyspark 3:033d2b7768f3 1792
tobyspark 0:87aab40d5806 1793 // Get new states of tap buttons, remembering at end of loop() assign these current values to the previous variables
tobyspark 5:f8b285ca41ba 1794 const bool tapLeft = !tapLeftDIN;
tobyspark 5:f8b285ca41ba 1795 const bool tapRight = !tapRightDIN;
tobyspark 0:87aab40d5806 1796
tobyspark 17:fc68d40b8b1f 1797 // We're taking a further median of the AINs on top of mbed libs v29.
tobyspark 17:fc68d40b8b1f 1798 // This takes some values from last passes and most from now. With debug off, seem to need median size > 5
tobyspark 17:fc68d40b8b1f 1799 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1800 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1801 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1802 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1803 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1804 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1805 xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1806 fadeUpFilter.process(fadeUpAIN.read());
tobyspark 17:fc68d40b8b1f 1807 const float xFadeAINCached = xFadeFilter.process(xFadeAIN.read());
tobyspark 17:fc68d40b8b1f 1808 const float fadeUpAINCached = fadeUpFilter.process(fadeUpAIN.read());
tobyspark 0:87aab40d5806 1809
tobyspark 0:87aab40d5806 1810 // When a tap is depressed, we can ignore any move of the crossfader but not fade to black
tobyspark 0:87aab40d5806 1811 if (tapLeft || tapRight)
tobyspark 0:87aab40d5806 1812 {
tobyspark 5:f8b285ca41ba 1813 // If both are pressed, take to the one that is new, ie. not the first pressed.
tobyspark 0:87aab40d5806 1814 if (tapLeft && tapRight)
tobyspark 0:87aab40d5806 1815 {
tobyspark 5:f8b285ca41ba 1816 xFade = tapLeftWasFirstPressed ? 1 : 0;
tobyspark 0:87aab40d5806 1817 }
tobyspark 5:f8b285ca41ba 1818 // If just one is pressed, take to that and remember which is pressed
tobyspark 5:f8b285ca41ba 1819 else if (tapLeft)
tobyspark 5:f8b285ca41ba 1820 {
tobyspark 5:f8b285ca41ba 1821 xFade = 0;
tobyspark 5:f8b285ca41ba 1822 tapLeftWasFirstPressed = 1;
tobyspark 5:f8b285ca41ba 1823 }
tobyspark 5:f8b285ca41ba 1824 else if (tapRight)
tobyspark 5:f8b285ca41ba 1825 {
tobyspark 5:f8b285ca41ba 1826 xFade = 1;
tobyspark 5:f8b285ca41ba 1827 tapLeftWasFirstPressed = 0;
tobyspark 5:f8b285ca41ba 1828 }
tobyspark 5:f8b285ca41ba 1829 }
tobyspark 18:ebe5da639a6a 1830 else xFade = 1.0 - fadeCalc(xFadeAINCached, xFadeTolerance);
tobyspark 0:87aab40d5806 1831
tobyspark 0:87aab40d5806 1832 fadeUp = 1.0 - fadeCalc(fadeUpAINCached, fadeUpTolerance);
tobyspark 0:87aab40d5806 1833
tobyspark 58:54347f2c3184 1834 //// TASK: Process Network Comms In, allowing hands-on controls to override
tobyspark 58:54347f2c3184 1835 if ((commsMode == commsOSC) || (commsMode == commsArtNet) || (commsMode == commsDMXIn))
tobyspark 3:033d2b7768f3 1836 {
tobyspark 58:54347f2c3184 1837 bool commsIn = false;
tobyspark 58:54347f2c3184 1838
tobyspark 58:54347f2c3184 1839 switch (commsMode)
tobyspark 58:54347f2c3184 1840 {
tobyspark 58:54347f2c3184 1841 case commsOSC: commsIn = processOSCIn(); break;
tobyspark 58:54347f2c3184 1842 case commsArtNet: commsIn = processArtNetIn(); break;
tobyspark 58:54347f2c3184 1843 case commsDMXIn: commsIn = processDMXIn(); break;
tobyspark 58:54347f2c3184 1844 }
tobyspark 58:54347f2c3184 1845
tobyspark 58:54347f2c3184 1846 if (commsIn)
tobyspark 3:033d2b7768f3 1847 {
tobyspark 58:54347f2c3184 1848 // Store hands-on control positions to compare for change later
tobyspark 58:54347f2c3184 1849 commsInActive = true;
tobyspark 58:54347f2c3184 1850 oldXFade = xFade;
tobyspark 58:54347f2c3184 1851 oldFadeUp = fadeUp;
tobyspark 58:54347f2c3184 1852 }
tobyspark 58:54347f2c3184 1853 else if (commsInActive)
tobyspark 58:54347f2c3184 1854 {
tobyspark 58:54347f2c3184 1855 // If no comms in update this loop, hold to the last unless hands-on controls have moved significantly
tobyspark 58:54347f2c3184 1856 bool movement = (fabs(oldXFade-xFade) > 0.1) || (fabs(oldFadeUp-fadeUp) > 0.1);
tobyspark 58:54347f2c3184 1857 if (movement) commsInActive = false;
tobyspark 58:54347f2c3184 1858 }
tobyspark 58:54347f2c3184 1859
tobyspark 58:54347f2c3184 1860 if (commsInActive)
tobyspark 58:54347f2c3184 1861 {
tobyspark 58:54347f2c3184 1862 xFade = commsXFade;
tobyspark 58:54347f2c3184 1863 fadeUp = commsFadeUp;
tobyspark 3:033d2b7768f3 1864 }
tobyspark 3:033d2b7768f3 1865 }
tobyspark 3:033d2b7768f3 1866
tobyspark 0:87aab40d5806 1867 // Calculate new A&B fade percents
tobyspark 0:87aab40d5806 1868 int newFadeAPercent = 0;
tobyspark 0:87aab40d5806 1869 int newFadeBPercent = 0;
tobyspark 0:87aab40d5806 1870
tobyspark 30:873979018850 1871 if (mixMode == mixBlend)
tobyspark 11:0783cfbeb746 1872 {
tobyspark 51:98cc27390484 1873 // This is the correct algorithm for blend where window A occludes B.
tobyspark 51:98cc27390484 1874 // Who knew a crossfade could be so tricky. The level of B has to be factored by what A is letting through.
tobyspark 51:98cc27390484 1875 // ie. if fully faded up, top window = xfade, bottom window = 100%
tobyspark 51:98cc27390484 1876 // This will however look very wrong if A is not occluding B, ie. mismatched aspect ratios.
tobyspark 51:98cc27390484 1877 if (xFade > 0) // avoids div by zero (if xFade = 0 and fadeUp = 1, B sum = 0 / 0)
tobyspark 51:98cc27390484 1878 {
tobyspark 51:98cc27390484 1879 newFadeAPercent = (1.0-xFade) * fadeUp * 100.0;
tobyspark 51:98cc27390484 1880 newFadeBPercent = (xFade*fadeUp) / (1.0 - fadeUp + xFade*fadeUp) * 100.0;
tobyspark 51:98cc27390484 1881 }
tobyspark 51:98cc27390484 1882 else
tobyspark 51:98cc27390484 1883 {
tobyspark 51:98cc27390484 1884 newFadeAPercent = fadeUp * 100.0;
tobyspark 51:98cc27390484 1885 newFadeBPercent = 0;
tobyspark 51:98cc27390484 1886 }
tobyspark 11:0783cfbeb746 1887 }
tobyspark 15:4b394c64b461 1888 else if (mixMode == mixAdditive)
tobyspark 11:0783cfbeb746 1889 {
tobyspark 22:90054fe6d86c 1890 // we need to set fade level of both windows according to the fade curve profile
tobyspark 22:90054fe6d86c 1891 float newFadeA = (1.0-xFade) * (1.0 + fadeCurve);
tobyspark 22:90054fe6d86c 1892 float newFadeB = xFade * (1 + fadeCurve);
tobyspark 22:90054fe6d86c 1893 if (newFadeA > 1.0) newFadeA = 1.0;
tobyspark 22:90054fe6d86c 1894 if (newFadeB > 1.0) newFadeB = 1.0;
tobyspark 22:90054fe6d86c 1895
tobyspark 22:90054fe6d86c 1896 newFadeAPercent = newFadeA * fadeUp * 100.0;
tobyspark 22:90054fe6d86c 1897 newFadeBPercent = newFadeB * fadeUp * 100.0;
tobyspark 11:0783cfbeb746 1898 }
tobyspark 36:8b5c75c8bc23 1899 else if (mixMode >= mixKeyStartIndex)
tobyspark 11:0783cfbeb746 1900 {
tobyspark 0:87aab40d5806 1901 newFadeAPercent = (1.0-xFade) * fadeUp * 100.0;
tobyspark 0:87aab40d5806 1902 newFadeBPercent = fadeUp * 100.0;
tobyspark 0:87aab40d5806 1903 }
tobyspark 0:87aab40d5806 1904
tobyspark 17:fc68d40b8b1f 1905 //// TASK: Send to TVOne if percents have changed
tobyspark 17:fc68d40b8b1f 1906
tobyspark 17:fc68d40b8b1f 1907 // No amount of median filtering is stopping flipflopping between two adjacent percents, so...
tobyspark 17:fc68d40b8b1f 1908 bool fadeAPercentHasChanged;
tobyspark 17:fc68d40b8b1f 1909 bool fadeBPercentHasChanged;
tobyspark 17:fc68d40b8b1f 1910 if (oldFadeAPercent == newFadeAPercent && (newFadeAPercent == fadeAPercent - 1 || newFadeAPercent == fadeAPercent + 1))
tobyspark 17:fc68d40b8b1f 1911 fadeAPercentHasChanged = false;
tobyspark 17:fc68d40b8b1f 1912 else
tobyspark 17:fc68d40b8b1f 1913 fadeAPercentHasChanged = newFadeAPercent != fadeAPercent;
tobyspark 17:fc68d40b8b1f 1914 if (oldFadeBPercent == newFadeBPercent && (newFadeBPercent == fadeBPercent - 1 || newFadeBPercent == fadeBPercent + 1))
tobyspark 17:fc68d40b8b1f 1915 fadeBPercentHasChanged = false;
tobyspark 17:fc68d40b8b1f 1916 else
tobyspark 17:fc68d40b8b1f 1917 fadeBPercentHasChanged = newFadeBPercent != fadeBPercent;
tobyspark 17:fc68d40b8b1f 1918
tobyspark 35:d5d9f0838f99 1919 // If changing mixMode from additive, we want to do this before updating fade values
tobyspark 49:16309f39cead 1920 if (mixMode != mixModeOld && mixModeOld == mixAdditive) actionMixMode();
tobyspark 35:d5d9f0838f99 1921
tobyspark 9:f83eadd8917a 1922 // We want to send the higher first, otherwise black flashes can happen on taps
tobyspark 17:fc68d40b8b1f 1923 if (fadeAPercentHasChanged && newFadeAPercent >= newFadeBPercent)
tobyspark 8:d46cc49f0f37 1924 {
tobyspark 17:fc68d40b8b1f 1925 oldFadeAPercent = fadeAPercent;
tobyspark 0:87aab40d5806 1926 fadeAPercent = newFadeAPercent;
tobyspark 0:87aab40d5806 1927 updateFade = true;
tobyspark 0:87aab40d5806 1928
tobyspark 0:87aab40d5806 1929 fadeAPO = fadeAPercent / 100.0;
tobyspark 0:87aab40d5806 1930 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent);
tobyspark 0:87aab40d5806 1931 }
tobyspark 17:fc68d40b8b1f 1932 if (fadeBPercentHasChanged)
tobyspark 8:d46cc49f0f37 1933 {
tobyspark 17:fc68d40b8b1f 1934 oldFadeBPercent = fadeBPercent;
tobyspark 0:87aab40d5806 1935 fadeBPercent = newFadeBPercent;
tobyspark 0:87aab40d5806 1936 updateFade = true;
tobyspark 0:87aab40d5806 1937
tobyspark 0:87aab40d5806 1938 fadeBPO = fadeBPercent / 100.0;
tobyspark 0:87aab40d5806 1939 tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent);
tobyspark 0:87aab40d5806 1940 }
tobyspark 17:fc68d40b8b1f 1941 if (fadeAPercentHasChanged && newFadeAPercent < newFadeBPercent)
tobyspark 9:f83eadd8917a 1942 {
tobyspark 17:fc68d40b8b1f 1943 oldFadeAPercent = fadeAPercent;
tobyspark 9:f83eadd8917a 1944 fadeAPercent = newFadeAPercent;
tobyspark 9:f83eadd8917a 1945 updateFade = true;
tobyspark 9:f83eadd8917a 1946
tobyspark 9:f83eadd8917a 1947 fadeAPO = fadeAPercent / 100.0;
tobyspark 9:f83eadd8917a 1948 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent);
tobyspark 9:f83eadd8917a 1949 }
tobyspark 8:d46cc49f0f37 1950 if (updateFade && debug)
tobyspark 8:d46cc49f0f37 1951 {
tobyspark 0:87aab40d5806 1952 //debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAIN.read(), fadeUpAIN.read());
tobyspark 0:87aab40d5806 1953 debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAINCached, fadeUpAINCached);
tobyspark 0:87aab40d5806 1954 debug->printf("xFade = %3f fadeUp = %3f fadeA% = %i fadeB% = %i \r\n", xFade, fadeUp, fadeAPercent, fadeBPercent);
tobyspark 18:ebe5da639a6a 1955 debug->printf("\r\n");
tobyspark 0:87aab40d5806 1956 }
tobyspark 30:873979018850 1957
tobyspark 49:16309f39cead 1958 // If changing mixMode to additive, we want to do this after updating fade values
tobyspark 49:16309f39cead 1959 if (mixMode != mixModeOld) actionMixMode();
tobyspark 35:d5d9f0838f99 1960
tobyspark 33:e6672a9bd571 1961 //// TASK: Process Network Comms Out, ie. send out any fade updates
tobyspark 33:e6672a9bd571 1962 if (commsMode == commsOSC && updateFade)
tobyspark 33:e6672a9bd571 1963 {
tobyspark 33:e6672a9bd571 1964 processOSCOut(xFade, fadeUp);
tobyspark 33:e6672a9bd571 1965 }
tobyspark 33:e6672a9bd571 1966
tobyspark 33:e6672a9bd571 1967 if (commsMode == commsArtNet && updateFade)
tobyspark 33:e6672a9bd571 1968 {
tobyspark 33:e6672a9bd571 1969 processArtNetOut(xFade, fadeUp);
tobyspark 33:e6672a9bd571 1970 }
tobyspark 33:e6672a9bd571 1971
tobyspark 33:e6672a9bd571 1972 if (commsMode == commsDMXOut && updateFade)
tobyspark 33:e6672a9bd571 1973 {
tobyspark 33:e6672a9bd571 1974 processDMXOut(xFade, fadeUp);
tobyspark 33:e6672a9bd571 1975 }
tobyspark 33:e6672a9bd571 1976
tobyspark 45:cf8c2400be5c 1977 //// TASK: Housekeeping
tobyspark 45:cf8c2400be5c 1978
tobyspark 49:16309f39cead 1979 if (tvOne.millisSinceLastCommandSent() > tvOne.getCommandTimeoutPeriod() + 1000)
tobyspark 30:873979018850 1980 {
tobyspark 45:cf8c2400be5c 1981 // Lets check on our sources
tobyspark 45:cf8c2400be5c 1982 handleTVOneSources();
tobyspark 49:16309f39cead 1983
tobyspark 49:16309f39cead 1984 // Lets check on our fade levels
tobyspark 49:16309f39cead 1985 checkTVOneMixStatus();
tobyspark 30:873979018850 1986 }
tobyspark 0:87aab40d5806 1987 }
tobyspark 30:873979018850 1988 }