![](/media/cache/profiles/89a26a363b87a87ac6a94277e841b7f4.50x50_q85.jpg)
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
main.cpp@17:fc68d40b8b1f, 2012-10-07 (annotated)
- Committer:
- tobyspark
- Date:
- Sun Oct 07 12:48:44 2012 +0000
- Revision:
- 17:fc68d40b8b1f
- Parent:
- 16:52484666b323
- Child:
- 18:ebe5da639a6a
Further mixing implementation tweaks; 'Conform Processor' troubleshooting item.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tobyspark | 8:d46cc49f0f37 | 1 | /* *SPARK D-FUSER |
tobyspark | 8:d46cc49f0f37 | 2 | * A project by Toby Harris |
tobyspark | 8:d46cc49f0f37 | 3 | * |
tobyspark | 8:d46cc49f0f37 | 4 | * 'DJ' controller styke RS232 Control for TV-One products |
tobyspark | 8:d46cc49f0f37 | 5 | * Good for 1T-C2-750, others will need some extra work |
tobyspark | 8:d46cc49f0f37 | 6 | * |
tobyspark | 8:d46cc49f0f37 | 7 | * www.sparkav.co.uk/dvimixer |
tobyspark | 8:d46cc49f0f37 | 8 | */ |
tobyspark | 0:87aab40d5806 | 9 | |
tobyspark | 8:d46cc49f0f37 | 10 | /* Copyright (c) 2011 Toby Harris, MIT License |
tobyspark | 8:d46cc49f0f37 | 11 | * |
tobyspark | 8:d46cc49f0f37 | 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
tobyspark | 8:d46cc49f0f37 | 13 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
tobyspark | 8:d46cc49f0f37 | 14 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
tobyspark | 8:d46cc49f0f37 | 15 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
tobyspark | 8:d46cc49f0f37 | 16 | * furnished to do so, subject to the following conditions: |
tobyspark | 8:d46cc49f0f37 | 17 | * |
tobyspark | 8:d46cc49f0f37 | 18 | * The above copyright notice and this permission notice shall be included in all copies or |
tobyspark | 8:d46cc49f0f37 | 19 | * substantial portions of the Software. |
tobyspark | 8:d46cc49f0f37 | 20 | * |
tobyspark | 8:d46cc49f0f37 | 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
tobyspark | 8:d46cc49f0f37 | 22 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
tobyspark | 8:d46cc49f0f37 | 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
tobyspark | 8:d46cc49f0f37 | 24 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
tobyspark | 8:d46cc49f0f37 | 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
tobyspark | 8:d46cc49f0f37 | 26 | */ |
tobyspark | 8:d46cc49f0f37 | 27 | |
tobyspark | 8:d46cc49f0f37 | 28 | /* ROADMAP / HISTORY |
tobyspark | 8:d46cc49f0f37 | 29 | * v10 - Port to mBed, keying redux - Apr'11 |
tobyspark | 8:d46cc49f0f37 | 30 | * v11 - Sign callbacks, code clean-up - Apr'11 |
tobyspark | 8:d46cc49f0f37 | 31 | * v12 - TVOne header split into two: defines and mbed class. v002 header updates pulled down. Removed sign callbacks, rewrite of debug and signing. - Apr'11 |
tobyspark | 8:d46cc49f0f37 | 32 | * v13 - Menu system for Resolution + Keying implemented, it writing to debug, it sending TVOne commands - Apr'11 |
tobyspark | 8:d46cc49f0f37 | 33 | * v14 - Fixes for new PCB - Oct'11 |
tobyspark | 8:d46cc49f0f37 | 34 | * v15 - TBZ PCB, OLED - Mar'12 |
tobyspark | 8:d46cc49f0f37 | 35 | * v16 - Comms menu, OSC, ArtNet - April'12 |
tobyspark | 8:d46cc49f0f37 | 36 | * v17 - RJ45 - May'12 |
tobyspark | 8:d46cc49f0f37 | 37 | * v18 - DMX - July'12 |
tobyspark | 13:3796bde6ba8f | 38 | * v19 - TVOne mixing comms further optimised - August'12 |
tobyspark | 8:d46cc49f0f37 | 39 | * vxx - TODO: Keying values load from USB mass storage |
tobyspark | 10:c011b0e5c17e | 40 | * vxx - TODO: Set keying values from controller, requires a guided, step-through process for user |
tobyspark | 8:d46cc49f0f37 | 41 | * vxx - TODO: Defaults load/save from USB mass storage |
tobyspark | 8:d46cc49f0f37 | 42 | * vxx - TODO: EDID upload from USB mass storage |
tobyspark | 8:d46cc49f0f37 | 43 | * vxx - TODO: EDID creation from resolution |
tobyspark | 8:d46cc49f0f37 | 44 | */ |
tobyspark | 8:d46cc49f0f37 | 45 | |
tobyspark | 0:87aab40d5806 | 46 | #include "mbed.h" |
tobyspark | 0:87aab40d5806 | 47 | |
tobyspark | 0:87aab40d5806 | 48 | #include "spk_tvone_mbed.h" |
tobyspark | 0:87aab40d5806 | 49 | #include "spk_utils.h" |
tobyspark | 0:87aab40d5806 | 50 | #include "spk_mRotaryEncoder.h" |
tobyspark | 0:87aab40d5806 | 51 | #include "spk_oled_ssd1305.h" |
tobyspark | 2:50043054e4f7 | 52 | #include "spk_oled_gfx.h" |
tobyspark | 11:0783cfbeb746 | 53 | #include "spk_settings.h" |
tobyspark | 1:f9fca21102e0 | 54 | #include "EthernetNetIf.h" |
tobyspark | 1:f9fca21102e0 | 55 | #include "mbedOSC.h" |
tobyspark | 3:033d2b7768f3 | 56 | #include "DmxArtNet.h" |
tobyspark | 5:f8b285ca41ba | 57 | #include "DMX.h" |
tobyspark | 17:fc68d40b8b1f | 58 | #include "filter.h" |
tobyspark | 0:87aab40d5806 | 59 | |
tobyspark | 0:87aab40d5806 | 60 | #include <sstream> |
tobyspark | 0:87aab40d5806 | 61 | |
tobyspark | 13:3796bde6ba8f | 62 | #define kSPKDFSoftwareVersion "beta.19" |
tobyspark | 13:3796bde6ba8f | 63 | |
tobyspark | 5:f8b285ca41ba | 64 | // MBED PINS |
tobyspark | 5:f8b285ca41ba | 65 | |
tobyspark | 5:f8b285ca41ba | 66 | #define kMBED_AIN_XFADE p20 |
tobyspark | 5:f8b285ca41ba | 67 | #define kMBED_AIN_FADEUP p19 |
tobyspark | 5:f8b285ca41ba | 68 | #define kMBED_DIN_TAP_L p24 |
tobyspark | 5:f8b285ca41ba | 69 | #define kMBED_DIN_TAP_R p23 |
tobyspark | 5:f8b285ca41ba | 70 | #define kMBED_ENC_SW p15 |
tobyspark | 5:f8b285ca41ba | 71 | #define kMBED_ENC_A p16 |
tobyspark | 5:f8b285ca41ba | 72 | #define kMBED_ENC_B p17 |
tobyspark | 5:f8b285ca41ba | 73 | |
tobyspark | 5:f8b285ca41ba | 74 | #define kMBED_RS232_TTLTX p13 |
tobyspark | 5:f8b285ca41ba | 75 | #define kMBED_RS232_TTLRX p14 |
tobyspark | 5:f8b285ca41ba | 76 | |
tobyspark | 5:f8b285ca41ba | 77 | #define kMBED_OLED_MOSI p5 |
tobyspark | 5:f8b285ca41ba | 78 | #define kMBED_OLED_SCK p7 |
tobyspark | 5:f8b285ca41ba | 79 | #define kMBED_OLED_CS p8 |
tobyspark | 5:f8b285ca41ba | 80 | #define kMBED_OLED_RES p9 |
tobyspark | 5:f8b285ca41ba | 81 | #define kMBED_OLED_DC p10 |
tobyspark | 5:f8b285ca41ba | 82 | |
tobyspark | 5:f8b285ca41ba | 83 | #define kMBED_DIN_ETHLO_DMXHI p30 |
tobyspark | 5:f8b285ca41ba | 84 | #define kMBED_DOUT_RS485_TXHI_RXLO p29 |
tobyspark | 5:f8b285ca41ba | 85 | #define kMBED_RS485_TTLTX p28 |
tobyspark | 5:f8b285ca41ba | 86 | #define kMBED_RS485_TTLRX p27 |
tobyspark | 5:f8b285ca41ba | 87 | |
tobyspark | 5:f8b285ca41ba | 88 | // DISPLAY |
tobyspark | 5:f8b285ca41ba | 89 | |
tobyspark | 1:f9fca21102e0 | 90 | #define kMenuLine1 3 |
tobyspark | 1:f9fca21102e0 | 91 | #define kMenuLine2 4 |
tobyspark | 1:f9fca21102e0 | 92 | #define kCommsStatusLine 6 |
tobyspark | 1:f9fca21102e0 | 93 | #define kTVOneStatusLine 7 |
tobyspark | 1:f9fca21102e0 | 94 | |
tobyspark | 5:f8b285ca41ba | 95 | // NETWORKING |
tobyspark | 5:f8b285ca41ba | 96 | |
tobyspark | 1:f9fca21102e0 | 97 | #define kOSCMbedPort 10000 |
tobyspark | 1:f9fca21102e0 | 98 | #define kOSCMbedIPAddress 10,0,0,2 |
tobyspark | 1:f9fca21102e0 | 99 | #define kOSCMbedSubnetMask 255,255,255,0 |
tobyspark | 1:f9fca21102e0 | 100 | #define kOSCMbedGateway 10,0,0,1 |
tobyspark | 1:f9fca21102e0 | 101 | #define kOSCMbedDNS 10,0,0,1 |
tobyspark | 0:87aab40d5806 | 102 | |
tobyspark | 3:033d2b7768f3 | 103 | #define kArtNetBindIPAddress 2,0,0,100 |
tobyspark | 3:033d2b7768f3 | 104 | #define kArtNetBroadcastAddress 2,255,255,255 |
tobyspark | 3:033d2b7768f3 | 105 | |
tobyspark | 5:f8b285ca41ba | 106 | #define kDMXInChannelXFade 0 |
tobyspark | 5:f8b285ca41ba | 107 | #define kDMXInChannelFadeUp 1 |
tobyspark | 5:f8b285ca41ba | 108 | #define kDMXOutChannelXFade 0 |
tobyspark | 5:f8b285ca41ba | 109 | #define kDMXOutChannelFadeUp 1 |
tobyspark | 5:f8b285ca41ba | 110 | |
tobyspark | 13:3796bde6ba8f | 111 | // 8.3 format filename only, no subdirs |
tobyspark | 13:3796bde6ba8f | 112 | #define kSPKDFSettingsFilename "SPKDF.ini" |
tobyspark | 11:0783cfbeb746 | 113 | |
tobyspark | 0:87aab40d5806 | 114 | //// DEBUG |
tobyspark | 0:87aab40d5806 | 115 | |
tobyspark | 0:87aab40d5806 | 116 | // Comment out one or the other... |
tobyspark | 17:fc68d40b8b1f | 117 | //Serial *debug = new Serial(USBTX, USBRX); // For debugging via USB serial |
tobyspark | 17:fc68d40b8b1f | 118 | Serial *debug = NULL; // For release (no debugging) |
tobyspark | 0:87aab40d5806 | 119 | |
tobyspark | 15:4b394c64b461 | 120 | //// SOFT RESET |
tobyspark | 15:4b394c64b461 | 121 | |
tobyspark | 15:4b394c64b461 | 122 | extern "C" void mbed_reset(); |
tobyspark | 15:4b394c64b461 | 123 | |
tobyspark | 0:87aab40d5806 | 124 | //// mBED PIN ASSIGNMENTS |
tobyspark | 0:87aab40d5806 | 125 | |
tobyspark | 0:87aab40d5806 | 126 | // Inputs |
tobyspark | 5:f8b285ca41ba | 127 | AnalogIn xFadeAIN(kMBED_AIN_XFADE); |
tobyspark | 5:f8b285ca41ba | 128 | AnalogIn fadeUpAIN(kMBED_AIN_FADEUP); |
tobyspark | 5:f8b285ca41ba | 129 | DigitalIn tapLeftDIN(kMBED_DIN_TAP_L); |
tobyspark | 5:f8b285ca41ba | 130 | DigitalIn tapRightDIN(kMBED_DIN_TAP_R); |
tobyspark | 17:fc68d40b8b1f | 131 | medianFilter xFadeFilter(9); |
tobyspark | 17:fc68d40b8b1f | 132 | medianFilter fadeUpFilter(9); |
tobyspark | 0:87aab40d5806 | 133 | |
tobyspark | 5:f8b285ca41ba | 134 | SPKRotaryEncoder menuEnc(kMBED_ENC_A, kMBED_ENC_B, kMBED_ENC_SW); |
tobyspark | 5:f8b285ca41ba | 135 | |
tobyspark | 5:f8b285ca41ba | 136 | DigitalIn rj45ModeDIN(kMBED_DIN_ETHLO_DMXHI); |
tobyspark | 0:87aab40d5806 | 137 | |
tobyspark | 0:87aab40d5806 | 138 | // Outputs |
tobyspark | 0:87aab40d5806 | 139 | PwmOut fadeAPO(LED1); |
tobyspark | 0:87aab40d5806 | 140 | PwmOut fadeBPO(LED2); |
tobyspark | 0:87aab40d5806 | 141 | |
tobyspark | 5:f8b285ca41ba | 142 | DigitalOut dmxDirectionDOUT(kMBED_DOUT_RS485_TXHI_RXLO); |
tobyspark | 5:f8b285ca41ba | 143 | |
tobyspark | 0:87aab40d5806 | 144 | // SPKTVOne(PinName txPin, PinName rxPin, PinName signWritePin, PinName signErrorPin, Serial *debugSerial) |
tobyspark | 5:f8b285ca41ba | 145 | SPKTVOne tvOne(kMBED_RS232_TTLTX, kMBED_RS232_TTLRX, LED3, LED4, debug); |
tobyspark | 0:87aab40d5806 | 146 | |
tobyspark | 0:87aab40d5806 | 147 | // SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL); |
tobyspark | 5:f8b285ca41ba | 148 | SPKDisplay screen(kMBED_OLED_MOSI, kMBED_OLED_SCK, kMBED_OLED_CS, kMBED_OLED_DC, kMBED_OLED_RES, debug); |
tobyspark | 0:87aab40d5806 | 149 | |
tobyspark | 11:0783cfbeb746 | 150 | // Saved Settings |
tobyspark | 11:0783cfbeb746 | 151 | SPKSettings settings; |
tobyspark | 11:0783cfbeb746 | 152 | |
tobyspark | 0:87aab40d5806 | 153 | // Menu |
tobyspark | 0:87aab40d5806 | 154 | SPKMenu *selectedMenu; |
tobyspark | 0:87aab40d5806 | 155 | SPKMenu *lastSelectedMenu; |
tobyspark | 0:87aab40d5806 | 156 | SPKMenuOfMenus mainMenu; |
tobyspark | 0:87aab40d5806 | 157 | SPKMenuPayload resolutionMenu; |
tobyspark | 0:87aab40d5806 | 158 | SPKMenuPayload mixModeMenu; |
tobyspark | 12:c270870bdd23 | 159 | SPKMenuPayload advancedMenu; |
tobyspark | 12:c270870bdd23 | 160 | |
tobyspark | 15:4b394c64b461 | 161 | enum { mixBlend, mixAdditive, mixKey }; // additive will require custom TVOne firmware. |
tobyspark | 15:4b394c64b461 | 162 | int mixMode = mixBlend; |
tobyspark | 1:f9fca21102e0 | 163 | SPKMenuPayload commsMenu; |
tobyspark | 5:f8b285ca41ba | 164 | enum { commsNone, commsOSC, commsArtNet, commsDMXIn, commsDMXOut}; |
tobyspark | 5:f8b285ca41ba | 165 | int commsMode = commsNone; |
tobyspark | 17:fc68d40b8b1f | 166 | enum { advancedHDCPOn, advancedHDCPOff, advancedConformProcessor, advancedLoadDefaults, advancedSelfTest }; |
tobyspark | 1:f9fca21102e0 | 167 | |
tobyspark | 5:f8b285ca41ba | 168 | // RJ45 Comms |
tobyspark | 5:f8b285ca41ba | 169 | enum { rj45Ethernet = 0, rj45DMX = 1}; // These values from circuit |
tobyspark | 5:f8b285ca41ba | 170 | int rj45Mode = -1; |
tobyspark | 1:f9fca21102e0 | 171 | EthernetNetIf *ethernet = NULL; |
tobyspark | 1:f9fca21102e0 | 172 | OSCClass *osc = NULL; |
tobyspark | 3:033d2b7768f3 | 173 | OSCMessage recMessage; |
tobyspark | 3:033d2b7768f3 | 174 | DmxArtNet *artNet = NULL; |
tobyspark | 5:f8b285ca41ba | 175 | DMX *dmx = NULL; |
tobyspark | 0:87aab40d5806 | 176 | |
tobyspark | 3:033d2b7768f3 | 177 | // Fade logic constants |
tobyspark | 0:87aab40d5806 | 178 | const float xFadeTolerance = 0.05; |
tobyspark | 0:87aab40d5806 | 179 | const float fadeUpTolerance = 0.05; |
tobyspark | 0:87aab40d5806 | 180 | |
tobyspark | 0:87aab40d5806 | 181 | // A&B Fade as resolved percent |
tobyspark | 0:87aab40d5806 | 182 | int fadeAPercent = 0; |
tobyspark | 0:87aab40d5806 | 183 | int fadeBPercent = 0; |
tobyspark | 17:fc68d40b8b1f | 184 | int oldFadeAPercent = 0; |
tobyspark | 17:fc68d40b8b1f | 185 | int oldFadeBPercent = 0; |
tobyspark | 0:87aab40d5806 | 186 | |
tobyspark | 0:87aab40d5806 | 187 | // Tap button states |
tobyspark | 5:f8b285ca41ba | 188 | bool tapLeftWasFirstPressed = false; |
tobyspark | 0:87aab40d5806 | 189 | |
tobyspark | 0:87aab40d5806 | 190 | // Key mode parameters |
tobyspark | 0:87aab40d5806 | 191 | int keyerParamsSet = -1; // last keyParams index uploaded to unit |
tobyspark | 0:87aab40d5806 | 192 | |
tobyspark | 3:033d2b7768f3 | 193 | void processOSC(float &xFade, float &fadeUp) { |
tobyspark | 3:033d2b7768f3 | 194 | std::stringstream statusMessage; |
tobyspark | 3:033d2b7768f3 | 195 | statusMessage.setf(ios::fixed,ios::floatfield); |
tobyspark | 3:033d2b7768f3 | 196 | statusMessage.precision(2); |
tobyspark | 3:033d2b7768f3 | 197 | |
tobyspark | 3:033d2b7768f3 | 198 | if (!strcmp( recMessage.getTopAddress() , "dvimxr" )) |
tobyspark | 3:033d2b7768f3 | 199 | { |
tobyspark | 3:033d2b7768f3 | 200 | statusMessage << "OSC: /dvimxr"; |
tobyspark | 3:033d2b7768f3 | 201 | if (!strcmp( recMessage.getSubAddress() , "xFade" )) |
tobyspark | 3:033d2b7768f3 | 202 | if (recMessage.getArgNum() == 1) |
tobyspark | 3:033d2b7768f3 | 203 | if (recMessage.getTypeTag(0) == 'f') |
tobyspark | 3:033d2b7768f3 | 204 | { |
tobyspark | 3:033d2b7768f3 | 205 | double newXFade = recMessage.getArgFloat(0); |
tobyspark | 3:033d2b7768f3 | 206 | statusMessage << "/xFade " << newXFade; |
tobyspark | 3:033d2b7768f3 | 207 | xFade = newXFade; |
tobyspark | 3:033d2b7768f3 | 208 | } |
tobyspark | 3:033d2b7768f3 | 209 | else if (!strcmp( recMessage.getSubAddress() , "fadeUp" )) |
tobyspark | 3:033d2b7768f3 | 210 | if (recMessage.getArgNum() == 1) |
tobyspark | 3:033d2b7768f3 | 211 | if (recMessage.getTypeTag(0) == 'f') |
tobyspark | 3:033d2b7768f3 | 212 | { |
tobyspark | 3:033d2b7768f3 | 213 | double newFadeUp = recMessage.getArgFloat(0); |
tobyspark | 3:033d2b7768f3 | 214 | statusMessage << "/fadeUp " << newFadeUp; |
tobyspark | 3:033d2b7768f3 | 215 | xFade = newFadeUp; |
tobyspark | 3:033d2b7768f3 | 216 | } |
tobyspark | 3:033d2b7768f3 | 217 | else statusMessage << recMessage.getSubAddress() << " - Ignoring"; |
tobyspark | 3:033d2b7768f3 | 218 | } |
tobyspark | 3:033d2b7768f3 | 219 | else |
tobyspark | 3:033d2b7768f3 | 220 | { |
tobyspark | 3:033d2b7768f3 | 221 | statusMessage << "OSC: " << recMessage.getTopAddress() << " - Ignoring"; |
tobyspark | 3:033d2b7768f3 | 222 | } |
tobyspark | 3:033d2b7768f3 | 223 | |
tobyspark | 3:033d2b7768f3 | 224 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 225 | screen.textToBuffer(statusMessage.str(), kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 226 | screen.sendBuffer(); |
tobyspark | 3:033d2b7768f3 | 227 | if (debug) debug->printf("%s \r\n", statusMessage.str().c_str()); |
tobyspark | 3:033d2b7768f3 | 228 | |
tobyspark | 3:033d2b7768f3 | 229 | } |
tobyspark | 3:033d2b7768f3 | 230 | |
tobyspark | 8:d46cc49f0f37 | 231 | void processArtNet(float &xFade, float &fadeUp) |
tobyspark | 8:d46cc49f0f37 | 232 | { |
tobyspark | 3:033d2b7768f3 | 233 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 234 | screen.textToBuffer("ArtNet activity", kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 235 | screen.sendBuffer(); |
tobyspark | 3:033d2b7768f3 | 236 | if (debug) debug->printf("ArtNet activity"); |
tobyspark | 3:033d2b7768f3 | 237 | } |
tobyspark | 0:87aab40d5806 | 238 | |
tobyspark | 8:d46cc49f0f37 | 239 | void processDMXIn(float &xFade, float &fadeUp) |
tobyspark | 8:d46cc49f0f37 | 240 | { |
tobyspark | 5:f8b285ca41ba | 241 | std::stringstream statusMessage; |
tobyspark | 5:f8b285ca41ba | 242 | |
tobyspark | 5:f8b285ca41ba | 243 | int xFadeDMX = dmx->get(kDMXInChannelXFade); |
tobyspark | 7:e6717468c18d | 244 | int fadeUpDMX = dmx->get(kDMXInChannelFadeUp); |
tobyspark | 5:f8b285ca41ba | 245 | |
tobyspark | 5:f8b285ca41ba | 246 | xFade = (float)xFadeDMX/255; |
tobyspark | 5:f8b285ca41ba | 247 | fadeUp = (float)fadeUpDMX/255; |
tobyspark | 5:f8b285ca41ba | 248 | |
tobyspark | 5:f8b285ca41ba | 249 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 250 | statusMessage << "DMX In: xF " << xFadeDMX << " fUp " << fadeUpDMX; |
tobyspark | 5:f8b285ca41ba | 251 | screen.textToBuffer(statusMessage.str(), kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 252 | screen.sendBuffer(); |
tobyspark | 5:f8b285ca41ba | 253 | if (debug) debug->printf(statusMessage.str().c_str()); |
tobyspark | 5:f8b285ca41ba | 254 | } |
tobyspark | 5:f8b285ca41ba | 255 | |
tobyspark | 8:d46cc49f0f37 | 256 | void processDMXOut(float &xFade, float &fadeUp) |
tobyspark | 8:d46cc49f0f37 | 257 | { |
tobyspark | 5:f8b285ca41ba | 258 | std::stringstream statusMessage; |
tobyspark | 5:f8b285ca41ba | 259 | |
tobyspark | 5:f8b285ca41ba | 260 | int xFadeDMX = xFade*255; |
tobyspark | 5:f8b285ca41ba | 261 | int fadeUpDMX = fadeUp*255; |
tobyspark | 5:f8b285ca41ba | 262 | |
tobyspark | 5:f8b285ca41ba | 263 | dmx->put(kDMXOutChannelXFade, xFadeDMX); |
tobyspark | 5:f8b285ca41ba | 264 | dmx->put(kDMXOutChannelFadeUp, fadeUpDMX); |
tobyspark | 5:f8b285ca41ba | 265 | |
tobyspark | 5:f8b285ca41ba | 266 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 267 | statusMessage << "DMX Out: xF " << xFadeDMX << " fUp " << fadeUpDMX; |
tobyspark | 5:f8b285ca41ba | 268 | screen.textToBuffer(statusMessage.str(), kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 269 | screen.sendBuffer(); |
tobyspark | 5:f8b285ca41ba | 270 | if (debug) debug->printf(statusMessage.str().c_str()); |
tobyspark | 5:f8b285ca41ba | 271 | } |
tobyspark | 0:87aab40d5806 | 272 | |
tobyspark | 8:d46cc49f0f37 | 273 | inline float fadeCalc (const float AIN, const float tolerance) |
tobyspark | 8:d46cc49f0f37 | 274 | { |
tobyspark | 0:87aab40d5806 | 275 | float pos ; |
tobyspark | 0:87aab40d5806 | 276 | if (AIN < tolerance) pos = 0; |
tobyspark | 0:87aab40d5806 | 277 | else if (AIN > 1.0 - tolerance) pos = 1; |
tobyspark | 0:87aab40d5806 | 278 | else pos = (AIN - tolerance) / (1 - 2*tolerance); |
tobyspark | 0:87aab40d5806 | 279 | if (debug && false) debug->printf("fadeCalc in: %f out: %f \r\n", AIN, pos); |
tobyspark | 0:87aab40d5806 | 280 | return pos; |
tobyspark | 0:87aab40d5806 | 281 | } |
tobyspark | 0:87aab40d5806 | 282 | |
tobyspark | 8:d46cc49f0f37 | 283 | bool setKeyParamsTo(int index) |
tobyspark | 8:d46cc49f0f37 | 284 | { |
tobyspark | 0:87aab40d5806 | 285 | // Only spend the time uploading six parameters if we need to |
tobyspark | 0:87aab40d5806 | 286 | // Might want to bounds check here |
tobyspark | 0:87aab40d5806 | 287 | |
tobyspark | 9:f83eadd8917a | 288 | bool ok; |
tobyspark | 0:87aab40d5806 | 289 | |
tobyspark | 0:87aab40d5806 | 290 | if (index != keyerParamsSet) |
tobyspark | 0:87aab40d5806 | 291 | { |
tobyspark | 11:0783cfbeb746 | 292 | ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, settings.keyerParamSet(index)[0]); |
tobyspark | 11:0783cfbeb746 | 293 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, settings.keyerParamSet(index)[1]); |
tobyspark | 11:0783cfbeb746 | 294 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, settings.keyerParamSet(index)[2]); |
tobyspark | 11:0783cfbeb746 | 295 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, settings.keyerParamSet(index)[3]); |
tobyspark | 11:0783cfbeb746 | 296 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, settings.keyerParamSet(index)[4]); |
tobyspark | 11:0783cfbeb746 | 297 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, settings.keyerParamSet(index)[5]); |
tobyspark | 0:87aab40d5806 | 298 | |
tobyspark | 0:87aab40d5806 | 299 | keyerParamsSet = index; |
tobyspark | 9:f83eadd8917a | 300 | } |
tobyspark | 9:f83eadd8917a | 301 | else |
tobyspark | 9:f83eadd8917a | 302 | { |
tobyspark | 9:f83eadd8917a | 303 | ok = true; |
tobyspark | 9:f83eadd8917a | 304 | } |
tobyspark | 0:87aab40d5806 | 305 | |
tobyspark | 0:87aab40d5806 | 306 | return ok; |
tobyspark | 0:87aab40d5806 | 307 | } |
tobyspark | 0:87aab40d5806 | 308 | |
tobyspark | 17:fc68d40b8b1f | 309 | bool conformProcessor() |
tobyspark | 17:fc68d40b8b1f | 310 | { |
tobyspark | 17:fc68d40b8b1f | 311 | bool ok = true; |
tobyspark | 17:fc68d40b8b1f | 312 | |
tobyspark | 17:fc68d40b8b1f | 313 | int32_t on = 1; |
tobyspark | 17:fc68d40b8b1f | 314 | int32_t off = 0; |
tobyspark | 17:fc68d40b8b1f | 315 | |
tobyspark | 17:fc68d40b8b1f | 316 | // Make sure our windows exist |
tobyspark | 17:fc68d40b8b1f | 317 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsEnable, on); |
tobyspark | 17:fc68d40b8b1f | 318 | ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsEnable, on); |
tobyspark | 17:fc68d40b8b1f | 319 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsLayerPriority, 1); // TODO: Setting this to 4 caused controller freeze? |
tobyspark | 17:fc68d40b8b1f | 320 | ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsLayerPriority, 2); |
tobyspark | 17:fc68d40b8b1f | 321 | |
tobyspark | 17:fc68d40b8b1f | 322 | // Assign inputs to windows, so that left on the crossfader is left on the processor viewed from front |
tobyspark | 17:fc68d40b8b1f | 323 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB2); |
tobyspark | 17:fc68d40b8b1f | 324 | ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB1); |
tobyspark | 17:fc68d40b8b1f | 325 | |
tobyspark | 17:fc68d40b8b1f | 326 | // Set scaling to fit source within output, maintaining aspect ratio |
tobyspark | 17:fc68d40b8b1f | 327 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustWindowsZoomLevel, 100); |
tobyspark | 17:fc68d40b8b1f | 328 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDB, kTV1FunctionAdjustWindowsZoomLevel, 100); |
tobyspark | 17:fc68d40b8b1f | 329 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustWindowsShrinkEnable, off); |
tobyspark | 17:fc68d40b8b1f | 330 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDB, kTV1FunctionAdjustWindowsShrinkEnable, off); |
tobyspark | 17:fc68d40b8b1f | 331 | int32_t fit = 1; |
tobyspark | 17:fc68d40b8b1f | 332 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, fit); |
tobyspark | 17:fc68d40b8b1f | 333 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, fit); |
tobyspark | 17:fc68d40b8b1f | 334 | |
tobyspark | 17:fc68d40b8b1f | 335 | // On source loss, hold on the last frame received. |
tobyspark | 17:fc68d40b8b1f | 336 | int32_t freeze = 1; |
tobyspark | 17:fc68d40b8b1f | 337 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze); |
tobyspark | 17:fc68d40b8b1f | 338 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze); |
tobyspark | 17:fc68d40b8b1f | 339 | |
tobyspark | 17:fc68d40b8b1f | 340 | // Finally, autoset to sources? |
tobyspark | 17:fc68d40b8b1f | 341 | //int32_t start = 1; |
tobyspark | 17:fc68d40b8b1f | 342 | //ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAutoSet, start); |
tobyspark | 17:fc68d40b8b1f | 343 | //ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAutoSet, start); |
tobyspark | 17:fc68d40b8b1f | 344 | |
tobyspark | 17:fc68d40b8b1f | 345 | return ok; |
tobyspark | 17:fc68d40b8b1f | 346 | } |
tobyspark | 17:fc68d40b8b1f | 347 | |
tobyspark | 17:fc68d40b8b1f | 348 | void selfTest() |
tobyspark | 17:fc68d40b8b1f | 349 | { |
tobyspark | 17:fc68d40b8b1f | 350 | /* SELF TEST - Pixels |
tobyspark | 17:fc68d40b8b1f | 351 | * Clicking �self-test� menu will display a solid lit screen. Check all pixels lit. |
tobyspark | 17:fc68d40b8b1f | 352 | * Verified: Display |
tobyspark | 17:fc68d40b8b1f | 353 | */ |
tobyspark | 17:fc68d40b8b1f | 354 | |
tobyspark | 17:fc68d40b8b1f | 355 | screen.imageToBuffer(spkDisplayAllPixelsOn); |
tobyspark | 17:fc68d40b8b1f | 356 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 357 | |
tobyspark | 17:fc68d40b8b1f | 358 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 359 | { |
tobyspark | 17:fc68d40b8b1f | 360 | // do nothing, wait for press |
tobyspark | 17:fc68d40b8b1f | 361 | } |
tobyspark | 17:fc68d40b8b1f | 362 | |
tobyspark | 17:fc68d40b8b1f | 363 | /* SELF TEST - Mixing Controls |
tobyspark | 17:fc68d40b8b1f | 364 | * Clicking again will prompt to check crossfader, fade to black and tap buttons. Check movement of physical controls against 0.0-1.0 values on- screen. |
tobyspark | 17:fc68d40b8b1f | 365 | * Verified: Mixing controls. |
tobyspark | 17:fc68d40b8b1f | 366 | */ |
tobyspark | 17:fc68d40b8b1f | 367 | |
tobyspark | 17:fc68d40b8b1f | 368 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 369 | screen.textToBuffer("Self test - Mixing Controls", 0); |
tobyspark | 17:fc68d40b8b1f | 370 | |
tobyspark | 17:fc68d40b8b1f | 371 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 372 | { |
tobyspark | 17:fc68d40b8b1f | 373 | stringstream xFadeReadOut; |
tobyspark | 17:fc68d40b8b1f | 374 | stringstream fadeToBlackReadOut; |
tobyspark | 17:fc68d40b8b1f | 375 | stringstream tapsReadOut; |
tobyspark | 17:fc68d40b8b1f | 376 | |
tobyspark | 17:fc68d40b8b1f | 377 | xFadeReadOut.precision(2); |
tobyspark | 17:fc68d40b8b1f | 378 | fadeToBlackReadOut.precision(2); |
tobyspark | 17:fc68d40b8b1f | 379 | tapsReadOut.precision(1); |
tobyspark | 17:fc68d40b8b1f | 380 | |
tobyspark | 17:fc68d40b8b1f | 381 | xFadeReadOut << "Crossfade: " << xFadeAIN.read(); |
tobyspark | 17:fc68d40b8b1f | 382 | fadeToBlackReadOut << "Fade to black: " << fadeUpAIN.read(); |
tobyspark | 17:fc68d40b8b1f | 383 | tapsReadOut << "Tap left: " << tapLeftDIN.read() << " right: " << tapRightDIN.read(); |
tobyspark | 17:fc68d40b8b1f | 384 | |
tobyspark | 17:fc68d40b8b1f | 385 | screen.clearBufferRow(1); |
tobyspark | 17:fc68d40b8b1f | 386 | screen.clearBufferRow(2); |
tobyspark | 17:fc68d40b8b1f | 387 | screen.clearBufferRow(3); |
tobyspark | 17:fc68d40b8b1f | 388 | |
tobyspark | 17:fc68d40b8b1f | 389 | screen.textToBuffer(xFadeReadOut.str(), 1); |
tobyspark | 17:fc68d40b8b1f | 390 | screen.textToBuffer(fadeToBlackReadOut.str(), 2); |
tobyspark | 17:fc68d40b8b1f | 391 | screen.textToBuffer(tapsReadOut.str(), 3); |
tobyspark | 17:fc68d40b8b1f | 392 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 393 | } |
tobyspark | 17:fc68d40b8b1f | 394 | |
tobyspark | 17:fc68d40b8b1f | 395 | /* SELF TEST - RS232 |
tobyspark | 17:fc68d40b8b1f | 396 | * Click the controller menu control. Should see �RS232 test� prompt and test message. Ensure PC is displaying the test message. |
tobyspark | 17:fc68d40b8b1f | 397 | * Verified: RS232 connection. |
tobyspark | 17:fc68d40b8b1f | 398 | */ |
tobyspark | 17:fc68d40b8b1f | 399 | |
tobyspark | 17:fc68d40b8b1f | 400 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 401 | screen.textToBuffer("Self test - RS232", 0); |
tobyspark | 17:fc68d40b8b1f | 402 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 403 | |
tobyspark | 17:fc68d40b8b1f | 404 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 405 | { |
tobyspark | 17:fc68d40b8b1f | 406 | screen.textToBuffer("TODO!", 1); |
tobyspark | 17:fc68d40b8b1f | 407 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 408 | } |
tobyspark | 17:fc68d40b8b1f | 409 | |
tobyspark | 17:fc68d40b8b1f | 410 | /* SELF TEST - DMX |
tobyspark | 17:fc68d40b8b1f | 411 | * Click the controller menu control. Should see �DMX test� prompt and test message. Ensure PC is displaying the test message. |
tobyspark | 17:fc68d40b8b1f | 412 | * Verified: RS485 connection and DMX library. |
tobyspark | 17:fc68d40b8b1f | 413 | */ |
tobyspark | 17:fc68d40b8b1f | 414 | |
tobyspark | 17:fc68d40b8b1f | 415 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 416 | screen.textToBuffer("Self test - DMX", 0); |
tobyspark | 17:fc68d40b8b1f | 417 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 418 | |
tobyspark | 17:fc68d40b8b1f | 419 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 420 | { |
tobyspark | 17:fc68d40b8b1f | 421 | screen.textToBuffer("TODO!", 1); |
tobyspark | 17:fc68d40b8b1f | 422 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 423 | } |
tobyspark | 17:fc68d40b8b1f | 424 | |
tobyspark | 17:fc68d40b8b1f | 425 | /* SELF TEST - OSC |
tobyspark | 17:fc68d40b8b1f | 426 | * Click the controller menu control. Should see �OSC test� prompt and test message. Ensure PC is displaying the test message. |
tobyspark | 17:fc68d40b8b1f | 427 | * Verified: Ethernet connection and OSC library. |
tobyspark | 17:fc68d40b8b1f | 428 | */ |
tobyspark | 17:fc68d40b8b1f | 429 | |
tobyspark | 17:fc68d40b8b1f | 430 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 431 | screen.textToBuffer("Self test - DMX", 0); |
tobyspark | 17:fc68d40b8b1f | 432 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 433 | |
tobyspark | 17:fc68d40b8b1f | 434 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 435 | { |
tobyspark | 17:fc68d40b8b1f | 436 | screen.textToBuffer("TODO!", 1); |
tobyspark | 17:fc68d40b8b1f | 437 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 438 | } |
tobyspark | 17:fc68d40b8b1f | 439 | |
tobyspark | 17:fc68d40b8b1f | 440 | /* SELF TEST - Exit! |
tobyspark | 17:fc68d40b8b1f | 441 | * To do this, we could just do nothing but we'd need to recreate screen and comms as they were. |
tobyspark | 17:fc68d40b8b1f | 442 | * Instead, lets just restart the mbed |
tobyspark | 17:fc68d40b8b1f | 443 | */ |
tobyspark | 17:fc68d40b8b1f | 444 | |
tobyspark | 17:fc68d40b8b1f | 445 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 446 | screen.textToBuffer("Self test complete", 0); |
tobyspark | 17:fc68d40b8b1f | 447 | screen.textToBuffer("Press to restart controller", 1); |
tobyspark | 17:fc68d40b8b1f | 448 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 449 | |
tobyspark | 17:fc68d40b8b1f | 450 | while(!menuEnc.hasPressed()) {} |
tobyspark | 17:fc68d40b8b1f | 451 | |
tobyspark | 17:fc68d40b8b1f | 452 | mbed_reset(); |
tobyspark | 17:fc68d40b8b1f | 453 | } |
tobyspark | 17:fc68d40b8b1f | 454 | |
tobyspark | 0:87aab40d5806 | 455 | int main() |
tobyspark | 0:87aab40d5806 | 456 | { |
tobyspark | 0:87aab40d5806 | 457 | if (debug) |
tobyspark | 0:87aab40d5806 | 458 | { |
tobyspark | 0:87aab40d5806 | 459 | debug->printf("\r\n\r\n"); |
tobyspark | 0:87aab40d5806 | 460 | debug->printf("*spark d-fuser -----------\r\n"); |
tobyspark | 0:87aab40d5806 | 461 | debug->printf(" debug channel\r\n"); |
tobyspark | 0:87aab40d5806 | 462 | } |
tobyspark | 2:50043054e4f7 | 463 | |
tobyspark | 2:50043054e4f7 | 464 | // Set display font |
tobyspark | 2:50043054e4f7 | 465 | screen.fontStartCharacter = &characterBytesStartChar; |
tobyspark | 2:50043054e4f7 | 466 | screen.fontEndCharacter = &characterBytesEndChar; |
tobyspark | 2:50043054e4f7 | 467 | screen.fontCharacters = characterBytes; |
tobyspark | 2:50043054e4f7 | 468 | |
tobyspark | 0:87aab40d5806 | 469 | // Splash screen |
tobyspark | 2:50043054e4f7 | 470 | screen.imageToBuffer(spkDisplayLogo); |
tobyspark | 0:87aab40d5806 | 471 | screen.textToBuffer("SPK:D-Fuser",0); |
tobyspark | 13:3796bde6ba8f | 472 | screen.textToBuffer(string("SW ") + kSPKDFSoftwareVersion,1); |
tobyspark | 5:f8b285ca41ba | 473 | screen.sendBuffer(); |
tobyspark | 0:87aab40d5806 | 474 | |
tobyspark | 11:0783cfbeb746 | 475 | // Load saved settings |
tobyspark | 16:52484666b323 | 476 | bool settingsAreCustom = false; |
tobyspark | 13:3796bde6ba8f | 477 | /* CRAZY, see note in spk_settings.h |
tobyspark | 16:52484666b323 | 478 | settingsAreCustom = settings.load(kSPKDFSettingsFilename); |
tobyspark | 16:52484666b323 | 479 | if (settingsAreCustom) |
tobyspark | 13:3796bde6ba8f | 480 | {screen.textToBuffer("Settings Read",2); screen.sendBuffer();} |
tobyspark | 13:3796bde6ba8f | 481 | else |
tobyspark | 13:3796bde6ba8f | 482 | {screen.textToBuffer("Settings NOT Read",2); screen.sendBuffer();} |
tobyspark | 13:3796bde6ba8f | 483 | */ |
tobyspark | 0:87aab40d5806 | 484 | // Set menu structure |
tobyspark | 0:87aab40d5806 | 485 | mixModeMenu.title = "Mix Mode"; |
tobyspark | 15:4b394c64b461 | 486 | mixModeMenu.addMenuItem("Blend", mixBlend, 0); |
tobyspark | 11:0783cfbeb746 | 487 | for (int i=0; i < settings.keyerSetCount(); i++) |
tobyspark | 11:0783cfbeb746 | 488 | { |
tobyspark | 15:4b394c64b461 | 489 | mixModeMenu.addMenuItem(settings.keyerParamName(i), mixKey+i, 0); |
tobyspark | 11:0783cfbeb746 | 490 | } |
tobyspark | 0:87aab40d5806 | 491 | |
tobyspark | 0:87aab40d5806 | 492 | resolutionMenu.title = "Resolution"; |
tobyspark | 16:52484666b323 | 493 | for (int i=0; i < settings.resolutionsCount(); i++) |
tobyspark | 16:52484666b323 | 494 | { |
tobyspark | 16:52484666b323 | 495 | resolutionMenu.addMenuItem(settings.resolutionName(i), settings.resolutionIndex(i), settings.resolutionEDIDIndex(i)); |
tobyspark | 16:52484666b323 | 496 | } |
tobyspark | 0:87aab40d5806 | 497 | |
tobyspark | 5:f8b285ca41ba | 498 | commsMenu.title = "Network Mode"; |
tobyspark | 1:f9fca21102e0 | 499 | commsMenu.addMenuItem("None", commsNone, 0); |
tobyspark | 1:f9fca21102e0 | 500 | commsMenu.addMenuItem("OSC", commsOSC, 0); |
tobyspark | 1:f9fca21102e0 | 501 | commsMenu.addMenuItem("ArtNet", commsArtNet, 0); |
tobyspark | 5:f8b285ca41ba | 502 | commsMenu.addMenuItem("DMX In", commsDMXIn, 0); |
tobyspark | 5:f8b285ca41ba | 503 | commsMenu.addMenuItem("DMX Out", commsDMXOut, 0); |
tobyspark | 1:f9fca21102e0 | 504 | |
tobyspark | 15:4b394c64b461 | 505 | advancedMenu.title = "Troubleshooting"; |
tobyspark | 12:c270870bdd23 | 506 | advancedMenu.addMenuItem("HDCP Off", advancedHDCPOff, 0); |
tobyspark | 15:4b394c64b461 | 507 | advancedMenu.addMenuItem("HDCP On", advancedHDCPOn, 0); |
tobyspark | 17:fc68d40b8b1f | 508 | advancedMenu.addMenuItem("Conform Processor", advancedConformProcessor, 0); |
tobyspark | 16:52484666b323 | 509 | if (settingsAreCustom) advancedMenu.addMenuItem("Revert to defaults", advancedLoadDefaults, 0); |
tobyspark | 15:4b394c64b461 | 510 | advancedMenu.addMenuItem("Start Self-Test", advancedSelfTest, 0); |
tobyspark | 12:c270870bdd23 | 511 | |
tobyspark | 0:87aab40d5806 | 512 | mainMenu.title = "Main Menu"; |
tobyspark | 0:87aab40d5806 | 513 | mainMenu.addMenuItem(&mixModeMenu); |
tobyspark | 0:87aab40d5806 | 514 | mainMenu.addMenuItem(&resolutionMenu); |
tobyspark | 1:f9fca21102e0 | 515 | mainMenu.addMenuItem(&commsMenu); |
tobyspark | 12:c270870bdd23 | 516 | mainMenu.addMenuItem(&advancedMenu); |
tobyspark | 0:87aab40d5806 | 517 | |
tobyspark | 0:87aab40d5806 | 518 | selectedMenu = &mainMenu; |
tobyspark | 0:87aab40d5806 | 519 | lastSelectedMenu = &mainMenu; |
tobyspark | 0:87aab40d5806 | 520 | |
tobyspark | 0:87aab40d5806 | 521 | // Misc I/O stuff |
tobyspark | 0:87aab40d5806 | 522 | |
tobyspark | 0:87aab40d5806 | 523 | fadeAPO.period(0.001); |
tobyspark | 0:87aab40d5806 | 524 | fadeBPO.period(0.001); |
tobyspark | 0:87aab40d5806 | 525 | |
tobyspark | 12:c270870bdd23 | 526 | // TODO: Test for TVOne connectivity here and display in status line |
tobyspark | 0:87aab40d5806 | 527 | |
tobyspark | 12:c270870bdd23 | 528 | // Display menu and framing lines |
tobyspark | 0:87aab40d5806 | 529 | screen.horizLineToBuffer(kMenuLine1*pixInPage - 1); |
tobyspark | 0:87aab40d5806 | 530 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 531 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 532 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 533 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 534 | screen.horizLineToBuffer(kMenuLine2*pixInPage + pixInPage); |
tobyspark | 1:f9fca21102e0 | 535 | screen.horizLineToBuffer(kCommsStatusLine*pixInPage - 1); |
tobyspark | 1:f9fca21102e0 | 536 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 537 | screen.textToBuffer(commsMenu.selectedString(), kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 538 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 539 | screen.sendBuffer(); |
tobyspark | 0:87aab40d5806 | 540 | |
tobyspark | 0:87aab40d5806 | 541 | |
tobyspark | 0:87aab40d5806 | 542 | //// CONTROLS TEST |
tobyspark | 0:87aab40d5806 | 543 | |
tobyspark | 0:87aab40d5806 | 544 | while (0) { |
tobyspark | 0:87aab40d5806 | 545 | 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 | 546 | } |
tobyspark | 0:87aab40d5806 | 547 | |
tobyspark | 0:87aab40d5806 | 548 | //// MIXER RUN |
tobyspark | 0:87aab40d5806 | 549 | |
tobyspark | 8:d46cc49f0f37 | 550 | while (1) |
tobyspark | 8:d46cc49f0f37 | 551 | { |
tobyspark | 1:f9fca21102e0 | 552 | //// Task background things |
tobyspark | 5:f8b285ca41ba | 553 | if (ethernet && rj45Mode == rj45Ethernet) |
tobyspark | 5:f8b285ca41ba | 554 | { |
tobyspark | 5:f8b285ca41ba | 555 | if (debug) debug->printf("net poll"); |
tobyspark | 5:f8b285ca41ba | 556 | Net::poll(); |
tobyspark | 5:f8b285ca41ba | 557 | } |
tobyspark | 5:f8b285ca41ba | 558 | |
tobyspark | 5:f8b285ca41ba | 559 | //// RJ45 SWITCH |
tobyspark | 5:f8b285ca41ba | 560 | |
tobyspark | 5:f8b285ca41ba | 561 | if (rj45ModeDIN != rj45Mode) |
tobyspark | 1:f9fca21102e0 | 562 | { |
tobyspark | 5:f8b285ca41ba | 563 | // update state |
tobyspark | 5:f8b285ca41ba | 564 | rj45Mode = rj45ModeDIN; |
tobyspark | 5:f8b285ca41ba | 565 | if (rj45Mode == rj45Ethernet) commsMenu.title = "Network Mode [Ethernet]"; |
tobyspark | 5:f8b285ca41ba | 566 | if (rj45Mode == rj45DMX) commsMenu.title = "Network Mode [DMX]"; |
tobyspark | 5:f8b285ca41ba | 567 | |
tobyspark | 5:f8b285ca41ba | 568 | // cancel old comms |
tobyspark | 5:f8b285ca41ba | 569 | commsMode = commsNone; |
tobyspark | 5:f8b285ca41ba | 570 | commsMenu = commsMode; |
tobyspark | 5:f8b285ca41ba | 571 | |
tobyspark | 5:f8b285ca41ba | 572 | // refresh display |
tobyspark | 5:f8b285ca41ba | 573 | if (selectedMenu == &commsMenu) screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 5:f8b285ca41ba | 574 | if (rj45Mode == rj45Ethernet) screen.textToBuffer("RJ45: Ethernet Engaged", kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 575 | if (rj45Mode == rj45DMX) screen.textToBuffer("RJ45: DMX Engaged", kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 576 | } |
tobyspark | 1:f9fca21102e0 | 577 | |
tobyspark | 0:87aab40d5806 | 578 | //// MENU |
tobyspark | 0:87aab40d5806 | 579 | |
tobyspark | 0:87aab40d5806 | 580 | int menuChange = menuEnc.getChange(); |
tobyspark | 0:87aab40d5806 | 581 | |
tobyspark | 0:87aab40d5806 | 582 | // Update GUI |
tobyspark | 0:87aab40d5806 | 583 | if (menuChange != 0) |
tobyspark | 0:87aab40d5806 | 584 | { |
tobyspark | 0:87aab40d5806 | 585 | if (debug) debug->printf("Menu changed by %i\r\n", menuChange); |
tobyspark | 0:87aab40d5806 | 586 | |
tobyspark | 0:87aab40d5806 | 587 | *selectedMenu = selectedMenu->selectedIndex() + menuChange; |
tobyspark | 0:87aab40d5806 | 588 | |
tobyspark | 0:87aab40d5806 | 589 | // update OLED line 2 here |
tobyspark | 0:87aab40d5806 | 590 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 591 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 592 | |
tobyspark | 0:87aab40d5806 | 593 | if (debug) debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 0:87aab40d5806 | 594 | } |
tobyspark | 0:87aab40d5806 | 595 | |
tobyspark | 0:87aab40d5806 | 596 | // Action menu item |
tobyspark | 0:87aab40d5806 | 597 | if (menuEnc.hasPressed()) |
tobyspark | 0:87aab40d5806 | 598 | { |
tobyspark | 0:87aab40d5806 | 599 | if (debug) debug->printf("Action Menu Item!\r\n"); |
tobyspark | 0:87aab40d5806 | 600 | |
tobyspark | 0:87aab40d5806 | 601 | // Are we changing menus? |
tobyspark | 0:87aab40d5806 | 602 | if (selectedMenu->type() == menuOfMenus) |
tobyspark | 0:87aab40d5806 | 603 | { |
tobyspark | 0:87aab40d5806 | 604 | // point selected menu to the new menu |
tobyspark | 0:87aab40d5806 | 605 | // 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 | 606 | if (selectedMenu == &mainMenu) selectedMenu = mainMenu.selectedMenu(); |
tobyspark | 0:87aab40d5806 | 607 | else if (debug) debug->printf("FIXME: You've missed a SPKMenuOfMenus"); |
tobyspark | 0:87aab40d5806 | 608 | |
tobyspark | 0:87aab40d5806 | 609 | // reset the selection within that menu to the first position |
tobyspark | 0:87aab40d5806 | 610 | (*selectedMenu) = 0; |
tobyspark | 0:87aab40d5806 | 611 | |
tobyspark | 0:87aab40d5806 | 612 | // update OLED lines 1&2 |
tobyspark | 0:87aab40d5806 | 613 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 614 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 615 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 616 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 617 | |
tobyspark | 0:87aab40d5806 | 618 | if (debug) |
tobyspark | 0:87aab40d5806 | 619 | { |
tobyspark | 0:87aab40d5806 | 620 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 621 | debug->printf("%s \r\n", selectedMenu->title.c_str()); |
tobyspark | 0:87aab40d5806 | 622 | debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 0:87aab40d5806 | 623 | } |
tobyspark | 0:87aab40d5806 | 624 | } |
tobyspark | 0:87aab40d5806 | 625 | // Are we cancelling? |
tobyspark | 0:87aab40d5806 | 626 | else if (selectedMenu->type() == payload && selectedMenu->selectedIndex() == 0) |
tobyspark | 0:87aab40d5806 | 627 | { |
tobyspark | 0:87aab40d5806 | 628 | selectedMenu = lastSelectedMenu; |
tobyspark | 0:87aab40d5806 | 629 | |
tobyspark | 0:87aab40d5806 | 630 | // update OLED lines 1&2 |
tobyspark | 0:87aab40d5806 | 631 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 632 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 633 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 634 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 635 | |
tobyspark | 0:87aab40d5806 | 636 | if (debug) |
tobyspark | 0:87aab40d5806 | 637 | { |
tobyspark | 0:87aab40d5806 | 638 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 639 | debug->printf("%s \r\n", selectedMenu->title.c_str()); |
tobyspark | 0:87aab40d5806 | 640 | debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 0:87aab40d5806 | 641 | } |
tobyspark | 0:87aab40d5806 | 642 | } |
tobyspark | 0:87aab40d5806 | 643 | // With that out of the way, we should be actioning a specific menu's payload? |
tobyspark | 0:87aab40d5806 | 644 | else if (selectedMenu == &mixModeMenu) |
tobyspark | 0:87aab40d5806 | 645 | { |
tobyspark | 5:f8b285ca41ba | 646 | mixMode = mixModeMenu.selectedPayload1(); |
tobyspark | 5:f8b285ca41ba | 647 | |
tobyspark | 9:f83eadd8917a | 648 | bool ok = true; |
tobyspark | 0:87aab40d5806 | 649 | std::string sentOK; |
tobyspark | 0:87aab40d5806 | 650 | std::stringstream sentMSG; |
tobyspark | 0:87aab40d5806 | 651 | |
tobyspark | 11:0783cfbeb746 | 652 | // Set Keyer |
tobyspark | 15:4b394c64b461 | 653 | if (mixModeMenu.selectedPayload1() < mixKey) |
tobyspark | 11:0783cfbeb746 | 654 | { |
tobyspark | 11:0783cfbeb746 | 655 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, false); |
tobyspark | 11:0783cfbeb746 | 656 | sentMSG << "Keyer Off"; |
tobyspark | 11:0783cfbeb746 | 657 | } |
tobyspark | 11:0783cfbeb746 | 658 | else |
tobyspark | 11:0783cfbeb746 | 659 | { |
tobyspark | 11:0783cfbeb746 | 660 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, true); |
tobyspark | 11:0783cfbeb746 | 661 | sentMSG << "Keyer On"; |
tobyspark | 11:0783cfbeb746 | 662 | |
tobyspark | 15:4b394c64b461 | 663 | int index = mixModeMenu.selectedPayload1() - mixKey; |
tobyspark | 11:0783cfbeb746 | 664 | ok = ok && setKeyParamsTo(index); |
tobyspark | 11:0783cfbeb746 | 665 | sentMSG << " with " << index; |
tobyspark | 0:87aab40d5806 | 666 | } |
tobyspark | 0:87aab40d5806 | 667 | |
tobyspark | 0:87aab40d5806 | 668 | if (ok) sentOK = "Sent:"; |
tobyspark | 0:87aab40d5806 | 669 | else sentOK = "Send Error:"; |
tobyspark | 0:87aab40d5806 | 670 | |
tobyspark | 1:f9fca21102e0 | 671 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 1:f9fca21102e0 | 672 | screen.textToBuffer(sentOK + sentMSG.str(), kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 673 | |
tobyspark | 0:87aab40d5806 | 674 | if (debug) { debug->printf("Changing mix mode"); } |
tobyspark | 0:87aab40d5806 | 675 | } |
tobyspark | 0:87aab40d5806 | 676 | else if (selectedMenu == &resolutionMenu) |
tobyspark | 0:87aab40d5806 | 677 | { |
tobyspark | 9:f83eadd8917a | 678 | bool ok = true; |
tobyspark | 0:87aab40d5806 | 679 | |
tobyspark | 0:87aab40d5806 | 680 | ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputResolution, resolutionMenu.selectedPayload1()); |
tobyspark | 0:87aab40d5806 | 681 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedPayload2()); |
tobyspark | 0:87aab40d5806 | 682 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedPayload2()); |
tobyspark | 0:87aab40d5806 | 683 | |
tobyspark | 0:87aab40d5806 | 684 | std::string sentOK; |
tobyspark | 0:87aab40d5806 | 685 | if (ok) sentOK = "Sent: "; |
tobyspark | 0:87aab40d5806 | 686 | else sentOK = "Send Error: "; |
tobyspark | 0:87aab40d5806 | 687 | |
tobyspark | 0:87aab40d5806 | 688 | std::stringstream sentMSG; |
tobyspark | 0:87aab40d5806 | 689 | sentMSG << "Res " << resolutionMenu.selectedPayload1() << ", EDID " << resolutionMenu.selectedPayload2(); |
tobyspark | 0:87aab40d5806 | 690 | |
tobyspark | 1:f9fca21102e0 | 691 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 1:f9fca21102e0 | 692 | screen.textToBuffer(sentOK + sentMSG.str(), kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 693 | |
tobyspark | 0:87aab40d5806 | 694 | if (debug) { debug->printf("Changing resolution"); } |
tobyspark | 0:87aab40d5806 | 695 | } |
tobyspark | 1:f9fca21102e0 | 696 | else if (selectedMenu == &commsMenu) |
tobyspark | 1:f9fca21102e0 | 697 | { |
tobyspark | 5:f8b285ca41ba | 698 | std::string commsTypeString = "Network: --"; |
tobyspark | 1:f9fca21102e0 | 699 | std::stringstream commsStatus; |
tobyspark | 1:f9fca21102e0 | 700 | |
tobyspark | 1:f9fca21102e0 | 701 | // Tear down any existing comms |
tobyspark | 1:f9fca21102e0 | 702 | // This is the action of commsNone |
tobyspark | 1:f9fca21102e0 | 703 | // And also clears the way for other comms actions |
tobyspark | 5:f8b285ca41ba | 704 | if (osc) {delete osc; osc = NULL;} |
tobyspark | 5:f8b285ca41ba | 705 | if (ethernet) {delete ethernet; ethernet = NULL;} |
tobyspark | 5:f8b285ca41ba | 706 | if (artNet) {delete artNet; artNet = NULL;} |
tobyspark | 5:f8b285ca41ba | 707 | if (dmx) {delete dmx; dmx = NULL;} |
tobyspark | 5:f8b285ca41ba | 708 | |
tobyspark | 5:f8b285ca41ba | 709 | // Ensure we can't change to comms modes the hardware isn't switched to |
tobyspark | 5:f8b285ca41ba | 710 | if (rj45Mode == rj45DMX && (commsMenu.selectedPayload1() == commsOSC || commsMenu.selectedPayload1() == commsArtNet)) |
tobyspark | 1:f9fca21102e0 | 711 | { |
tobyspark | 5:f8b285ca41ba | 712 | commsTypeString = "RJ45 not in Ethernet mode"; |
tobyspark | 5:f8b285ca41ba | 713 | } |
tobyspark | 5:f8b285ca41ba | 714 | else if (rj45Mode == rj45Ethernet && (commsMenu.selectedPayload1() == commsDMXIn || commsMenu.selectedPayload1() == commsDMXOut)) |
tobyspark | 5:f8b285ca41ba | 715 | { |
tobyspark | 5:f8b285ca41ba | 716 | commsTypeString = "RJ45 not in DMX mode"; |
tobyspark | 5:f8b285ca41ba | 717 | } |
tobyspark | 5:f8b285ca41ba | 718 | // Action! |
tobyspark | 5:f8b285ca41ba | 719 | else if (commsMenu.selectedPayload1() == commsOSC) |
tobyspark | 5:f8b285ca41ba | 720 | { |
tobyspark | 5:f8b285ca41ba | 721 | commsMode = commsOSC; |
tobyspark | 5:f8b285ca41ba | 722 | commsTypeString = "OSC: "; |
tobyspark | 1:f9fca21102e0 | 723 | |
tobyspark | 1:f9fca21102e0 | 724 | ethernet = new EthernetNetIf( |
tobyspark | 1:f9fca21102e0 | 725 | IpAddr(kOSCMbedIPAddress), |
tobyspark | 1:f9fca21102e0 | 726 | IpAddr(kOSCMbedSubnetMask), |
tobyspark | 1:f9fca21102e0 | 727 | IpAddr(kOSCMbedGateway), |
tobyspark | 1:f9fca21102e0 | 728 | IpAddr(kOSCMbedDNS) |
tobyspark | 1:f9fca21102e0 | 729 | ); |
tobyspark | 3:033d2b7768f3 | 730 | |
tobyspark | 1:f9fca21102e0 | 731 | EthernetErr ethError = ethernet->setup(); |
tobyspark | 1:f9fca21102e0 | 732 | if(ethError) |
tobyspark | 1:f9fca21102e0 | 733 | { |
tobyspark | 1:f9fca21102e0 | 734 | if (debug) debug->printf("Ethernet setup error, %d", ethError); |
tobyspark | 1:f9fca21102e0 | 735 | commsStatus << "Ethernet setup failed"; |
tobyspark | 5:f8b285ca41ba | 736 | commsMenu = commsNone; |
tobyspark | 1:f9fca21102e0 | 737 | // break out of here. this setup should be a function that returns a boolean |
tobyspark | 1:f9fca21102e0 | 738 | } |
tobyspark | 1:f9fca21102e0 | 739 | |
tobyspark | 1:f9fca21102e0 | 740 | osc = new OSCClass(); |
tobyspark | 3:033d2b7768f3 | 741 | osc->setReceiveMessage(&recMessage); |
tobyspark | 1:f9fca21102e0 | 742 | osc->begin(kOSCMbedPort); |
tobyspark | 1:f9fca21102e0 | 743 | |
tobyspark | 3:033d2b7768f3 | 744 | commsStatus << "Listening on " << kOSCMbedPort; |
tobyspark | 1:f9fca21102e0 | 745 | } |
tobyspark | 1:f9fca21102e0 | 746 | else if (commsMenu.selectedPayload1() == commsArtNet) |
tobyspark | 1:f9fca21102e0 | 747 | { |
tobyspark | 5:f8b285ca41ba | 748 | commsMode = commsArtNet; |
tobyspark | 5:f8b285ca41ba | 749 | commsTypeString = "ArtNet: "; |
tobyspark | 3:033d2b7768f3 | 750 | |
tobyspark | 3:033d2b7768f3 | 751 | artNet = new DmxArtNet(); |
tobyspark | 1:f9fca21102e0 | 752 | |
tobyspark | 3:033d2b7768f3 | 753 | artNet->BindIpAddress = IpAddr(kArtNetBindIPAddress); |
tobyspark | 3:033d2b7768f3 | 754 | artNet->BCastAddress = IpAddr(kArtNetBroadcastAddress); |
tobyspark | 3:033d2b7768f3 | 755 | |
tobyspark | 3:033d2b7768f3 | 756 | artNet->InitArtPollReplyDefaults(); |
tobyspark | 3:033d2b7768f3 | 757 | |
tobyspark | 3:033d2b7768f3 | 758 | artNet->ArtPollReply.PortType[0] = 128; // output |
tobyspark | 3:033d2b7768f3 | 759 | artNet->ArtPollReply.PortType[2] = 64; // input |
tobyspark | 3:033d2b7768f3 | 760 | artNet->ArtPollReply.GoodInput[2] = 4; |
tobyspark | 3:033d2b7768f3 | 761 | |
tobyspark | 3:033d2b7768f3 | 762 | artNet->Init(); |
tobyspark | 3:033d2b7768f3 | 763 | artNet->SendArtPollReply(); // announce to art-net nodes |
tobyspark | 3:033d2b7768f3 | 764 | |
tobyspark | 3:033d2b7768f3 | 765 | commsStatus << "Listening"; |
tobyspark | 1:f9fca21102e0 | 766 | } |
tobyspark | 5:f8b285ca41ba | 767 | else if (commsMenu.selectedPayload1() == commsDMXIn) |
tobyspark | 1:f9fca21102e0 | 768 | { |
tobyspark | 5:f8b285ca41ba | 769 | commsMode = commsDMXIn; |
tobyspark | 5:f8b285ca41ba | 770 | commsTypeString = "DMX In: "; |
tobyspark | 1:f9fca21102e0 | 771 | |
tobyspark | 5:f8b285ca41ba | 772 | dmxDirectionDOUT = 0; |
tobyspark | 5:f8b285ca41ba | 773 | |
tobyspark | 5:f8b285ca41ba | 774 | dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX); |
tobyspark | 1:f9fca21102e0 | 775 | } |
tobyspark | 5:f8b285ca41ba | 776 | else if (commsMenu.selectedPayload1() == commsDMXOut) |
tobyspark | 5:f8b285ca41ba | 777 | { |
tobyspark | 5:f8b285ca41ba | 778 | commsMode = commsDMXOut; |
tobyspark | 5:f8b285ca41ba | 779 | commsTypeString = "DMX Out: "; |
tobyspark | 5:f8b285ca41ba | 780 | |
tobyspark | 5:f8b285ca41ba | 781 | dmxDirectionDOUT = 1; |
tobyspark | 5:f8b285ca41ba | 782 | |
tobyspark | 5:f8b285ca41ba | 783 | dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX); |
tobyspark | 5:f8b285ca41ba | 784 | } |
tobyspark | 5:f8b285ca41ba | 785 | |
tobyspark | 1:f9fca21102e0 | 786 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 787 | screen.textToBuffer(commsTypeString + commsStatus.str(), kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 788 | } |
tobyspark | 12:c270870bdd23 | 789 | else if (selectedMenu == &advancedMenu) |
tobyspark | 12:c270870bdd23 | 790 | { |
tobyspark | 12:c270870bdd23 | 791 | if (advancedMenu.selectedPayload1() == advancedHDCPOff) |
tobyspark | 12:c270870bdd23 | 792 | { |
tobyspark | 12:c270870bdd23 | 793 | bool ok = false; |
tobyspark | 12:c270870bdd23 | 794 | |
tobyspark | 15:4b394c64b461 | 795 | ok = tvOne.setHDCPOn(false); |
tobyspark | 12:c270870bdd23 | 796 | |
tobyspark | 12:c270870bdd23 | 797 | std::string sendOK = ok ? "Sent: HDCP Off" : "Send Error: HDCP Off"; |
tobyspark | 12:c270870bdd23 | 798 | |
tobyspark | 12:c270870bdd23 | 799 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 12:c270870bdd23 | 800 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 12:c270870bdd23 | 801 | } |
tobyspark | 15:4b394c64b461 | 802 | else if (advancedMenu.selectedPayload1() == advancedHDCPOn) |
tobyspark | 15:4b394c64b461 | 803 | { |
tobyspark | 15:4b394c64b461 | 804 | bool ok = false; |
tobyspark | 15:4b394c64b461 | 805 | |
tobyspark | 15:4b394c64b461 | 806 | ok = tvOne.setHDCPOn(true); |
tobyspark | 15:4b394c64b461 | 807 | |
tobyspark | 15:4b394c64b461 | 808 | std::string sendOK = ok ? "Sent: HDCP On" : "Send Error: HDCP On"; |
tobyspark | 15:4b394c64b461 | 809 | |
tobyspark | 15:4b394c64b461 | 810 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 15:4b394c64b461 | 811 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 15:4b394c64b461 | 812 | } |
tobyspark | 17:fc68d40b8b1f | 813 | else if (advancedMenu.selectedPayload1() == advancedConformProcessor) |
tobyspark | 17:fc68d40b8b1f | 814 | { |
tobyspark | 17:fc68d40b8b1f | 815 | bool ok = conformProcessor(); |
tobyspark | 17:fc68d40b8b1f | 816 | |
tobyspark | 17:fc68d40b8b1f | 817 | std::string sendOK = ok ? "Conform success" : "Send Error: Conform"; |
tobyspark | 17:fc68d40b8b1f | 818 | |
tobyspark | 17:fc68d40b8b1f | 819 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 17:fc68d40b8b1f | 820 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 17:fc68d40b8b1f | 821 | } |
tobyspark | 16:52484666b323 | 822 | else if (advancedMenu.selectedPayload1() == advancedLoadDefaults) |
tobyspark | 16:52484666b323 | 823 | { |
tobyspark | 16:52484666b323 | 824 | settings.loadDefaults(); |
tobyspark | 16:52484666b323 | 825 | |
tobyspark | 16:52484666b323 | 826 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 16:52484666b323 | 827 | screen.textToBuffer("Controller reverted", kTVOneStatusLine); |
tobyspark | 16:52484666b323 | 828 | } |
tobyspark | 15:4b394c64b461 | 829 | else if (advancedMenu.selectedPayload1() == advancedSelfTest) |
tobyspark | 15:4b394c64b461 | 830 | { |
tobyspark | 17:fc68d40b8b1f | 831 | selfTest(); |
tobyspark | 15:4b394c64b461 | 832 | } |
tobyspark | 12:c270870bdd23 | 833 | } |
tobyspark | 0:87aab40d5806 | 834 | else |
tobyspark | 0:87aab40d5806 | 835 | { |
tobyspark | 0:87aab40d5806 | 836 | if (debug) { debug->printf("Warning: No action identified"); } |
tobyspark | 0:87aab40d5806 | 837 | } |
tobyspark | 0:87aab40d5806 | 838 | } |
tobyspark | 0:87aab40d5806 | 839 | |
tobyspark | 2:50043054e4f7 | 840 | // Send any updates to the display |
tobyspark | 2:50043054e4f7 | 841 | screen.sendBuffer(); |
tobyspark | 5:f8b285ca41ba | 842 | |
tobyspark | 0:87aab40d5806 | 843 | |
tobyspark | 5:f8b285ca41ba | 844 | //// MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIXMIX MIX MIXMIX MIX MIX MIX MIX MIXMIX MIX MIX |
tobyspark | 0:87aab40d5806 | 845 | |
tobyspark | 0:87aab40d5806 | 846 | bool updateFade = false; |
tobyspark | 3:033d2b7768f3 | 847 | float xFade = 0; |
tobyspark | 3:033d2b7768f3 | 848 | float fadeUp = 1; |
tobyspark | 3:033d2b7768f3 | 849 | |
tobyspark | 3:033d2b7768f3 | 850 | //// TASK: Process control surface |
tobyspark | 3:033d2b7768f3 | 851 | |
tobyspark | 0:87aab40d5806 | 852 | // Get new states of tap buttons, remembering at end of loop() assign these current values to the previous variables |
tobyspark | 5:f8b285ca41ba | 853 | const bool tapLeft = !tapLeftDIN; |
tobyspark | 5:f8b285ca41ba | 854 | const bool tapRight = !tapRightDIN; |
tobyspark | 0:87aab40d5806 | 855 | |
tobyspark | 17:fc68d40b8b1f | 856 | // We're taking a further median of the AINs on top of mbed libs v29. |
tobyspark | 17:fc68d40b8b1f | 857 | // This takes some values from last passes and most from now. With debug off, seem to need median size > 5 |
tobyspark | 17:fc68d40b8b1f | 858 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 859 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 860 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 861 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 862 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 863 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 864 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 865 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 866 | const float xFadeAINCached = xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 867 | const float fadeUpAINCached = fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 0:87aab40d5806 | 868 | |
tobyspark | 0:87aab40d5806 | 869 | // When a tap is depressed, we can ignore any move of the crossfader but not fade to black |
tobyspark | 0:87aab40d5806 | 870 | if (tapLeft || tapRight) |
tobyspark | 0:87aab40d5806 | 871 | { |
tobyspark | 5:f8b285ca41ba | 872 | // If both are pressed, take to the one that is new, ie. not the first pressed. |
tobyspark | 0:87aab40d5806 | 873 | if (tapLeft && tapRight) |
tobyspark | 0:87aab40d5806 | 874 | { |
tobyspark | 5:f8b285ca41ba | 875 | xFade = tapLeftWasFirstPressed ? 1 : 0; |
tobyspark | 0:87aab40d5806 | 876 | } |
tobyspark | 5:f8b285ca41ba | 877 | // If just one is pressed, take to that and remember which is pressed |
tobyspark | 5:f8b285ca41ba | 878 | else if (tapLeft) |
tobyspark | 5:f8b285ca41ba | 879 | { |
tobyspark | 5:f8b285ca41ba | 880 | xFade = 0; |
tobyspark | 5:f8b285ca41ba | 881 | tapLeftWasFirstPressed = 1; |
tobyspark | 5:f8b285ca41ba | 882 | } |
tobyspark | 5:f8b285ca41ba | 883 | else if (tapRight) |
tobyspark | 5:f8b285ca41ba | 884 | { |
tobyspark | 5:f8b285ca41ba | 885 | xFade = 1; |
tobyspark | 5:f8b285ca41ba | 886 | tapLeftWasFirstPressed = 0; |
tobyspark | 5:f8b285ca41ba | 887 | } |
tobyspark | 5:f8b285ca41ba | 888 | } |
tobyspark | 0:87aab40d5806 | 889 | else xFade = fadeCalc(xFadeAINCached, xFadeTolerance); |
tobyspark | 0:87aab40d5806 | 890 | |
tobyspark | 0:87aab40d5806 | 891 | fadeUp = 1.0 - fadeCalc(fadeUpAINCached, fadeUpTolerance); |
tobyspark | 0:87aab40d5806 | 892 | |
tobyspark | 3:033d2b7768f3 | 893 | //// TASK: Process Network Comms |
tobyspark | 5:f8b285ca41ba | 894 | if (commsMode == commsOSC) |
tobyspark | 3:033d2b7768f3 | 895 | { |
tobyspark | 3:033d2b7768f3 | 896 | if (osc->newMessage) |
tobyspark | 3:033d2b7768f3 | 897 | { |
tobyspark | 3:033d2b7768f3 | 898 | osc->newMessage = false; // fixme! |
tobyspark | 3:033d2b7768f3 | 899 | processOSC(xFade, fadeUp); |
tobyspark | 3:033d2b7768f3 | 900 | } |
tobyspark | 3:033d2b7768f3 | 901 | } |
tobyspark | 3:033d2b7768f3 | 902 | |
tobyspark | 5:f8b285ca41ba | 903 | if (commsMode == commsArtNet) |
tobyspark | 3:033d2b7768f3 | 904 | { |
tobyspark | 3:033d2b7768f3 | 905 | if (artNet->Work()) processArtNet(xFade, fadeUp); |
tobyspark | 3:033d2b7768f3 | 906 | } |
tobyspark | 3:033d2b7768f3 | 907 | |
tobyspark | 5:f8b285ca41ba | 908 | if (commsMode == commsDMXIn) |
tobyspark | 5:f8b285ca41ba | 909 | { |
tobyspark | 5:f8b285ca41ba | 910 | processDMXIn(xFade, fadeUp); |
tobyspark | 5:f8b285ca41ba | 911 | } |
tobyspark | 5:f8b285ca41ba | 912 | |
tobyspark | 5:f8b285ca41ba | 913 | if (commsMode == commsDMXOut) |
tobyspark | 5:f8b285ca41ba | 914 | { |
tobyspark | 5:f8b285ca41ba | 915 | processDMXOut(xFade, fadeUp); |
tobyspark | 5:f8b285ca41ba | 916 | } |
tobyspark | 0:87aab40d5806 | 917 | |
tobyspark | 0:87aab40d5806 | 918 | // Calculate new A&B fade percents |
tobyspark | 0:87aab40d5806 | 919 | int newFadeAPercent = 0; |
tobyspark | 0:87aab40d5806 | 920 | int newFadeBPercent = 0; |
tobyspark | 0:87aab40d5806 | 921 | |
tobyspark | 15:4b394c64b461 | 922 | if (mixMode == mixBlend) |
tobyspark | 11:0783cfbeb746 | 923 | { |
tobyspark | 9:f83eadd8917a | 924 | if (fadeUp < 1.0) |
tobyspark | 9:f83eadd8917a | 925 | { |
tobyspark | 9:f83eadd8917a | 926 | // we need to set fade level of both windows as there is no way AFAIK to implement fade to black as a further window on top of A&B |
tobyspark | 9:f83eadd8917a | 927 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 9:f83eadd8917a | 928 | newFadeBPercent = xFade * fadeUp * 100.0; |
tobyspark | 9:f83eadd8917a | 929 | } |
tobyspark | 9:f83eadd8917a | 930 | else |
tobyspark | 9:f83eadd8917a | 931 | { |
tobyspark | 9:f83eadd8917a | 932 | // we can optimise and just fade A in and out over a fully up B, doubling the rate of fadeA commands sent. |
tobyspark | 9:f83eadd8917a | 933 | newFadeAPercent = (1.0-xFade) * 100.0; |
tobyspark | 9:f83eadd8917a | 934 | newFadeBPercent = 100.0; |
tobyspark | 9:f83eadd8917a | 935 | } |
tobyspark | 11:0783cfbeb746 | 936 | } |
tobyspark | 15:4b394c64b461 | 937 | else if (mixMode == mixAdditive) |
tobyspark | 11:0783cfbeb746 | 938 | { |
tobyspark | 9:f83eadd8917a | 939 | // we need to set fade level of both windows according to the fade curve profile (yet to implement - to do when tvone supply additive capability) |
tobyspark | 0:87aab40d5806 | 940 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 941 | newFadeBPercent = xFade * fadeUp * 100.0; |
tobyspark | 11:0783cfbeb746 | 942 | } |
tobyspark | 15:4b394c64b461 | 943 | else if (mixMode >= mixKey) |
tobyspark | 11:0783cfbeb746 | 944 | { |
tobyspark | 0:87aab40d5806 | 945 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 946 | newFadeBPercent = fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 947 | } |
tobyspark | 0:87aab40d5806 | 948 | |
tobyspark | 17:fc68d40b8b1f | 949 | //// TASK: Send to TVOne if percents have changed |
tobyspark | 17:fc68d40b8b1f | 950 | |
tobyspark | 17:fc68d40b8b1f | 951 | // No amount of median filtering is stopping flipflopping between two adjacent percents, so... |
tobyspark | 17:fc68d40b8b1f | 952 | bool fadeAPercentHasChanged; |
tobyspark | 17:fc68d40b8b1f | 953 | bool fadeBPercentHasChanged; |
tobyspark | 17:fc68d40b8b1f | 954 | if (oldFadeAPercent == newFadeAPercent && (newFadeAPercent == fadeAPercent - 1 || newFadeAPercent == fadeAPercent + 1)) |
tobyspark | 17:fc68d40b8b1f | 955 | fadeAPercentHasChanged = false; |
tobyspark | 17:fc68d40b8b1f | 956 | else |
tobyspark | 17:fc68d40b8b1f | 957 | fadeAPercentHasChanged = newFadeAPercent != fadeAPercent; |
tobyspark | 17:fc68d40b8b1f | 958 | if (oldFadeBPercent == newFadeBPercent && (newFadeBPercent == fadeBPercent - 1 || newFadeBPercent == fadeBPercent + 1)) |
tobyspark | 17:fc68d40b8b1f | 959 | fadeBPercentHasChanged = false; |
tobyspark | 17:fc68d40b8b1f | 960 | else |
tobyspark | 17:fc68d40b8b1f | 961 | fadeBPercentHasChanged = newFadeBPercent != fadeBPercent; |
tobyspark | 17:fc68d40b8b1f | 962 | |
tobyspark | 9:f83eadd8917a | 963 | // We want to send the higher first, otherwise black flashes can happen on taps |
tobyspark | 17:fc68d40b8b1f | 964 | if (fadeAPercentHasChanged && newFadeAPercent >= newFadeBPercent) |
tobyspark | 8:d46cc49f0f37 | 965 | { |
tobyspark | 17:fc68d40b8b1f | 966 | oldFadeAPercent = fadeAPercent; |
tobyspark | 0:87aab40d5806 | 967 | fadeAPercent = newFadeAPercent; |
tobyspark | 0:87aab40d5806 | 968 | updateFade = true; |
tobyspark | 0:87aab40d5806 | 969 | |
tobyspark | 0:87aab40d5806 | 970 | fadeAPO = fadeAPercent / 100.0; |
tobyspark | 0:87aab40d5806 | 971 | tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent); |
tobyspark | 0:87aab40d5806 | 972 | } |
tobyspark | 17:fc68d40b8b1f | 973 | if (fadeBPercentHasChanged) |
tobyspark | 8:d46cc49f0f37 | 974 | { |
tobyspark | 17:fc68d40b8b1f | 975 | oldFadeBPercent = fadeBPercent; |
tobyspark | 0:87aab40d5806 | 976 | fadeBPercent = newFadeBPercent; |
tobyspark | 0:87aab40d5806 | 977 | updateFade = true; |
tobyspark | 0:87aab40d5806 | 978 | |
tobyspark | 0:87aab40d5806 | 979 | fadeBPO = fadeBPercent / 100.0; |
tobyspark | 0:87aab40d5806 | 980 | tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent); |
tobyspark | 0:87aab40d5806 | 981 | } |
tobyspark | 17:fc68d40b8b1f | 982 | if (fadeAPercentHasChanged && newFadeAPercent < newFadeBPercent) |
tobyspark | 9:f83eadd8917a | 983 | { |
tobyspark | 17:fc68d40b8b1f | 984 | oldFadeAPercent = fadeAPercent; |
tobyspark | 9:f83eadd8917a | 985 | fadeAPercent = newFadeAPercent; |
tobyspark | 9:f83eadd8917a | 986 | updateFade = true; |
tobyspark | 9:f83eadd8917a | 987 | |
tobyspark | 9:f83eadd8917a | 988 | fadeAPO = fadeAPercent / 100.0; |
tobyspark | 9:f83eadd8917a | 989 | tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent); |
tobyspark | 9:f83eadd8917a | 990 | } |
tobyspark | 8:d46cc49f0f37 | 991 | if (updateFade && debug) |
tobyspark | 8:d46cc49f0f37 | 992 | { |
tobyspark | 0:87aab40d5806 | 993 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 994 | //debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAIN.read(), fadeUpAIN.read()); |
tobyspark | 0:87aab40d5806 | 995 | debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAINCached, fadeUpAINCached); |
tobyspark | 0:87aab40d5806 | 996 | debug->printf("xFade = %3f fadeUp = %3f fadeA% = %i fadeB% = %i \r\n", xFade, fadeUp, fadeAPercent, fadeBPercent); |
tobyspark | 0:87aab40d5806 | 997 | } |
tobyspark | 0:87aab40d5806 | 998 | } |
tobyspark | 0:87aab40d5806 | 999 | } |