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:
Fri Jul 20 17:21:48 2012 +0000
Revision:
7:e6717468c18d
Parent:
5:f8b285ca41ba
Child:
8:d46cc49f0f37
trivial dmx tweak

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 0:87aab40d5806 1 // *SPARK D-FUSER
tobyspark 0:87aab40d5806 2 // A project by *spark audio-visual
tobyspark 0:87aab40d5806 3 //
tobyspark 0:87aab40d5806 4 // 'DJ' controller styke RS232 Control for TV-One products
tobyspark 0:87aab40d5806 5 // Good for 1T-C2-750, others will need some extra work
tobyspark 0:87aab40d5806 6 //
tobyspark 0:87aab40d5806 7 // Copyright *spark audio-visual 2009-2011
tobyspark 0:87aab40d5806 8 //
tobyspark 0:87aab40d5806 9 // v10 - Port to mBed, keying redux - Apr'11
tobyspark 0:87aab40d5806 10 // v11 - Sign callbacks, code clean-up - Apr'11
tobyspark 0:87aab40d5806 11 // 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 0:87aab40d5806 12 // v13 - Menu system for Resolution + Keying implemented, it writing to debug, it sending TVOne commands - Apr'11
tobyspark 0:87aab40d5806 13 // v14 - Fixes for new PCB - Oct'11
tobyspark 0:87aab40d5806 14 // v15 - TBZ PCB, OLED - Mar'12
tobyspark 5:f8b285ca41ba 15 // v16 - Comms menu, OSC, ArtNet - April'12
tobyspark 5:f8b285ca41ba 16 // v17 - RJ45 - May'12
tobyspark 5:f8b285ca41ba 17 // v18 - DMX - July'12
tobyspark 1:f9fca21102e0 18 // vxx - TODO: EDID upload from USB mass storage
tobyspark 1:f9fca21102e0 19 // vxx - TODO: EDID creation from resolution
tobyspark 0:87aab40d5806 20
tobyspark 0:87aab40d5806 21 #include "mbed.h"
tobyspark 0:87aab40d5806 22
tobyspark 0:87aab40d5806 23 #include "spk_tvone_mbed.h"
tobyspark 0:87aab40d5806 24 #include "spk_utils.h"
tobyspark 0:87aab40d5806 25 #include "spk_mRotaryEncoder.h"
tobyspark 0:87aab40d5806 26 #include "spk_oled_ssd1305.h"
tobyspark 2:50043054e4f7 27 #include "spk_oled_gfx.h"
tobyspark 1:f9fca21102e0 28 #include "EthernetNetIf.h"
tobyspark 1:f9fca21102e0 29 #include "mbedOSC.h"
tobyspark 3:033d2b7768f3 30 #include "DmxArtNet.h"
tobyspark 5:f8b285ca41ba 31 #include "DMX.h"
tobyspark 0:87aab40d5806 32
tobyspark 0:87aab40d5806 33 #include <sstream>
tobyspark 0:87aab40d5806 34
tobyspark 5:f8b285ca41ba 35 // MBED PINS
tobyspark 5:f8b285ca41ba 36
tobyspark 5:f8b285ca41ba 37 #define kMBED_AIN_XFADE p20
tobyspark 5:f8b285ca41ba 38 #define kMBED_AIN_FADEUP p19
tobyspark 5:f8b285ca41ba 39 #define kMBED_DIN_TAP_L p24
tobyspark 5:f8b285ca41ba 40 #define kMBED_DIN_TAP_R p23
tobyspark 5:f8b285ca41ba 41 #define kMBED_ENC_SW p15
tobyspark 5:f8b285ca41ba 42 #define kMBED_ENC_A p16
tobyspark 5:f8b285ca41ba 43 #define kMBED_ENC_B p17
tobyspark 5:f8b285ca41ba 44
tobyspark 5:f8b285ca41ba 45 #define kMBED_RS232_TTLTX p13
tobyspark 5:f8b285ca41ba 46 #define kMBED_RS232_TTLRX p14
tobyspark 5:f8b285ca41ba 47
tobyspark 5:f8b285ca41ba 48 #define kMBED_OLED_MOSI p5
tobyspark 5:f8b285ca41ba 49 #define kMBED_OLED_SCK p7
tobyspark 5:f8b285ca41ba 50 #define kMBED_OLED_CS p8
tobyspark 5:f8b285ca41ba 51 #define kMBED_OLED_RES p9
tobyspark 5:f8b285ca41ba 52 #define kMBED_OLED_DC p10
tobyspark 5:f8b285ca41ba 53
tobyspark 5:f8b285ca41ba 54 #define kMBED_DIN_ETHLO_DMXHI p30
tobyspark 5:f8b285ca41ba 55 #define kMBED_DOUT_RS485_TXHI_RXLO p29
tobyspark 5:f8b285ca41ba 56 #define kMBED_RS485_TTLTX p28
tobyspark 5:f8b285ca41ba 57 #define kMBED_RS485_TTLRX p27
tobyspark 5:f8b285ca41ba 58
tobyspark 5:f8b285ca41ba 59 // DISPLAY
tobyspark 5:f8b285ca41ba 60
tobyspark 1:f9fca21102e0 61 #define kMenuLine1 3
tobyspark 1:f9fca21102e0 62 #define kMenuLine2 4
tobyspark 1:f9fca21102e0 63 #define kCommsStatusLine 6
tobyspark 1:f9fca21102e0 64 #define kTVOneStatusLine 7
tobyspark 1:f9fca21102e0 65
tobyspark 5:f8b285ca41ba 66 // NETWORKING
tobyspark 5:f8b285ca41ba 67
tobyspark 1:f9fca21102e0 68 #define kOSCMbedPort 10000
tobyspark 1:f9fca21102e0 69 #define kOSCMbedIPAddress 10,0,0,2
tobyspark 1:f9fca21102e0 70 #define kOSCMbedSubnetMask 255,255,255,0
tobyspark 1:f9fca21102e0 71 #define kOSCMbedGateway 10,0,0,1
tobyspark 1:f9fca21102e0 72 #define kOSCMbedDNS 10,0,0,1
tobyspark 0:87aab40d5806 73
tobyspark 3:033d2b7768f3 74 #define kArtNetBindIPAddress 2,0,0,100
tobyspark 3:033d2b7768f3 75 #define kArtNetBroadcastAddress 2,255,255,255
tobyspark 3:033d2b7768f3 76
tobyspark 5:f8b285ca41ba 77 #define kDMXInChannelXFade 0
tobyspark 5:f8b285ca41ba 78 #define kDMXInChannelFadeUp 1
tobyspark 5:f8b285ca41ba 79 #define kDMXOutChannelXFade 0
tobyspark 5:f8b285ca41ba 80 #define kDMXOutChannelFadeUp 1
tobyspark 5:f8b285ca41ba 81
tobyspark 0:87aab40d5806 82 //// DEBUG
tobyspark 0:87aab40d5806 83
tobyspark 0:87aab40d5806 84 // Comment out one or the other...
tobyspark 5:f8b285ca41ba 85 //Serial *debug = new Serial(USBTX, USBRX); // For debugging via USB serial
tobyspark 5:f8b285ca41ba 86 Serial *debug = NULL; // For release (no debugging)
tobyspark 0:87aab40d5806 87
tobyspark 0:87aab40d5806 88 //// mBED PIN ASSIGNMENTS
tobyspark 0:87aab40d5806 89
tobyspark 0:87aab40d5806 90 // Inputs
tobyspark 5:f8b285ca41ba 91 AnalogIn xFadeAIN(kMBED_AIN_XFADE);
tobyspark 5:f8b285ca41ba 92 AnalogIn fadeUpAIN(kMBED_AIN_FADEUP);
tobyspark 5:f8b285ca41ba 93 DigitalIn tapLeftDIN(kMBED_DIN_TAP_L);
tobyspark 5:f8b285ca41ba 94 DigitalIn tapRightDIN(kMBED_DIN_TAP_R);
tobyspark 0:87aab40d5806 95
tobyspark 5:f8b285ca41ba 96 SPKRotaryEncoder menuEnc(kMBED_ENC_A, kMBED_ENC_B, kMBED_ENC_SW);
tobyspark 5:f8b285ca41ba 97
tobyspark 5:f8b285ca41ba 98 DigitalIn rj45ModeDIN(kMBED_DIN_ETHLO_DMXHI);
tobyspark 0:87aab40d5806 99
tobyspark 0:87aab40d5806 100 // Outputs
tobyspark 0:87aab40d5806 101 PwmOut fadeAPO(LED1);
tobyspark 0:87aab40d5806 102 PwmOut fadeBPO(LED2);
tobyspark 0:87aab40d5806 103
tobyspark 5:f8b285ca41ba 104 DigitalOut dmxDirectionDOUT(kMBED_DOUT_RS485_TXHI_RXLO);
tobyspark 5:f8b285ca41ba 105
tobyspark 0:87aab40d5806 106 // SPKTVOne(PinName txPin, PinName rxPin, PinName signWritePin, PinName signErrorPin, Serial *debugSerial)
tobyspark 5:f8b285ca41ba 107 SPKTVOne tvOne(kMBED_RS232_TTLTX, kMBED_RS232_TTLRX, LED3, LED4, debug);
tobyspark 0:87aab40d5806 108
tobyspark 0:87aab40d5806 109 // SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL);
tobyspark 5:f8b285ca41ba 110 SPKDisplay screen(kMBED_OLED_MOSI, kMBED_OLED_SCK, kMBED_OLED_CS, kMBED_OLED_DC, kMBED_OLED_RES, debug);
tobyspark 0:87aab40d5806 111
tobyspark 0:87aab40d5806 112 // Menu
tobyspark 0:87aab40d5806 113 SPKMenu *selectedMenu;
tobyspark 0:87aab40d5806 114 SPKMenu *lastSelectedMenu;
tobyspark 0:87aab40d5806 115 SPKMenuOfMenus mainMenu;
tobyspark 0:87aab40d5806 116 SPKMenuPayload resolutionMenu;
tobyspark 0:87aab40d5806 117 SPKMenuPayload mixModeMenu;
tobyspark 5:f8b285ca41ba 118 enum { blend, additive, lumaKey, chromaKey1, chromaKey2, chromaKey3 }; // additive will require custom TVOne firmware.
tobyspark 5:f8b285ca41ba 119 int mixMode = blend;
tobyspark 1:f9fca21102e0 120 SPKMenuPayload commsMenu;
tobyspark 5:f8b285ca41ba 121 enum { commsNone, commsOSC, commsArtNet, commsDMXIn, commsDMXOut};
tobyspark 5:f8b285ca41ba 122 int commsMode = commsNone;
tobyspark 1:f9fca21102e0 123
tobyspark 5:f8b285ca41ba 124 // RJ45 Comms
tobyspark 5:f8b285ca41ba 125 enum { rj45Ethernet = 0, rj45DMX = 1}; // These values from circuit
tobyspark 5:f8b285ca41ba 126 int rj45Mode = -1;
tobyspark 1:f9fca21102e0 127 EthernetNetIf *ethernet = NULL;
tobyspark 1:f9fca21102e0 128 OSCClass *osc = NULL;
tobyspark 3:033d2b7768f3 129 OSCMessage recMessage;
tobyspark 3:033d2b7768f3 130 DmxArtNet *artNet = NULL;
tobyspark 5:f8b285ca41ba 131 DMX *dmx = NULL;
tobyspark 0:87aab40d5806 132
tobyspark 3:033d2b7768f3 133 // Fade logic constants
tobyspark 0:87aab40d5806 134 const float xFadeTolerance = 0.05;
tobyspark 0:87aab40d5806 135 const float fadeUpTolerance = 0.05;
tobyspark 0:87aab40d5806 136
tobyspark 0:87aab40d5806 137 // A&B Fade as resolved percent
tobyspark 0:87aab40d5806 138 int fadeAPercent = 0;
tobyspark 0:87aab40d5806 139 int fadeBPercent = 0;
tobyspark 0:87aab40d5806 140
tobyspark 0:87aab40d5806 141 // Tap button states
tobyspark 5:f8b285ca41ba 142 bool tapLeftWasFirstPressed = false;
tobyspark 0:87aab40d5806 143
tobyspark 0:87aab40d5806 144 // Key mode parameters
tobyspark 0:87aab40d5806 145 int keyerParamsSet = -1; // last keyParams index uploaded to unit
tobyspark 0:87aab40d5806 146 // {lumakey, chroma on blue [, to be extended as needed] }
tobyspark 0:87aab40d5806 147 // {minY, maxY, minU, maxU, minV, maxV }
tobyspark 0:87aab40d5806 148 int keyerParams[2][6] =
tobyspark 0:87aab40d5806 149 {
tobyspark 0:87aab40d5806 150 {0, 18, 128, 129, 128, 129}, // lumakey
tobyspark 0:87aab40d5806 151 {41, 42, 240, 241, 109, 110} // chroma on blue
tobyspark 0:87aab40d5806 152 // ...
tobyspark 0:87aab40d5806 153 };
tobyspark 0:87aab40d5806 154
tobyspark 3:033d2b7768f3 155 void processOSC(float &xFade, float &fadeUp) {
tobyspark 3:033d2b7768f3 156 std::stringstream statusMessage;
tobyspark 3:033d2b7768f3 157 statusMessage.setf(ios::fixed,ios::floatfield);
tobyspark 3:033d2b7768f3 158 statusMessage.precision(2);
tobyspark 3:033d2b7768f3 159
tobyspark 3:033d2b7768f3 160 if (!strcmp( recMessage.getTopAddress() , "dvimxr" ))
tobyspark 3:033d2b7768f3 161 {
tobyspark 3:033d2b7768f3 162 statusMessage << "OSC: /dvimxr";
tobyspark 3:033d2b7768f3 163 if (!strcmp( recMessage.getSubAddress() , "xFade" ))
tobyspark 3:033d2b7768f3 164 if (recMessage.getArgNum() == 1)
tobyspark 3:033d2b7768f3 165 if (recMessage.getTypeTag(0) == 'f')
tobyspark 3:033d2b7768f3 166 {
tobyspark 3:033d2b7768f3 167 double newXFade = recMessage.getArgFloat(0);
tobyspark 3:033d2b7768f3 168 statusMessage << "/xFade " << newXFade;
tobyspark 3:033d2b7768f3 169 xFade = newXFade;
tobyspark 3:033d2b7768f3 170 }
tobyspark 3:033d2b7768f3 171 else if (!strcmp( recMessage.getSubAddress() , "fadeUp" ))
tobyspark 3:033d2b7768f3 172 if (recMessage.getArgNum() == 1)
tobyspark 3:033d2b7768f3 173 if (recMessage.getTypeTag(0) == 'f')
tobyspark 3:033d2b7768f3 174 {
tobyspark 3:033d2b7768f3 175 double newFadeUp = recMessage.getArgFloat(0);
tobyspark 3:033d2b7768f3 176 statusMessage << "/fadeUp " << newFadeUp;
tobyspark 3:033d2b7768f3 177 xFade = newFadeUp;
tobyspark 3:033d2b7768f3 178 }
tobyspark 3:033d2b7768f3 179 else statusMessage << recMessage.getSubAddress() << " - Ignoring";
tobyspark 3:033d2b7768f3 180 }
tobyspark 3:033d2b7768f3 181 else
tobyspark 3:033d2b7768f3 182 {
tobyspark 3:033d2b7768f3 183 statusMessage << "OSC: " << recMessage.getTopAddress() << " - Ignoring";
tobyspark 3:033d2b7768f3 184 }
tobyspark 3:033d2b7768f3 185
tobyspark 3:033d2b7768f3 186 screen.clearBufferRow(kCommsStatusLine);
tobyspark 3:033d2b7768f3 187 screen.textToBuffer(statusMessage.str(), kCommsStatusLine);
tobyspark 3:033d2b7768f3 188 screen.sendBuffer();
tobyspark 3:033d2b7768f3 189 if (debug) debug->printf("%s \r\n", statusMessage.str().c_str());
tobyspark 3:033d2b7768f3 190
tobyspark 3:033d2b7768f3 191 }
tobyspark 3:033d2b7768f3 192
tobyspark 3:033d2b7768f3 193 void processArtNet(float &xFade, float &fadeUp) {
tobyspark 3:033d2b7768f3 194
tobyspark 3:033d2b7768f3 195 screen.clearBufferRow(kCommsStatusLine);
tobyspark 3:033d2b7768f3 196 screen.textToBuffer("ArtNet activity", kCommsStatusLine);
tobyspark 3:033d2b7768f3 197 screen.sendBuffer();
tobyspark 3:033d2b7768f3 198 if (debug) debug->printf("ArtNet activity");
tobyspark 3:033d2b7768f3 199 }
tobyspark 0:87aab40d5806 200
tobyspark 5:f8b285ca41ba 201 void processDMXIn(float &xFade, float &fadeUp) {
tobyspark 5:f8b285ca41ba 202
tobyspark 5:f8b285ca41ba 203 std::stringstream statusMessage;
tobyspark 5:f8b285ca41ba 204
tobyspark 5:f8b285ca41ba 205 int xFadeDMX = dmx->get(kDMXInChannelXFade);
tobyspark 7:e6717468c18d 206 int fadeUpDMX = dmx->get(kDMXInChannelFadeUp);
tobyspark 5:f8b285ca41ba 207
tobyspark 5:f8b285ca41ba 208 xFade = (float)xFadeDMX/255;
tobyspark 5:f8b285ca41ba 209 fadeUp = (float)fadeUpDMX/255;
tobyspark 5:f8b285ca41ba 210
tobyspark 5:f8b285ca41ba 211 screen.clearBufferRow(kCommsStatusLine);
tobyspark 5:f8b285ca41ba 212 statusMessage << "DMX In: xF " << xFadeDMX << " fUp " << fadeUpDMX;
tobyspark 5:f8b285ca41ba 213 screen.textToBuffer(statusMessage.str(), kCommsStatusLine);
tobyspark 5:f8b285ca41ba 214 screen.sendBuffer();
tobyspark 5:f8b285ca41ba 215 if (debug) debug->printf(statusMessage.str().c_str());
tobyspark 5:f8b285ca41ba 216 }
tobyspark 5:f8b285ca41ba 217
tobyspark 5:f8b285ca41ba 218 void processDMXOut(float &xFade, float &fadeUp) {
tobyspark 5:f8b285ca41ba 219
tobyspark 5:f8b285ca41ba 220 std::stringstream statusMessage;
tobyspark 5:f8b285ca41ba 221
tobyspark 5:f8b285ca41ba 222 int xFadeDMX = xFade*255;
tobyspark 5:f8b285ca41ba 223 int fadeUpDMX = fadeUp*255;
tobyspark 5:f8b285ca41ba 224
tobyspark 5:f8b285ca41ba 225 dmx->put(kDMXOutChannelXFade, xFadeDMX);
tobyspark 5:f8b285ca41ba 226 dmx->put(kDMXOutChannelFadeUp, fadeUpDMX);
tobyspark 5:f8b285ca41ba 227
tobyspark 5:f8b285ca41ba 228 screen.clearBufferRow(kCommsStatusLine);
tobyspark 5:f8b285ca41ba 229 statusMessage << "DMX Out: xF " << xFadeDMX << " fUp " << fadeUpDMX;
tobyspark 5:f8b285ca41ba 230 screen.textToBuffer(statusMessage.str(), kCommsStatusLine);
tobyspark 5:f8b285ca41ba 231 screen.sendBuffer();
tobyspark 5:f8b285ca41ba 232 if (debug) debug->printf(statusMessage.str().c_str());
tobyspark 5:f8b285ca41ba 233 }
tobyspark 0:87aab40d5806 234
tobyspark 0:87aab40d5806 235 inline float fadeCalc (const float AIN, const float tolerance) {
tobyspark 0:87aab40d5806 236 float pos ;
tobyspark 0:87aab40d5806 237 if (AIN < tolerance) pos = 0;
tobyspark 0:87aab40d5806 238 else if (AIN > 1.0 - tolerance) pos = 1;
tobyspark 0:87aab40d5806 239 else pos = (AIN - tolerance) / (1 - 2*tolerance);
tobyspark 0:87aab40d5806 240 if (debug && false) debug->printf("fadeCalc in: %f out: %f \r\n", AIN, pos);
tobyspark 0:87aab40d5806 241 return pos;
tobyspark 0:87aab40d5806 242 }
tobyspark 0:87aab40d5806 243
tobyspark 0:87aab40d5806 244 bool setKeyParamsTo(int index) {
tobyspark 0:87aab40d5806 245 // Only spend the time uploading six parameters if we need to
tobyspark 0:87aab40d5806 246 // Might want to bounds check here
tobyspark 0:87aab40d5806 247
tobyspark 0:87aab40d5806 248 bool ok = false;
tobyspark 0:87aab40d5806 249
tobyspark 0:87aab40d5806 250 if (index != keyerParamsSet)
tobyspark 0:87aab40d5806 251 {
tobyspark 0:87aab40d5806 252 ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, keyerParams[index][0]);
tobyspark 0:87aab40d5806 253 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, keyerParams[index][1]);
tobyspark 0:87aab40d5806 254 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, keyerParams[index][2]);
tobyspark 0:87aab40d5806 255 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, keyerParams[index][3]);
tobyspark 0:87aab40d5806 256 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, keyerParams[index][4]);
tobyspark 0:87aab40d5806 257 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, keyerParams[index][5]);
tobyspark 0:87aab40d5806 258
tobyspark 0:87aab40d5806 259 keyerParamsSet = index;
tobyspark 0:87aab40d5806 260 }
tobyspark 0:87aab40d5806 261
tobyspark 0:87aab40d5806 262 return ok;
tobyspark 0:87aab40d5806 263 }
tobyspark 0:87aab40d5806 264
tobyspark 0:87aab40d5806 265 int main()
tobyspark 0:87aab40d5806 266 {
tobyspark 0:87aab40d5806 267 if (debug)
tobyspark 0:87aab40d5806 268 {
tobyspark 0:87aab40d5806 269 debug->printf("\r\n\r\n");
tobyspark 0:87aab40d5806 270 debug->printf("*spark d-fuser -----------\r\n");
tobyspark 0:87aab40d5806 271 debug->printf(" debug channel\r\n");
tobyspark 0:87aab40d5806 272 }
tobyspark 2:50043054e4f7 273
tobyspark 2:50043054e4f7 274 // Set display font
tobyspark 2:50043054e4f7 275 screen.fontStartCharacter = &characterBytesStartChar;
tobyspark 2:50043054e4f7 276 screen.fontEndCharacter = &characterBytesEndChar;
tobyspark 2:50043054e4f7 277 screen.fontCharacters = characterBytes;
tobyspark 2:50043054e4f7 278
tobyspark 0:87aab40d5806 279 // Splash screen
tobyspark 2:50043054e4f7 280 screen.imageToBuffer(spkDisplayLogo);
tobyspark 0:87aab40d5806 281 screen.textToBuffer("SPK:D-Fuser",0);
tobyspark 5:f8b285ca41ba 282 screen.textToBuffer("SW beta.18",1);
tobyspark 5:f8b285ca41ba 283 screen.sendBuffer();
tobyspark 0:87aab40d5806 284
tobyspark 0:87aab40d5806 285 // Set menu structure
tobyspark 0:87aab40d5806 286 mixModeMenu.title = "Mix Mode";
tobyspark 0:87aab40d5806 287 mixModeMenu.addMenuItem("Blend", blend, 0);
tobyspark 0:87aab40d5806 288 mixModeMenu.addMenuItem("LumaKey", lumaKey, 0);
tobyspark 0:87aab40d5806 289 mixModeMenu.addMenuItem("ChromaKey - Blue", chromaKey1, 0);
tobyspark 0:87aab40d5806 290
tobyspark 0:87aab40d5806 291 resolutionMenu.title = "Resolution";
tobyspark 0:87aab40d5806 292 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionVGA, kTV1ResolutionVGA, 5);
tobyspark 0:87aab40d5806 293 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionSVGA, kTV1ResolutionSVGA, 5);
tobyspark 0:87aab40d5806 294 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionXGAp60, kTV1ResolutionXGAp60, 5);
tobyspark 0:87aab40d5806 295 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionWSXGAPLUSp60, kTV1ResolutionWSXGAPLUSp60, 5);
tobyspark 0:87aab40d5806 296 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionWUXGAp60, kTV1ResolutionWUXGAp60, 5);
tobyspark 0:87aab40d5806 297 resolutionMenu.addMenuItem(kTV1ResolutionDescription720p60, kTV1Resolution720p60, 5);
tobyspark 0:87aab40d5806 298 resolutionMenu.addMenuItem(kTV1ResolutionDescription1080p60, kTV1Resolution1080p60, 5);
tobyspark 0:87aab40d5806 299 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionDualHeadSVGAp60, kTV1ResolutionDualHeadSVGAp60, 0);
tobyspark 0:87aab40d5806 300 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionDualHeadXGAp60, kTV1ResolutionDualHeadXGAp60, 0);
tobyspark 0:87aab40d5806 301 resolutionMenu.addMenuItem(kTV1ResolutionDescriptionTripleHeadVGAp60, kTV1ResolutionTripleHeadVGAp60, 0);
tobyspark 0:87aab40d5806 302
tobyspark 5:f8b285ca41ba 303 commsMenu.title = "Network Mode";
tobyspark 1:f9fca21102e0 304 commsMenu.addMenuItem("None", commsNone, 0);
tobyspark 1:f9fca21102e0 305 commsMenu.addMenuItem("OSC", commsOSC, 0);
tobyspark 1:f9fca21102e0 306 commsMenu.addMenuItem("ArtNet", commsArtNet, 0);
tobyspark 5:f8b285ca41ba 307 commsMenu.addMenuItem("DMX In", commsDMXIn, 0);
tobyspark 5:f8b285ca41ba 308 commsMenu.addMenuItem("DMX Out", commsDMXOut, 0);
tobyspark 1:f9fca21102e0 309
tobyspark 0:87aab40d5806 310 mainMenu.title = "Main Menu";
tobyspark 0:87aab40d5806 311 mainMenu.addMenuItem(&mixModeMenu);
tobyspark 0:87aab40d5806 312 mainMenu.addMenuItem(&resolutionMenu);
tobyspark 1:f9fca21102e0 313 mainMenu.addMenuItem(&commsMenu);
tobyspark 0:87aab40d5806 314
tobyspark 0:87aab40d5806 315 selectedMenu = &mainMenu;
tobyspark 0:87aab40d5806 316 lastSelectedMenu = &mainMenu;
tobyspark 0:87aab40d5806 317
tobyspark 0:87aab40d5806 318 // Misc I/O stuff
tobyspark 0:87aab40d5806 319
tobyspark 0:87aab40d5806 320 fadeAPO.period(0.001);
tobyspark 0:87aab40d5806 321 fadeBPO.period(0.001);
tobyspark 0:87aab40d5806 322
tobyspark 0:87aab40d5806 323 // TVOne setup
tobyspark 0:87aab40d5806 324
tobyspark 0:87aab40d5806 325 bool ok = false;
tobyspark 0:87aab40d5806 326
tobyspark 0:87aab40d5806 327 // horrid, horrid HDCP
tobyspark 0:87aab40d5806 328 ok = tvOne.setHDCPOff();
tobyspark 0:87aab40d5806 329
tobyspark 0:87aab40d5806 330 std::string sendOK = ok ? "Sent: HDCP Off" : "Send Error: HDCP Off";
tobyspark 0:87aab40d5806 331
tobyspark 0:87aab40d5806 332 // display menu and framing lines
tobyspark 0:87aab40d5806 333 screen.horizLineToBuffer(kMenuLine1*pixInPage - 1);
tobyspark 0:87aab40d5806 334 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 335 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 336 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 337 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 338 screen.horizLineToBuffer(kMenuLine2*pixInPage + pixInPage);
tobyspark 1:f9fca21102e0 339 screen.horizLineToBuffer(kCommsStatusLine*pixInPage - 1);
tobyspark 1:f9fca21102e0 340 screen.clearBufferRow(kCommsStatusLine);
tobyspark 1:f9fca21102e0 341 screen.textToBuffer(commsMenu.selectedString(), kCommsStatusLine);
tobyspark 1:f9fca21102e0 342 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 1:f9fca21102e0 343 screen.textToBuffer(sendOK, kTVOneStatusLine);
tobyspark 0:87aab40d5806 344 screen.sendBuffer();
tobyspark 0:87aab40d5806 345
tobyspark 0:87aab40d5806 346
tobyspark 0:87aab40d5806 347 //// CONTROLS TEST
tobyspark 0:87aab40d5806 348
tobyspark 0:87aab40d5806 349 while (0) {
tobyspark 0:87aab40d5806 350 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 351 }
tobyspark 0:87aab40d5806 352
tobyspark 0:87aab40d5806 353 //// MIXER RUN
tobyspark 0:87aab40d5806 354
tobyspark 0:87aab40d5806 355 while (1) {
tobyspark 0:87aab40d5806 356
tobyspark 1:f9fca21102e0 357 //// Task background things
tobyspark 5:f8b285ca41ba 358 if (ethernet && rj45Mode == rj45Ethernet)
tobyspark 5:f8b285ca41ba 359 {
tobyspark 5:f8b285ca41ba 360 if (debug) debug->printf("net poll");
tobyspark 5:f8b285ca41ba 361 Net::poll();
tobyspark 5:f8b285ca41ba 362 }
tobyspark 5:f8b285ca41ba 363
tobyspark 5:f8b285ca41ba 364 //// RJ45 SWITCH
tobyspark 5:f8b285ca41ba 365
tobyspark 5:f8b285ca41ba 366 if (rj45ModeDIN != rj45Mode)
tobyspark 1:f9fca21102e0 367 {
tobyspark 5:f8b285ca41ba 368 // update state
tobyspark 5:f8b285ca41ba 369 rj45Mode = rj45ModeDIN;
tobyspark 5:f8b285ca41ba 370 if (rj45Mode == rj45Ethernet) commsMenu.title = "Network Mode [Ethernet]";
tobyspark 5:f8b285ca41ba 371 if (rj45Mode == rj45DMX) commsMenu.title = "Network Mode [DMX]";
tobyspark 5:f8b285ca41ba 372
tobyspark 5:f8b285ca41ba 373 // cancel old comms
tobyspark 5:f8b285ca41ba 374 commsMode = commsNone;
tobyspark 5:f8b285ca41ba 375 commsMenu = commsMode;
tobyspark 5:f8b285ca41ba 376
tobyspark 5:f8b285ca41ba 377 // refresh display
tobyspark 5:f8b285ca41ba 378 if (selectedMenu == &commsMenu) screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 5:f8b285ca41ba 379 if (rj45Mode == rj45Ethernet) screen.textToBuffer("RJ45: Ethernet Engaged", kCommsStatusLine);
tobyspark 5:f8b285ca41ba 380 if (rj45Mode == rj45DMX) screen.textToBuffer("RJ45: DMX Engaged", kCommsStatusLine);
tobyspark 1:f9fca21102e0 381 }
tobyspark 1:f9fca21102e0 382
tobyspark 0:87aab40d5806 383 //// MENU
tobyspark 0:87aab40d5806 384
tobyspark 0:87aab40d5806 385 int menuChange = menuEnc.getChange();
tobyspark 0:87aab40d5806 386
tobyspark 0:87aab40d5806 387 // Update GUI
tobyspark 0:87aab40d5806 388 if (menuChange != 0)
tobyspark 0:87aab40d5806 389 {
tobyspark 0:87aab40d5806 390 if (debug) debug->printf("Menu changed by %i\r\n", menuChange);
tobyspark 0:87aab40d5806 391
tobyspark 0:87aab40d5806 392 *selectedMenu = selectedMenu->selectedIndex() + menuChange;
tobyspark 0:87aab40d5806 393
tobyspark 0:87aab40d5806 394 // update OLED line 2 here
tobyspark 0:87aab40d5806 395 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 396 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 397
tobyspark 0:87aab40d5806 398 if (debug) debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 0:87aab40d5806 399 }
tobyspark 0:87aab40d5806 400
tobyspark 0:87aab40d5806 401 // Action menu item
tobyspark 0:87aab40d5806 402 if (menuEnc.hasPressed())
tobyspark 0:87aab40d5806 403 {
tobyspark 0:87aab40d5806 404 if (debug) debug->printf("Action Menu Item!\r\n");
tobyspark 0:87aab40d5806 405
tobyspark 0:87aab40d5806 406 // Are we changing menus?
tobyspark 0:87aab40d5806 407 if (selectedMenu->type() == menuOfMenus)
tobyspark 0:87aab40d5806 408 {
tobyspark 0:87aab40d5806 409 // point selected menu to the new menu
tobyspark 0:87aab40d5806 410 // FIXME. Make this function abstract virtual of base class or get dynamic_cast working. BTW: C++ sucks / Obj-c rocks / Right now.
tobyspark 0:87aab40d5806 411 if (selectedMenu == &mainMenu) selectedMenu = mainMenu.selectedMenu();
tobyspark 0:87aab40d5806 412 else if (debug) debug->printf("FIXME: You've missed a SPKMenuOfMenus");
tobyspark 0:87aab40d5806 413
tobyspark 0:87aab40d5806 414 // reset the selection within that menu to the first position
tobyspark 0:87aab40d5806 415 (*selectedMenu) = 0;
tobyspark 0:87aab40d5806 416
tobyspark 0:87aab40d5806 417 // update OLED lines 1&2
tobyspark 0:87aab40d5806 418 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 419 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 420 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 421 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 422
tobyspark 0:87aab40d5806 423 if (debug)
tobyspark 0:87aab40d5806 424 {
tobyspark 0:87aab40d5806 425 debug->printf("\r\n");
tobyspark 0:87aab40d5806 426 debug->printf("%s \r\n", selectedMenu->title.c_str());
tobyspark 0:87aab40d5806 427 debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 0:87aab40d5806 428 }
tobyspark 0:87aab40d5806 429 }
tobyspark 0:87aab40d5806 430 // Are we cancelling?
tobyspark 0:87aab40d5806 431 else if (selectedMenu->type() == payload && selectedMenu->selectedIndex() == 0)
tobyspark 0:87aab40d5806 432 {
tobyspark 0:87aab40d5806 433 selectedMenu = lastSelectedMenu;
tobyspark 0:87aab40d5806 434
tobyspark 0:87aab40d5806 435 // update OLED lines 1&2
tobyspark 0:87aab40d5806 436 screen.clearBufferRow(kMenuLine1);
tobyspark 0:87aab40d5806 437 screen.clearBufferRow(kMenuLine2);
tobyspark 0:87aab40d5806 438 screen.textToBuffer(selectedMenu->title, kMenuLine1);
tobyspark 0:87aab40d5806 439 screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2);
tobyspark 0:87aab40d5806 440
tobyspark 0:87aab40d5806 441 if (debug)
tobyspark 0:87aab40d5806 442 {
tobyspark 0:87aab40d5806 443 debug->printf("\r\n");
tobyspark 0:87aab40d5806 444 debug->printf("%s \r\n", selectedMenu->title.c_str());
tobyspark 0:87aab40d5806 445 debug->printf("%s \r\n", selectedMenu->selectedString().c_str());
tobyspark 0:87aab40d5806 446 }
tobyspark 0:87aab40d5806 447 }
tobyspark 0:87aab40d5806 448 // With that out of the way, we should be actioning a specific menu's payload?
tobyspark 0:87aab40d5806 449 else if (selectedMenu == &mixModeMenu)
tobyspark 0:87aab40d5806 450 {
tobyspark 5:f8b285ca41ba 451 mixMode = mixModeMenu.selectedPayload1();
tobyspark 5:f8b285ca41ba 452
tobyspark 0:87aab40d5806 453 bool ok = false;
tobyspark 0:87aab40d5806 454 std::string sentOK;
tobyspark 0:87aab40d5806 455 std::stringstream sentMSG;
tobyspark 0:87aab40d5806 456
tobyspark 0:87aab40d5806 457 // Set keying parameters
tobyspark 0:87aab40d5806 458 switch (mixModeMenu.selectedPayload1()) {
tobyspark 0:87aab40d5806 459 case lumaKey:
tobyspark 0:87aab40d5806 460 ok = setKeyParamsTo(0);
tobyspark 0:87aab40d5806 461 sentMSG << "Keyer Params 0, ";
tobyspark 0:87aab40d5806 462 break;
tobyspark 0:87aab40d5806 463 case chromaKey1:
tobyspark 0:87aab40d5806 464 ok = setKeyParamsTo(1);
tobyspark 0:87aab40d5806 465 sentMSG << "Keyer Params 1, ";
tobyspark 0:87aab40d5806 466 break;
tobyspark 0:87aab40d5806 467 }
tobyspark 0:87aab40d5806 468
tobyspark 0:87aab40d5806 469 // Set keying on or off
tobyspark 0:87aab40d5806 470 switch (mixModeMenu.selectedPayload1()) {
tobyspark 0:87aab40d5806 471 case blend:
tobyspark 0:87aab40d5806 472 case additive:
tobyspark 0:87aab40d5806 473 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, false);
tobyspark 0:87aab40d5806 474 sentMSG << "Keyer Off";
tobyspark 0:87aab40d5806 475 break;
tobyspark 0:87aab40d5806 476 case lumaKey:
tobyspark 0:87aab40d5806 477 case chromaKey1:
tobyspark 0:87aab40d5806 478 case chromaKey2:
tobyspark 0:87aab40d5806 479 case chromaKey3:
tobyspark 0:87aab40d5806 480 ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, true);
tobyspark 0:87aab40d5806 481 sentMSG << "Keyer On";
tobyspark 0:87aab40d5806 482 break;
tobyspark 0:87aab40d5806 483 }
tobyspark 0:87aab40d5806 484
tobyspark 0:87aab40d5806 485 if (ok) sentOK = "Sent:";
tobyspark 0:87aab40d5806 486 else sentOK = "Send Error:";
tobyspark 0:87aab40d5806 487
tobyspark 1:f9fca21102e0 488 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 1:f9fca21102e0 489 screen.textToBuffer(sentOK + sentMSG.str(), kTVOneStatusLine);
tobyspark 0:87aab40d5806 490
tobyspark 0:87aab40d5806 491 if (debug) { debug->printf("Changing mix mode"); }
tobyspark 0:87aab40d5806 492 }
tobyspark 0:87aab40d5806 493 else if (selectedMenu == &resolutionMenu)
tobyspark 0:87aab40d5806 494 {
tobyspark 0:87aab40d5806 495 bool ok = false;
tobyspark 0:87aab40d5806 496
tobyspark 0:87aab40d5806 497 ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputResolution, resolutionMenu.selectedPayload1());
tobyspark 0:87aab40d5806 498 ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedPayload2());
tobyspark 0:87aab40d5806 499 ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedPayload2());
tobyspark 0:87aab40d5806 500
tobyspark 0:87aab40d5806 501 std::string sentOK;
tobyspark 0:87aab40d5806 502 if (ok) sentOK = "Sent: ";
tobyspark 0:87aab40d5806 503 else sentOK = "Send Error: ";
tobyspark 0:87aab40d5806 504
tobyspark 0:87aab40d5806 505 std::stringstream sentMSG;
tobyspark 0:87aab40d5806 506 sentMSG << "Res " << resolutionMenu.selectedPayload1() << ", EDID " << resolutionMenu.selectedPayload2();
tobyspark 0:87aab40d5806 507
tobyspark 1:f9fca21102e0 508 screen.clearBufferRow(kTVOneStatusLine);
tobyspark 1:f9fca21102e0 509 screen.textToBuffer(sentOK + sentMSG.str(), kTVOneStatusLine);
tobyspark 0:87aab40d5806 510
tobyspark 0:87aab40d5806 511 if (debug) { debug->printf("Changing resolution"); }
tobyspark 0:87aab40d5806 512 }
tobyspark 1:f9fca21102e0 513 else if (selectedMenu == &commsMenu)
tobyspark 1:f9fca21102e0 514 {
tobyspark 5:f8b285ca41ba 515 std::string commsTypeString = "Network: --";
tobyspark 1:f9fca21102e0 516 std::stringstream commsStatus;
tobyspark 1:f9fca21102e0 517
tobyspark 1:f9fca21102e0 518 // Tear down any existing comms
tobyspark 1:f9fca21102e0 519 // This is the action of commsNone
tobyspark 1:f9fca21102e0 520 // And also clears the way for other comms actions
tobyspark 5:f8b285ca41ba 521 if (osc) {delete osc; osc = NULL;}
tobyspark 5:f8b285ca41ba 522 if (ethernet) {delete ethernet; ethernet = NULL;}
tobyspark 5:f8b285ca41ba 523 if (artNet) {delete artNet; artNet = NULL;}
tobyspark 5:f8b285ca41ba 524 if (dmx) {delete dmx; dmx = NULL;}
tobyspark 5:f8b285ca41ba 525
tobyspark 5:f8b285ca41ba 526 // Ensure we can't change to comms modes the hardware isn't switched to
tobyspark 5:f8b285ca41ba 527 if (rj45Mode == rj45DMX && (commsMenu.selectedPayload1() == commsOSC || commsMenu.selectedPayload1() == commsArtNet))
tobyspark 1:f9fca21102e0 528 {
tobyspark 5:f8b285ca41ba 529 commsTypeString = "RJ45 not in Ethernet mode";
tobyspark 5:f8b285ca41ba 530 }
tobyspark 5:f8b285ca41ba 531 else if (rj45Mode == rj45Ethernet && (commsMenu.selectedPayload1() == commsDMXIn || commsMenu.selectedPayload1() == commsDMXOut))
tobyspark 5:f8b285ca41ba 532 {
tobyspark 5:f8b285ca41ba 533 commsTypeString = "RJ45 not in DMX mode";
tobyspark 5:f8b285ca41ba 534 }
tobyspark 5:f8b285ca41ba 535 // Action!
tobyspark 5:f8b285ca41ba 536 else if (commsMenu.selectedPayload1() == commsOSC)
tobyspark 5:f8b285ca41ba 537 {
tobyspark 5:f8b285ca41ba 538 commsMode = commsOSC;
tobyspark 5:f8b285ca41ba 539 commsTypeString = "OSC: ";
tobyspark 1:f9fca21102e0 540
tobyspark 1:f9fca21102e0 541 ethernet = new EthernetNetIf(
tobyspark 1:f9fca21102e0 542 IpAddr(kOSCMbedIPAddress),
tobyspark 1:f9fca21102e0 543 IpAddr(kOSCMbedSubnetMask),
tobyspark 1:f9fca21102e0 544 IpAddr(kOSCMbedGateway),
tobyspark 1:f9fca21102e0 545 IpAddr(kOSCMbedDNS)
tobyspark 1:f9fca21102e0 546 );
tobyspark 3:033d2b7768f3 547
tobyspark 1:f9fca21102e0 548 EthernetErr ethError = ethernet->setup();
tobyspark 1:f9fca21102e0 549 if(ethError)
tobyspark 1:f9fca21102e0 550 {
tobyspark 1:f9fca21102e0 551 if (debug) debug->printf("Ethernet setup error, %d", ethError);
tobyspark 1:f9fca21102e0 552 commsStatus << "Ethernet setup failed";
tobyspark 5:f8b285ca41ba 553 commsMenu = commsNone;
tobyspark 1:f9fca21102e0 554 // break out of here. this setup should be a function that returns a boolean
tobyspark 1:f9fca21102e0 555 }
tobyspark 1:f9fca21102e0 556
tobyspark 1:f9fca21102e0 557 osc = new OSCClass();
tobyspark 3:033d2b7768f3 558 osc->setReceiveMessage(&recMessage);
tobyspark 1:f9fca21102e0 559 osc->begin(kOSCMbedPort);
tobyspark 1:f9fca21102e0 560
tobyspark 3:033d2b7768f3 561 commsStatus << "Listening on " << kOSCMbedPort;
tobyspark 1:f9fca21102e0 562 }
tobyspark 1:f9fca21102e0 563 else if (commsMenu.selectedPayload1() == commsArtNet)
tobyspark 1:f9fca21102e0 564 {
tobyspark 5:f8b285ca41ba 565 commsMode = commsArtNet;
tobyspark 5:f8b285ca41ba 566 commsTypeString = "ArtNet: ";
tobyspark 3:033d2b7768f3 567
tobyspark 3:033d2b7768f3 568 artNet = new DmxArtNet();
tobyspark 1:f9fca21102e0 569
tobyspark 3:033d2b7768f3 570 artNet->BindIpAddress = IpAddr(kArtNetBindIPAddress);
tobyspark 3:033d2b7768f3 571 artNet->BCastAddress = IpAddr(kArtNetBroadcastAddress);
tobyspark 3:033d2b7768f3 572
tobyspark 3:033d2b7768f3 573 artNet->InitArtPollReplyDefaults();
tobyspark 3:033d2b7768f3 574
tobyspark 3:033d2b7768f3 575 artNet->ArtPollReply.PortType[0] = 128; // output
tobyspark 3:033d2b7768f3 576 artNet->ArtPollReply.PortType[2] = 64; // input
tobyspark 3:033d2b7768f3 577 artNet->ArtPollReply.GoodInput[2] = 4;
tobyspark 3:033d2b7768f3 578
tobyspark 3:033d2b7768f3 579 artNet->Init();
tobyspark 3:033d2b7768f3 580 artNet->SendArtPollReply(); // announce to art-net nodes
tobyspark 3:033d2b7768f3 581
tobyspark 3:033d2b7768f3 582 commsStatus << "Listening";
tobyspark 1:f9fca21102e0 583 }
tobyspark 5:f8b285ca41ba 584 else if (commsMenu.selectedPayload1() == commsDMXIn)
tobyspark 1:f9fca21102e0 585 {
tobyspark 5:f8b285ca41ba 586 commsMode = commsDMXIn;
tobyspark 5:f8b285ca41ba 587 commsTypeString = "DMX In: ";
tobyspark 1:f9fca21102e0 588
tobyspark 5:f8b285ca41ba 589 dmxDirectionDOUT = 0;
tobyspark 5:f8b285ca41ba 590
tobyspark 5:f8b285ca41ba 591 dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX);
tobyspark 1:f9fca21102e0 592 }
tobyspark 5:f8b285ca41ba 593 else if (commsMenu.selectedPayload1() == commsDMXOut)
tobyspark 5:f8b285ca41ba 594 {
tobyspark 5:f8b285ca41ba 595 commsMode = commsDMXOut;
tobyspark 5:f8b285ca41ba 596 commsTypeString = "DMX Out: ";
tobyspark 5:f8b285ca41ba 597
tobyspark 5:f8b285ca41ba 598 dmxDirectionDOUT = 1;
tobyspark 5:f8b285ca41ba 599
tobyspark 5:f8b285ca41ba 600 dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX);
tobyspark 5:f8b285ca41ba 601 }
tobyspark 5:f8b285ca41ba 602
tobyspark 1:f9fca21102e0 603 screen.clearBufferRow(kCommsStatusLine);
tobyspark 5:f8b285ca41ba 604 screen.textToBuffer(commsTypeString + commsStatus.str(), kCommsStatusLine);
tobyspark 1:f9fca21102e0 605 }
tobyspark 0:87aab40d5806 606 else
tobyspark 0:87aab40d5806 607 {
tobyspark 0:87aab40d5806 608 if (debug) { debug->printf("Warning: No action identified"); }
tobyspark 0:87aab40d5806 609 }
tobyspark 0:87aab40d5806 610 }
tobyspark 0:87aab40d5806 611
tobyspark 2:50043054e4f7 612 // Send any updates to the display
tobyspark 2:50043054e4f7 613 screen.sendBuffer();
tobyspark 5:f8b285ca41ba 614
tobyspark 0:87aab40d5806 615
tobyspark 5:f8b285ca41ba 616 //// MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIXMIX MIX MIXMIX MIX MIX MIX MIX MIXMIX MIX MIX
tobyspark 0:87aab40d5806 617
tobyspark 0:87aab40d5806 618 bool updateFade = false;
tobyspark 3:033d2b7768f3 619 float xFade = 0;
tobyspark 3:033d2b7768f3 620 float fadeUp = 1;
tobyspark 3:033d2b7768f3 621
tobyspark 3:033d2b7768f3 622 //// TASK: Process control surface
tobyspark 3:033d2b7768f3 623
tobyspark 0:87aab40d5806 624 // Get new states of tap buttons, remembering at end of loop() assign these current values to the previous variables
tobyspark 5:f8b285ca41ba 625 const bool tapLeft = !tapLeftDIN;
tobyspark 5:f8b285ca41ba 626 const bool tapRight = !tapRightDIN;
tobyspark 0:87aab40d5806 627
tobyspark 0:87aab40d5806 628 // We're going to cache the analog in reads, as have seen wierdness otherwise
tobyspark 5:f8b285ca41ba 629 const float xFadeAINCached = 1-xFadeAIN.read();
tobyspark 0:87aab40d5806 630 const float fadeUpAINCached = fadeUpAIN.read();
tobyspark 0:87aab40d5806 631
tobyspark 0:87aab40d5806 632 // When a tap is depressed, we can ignore any move of the crossfader but not fade to black
tobyspark 0:87aab40d5806 633 if (tapLeft || tapRight)
tobyspark 0:87aab40d5806 634 {
tobyspark 5:f8b285ca41ba 635 // If both are pressed, take to the one that is new, ie. not the first pressed.
tobyspark 0:87aab40d5806 636 if (tapLeft && tapRight)
tobyspark 0:87aab40d5806 637 {
tobyspark 5:f8b285ca41ba 638 xFade = tapLeftWasFirstPressed ? 1 : 0;
tobyspark 0:87aab40d5806 639 }
tobyspark 5:f8b285ca41ba 640 // If just one is pressed, take to that and remember which is pressed
tobyspark 5:f8b285ca41ba 641 else if (tapLeft)
tobyspark 5:f8b285ca41ba 642 {
tobyspark 5:f8b285ca41ba 643 xFade = 0;
tobyspark 5:f8b285ca41ba 644 tapLeftWasFirstPressed = 1;
tobyspark 5:f8b285ca41ba 645 }
tobyspark 5:f8b285ca41ba 646 else if (tapRight)
tobyspark 5:f8b285ca41ba 647 {
tobyspark 5:f8b285ca41ba 648 xFade = 1;
tobyspark 5:f8b285ca41ba 649 tapLeftWasFirstPressed = 0;
tobyspark 5:f8b285ca41ba 650 }
tobyspark 5:f8b285ca41ba 651 }
tobyspark 0:87aab40d5806 652 else xFade = fadeCalc(xFadeAINCached, xFadeTolerance);
tobyspark 0:87aab40d5806 653
tobyspark 0:87aab40d5806 654 fadeUp = 1.0 - fadeCalc(fadeUpAINCached, fadeUpTolerance);
tobyspark 0:87aab40d5806 655
tobyspark 3:033d2b7768f3 656 //// TASK: Process Network Comms
tobyspark 5:f8b285ca41ba 657 if (commsMode == commsOSC)
tobyspark 3:033d2b7768f3 658 {
tobyspark 3:033d2b7768f3 659 if (osc->newMessage)
tobyspark 3:033d2b7768f3 660 {
tobyspark 3:033d2b7768f3 661 osc->newMessage = false; // fixme!
tobyspark 3:033d2b7768f3 662 processOSC(xFade, fadeUp);
tobyspark 3:033d2b7768f3 663 }
tobyspark 3:033d2b7768f3 664 }
tobyspark 3:033d2b7768f3 665
tobyspark 5:f8b285ca41ba 666 if (commsMode == commsArtNet)
tobyspark 3:033d2b7768f3 667 {
tobyspark 3:033d2b7768f3 668 if (artNet->Work()) processArtNet(xFade, fadeUp);
tobyspark 3:033d2b7768f3 669 }
tobyspark 3:033d2b7768f3 670
tobyspark 5:f8b285ca41ba 671 if (commsMode == commsDMXIn)
tobyspark 5:f8b285ca41ba 672 {
tobyspark 5:f8b285ca41ba 673 processDMXIn(xFade, fadeUp);
tobyspark 5:f8b285ca41ba 674 }
tobyspark 5:f8b285ca41ba 675
tobyspark 5:f8b285ca41ba 676 if (commsMode == commsDMXOut)
tobyspark 5:f8b285ca41ba 677 {
tobyspark 5:f8b285ca41ba 678 processDMXOut(xFade, fadeUp);
tobyspark 5:f8b285ca41ba 679 }
tobyspark 5:f8b285ca41ba 680
tobyspark 0:87aab40d5806 681 // WISH: Really, we should have B at 100% and A fading in over that, with fade to black implemented as a fade in black layer on top of that correct mix.
tobyspark 0:87aab40d5806 682 // There is no way to implement that though, and the alphas get messy, so this is the only way (afaik).
tobyspark 0:87aab40d5806 683
tobyspark 0:87aab40d5806 684 // Calculate new A&B fade percents
tobyspark 0:87aab40d5806 685 int newFadeAPercent = 0;
tobyspark 0:87aab40d5806 686 int newFadeBPercent = 0;
tobyspark 0:87aab40d5806 687
tobyspark 5:f8b285ca41ba 688 switch (mixMode) {
tobyspark 0:87aab40d5806 689 case blend:
tobyspark 0:87aab40d5806 690 case additive:
tobyspark 0:87aab40d5806 691 newFadeAPercent = (1.0-xFade) * fadeUp * 100.0;
tobyspark 0:87aab40d5806 692 newFadeBPercent = xFade * fadeUp * 100.0;
tobyspark 0:87aab40d5806 693 break;
tobyspark 0:87aab40d5806 694 case lumaKey:
tobyspark 0:87aab40d5806 695 case chromaKey1:
tobyspark 0:87aab40d5806 696 case chromaKey2:
tobyspark 0:87aab40d5806 697 case chromaKey3:
tobyspark 0:87aab40d5806 698 newFadeAPercent = (1.0-xFade) * fadeUp * 100.0;
tobyspark 0:87aab40d5806 699 newFadeBPercent = fadeUp * 100.0;
tobyspark 0:87aab40d5806 700 break;
tobyspark 0:87aab40d5806 701 }
tobyspark 0:87aab40d5806 702
tobyspark 0:87aab40d5806 703 // Send to TVOne if percents have changed
tobyspark 0:87aab40d5806 704 if (newFadeAPercent != fadeAPercent) {
tobyspark 0:87aab40d5806 705 fadeAPercent = newFadeAPercent;
tobyspark 0:87aab40d5806 706 updateFade = true;
tobyspark 0:87aab40d5806 707
tobyspark 0:87aab40d5806 708 fadeAPO = fadeAPercent / 100.0;
tobyspark 0:87aab40d5806 709 tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent);
tobyspark 0:87aab40d5806 710 }
tobyspark 0:87aab40d5806 711
tobyspark 0:87aab40d5806 712 if (newFadeBPercent != fadeBPercent) {
tobyspark 0:87aab40d5806 713 fadeBPercent = newFadeBPercent;
tobyspark 0:87aab40d5806 714 updateFade = true;
tobyspark 0:87aab40d5806 715
tobyspark 0:87aab40d5806 716 fadeBPO = fadeBPercent / 100.0;
tobyspark 0:87aab40d5806 717 tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent);
tobyspark 0:87aab40d5806 718 }
tobyspark 0:87aab40d5806 719
tobyspark 0:87aab40d5806 720 if (updateFade && debug) {
tobyspark 0:87aab40d5806 721 debug->printf("\r\n");
tobyspark 0:87aab40d5806 722 //debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAIN.read(), fadeUpAIN.read());
tobyspark 0:87aab40d5806 723 debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAINCached, fadeUpAINCached);
tobyspark 0:87aab40d5806 724 debug->printf("xFade = %3f fadeUp = %3f fadeA% = %i fadeB% = %i \r\n", xFade, fadeUp, fadeAPercent, fadeBPercent);
tobyspark 0:87aab40d5806 725 }
tobyspark 5:f8b285ca41ba 726
tobyspark 0:87aab40d5806 727 }
tobyspark 0:87aab40d5806 728 }