![](/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@29:95a7efe30527, 2012-10-28 (annotated)
- Committer:
- tobyspark
- Date:
- Sun Oct 28 19:55:35 2012 +0000
- Revision:
- 29:95a7efe30527
- Parent:
- 27:27851d3d2bba
- Child:
- 30:873979018850
Mixing implemented as continuum between Blend and Additive; Safe mix mode with no optimisations, eg. works when a source is not valid and has never had a frame to hold on.
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 | 13:3796bde6ba8f | 60 | #define kSPKDFSoftwareVersion "beta.19" |
tobyspark | 13:3796bde6ba8f | 61 | |
tobyspark | 5:f8b285ca41ba | 62 | // MBED PINS |
tobyspark | 5:f8b285ca41ba | 63 | |
tobyspark | 5:f8b285ca41ba | 64 | #define kMBED_AIN_XFADE p20 |
tobyspark | 5:f8b285ca41ba | 65 | #define kMBED_AIN_FADEUP p19 |
tobyspark | 5:f8b285ca41ba | 66 | #define kMBED_DIN_TAP_L p24 |
tobyspark | 5:f8b285ca41ba | 67 | #define kMBED_DIN_TAP_R p23 |
tobyspark | 5:f8b285ca41ba | 68 | #define kMBED_ENC_SW p15 |
tobyspark | 5:f8b285ca41ba | 69 | #define kMBED_ENC_A p16 |
tobyspark | 5:f8b285ca41ba | 70 | #define kMBED_ENC_B p17 |
tobyspark | 5:f8b285ca41ba | 71 | |
tobyspark | 5:f8b285ca41ba | 72 | #define kMBED_RS232_TTLTX p13 |
tobyspark | 5:f8b285ca41ba | 73 | #define kMBED_RS232_TTLRX p14 |
tobyspark | 5:f8b285ca41ba | 74 | |
tobyspark | 5:f8b285ca41ba | 75 | #define kMBED_OLED_MOSI p5 |
tobyspark | 5:f8b285ca41ba | 76 | #define kMBED_OLED_SCK p7 |
tobyspark | 5:f8b285ca41ba | 77 | #define kMBED_OLED_CS p8 |
tobyspark | 5:f8b285ca41ba | 78 | #define kMBED_OLED_RES p9 |
tobyspark | 5:f8b285ca41ba | 79 | #define kMBED_OLED_DC p10 |
tobyspark | 5:f8b285ca41ba | 80 | |
tobyspark | 5:f8b285ca41ba | 81 | #define kMBED_DIN_ETHLO_DMXHI p30 |
tobyspark | 5:f8b285ca41ba | 82 | #define kMBED_DOUT_RS485_TXHI_RXLO p29 |
tobyspark | 5:f8b285ca41ba | 83 | #define kMBED_RS485_TTLTX p28 |
tobyspark | 5:f8b285ca41ba | 84 | #define kMBED_RS485_TTLRX p27 |
tobyspark | 5:f8b285ca41ba | 85 | |
tobyspark | 5:f8b285ca41ba | 86 | // DISPLAY |
tobyspark | 5:f8b285ca41ba | 87 | |
tobyspark | 1:f9fca21102e0 | 88 | #define kMenuLine1 3 |
tobyspark | 1:f9fca21102e0 | 89 | #define kMenuLine2 4 |
tobyspark | 1:f9fca21102e0 | 90 | #define kCommsStatusLine 6 |
tobyspark | 1:f9fca21102e0 | 91 | #define kTVOneStatusLine 7 |
tobyspark | 1:f9fca21102e0 | 92 | |
tobyspark | 5:f8b285ca41ba | 93 | // NETWORKING |
tobyspark | 5:f8b285ca41ba | 94 | |
tobyspark | 1:f9fca21102e0 | 95 | #define kOSCMbedPort 10000 |
tobyspark | 1:f9fca21102e0 | 96 | #define kOSCMbedIPAddress 10,0,0,2 |
tobyspark | 1:f9fca21102e0 | 97 | #define kOSCMbedSubnetMask 255,255,255,0 |
tobyspark | 1:f9fca21102e0 | 98 | #define kOSCMbedGateway 10,0,0,1 |
tobyspark | 1:f9fca21102e0 | 99 | #define kOSCMbedDNS 10,0,0,1 |
tobyspark | 0:87aab40d5806 | 100 | |
tobyspark | 3:033d2b7768f3 | 101 | #define kArtNetBindIPAddress 2,0,0,100 |
tobyspark | 3:033d2b7768f3 | 102 | #define kArtNetBroadcastAddress 2,255,255,255 |
tobyspark | 3:033d2b7768f3 | 103 | |
tobyspark | 5:f8b285ca41ba | 104 | #define kDMXInChannelXFade 0 |
tobyspark | 5:f8b285ca41ba | 105 | #define kDMXInChannelFadeUp 1 |
tobyspark | 5:f8b285ca41ba | 106 | #define kDMXOutChannelXFade 0 |
tobyspark | 5:f8b285ca41ba | 107 | #define kDMXOutChannelFadeUp 1 |
tobyspark | 5:f8b285ca41ba | 108 | |
tobyspark | 13:3796bde6ba8f | 109 | // 8.3 format filename only, no subdirs |
tobyspark | 13:3796bde6ba8f | 110 | #define kSPKDFSettingsFilename "SPKDF.ini" |
tobyspark | 11:0783cfbeb746 | 111 | |
tobyspark | 26:0299f8760715 | 112 | #define kStringBufferLength 30 |
tobyspark | 26:0299f8760715 | 113 | |
tobyspark | 0:87aab40d5806 | 114 | //// DEBUG |
tobyspark | 0:87aab40d5806 | 115 | |
tobyspark | 0:87aab40d5806 | 116 | // Comment out one or the other... |
tobyspark | 29:95a7efe30527 | 117 | //Serial *debug = new Serial(USBTX, USBRX); // For debugging via USB serial |
tobyspark | 29:95a7efe30527 | 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 | 23:909928cafb95 | 155 | SPKMenu mainMenu; |
tobyspark | 23:909928cafb95 | 156 | SPKMenu resolutionMenu; |
tobyspark | 12:c270870bdd23 | 157 | |
tobyspark | 24:49c6624119ae | 158 | SPKMenu mixModeMenu; |
tobyspark | 24:49c6624119ae | 159 | SPKMenu mixModeAdditiveMenu; |
tobyspark | 29:95a7efe30527 | 160 | enum { mixSafe, mixBlend, mixAdditive, mixKey }; // additive will require custom TVOne firmware. |
tobyspark | 15:4b394c64b461 | 161 | int mixMode = mixBlend; |
tobyspark | 29:95a7efe30527 | 162 | float fadeCurve = 0.0f; // 0 = "X", ie. as per blend, 1 = "/\", ie. as per additive <-- pictograms! |
tobyspark | 22:90054fe6d86c | 163 | |
tobyspark | 23:909928cafb95 | 164 | SPKMenu commsMenu; |
tobyspark | 5:f8b285ca41ba | 165 | enum { commsNone, commsOSC, commsArtNet, commsDMXIn, commsDMXOut}; |
tobyspark | 5:f8b285ca41ba | 166 | int commsMode = commsNone; |
tobyspark | 22:90054fe6d86c | 167 | |
tobyspark | 23:909928cafb95 | 168 | SPKMenu advancedMenu; |
tobyspark | 29:95a7efe30527 | 169 | enum { advancedHDCPOn, advancedHDCPOff, advancedMixModeSafe, advancedConformProcessor, advancedLoadDefaults, advancedSelfTest, advancedSetResolutions }; |
tobyspark | 1:f9fca21102e0 | 170 | |
tobyspark | 5:f8b285ca41ba | 171 | // RJ45 Comms |
tobyspark | 5:f8b285ca41ba | 172 | enum { rj45Ethernet = 0, rj45DMX = 1}; // These values from circuit |
tobyspark | 5:f8b285ca41ba | 173 | int rj45Mode = -1; |
tobyspark | 1:f9fca21102e0 | 174 | EthernetNetIf *ethernet = NULL; |
tobyspark | 1:f9fca21102e0 | 175 | OSCClass *osc = NULL; |
tobyspark | 3:033d2b7768f3 | 176 | OSCMessage recMessage; |
tobyspark | 3:033d2b7768f3 | 177 | DmxArtNet *artNet = NULL; |
tobyspark | 5:f8b285ca41ba | 178 | DMX *dmx = NULL; |
tobyspark | 0:87aab40d5806 | 179 | |
tobyspark | 3:033d2b7768f3 | 180 | // Fade logic constants |
tobyspark | 0:87aab40d5806 | 181 | const float xFadeTolerance = 0.05; |
tobyspark | 0:87aab40d5806 | 182 | const float fadeUpTolerance = 0.05; |
tobyspark | 0:87aab40d5806 | 183 | |
tobyspark | 0:87aab40d5806 | 184 | // A&B Fade as resolved percent |
tobyspark | 0:87aab40d5806 | 185 | int fadeAPercent = 0; |
tobyspark | 0:87aab40d5806 | 186 | int fadeBPercent = 0; |
tobyspark | 17:fc68d40b8b1f | 187 | int oldFadeAPercent = 0; |
tobyspark | 17:fc68d40b8b1f | 188 | int oldFadeBPercent = 0; |
tobyspark | 0:87aab40d5806 | 189 | |
tobyspark | 0:87aab40d5806 | 190 | // Tap button states |
tobyspark | 5:f8b285ca41ba | 191 | bool tapLeftWasFirstPressed = false; |
tobyspark | 0:87aab40d5806 | 192 | |
tobyspark | 0:87aab40d5806 | 193 | // Key mode parameters |
tobyspark | 0:87aab40d5806 | 194 | int keyerParamsSet = -1; // last keyParams index uploaded to unit |
tobyspark | 0:87aab40d5806 | 195 | |
tobyspark | 3:033d2b7768f3 | 196 | void processOSC(float &xFade, float &fadeUp) { |
tobyspark | 25:3b519ef70341 | 197 | string statusMessage; |
tobyspark | 3:033d2b7768f3 | 198 | |
tobyspark | 3:033d2b7768f3 | 199 | if (!strcmp( recMessage.getTopAddress() , "dvimxr" )) |
tobyspark | 3:033d2b7768f3 | 200 | { |
tobyspark | 25:3b519ef70341 | 201 | statusMessage = "OSC: /dvimxr"; |
tobyspark | 3:033d2b7768f3 | 202 | if (!strcmp( recMessage.getSubAddress() , "xFade" )) |
tobyspark | 25:3b519ef70341 | 203 | { |
tobyspark | 25:3b519ef70341 | 204 | if (recMessage.getArgNum() == 1) |
tobyspark | 25:3b519ef70341 | 205 | if (recMessage.getTypeTag(0) == 'f') |
tobyspark | 25:3b519ef70341 | 206 | { |
tobyspark | 25:3b519ef70341 | 207 | xFade = recMessage.getArgFloat(0); |
tobyspark | 25:3b519ef70341 | 208 | char buffer[15]; |
tobyspark | 26:0299f8760715 | 209 | snprintf(buffer, kStringBufferLength, "/xFade %1.2f", xFade); |
tobyspark | 25:3b519ef70341 | 210 | statusMessage += buffer; |
tobyspark | 25:3b519ef70341 | 211 | } |
tobyspark | 25:3b519ef70341 | 212 | } |
tobyspark | 25:3b519ef70341 | 213 | else if (!strcmp( recMessage.getSubAddress() , "fadeUp" )) |
tobyspark | 25:3b519ef70341 | 214 | { |
tobyspark | 3:033d2b7768f3 | 215 | if (recMessage.getArgNum() == 1) |
tobyspark | 3:033d2b7768f3 | 216 | if (recMessage.getTypeTag(0) == 'f') |
tobyspark | 3:033d2b7768f3 | 217 | { |
tobyspark | 25:3b519ef70341 | 218 | fadeUp = recMessage.getArgFloat(0); |
tobyspark | 25:3b519ef70341 | 219 | char buffer[15]; |
tobyspark | 26:0299f8760715 | 220 | snprintf(buffer, kStringBufferLength, "/fadeUp %1.2f", fadeUp); |
tobyspark | 25:3b519ef70341 | 221 | statusMessage += buffer; |
tobyspark | 3:033d2b7768f3 | 222 | } |
tobyspark | 25:3b519ef70341 | 223 | } |
tobyspark | 25:3b519ef70341 | 224 | else |
tobyspark | 25:3b519ef70341 | 225 | { |
tobyspark | 25:3b519ef70341 | 226 | statusMessage += recMessage.getSubAddress(); |
tobyspark | 25:3b519ef70341 | 227 | statusMessage += " - Ignoring"; |
tobyspark | 25:3b519ef70341 | 228 | } |
tobyspark | 3:033d2b7768f3 | 229 | } |
tobyspark | 3:033d2b7768f3 | 230 | else |
tobyspark | 3:033d2b7768f3 | 231 | { |
tobyspark | 25:3b519ef70341 | 232 | statusMessage = "OSC: "; |
tobyspark | 25:3b519ef70341 | 233 | statusMessage += recMessage.getTopAddress(); |
tobyspark | 25:3b519ef70341 | 234 | statusMessage += " - Ignoring"; |
tobyspark | 3:033d2b7768f3 | 235 | } |
tobyspark | 3:033d2b7768f3 | 236 | |
tobyspark | 3:033d2b7768f3 | 237 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 25:3b519ef70341 | 238 | screen.textToBuffer(statusMessage, kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 239 | screen.sendBuffer(); |
tobyspark | 25:3b519ef70341 | 240 | if (debug) debug->printf("%s \r\n", statusMessage.c_str()); |
tobyspark | 3:033d2b7768f3 | 241 | |
tobyspark | 3:033d2b7768f3 | 242 | } |
tobyspark | 3:033d2b7768f3 | 243 | |
tobyspark | 8:d46cc49f0f37 | 244 | void processArtNet(float &xFade, float &fadeUp) |
tobyspark | 8:d46cc49f0f37 | 245 | { |
tobyspark | 3:033d2b7768f3 | 246 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 247 | screen.textToBuffer("ArtNet activity", kCommsStatusLine); |
tobyspark | 3:033d2b7768f3 | 248 | screen.sendBuffer(); |
tobyspark | 3:033d2b7768f3 | 249 | if (debug) debug->printf("ArtNet activity"); |
tobyspark | 3:033d2b7768f3 | 250 | } |
tobyspark | 0:87aab40d5806 | 251 | |
tobyspark | 8:d46cc49f0f37 | 252 | void processDMXIn(float &xFade, float &fadeUp) |
tobyspark | 8:d46cc49f0f37 | 253 | { |
tobyspark | 26:0299f8760715 | 254 | char statusMessageBuffer[kStringBufferLength]; |
tobyspark | 5:f8b285ca41ba | 255 | |
tobyspark | 5:f8b285ca41ba | 256 | int xFadeDMX = dmx->get(kDMXInChannelXFade); |
tobyspark | 7:e6717468c18d | 257 | int fadeUpDMX = dmx->get(kDMXInChannelFadeUp); |
tobyspark | 5:f8b285ca41ba | 258 | |
tobyspark | 5:f8b285ca41ba | 259 | xFade = (float)xFadeDMX/255; |
tobyspark | 5:f8b285ca41ba | 260 | fadeUp = (float)fadeUpDMX/255; |
tobyspark | 5:f8b285ca41ba | 261 | |
tobyspark | 5:f8b285ca41ba | 262 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 26:0299f8760715 | 263 | snprintf(statusMessageBuffer, kStringBufferLength, "DMX In: xF %3i fUp %3i", xFadeDMX, fadeUpDMX); |
tobyspark | 25:3b519ef70341 | 264 | screen.textToBuffer(statusMessageBuffer, kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 265 | screen.sendBuffer(); |
tobyspark | 25:3b519ef70341 | 266 | if (debug) debug->printf(statusMessageBuffer); |
tobyspark | 5:f8b285ca41ba | 267 | } |
tobyspark | 5:f8b285ca41ba | 268 | |
tobyspark | 8:d46cc49f0f37 | 269 | void processDMXOut(float &xFade, float &fadeUp) |
tobyspark | 8:d46cc49f0f37 | 270 | { |
tobyspark | 26:0299f8760715 | 271 | char statusMessageBuffer[kStringBufferLength]; |
tobyspark | 5:f8b285ca41ba | 272 | |
tobyspark | 5:f8b285ca41ba | 273 | int xFadeDMX = xFade*255; |
tobyspark | 5:f8b285ca41ba | 274 | int fadeUpDMX = fadeUp*255; |
tobyspark | 5:f8b285ca41ba | 275 | |
tobyspark | 5:f8b285ca41ba | 276 | dmx->put(kDMXOutChannelXFade, xFadeDMX); |
tobyspark | 5:f8b285ca41ba | 277 | dmx->put(kDMXOutChannelFadeUp, fadeUpDMX); |
tobyspark | 5:f8b285ca41ba | 278 | |
tobyspark | 5:f8b285ca41ba | 279 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 26:0299f8760715 | 280 | snprintf(statusMessageBuffer, kStringBufferLength, "DMX Out: xF %3i fUp %3i", xFadeDMX, fadeUpDMX); |
tobyspark | 25:3b519ef70341 | 281 | screen.textToBuffer(statusMessageBuffer, kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 282 | screen.sendBuffer(); |
tobyspark | 25:3b519ef70341 | 283 | if (debug) debug->printf(statusMessageBuffer); |
tobyspark | 5:f8b285ca41ba | 284 | } |
tobyspark | 0:87aab40d5806 | 285 | |
tobyspark | 8:d46cc49f0f37 | 286 | inline float fadeCalc (const float AIN, const float tolerance) |
tobyspark | 8:d46cc49f0f37 | 287 | { |
tobyspark | 0:87aab40d5806 | 288 | float pos ; |
tobyspark | 0:87aab40d5806 | 289 | if (AIN < tolerance) pos = 0; |
tobyspark | 0:87aab40d5806 | 290 | else if (AIN > 1.0 - tolerance) pos = 1; |
tobyspark | 0:87aab40d5806 | 291 | else pos = (AIN - tolerance) / (1 - 2*tolerance); |
tobyspark | 0:87aab40d5806 | 292 | if (debug && false) debug->printf("fadeCalc in: %f out: %f \r\n", AIN, pos); |
tobyspark | 0:87aab40d5806 | 293 | return pos; |
tobyspark | 0:87aab40d5806 | 294 | } |
tobyspark | 0:87aab40d5806 | 295 | |
tobyspark | 8:d46cc49f0f37 | 296 | bool setKeyParamsTo(int index) |
tobyspark | 8:d46cc49f0f37 | 297 | { |
tobyspark | 0:87aab40d5806 | 298 | // Only spend the time uploading six parameters if we need to |
tobyspark | 0:87aab40d5806 | 299 | // Might want to bounds check here |
tobyspark | 0:87aab40d5806 | 300 | |
tobyspark | 9:f83eadd8917a | 301 | bool ok; |
tobyspark | 0:87aab40d5806 | 302 | |
tobyspark | 0:87aab40d5806 | 303 | if (index != keyerParamsSet) |
tobyspark | 0:87aab40d5806 | 304 | { |
tobyspark | 11:0783cfbeb746 | 305 | ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinY, settings.keyerParamSet(index)[0]); |
tobyspark | 11:0783cfbeb746 | 306 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxY, settings.keyerParamSet(index)[1]); |
tobyspark | 11:0783cfbeb746 | 307 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinU, settings.keyerParamSet(index)[2]); |
tobyspark | 11:0783cfbeb746 | 308 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxU, settings.keyerParamSet(index)[3]); |
tobyspark | 11:0783cfbeb746 | 309 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMinV, settings.keyerParamSet(index)[4]); |
tobyspark | 11:0783cfbeb746 | 310 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerMaxV, settings.keyerParamSet(index)[5]); |
tobyspark | 0:87aab40d5806 | 311 | |
tobyspark | 0:87aab40d5806 | 312 | keyerParamsSet = index; |
tobyspark | 9:f83eadd8917a | 313 | } |
tobyspark | 9:f83eadd8917a | 314 | else |
tobyspark | 9:f83eadd8917a | 315 | { |
tobyspark | 9:f83eadd8917a | 316 | ok = true; |
tobyspark | 9:f83eadd8917a | 317 | } |
tobyspark | 0:87aab40d5806 | 318 | |
tobyspark | 0:87aab40d5806 | 319 | return ok; |
tobyspark | 0:87aab40d5806 | 320 | } |
tobyspark | 0:87aab40d5806 | 321 | |
tobyspark | 24:49c6624119ae | 322 | void actionMixMode() |
tobyspark | 24:49c6624119ae | 323 | { |
tobyspark | 24:49c6624119ae | 324 | bool ok = true; |
tobyspark | 25:3b519ef70341 | 325 | string sentOK; |
tobyspark | 26:0299f8760715 | 326 | char sentMSGBuffer[kStringBufferLength]; |
tobyspark | 24:49c6624119ae | 327 | |
tobyspark | 24:49c6624119ae | 328 | // Set Keyer |
tobyspark | 24:49c6624119ae | 329 | if (mixMode < mixKey) |
tobyspark | 24:49c6624119ae | 330 | { |
tobyspark | 29:95a7efe30527 | 331 | if (mixMode == mixBlend || mixMode == mixSafe) |
tobyspark | 24:49c6624119ae | 332 | { |
tobyspark | 24:49c6624119ae | 333 | // Waiting on TV One... |
tobyspark | 24:49c6624119ae | 334 | } |
tobyspark | 24:49c6624119ae | 335 | else if (mixMode == mixAdditive) |
tobyspark | 24:49c6624119ae | 336 | { |
tobyspark | 24:49c6624119ae | 337 | // Waiting on TV One... |
tobyspark | 24:49c6624119ae | 338 | } |
tobyspark | 24:49c6624119ae | 339 | |
tobyspark | 24:49c6624119ae | 340 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, false); |
tobyspark | 26:0299f8760715 | 341 | snprintf(sentMSGBuffer, kStringBufferLength, "Keyer Off"); |
tobyspark | 24:49c6624119ae | 342 | } |
tobyspark | 24:49c6624119ae | 343 | else |
tobyspark | 24:49c6624119ae | 344 | { |
tobyspark | 25:3b519ef70341 | 345 | int index = mixMode - mixKey; |
tobyspark | 25:3b519ef70341 | 346 | |
tobyspark | 24:49c6624119ae | 347 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustKeyerEnable, true); |
tobyspark | 24:49c6624119ae | 348 | ok = ok && setKeyParamsTo(index); |
tobyspark | 25:3b519ef70341 | 349 | |
tobyspark | 26:0299f8760715 | 350 | snprintf(sentMSGBuffer, kStringBufferLength, "Keyer On with %i", index); |
tobyspark | 24:49c6624119ae | 351 | } |
tobyspark | 24:49c6624119ae | 352 | |
tobyspark | 24:49c6624119ae | 353 | if (ok) sentOK = "Sent:"; |
tobyspark | 24:49c6624119ae | 354 | else sentOK = "Send Error:"; |
tobyspark | 24:49c6624119ae | 355 | |
tobyspark | 24:49c6624119ae | 356 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 25:3b519ef70341 | 357 | screen.textToBuffer(sentOK + sentMSGBuffer, kTVOneStatusLine); |
tobyspark | 24:49c6624119ae | 358 | |
tobyspark | 24:49c6624119ae | 359 | if (debug) { debug->printf("Changing mix mode"); } |
tobyspark | 24:49c6624119ae | 360 | } |
tobyspark | 24:49c6624119ae | 361 | |
tobyspark | 24:49c6624119ae | 362 | |
tobyspark | 17:fc68d40b8b1f | 363 | bool conformProcessor() |
tobyspark | 17:fc68d40b8b1f | 364 | { |
tobyspark | 17:fc68d40b8b1f | 365 | bool ok = true; |
tobyspark | 17:fc68d40b8b1f | 366 | |
tobyspark | 17:fc68d40b8b1f | 367 | int32_t on = 1; |
tobyspark | 17:fc68d40b8b1f | 368 | int32_t off = 0; |
tobyspark | 20:8b92d7922c48 | 369 | |
tobyspark | 20:8b92d7922c48 | 370 | // Independent output |
tobyspark | 20:8b92d7922c48 | 371 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputEnable, on); |
tobyspark | 20:8b92d7922c48 | 372 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsLockMethod, off); |
tobyspark | 17:fc68d40b8b1f | 373 | |
tobyspark | 17:fc68d40b8b1f | 374 | // Make sure our windows exist |
tobyspark | 17:fc68d40b8b1f | 375 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsEnable, on); |
tobyspark | 17:fc68d40b8b1f | 376 | ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsEnable, on); |
tobyspark | 18:ebe5da639a6a | 377 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsLayerPriority, 0); |
tobyspark | 18:ebe5da639a6a | 378 | ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsLayerPriority, 1); |
tobyspark | 17:fc68d40b8b1f | 379 | |
tobyspark | 17:fc68d40b8b1f | 380 | // Assign inputs to windows, so that left on the crossfader is left on the processor viewed from front |
tobyspark | 17:fc68d40b8b1f | 381 | ok = ok && tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB2); |
tobyspark | 17:fc68d40b8b1f | 382 | ok = ok && tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsWindowSource, kTV1SourceRGB1); |
tobyspark | 17:fc68d40b8b1f | 383 | |
tobyspark | 17:fc68d40b8b1f | 384 | // Set scaling to fit source within output, maintaining aspect ratio |
tobyspark | 17:fc68d40b8b1f | 385 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustWindowsZoomLevel, 100); |
tobyspark | 17:fc68d40b8b1f | 386 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDB, kTV1FunctionAdjustWindowsZoomLevel, 100); |
tobyspark | 17:fc68d40b8b1f | 387 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustWindowsShrinkEnable, off); |
tobyspark | 17:fc68d40b8b1f | 388 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDB, kTV1FunctionAdjustWindowsShrinkEnable, off); |
tobyspark | 17:fc68d40b8b1f | 389 | int32_t fit = 1; |
tobyspark | 17:fc68d40b8b1f | 390 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, fit); |
tobyspark | 17:fc68d40b8b1f | 391 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAspectCorrect, fit); |
tobyspark | 17:fc68d40b8b1f | 392 | |
tobyspark | 17:fc68d40b8b1f | 393 | // On source loss, hold on the last frame received. |
tobyspark | 17:fc68d40b8b1f | 394 | int32_t freeze = 1; |
tobyspark | 17:fc68d40b8b1f | 395 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze); |
tobyspark | 17:fc68d40b8b1f | 396 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceOnSourceLoss, freeze); |
tobyspark | 17:fc68d40b8b1f | 397 | |
tobyspark | 17:fc68d40b8b1f | 398 | // Finally, autoset to sources? |
tobyspark | 17:fc68d40b8b1f | 399 | //int32_t start = 1; |
tobyspark | 17:fc68d40b8b1f | 400 | //ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceAutoSet, start); |
tobyspark | 17:fc68d40b8b1f | 401 | //ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceAutoSet, start); |
tobyspark | 17:fc68d40b8b1f | 402 | |
tobyspark | 17:fc68d40b8b1f | 403 | return ok; |
tobyspark | 17:fc68d40b8b1f | 404 | } |
tobyspark | 17:fc68d40b8b1f | 405 | |
tobyspark | 17:fc68d40b8b1f | 406 | void selfTest() |
tobyspark | 17:fc68d40b8b1f | 407 | { |
tobyspark | 17:fc68d40b8b1f | 408 | /* SELF TEST - Pixels |
tobyspark | 17:fc68d40b8b1f | 409 | * Clicking �self-test� menu will display a solid lit screen. Check all pixels lit. |
tobyspark | 17:fc68d40b8b1f | 410 | * Verified: Display |
tobyspark | 17:fc68d40b8b1f | 411 | */ |
tobyspark | 17:fc68d40b8b1f | 412 | |
tobyspark | 17:fc68d40b8b1f | 413 | screen.imageToBuffer(spkDisplayAllPixelsOn); |
tobyspark | 17:fc68d40b8b1f | 414 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 415 | |
tobyspark | 17:fc68d40b8b1f | 416 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 417 | { |
tobyspark | 17:fc68d40b8b1f | 418 | // do nothing, wait for press |
tobyspark | 17:fc68d40b8b1f | 419 | } |
tobyspark | 17:fc68d40b8b1f | 420 | |
tobyspark | 17:fc68d40b8b1f | 421 | /* SELF TEST - Mixing Controls |
tobyspark | 17:fc68d40b8b1f | 422 | * 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 | 423 | * Verified: Mixing controls. |
tobyspark | 17:fc68d40b8b1f | 424 | */ |
tobyspark | 17:fc68d40b8b1f | 425 | |
tobyspark | 17:fc68d40b8b1f | 426 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 427 | screen.textToBuffer("Self test - Mixing Controls", 0); |
tobyspark | 17:fc68d40b8b1f | 428 | |
tobyspark | 17:fc68d40b8b1f | 429 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 430 | { |
tobyspark | 26:0299f8760715 | 431 | char xFadeReadOut[kStringBufferLength]; |
tobyspark | 26:0299f8760715 | 432 | char fadeToBlackReadOut[kStringBufferLength]; |
tobyspark | 26:0299f8760715 | 433 | char tapsReadOut[kStringBufferLength]; |
tobyspark | 17:fc68d40b8b1f | 434 | |
tobyspark | 26:0299f8760715 | 435 | snprintf(xFadeReadOut, kStringBufferLength, "Crossfade: %1.3f", xFadeAIN.read()); |
tobyspark | 26:0299f8760715 | 436 | snprintf(fadeToBlackReadOut, kStringBufferLength, "Fade to black: %1.3f", fadeUpAIN.read()); |
tobyspark | 26:0299f8760715 | 437 | snprintf(tapsReadOut, kStringBufferLength, "Tap left: %i, right: %i", tapLeftDIN.read(), tapRightDIN.read()); |
tobyspark | 17:fc68d40b8b1f | 438 | |
tobyspark | 17:fc68d40b8b1f | 439 | screen.clearBufferRow(1); |
tobyspark | 17:fc68d40b8b1f | 440 | screen.clearBufferRow(2); |
tobyspark | 17:fc68d40b8b1f | 441 | screen.clearBufferRow(3); |
tobyspark | 17:fc68d40b8b1f | 442 | |
tobyspark | 25:3b519ef70341 | 443 | screen.textToBuffer(xFadeReadOut, 1); |
tobyspark | 25:3b519ef70341 | 444 | screen.textToBuffer(fadeToBlackReadOut, 2); |
tobyspark | 25:3b519ef70341 | 445 | screen.textToBuffer(tapsReadOut, 3); |
tobyspark | 17:fc68d40b8b1f | 446 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 447 | } |
tobyspark | 17:fc68d40b8b1f | 448 | |
tobyspark | 17:fc68d40b8b1f | 449 | /* SELF TEST - RS232 |
tobyspark | 17:fc68d40b8b1f | 450 | * Click the controller menu control. Should see �RS232 test� prompt and test message. Ensure PC is displaying the test message. |
tobyspark | 17:fc68d40b8b1f | 451 | * Verified: RS232 connection. |
tobyspark | 17:fc68d40b8b1f | 452 | */ |
tobyspark | 17:fc68d40b8b1f | 453 | |
tobyspark | 17:fc68d40b8b1f | 454 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 455 | screen.textToBuffer("Self test - RS232", 0); |
tobyspark | 17:fc68d40b8b1f | 456 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 457 | |
tobyspark | 17:fc68d40b8b1f | 458 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 459 | { |
tobyspark | 17:fc68d40b8b1f | 460 | screen.textToBuffer("TODO!", 1); |
tobyspark | 17:fc68d40b8b1f | 461 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 462 | } |
tobyspark | 17:fc68d40b8b1f | 463 | |
tobyspark | 17:fc68d40b8b1f | 464 | /* SELF TEST - DMX |
tobyspark | 17:fc68d40b8b1f | 465 | * Click the controller menu control. Should see �DMX test� prompt and test message. Ensure PC is displaying the test message. |
tobyspark | 17:fc68d40b8b1f | 466 | * Verified: RS485 connection and DMX library. |
tobyspark | 17:fc68d40b8b1f | 467 | */ |
tobyspark | 17:fc68d40b8b1f | 468 | |
tobyspark | 17:fc68d40b8b1f | 469 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 470 | screen.textToBuffer("Self test - DMX", 0); |
tobyspark | 17:fc68d40b8b1f | 471 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 472 | |
tobyspark | 17:fc68d40b8b1f | 473 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 474 | { |
tobyspark | 17:fc68d40b8b1f | 475 | screen.textToBuffer("TODO!", 1); |
tobyspark | 17:fc68d40b8b1f | 476 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 477 | } |
tobyspark | 17:fc68d40b8b1f | 478 | |
tobyspark | 17:fc68d40b8b1f | 479 | /* SELF TEST - OSC |
tobyspark | 17:fc68d40b8b1f | 480 | * Click the controller menu control. Should see �OSC test� prompt and test message. Ensure PC is displaying the test message. |
tobyspark | 17:fc68d40b8b1f | 481 | * Verified: Ethernet connection and OSC library. |
tobyspark | 17:fc68d40b8b1f | 482 | */ |
tobyspark | 17:fc68d40b8b1f | 483 | |
tobyspark | 17:fc68d40b8b1f | 484 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 485 | screen.textToBuffer("Self test - DMX", 0); |
tobyspark | 17:fc68d40b8b1f | 486 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 487 | |
tobyspark | 17:fc68d40b8b1f | 488 | while(!menuEnc.hasPressed()) |
tobyspark | 17:fc68d40b8b1f | 489 | { |
tobyspark | 17:fc68d40b8b1f | 490 | screen.textToBuffer("TODO!", 1); |
tobyspark | 17:fc68d40b8b1f | 491 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 492 | } |
tobyspark | 17:fc68d40b8b1f | 493 | |
tobyspark | 17:fc68d40b8b1f | 494 | /* SELF TEST - Exit! |
tobyspark | 17:fc68d40b8b1f | 495 | * To do this, we could just do nothing but we'd need to recreate screen and comms as they were. |
tobyspark | 17:fc68d40b8b1f | 496 | * Instead, lets just restart the mbed |
tobyspark | 17:fc68d40b8b1f | 497 | */ |
tobyspark | 17:fc68d40b8b1f | 498 | |
tobyspark | 17:fc68d40b8b1f | 499 | screen.clearBuffer(); |
tobyspark | 17:fc68d40b8b1f | 500 | screen.textToBuffer("Self test complete", 0); |
tobyspark | 17:fc68d40b8b1f | 501 | screen.textToBuffer("Press to restart controller", 1); |
tobyspark | 17:fc68d40b8b1f | 502 | screen.sendBuffer(); |
tobyspark | 17:fc68d40b8b1f | 503 | |
tobyspark | 17:fc68d40b8b1f | 504 | while(!menuEnc.hasPressed()) {} |
tobyspark | 17:fc68d40b8b1f | 505 | |
tobyspark | 17:fc68d40b8b1f | 506 | mbed_reset(); |
tobyspark | 17:fc68d40b8b1f | 507 | } |
tobyspark | 17:fc68d40b8b1f | 508 | |
tobyspark | 27:27851d3d2bba | 509 | void setResolutionMenuItems() |
tobyspark | 27:27851d3d2bba | 510 | { |
tobyspark | 27:27851d3d2bba | 511 | resolutionMenu.clearMenuItems(); |
tobyspark | 27:27851d3d2bba | 512 | for (int i=0; i < settings.resolutionsCount(); i++) |
tobyspark | 27:27851d3d2bba | 513 | { |
tobyspark | 27:27851d3d2bba | 514 | resolutionMenu.addMenuItem(SPKMenuItem(settings.resolutionName(i), settings.resolutionIndex(i), settings.resolutionEDIDIndex(i))); |
tobyspark | 27:27851d3d2bba | 515 | } |
tobyspark | 27:27851d3d2bba | 516 | resolutionMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 27:27851d3d2bba | 517 | } |
tobyspark | 27:27851d3d2bba | 518 | |
tobyspark | 27:27851d3d2bba | 519 | void setMixModeMenuItems() |
tobyspark | 27:27851d3d2bba | 520 | { |
tobyspark | 27:27851d3d2bba | 521 | mixModeMenu.clearMenuItems(); |
tobyspark | 29:95a7efe30527 | 522 | mixModeMenu.addMenuItem(SPKMenuItem("Crossfade", &mixModeAdditiveMenu)); |
tobyspark | 27:27851d3d2bba | 523 | for (int i=0; i < settings.keyerSetCount(); i++) |
tobyspark | 27:27851d3d2bba | 524 | { |
tobyspark | 27:27851d3d2bba | 525 | mixModeMenu.addMenuItem(SPKMenuItem(settings.keyerParamName(i), mixKey+i)); |
tobyspark | 27:27851d3d2bba | 526 | } |
tobyspark | 27:27851d3d2bba | 527 | mixModeMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 27:27851d3d2bba | 528 | } |
tobyspark | 27:27851d3d2bba | 529 | |
tobyspark | 27:27851d3d2bba | 530 | void setCommsMenuItems() |
tobyspark | 27:27851d3d2bba | 531 | { |
tobyspark | 27:27851d3d2bba | 532 | if (rj45Mode == rj45Ethernet) |
tobyspark | 27:27851d3d2bba | 533 | { |
tobyspark | 27:27851d3d2bba | 534 | commsMenu.title = "Network Mode [Ethernet]"; |
tobyspark | 27:27851d3d2bba | 535 | commsMenu.clearMenuItems(); |
tobyspark | 27:27851d3d2bba | 536 | commsMenu.addMenuItem(SPKMenuItem("None", commsNone)); |
tobyspark | 27:27851d3d2bba | 537 | commsMenu.addMenuItem(SPKMenuItem("OSC", commsOSC)); |
tobyspark | 27:27851d3d2bba | 538 | commsMenu.addMenuItem(SPKMenuItem("ArtNet", commsArtNet)); |
tobyspark | 27:27851d3d2bba | 539 | commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 27:27851d3d2bba | 540 | } |
tobyspark | 27:27851d3d2bba | 541 | else if (rj45Mode == rj45DMX) |
tobyspark | 27:27851d3d2bba | 542 | { |
tobyspark | 27:27851d3d2bba | 543 | commsMenu.title = "Network Mode [DMX]"; |
tobyspark | 27:27851d3d2bba | 544 | commsMenu.clearMenuItems(); |
tobyspark | 27:27851d3d2bba | 545 | commsMenu.addMenuItem(SPKMenuItem("None", commsNone)); |
tobyspark | 27:27851d3d2bba | 546 | commsMenu.addMenuItem(SPKMenuItem("DMX In", commsDMXIn)); |
tobyspark | 27:27851d3d2bba | 547 | commsMenu.addMenuItem(SPKMenuItem("DMX Out", commsDMXOut)); |
tobyspark | 27:27851d3d2bba | 548 | commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 27:27851d3d2bba | 549 | } |
tobyspark | 27:27851d3d2bba | 550 | } |
tobyspark | 27:27851d3d2bba | 551 | |
tobyspark | 0:87aab40d5806 | 552 | int main() |
tobyspark | 0:87aab40d5806 | 553 | { |
tobyspark | 0:87aab40d5806 | 554 | if (debug) |
tobyspark | 0:87aab40d5806 | 555 | { |
tobyspark | 0:87aab40d5806 | 556 | debug->printf("\r\n\r\n"); |
tobyspark | 0:87aab40d5806 | 557 | debug->printf("*spark d-fuser -----------\r\n"); |
tobyspark | 0:87aab40d5806 | 558 | debug->printf(" debug channel\r\n"); |
tobyspark | 0:87aab40d5806 | 559 | } |
tobyspark | 2:50043054e4f7 | 560 | |
tobyspark | 2:50043054e4f7 | 561 | // Set display font |
tobyspark | 2:50043054e4f7 | 562 | screen.fontStartCharacter = &characterBytesStartChar; |
tobyspark | 2:50043054e4f7 | 563 | screen.fontEndCharacter = &characterBytesEndChar; |
tobyspark | 2:50043054e4f7 | 564 | screen.fontCharacters = characterBytes; |
tobyspark | 2:50043054e4f7 | 565 | |
tobyspark | 0:87aab40d5806 | 566 | // Splash screen |
tobyspark | 2:50043054e4f7 | 567 | screen.imageToBuffer(spkDisplayLogo); |
tobyspark | 0:87aab40d5806 | 568 | screen.textToBuffer("SPK:D-Fuser",0); |
tobyspark | 13:3796bde6ba8f | 569 | screen.textToBuffer(string("SW ") + kSPKDFSoftwareVersion,1); |
tobyspark | 5:f8b285ca41ba | 570 | screen.sendBuffer(); |
tobyspark | 0:87aab40d5806 | 571 | |
tobyspark | 11:0783cfbeb746 | 572 | // Load saved settings |
tobyspark | 16:52484666b323 | 573 | bool settingsAreCustom = false; |
tobyspark | 16:52484666b323 | 574 | settingsAreCustom = settings.load(kSPKDFSettingsFilename); |
tobyspark | 27:27851d3d2bba | 575 | if (settingsAreCustom) {screen.textToBuffer("SPKDF.ini OK", 0); screen.sendBuffer();} |
tobyspark | 27:27851d3d2bba | 576 | |
tobyspark | 0:87aab40d5806 | 577 | // Set menu structure |
tobyspark | 0:87aab40d5806 | 578 | mixModeMenu.title = "Mix Mode"; |
tobyspark | 27:27851d3d2bba | 579 | setMixModeMenuItems(); |
tobyspark | 24:49c6624119ae | 580 | |
tobyspark | 29:95a7efe30527 | 581 | mixModeAdditiveMenu.title = "Crossfade"; |
tobyspark | 29:95a7efe30527 | 582 | mixModeAdditiveMenu.addMenuItem(SPKMenuItem("Twist then click", &mixModeMenu, true)); |
tobyspark | 0:87aab40d5806 | 583 | |
tobyspark | 0:87aab40d5806 | 584 | resolutionMenu.title = "Resolution"; |
tobyspark | 27:27851d3d2bba | 585 | setResolutionMenuItems(); |
tobyspark | 0:87aab40d5806 | 586 | |
tobyspark | 27:27851d3d2bba | 587 | commsMenu.title = "Network Mode"; |
tobyspark | 27:27851d3d2bba | 588 | setCommsMenuItems(); |
tobyspark | 23:909928cafb95 | 589 | |
tobyspark | 15:4b394c64b461 | 590 | advancedMenu.title = "Troubleshooting"; |
tobyspark | 23:909928cafb95 | 591 | advancedMenu.addMenuItem(SPKMenuItem("HDCP Off", advancedHDCPOff)); |
tobyspark | 23:909928cafb95 | 592 | advancedMenu.addMenuItem(SPKMenuItem("HDCP On", advancedHDCPOn)); |
tobyspark | 29:95a7efe30527 | 593 | advancedMenu.addMenuItem(SPKMenuItem("Basic mix mode", advancedMixModeSafe)); |
tobyspark | 23:909928cafb95 | 594 | advancedMenu.addMenuItem(SPKMenuItem("Conform Processor", advancedConformProcessor)); |
tobyspark | 23:909928cafb95 | 595 | if (settingsAreCustom) advancedMenu.addMenuItem(SPKMenuItem("Revert to defaults", advancedLoadDefaults)); |
tobyspark | 23:909928cafb95 | 596 | advancedMenu.addMenuItem(SPKMenuItem("Start Self-Test", advancedSelfTest)); |
tobyspark | 24:49c6624119ae | 597 | advancedMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 23:909928cafb95 | 598 | |
tobyspark | 0:87aab40d5806 | 599 | mainMenu.title = "Main Menu"; |
tobyspark | 24:49c6624119ae | 600 | mainMenu.addMenuItem(SPKMenuItem(mixModeMenu.title, &mixModeMenu)); |
tobyspark | 24:49c6624119ae | 601 | mainMenu.addMenuItem(SPKMenuItem(resolutionMenu.title, &resolutionMenu)); |
tobyspark | 24:49c6624119ae | 602 | mainMenu.addMenuItem(SPKMenuItem(commsMenu.title, &commsMenu)); |
tobyspark | 24:49c6624119ae | 603 | mainMenu.addMenuItem(SPKMenuItem(advancedMenu.title, &advancedMenu)); |
tobyspark | 23:909928cafb95 | 604 | |
tobyspark | 0:87aab40d5806 | 605 | selectedMenu = &mainMenu; |
tobyspark | 23:909928cafb95 | 606 | |
tobyspark | 0:87aab40d5806 | 607 | // Misc I/O stuff |
tobyspark | 0:87aab40d5806 | 608 | |
tobyspark | 0:87aab40d5806 | 609 | fadeAPO.period(0.001); |
tobyspark | 0:87aab40d5806 | 610 | fadeBPO.period(0.001); |
tobyspark | 0:87aab40d5806 | 611 | |
tobyspark | 20:8b92d7922c48 | 612 | // Test for TV One connectivity and determine unit type |
tobyspark | 21:f9d63cb7cedb | 613 | int32_t testConnectionPayload = 0; |
tobyspark | 21:f9d63cb7cedb | 614 | |
tobyspark | 21:f9d63cb7cedb | 615 | // kTV1FunctionReadSoftwareVersion |
tobyspark | 21:f9d63cb7cedb | 616 | // kTV1FunctionReadProductType |
tobyspark | 21:f9d63cb7cedb | 617 | // kTV1FunctionReadBoardType |
tobyspark | 21:f9d63cb7cedb | 618 | bool ok = tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionReadSoftwareVersion, testConnectionPayload); |
tobyspark | 21:f9d63cb7cedb | 619 | |
tobyspark | 21:f9d63cb7cedb | 620 | string tvOneDetectString = ok ? "TVOne link ok" : "TVOne link failed"; |
tobyspark | 21:f9d63cb7cedb | 621 | |
tobyspark | 21:f9d63cb7cedb | 622 | // TODO: Use software version to select resolution slots etc? |
tobyspark | 21:f9d63cb7cedb | 623 | // TODO: Use product / board type to select TVOne conform type? |
tobyspark | 23:909928cafb95 | 624 | |
tobyspark | 12:c270870bdd23 | 625 | // Display menu and framing lines |
tobyspark | 0:87aab40d5806 | 626 | screen.horizLineToBuffer(kMenuLine1*pixInPage - 1); |
tobyspark | 0:87aab40d5806 | 627 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 628 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 629 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 630 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 631 | screen.horizLineToBuffer(kMenuLine2*pixInPage + pixInPage); |
tobyspark | 1:f9fca21102e0 | 632 | screen.horizLineToBuffer(kCommsStatusLine*pixInPage - 1); |
tobyspark | 1:f9fca21102e0 | 633 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 21:f9d63cb7cedb | 634 | screen.textToBuffer(tvOneDetectString, kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 635 | screen.sendBuffer(); |
tobyspark | 0:87aab40d5806 | 636 | |
tobyspark | 0:87aab40d5806 | 637 | //// CONTROLS TEST |
tobyspark | 0:87aab40d5806 | 638 | |
tobyspark | 0:87aab40d5806 | 639 | while (0) { |
tobyspark | 0:87aab40d5806 | 640 | 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 | 641 | } |
tobyspark | 0:87aab40d5806 | 642 | |
tobyspark | 0:87aab40d5806 | 643 | //// MIXER RUN |
tobyspark | 0:87aab40d5806 | 644 | |
tobyspark | 8:d46cc49f0f37 | 645 | while (1) |
tobyspark | 8:d46cc49f0f37 | 646 | { |
tobyspark | 1:f9fca21102e0 | 647 | //// Task background things |
tobyspark | 5:f8b285ca41ba | 648 | if (ethernet && rj45Mode == rj45Ethernet) |
tobyspark | 5:f8b285ca41ba | 649 | { |
tobyspark | 5:f8b285ca41ba | 650 | Net::poll(); |
tobyspark | 5:f8b285ca41ba | 651 | } |
tobyspark | 5:f8b285ca41ba | 652 | |
tobyspark | 5:f8b285ca41ba | 653 | //// RJ45 SWITCH |
tobyspark | 5:f8b285ca41ba | 654 | |
tobyspark | 5:f8b285ca41ba | 655 | if (rj45ModeDIN != rj45Mode) |
tobyspark | 1:f9fca21102e0 | 656 | { |
tobyspark | 23:909928cafb95 | 657 | if (debug) debug->printf("Handling RJ45 mode change\r\n"); |
tobyspark | 27:27851d3d2bba | 658 | |
tobyspark | 5:f8b285ca41ba | 659 | // update state |
tobyspark | 5:f8b285ca41ba | 660 | rj45Mode = rj45ModeDIN; |
tobyspark | 27:27851d3d2bba | 661 | |
tobyspark | 27:27851d3d2bba | 662 | setCommsMenuItems(); |
tobyspark | 5:f8b285ca41ba | 663 | |
tobyspark | 5:f8b285ca41ba | 664 | // cancel old comms |
tobyspark | 5:f8b285ca41ba | 665 | commsMode = commsNone; |
tobyspark | 5:f8b285ca41ba | 666 | commsMenu = commsMode; |
tobyspark | 5:f8b285ca41ba | 667 | |
tobyspark | 5:f8b285ca41ba | 668 | // refresh display |
tobyspark | 23:909928cafb95 | 669 | if (selectedMenu == &commsMenu) |
tobyspark | 23:909928cafb95 | 670 | { |
tobyspark | 23:909928cafb95 | 671 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 23:909928cafb95 | 672 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 23:909928cafb95 | 673 | } |
tobyspark | 5:f8b285ca41ba | 674 | if (rj45Mode == rj45Ethernet) screen.textToBuffer("RJ45: Ethernet Engaged", kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 675 | if (rj45Mode == rj45DMX) screen.textToBuffer("RJ45: DMX Engaged", kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 676 | } |
tobyspark | 1:f9fca21102e0 | 677 | |
tobyspark | 0:87aab40d5806 | 678 | //// MENU |
tobyspark | 0:87aab40d5806 | 679 | |
tobyspark | 0:87aab40d5806 | 680 | int menuChange = menuEnc.getChange(); |
tobyspark | 0:87aab40d5806 | 681 | |
tobyspark | 0:87aab40d5806 | 682 | // Update GUI |
tobyspark | 0:87aab40d5806 | 683 | if (menuChange != 0) |
tobyspark | 0:87aab40d5806 | 684 | { |
tobyspark | 24:49c6624119ae | 685 | if (selectedMenu->selectedItem().handlingControls) |
tobyspark | 24:49c6624119ae | 686 | { |
tobyspark | 24:49c6624119ae | 687 | if (selectedMenu == &mixModeAdditiveMenu) |
tobyspark | 24:49c6624119ae | 688 | { |
tobyspark | 24:49c6624119ae | 689 | fadeCurve += menuChange * 0.05; |
tobyspark | 24:49c6624119ae | 690 | if (fadeCurve > 1.0f) fadeCurve = 1.0f; |
tobyspark | 24:49c6624119ae | 691 | if (fadeCurve < 0.0f) fadeCurve = 0.0f; |
tobyspark | 29:95a7efe30527 | 692 | |
tobyspark | 29:95a7efe30527 | 693 | mixMode = (fadeCurve > 0.0f) ? mixAdditive: mixBlend; |
tobyspark | 29:95a7efe30527 | 694 | |
tobyspark | 24:49c6624119ae | 695 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 29:95a7efe30527 | 696 | screen.textToBuffer("Blend [ ----- ] Add", kMenuLine2); |
tobyspark | 29:95a7efe30527 | 697 | screen.characterToBuffer('X', 38 + fadeCurve*20.0f, kMenuLine2); |
tobyspark | 24:49c6624119ae | 698 | |
tobyspark | 24:49c6624119ae | 699 | if (debug) debug->printf("Fade curve changed by %i to %f", menuChange, fadeCurve); |
tobyspark | 24:49c6624119ae | 700 | } |
tobyspark | 24:49c6624119ae | 701 | } |
tobyspark | 24:49c6624119ae | 702 | else |
tobyspark | 24:49c6624119ae | 703 | { |
tobyspark | 24:49c6624119ae | 704 | if (debug) debug->printf("Menu changed by %i\r\n", menuChange); |
tobyspark | 24:49c6624119ae | 705 | |
tobyspark | 24:49c6624119ae | 706 | *selectedMenu = selectedMenu->selectedIndex() + menuChange; |
tobyspark | 24:49c6624119ae | 707 | |
tobyspark | 24:49c6624119ae | 708 | // update OLED line 2 here |
tobyspark | 24:49c6624119ae | 709 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 24:49c6624119ae | 710 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 24:49c6624119ae | 711 | |
tobyspark | 24:49c6624119ae | 712 | if (debug) debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 24:49c6624119ae | 713 | } |
tobyspark | 0:87aab40d5806 | 714 | } |
tobyspark | 0:87aab40d5806 | 715 | |
tobyspark | 0:87aab40d5806 | 716 | // Action menu item |
tobyspark | 0:87aab40d5806 | 717 | if (menuEnc.hasPressed()) |
tobyspark | 0:87aab40d5806 | 718 | { |
tobyspark | 0:87aab40d5806 | 719 | if (debug) debug->printf("Action Menu Item!\r\n"); |
tobyspark | 21:f9d63cb7cedb | 720 | |
tobyspark | 0:87aab40d5806 | 721 | // Are we changing menus? |
tobyspark | 23:909928cafb95 | 722 | if (selectedMenu->selectedItem().type == SPKMenuItem::changesToMenu) |
tobyspark | 0:87aab40d5806 | 723 | { |
tobyspark | 0:87aab40d5806 | 724 | // point selected menu to the new menu |
tobyspark | 23:909928cafb95 | 725 | selectedMenu = selectedMenu->selectedItem().payload.menu; |
tobyspark | 0:87aab40d5806 | 726 | |
tobyspark | 0:87aab40d5806 | 727 | // update OLED lines 1&2 |
tobyspark | 0:87aab40d5806 | 728 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 729 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 730 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 731 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 732 | |
tobyspark | 0:87aab40d5806 | 733 | if (debug) |
tobyspark | 0:87aab40d5806 | 734 | { |
tobyspark | 0:87aab40d5806 | 735 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 736 | debug->printf("%s \r\n", selectedMenu->title.c_str()); |
tobyspark | 0:87aab40d5806 | 737 | debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 0:87aab40d5806 | 738 | } |
tobyspark | 24:49c6624119ae | 739 | |
tobyspark | 24:49c6624119ae | 740 | // Are we changing menus that should have a command attached? |
tobyspark | 24:49c6624119ae | 741 | if (selectedMenu == &mixModeAdditiveMenu) |
tobyspark | 24:49c6624119ae | 742 | { |
tobyspark | 29:95a7efe30527 | 743 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 29:95a7efe30527 | 744 | screen.textToBuffer("Blend [ ----- ] Add", kMenuLine2); |
tobyspark | 29:95a7efe30527 | 745 | screen.characterToBuffer('X', 38 + fadeCurve*20.0f, kMenuLine2); |
tobyspark | 29:95a7efe30527 | 746 | |
tobyspark | 29:95a7efe30527 | 747 | mixMode = fadeCurve > 0 ? mixAdditive : mixBlend; |
tobyspark | 24:49c6624119ae | 748 | actionMixMode(); |
tobyspark | 24:49c6624119ae | 749 | } |
tobyspark | 0:87aab40d5806 | 750 | } |
tobyspark | 0:87aab40d5806 | 751 | // With that out of the way, we should be actioning a specific menu's payload? |
tobyspark | 0:87aab40d5806 | 752 | else if (selectedMenu == &mixModeMenu) |
tobyspark | 0:87aab40d5806 | 753 | { |
tobyspark | 23:909928cafb95 | 754 | mixMode = mixModeMenu.selectedItem().payload.command[0]; |
tobyspark | 24:49c6624119ae | 755 | actionMixMode(); |
tobyspark | 0:87aab40d5806 | 756 | } |
tobyspark | 0:87aab40d5806 | 757 | else if (selectedMenu == &resolutionMenu) |
tobyspark | 0:87aab40d5806 | 758 | { |
tobyspark | 9:f83eadd8917a | 759 | bool ok = true; |
tobyspark | 0:87aab40d5806 | 760 | |
tobyspark | 23:909928cafb95 | 761 | ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputResolution, resolutionMenu.selectedItem().payload.command[0]); |
tobyspark | 23:909928cafb95 | 762 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedItem().payload.command[1]); |
tobyspark | 23:909928cafb95 | 763 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedItem().payload.command[1]); |
tobyspark | 0:87aab40d5806 | 764 | |
tobyspark | 25:3b519ef70341 | 765 | string sentOK; |
tobyspark | 0:87aab40d5806 | 766 | if (ok) sentOK = "Sent: "; |
tobyspark | 0:87aab40d5806 | 767 | else sentOK = "Send Error: "; |
tobyspark | 0:87aab40d5806 | 768 | |
tobyspark | 26:0299f8760715 | 769 | char sentMSGBuffer[kStringBufferLength]; |
tobyspark | 26:0299f8760715 | 770 | snprintf(sentMSGBuffer, kStringBufferLength,"Res %i, EDID %i", resolutionMenu.selectedItem().payload.command[0], resolutionMenu.selectedItem().payload.command[1]); |
tobyspark | 0:87aab40d5806 | 771 | |
tobyspark | 1:f9fca21102e0 | 772 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 25:3b519ef70341 | 773 | screen.textToBuffer(sentOK + sentMSGBuffer, kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 774 | |
tobyspark | 0:87aab40d5806 | 775 | if (debug) { debug->printf("Changing resolution"); } |
tobyspark | 0:87aab40d5806 | 776 | } |
tobyspark | 1:f9fca21102e0 | 777 | else if (selectedMenu == &commsMenu) |
tobyspark | 1:f9fca21102e0 | 778 | { |
tobyspark | 26:0299f8760715 | 779 | string commsTypeString = "Network:"; |
tobyspark | 26:0299f8760715 | 780 | char commsStatusBuffer[kStringBufferLength] = "--"; |
tobyspark | 1:f9fca21102e0 | 781 | |
tobyspark | 1:f9fca21102e0 | 782 | // Tear down any existing comms |
tobyspark | 1:f9fca21102e0 | 783 | // This is the action of commsNone |
tobyspark | 1:f9fca21102e0 | 784 | // And also clears the way for other comms actions |
tobyspark | 26:0299f8760715 | 785 | commsMode = commsNone; |
tobyspark | 5:f8b285ca41ba | 786 | if (osc) {delete osc; osc = NULL;} |
tobyspark | 5:f8b285ca41ba | 787 | if (ethernet) {delete ethernet; ethernet = NULL;} |
tobyspark | 5:f8b285ca41ba | 788 | if (artNet) {delete artNet; artNet = NULL;} |
tobyspark | 5:f8b285ca41ba | 789 | if (dmx) {delete dmx; dmx = NULL;} |
tobyspark | 5:f8b285ca41ba | 790 | |
tobyspark | 5:f8b285ca41ba | 791 | // Ensure we can't change to comms modes the hardware isn't switched to |
tobyspark | 23:909928cafb95 | 792 | if (rj45Mode == rj45DMX && (commsMenu.selectedItem().payload.command[0] == commsOSC || commsMenu.selectedItem().payload.command[0] == commsArtNet)) |
tobyspark | 1:f9fca21102e0 | 793 | { |
tobyspark | 5:f8b285ca41ba | 794 | commsTypeString = "RJ45 not in Ethernet mode"; |
tobyspark | 5:f8b285ca41ba | 795 | } |
tobyspark | 23:909928cafb95 | 796 | else if (rj45Mode == rj45Ethernet && (commsMenu.selectedItem().payload.command[0] == commsDMXIn || commsMenu.selectedItem().payload.command[0] == commsDMXOut)) |
tobyspark | 5:f8b285ca41ba | 797 | { |
tobyspark | 5:f8b285ca41ba | 798 | commsTypeString = "RJ45 not in DMX mode"; |
tobyspark | 5:f8b285ca41ba | 799 | } |
tobyspark | 5:f8b285ca41ba | 800 | // Action! |
tobyspark | 23:909928cafb95 | 801 | else if (commsMenu.selectedItem().payload.command[0] == commsOSC) |
tobyspark | 5:f8b285ca41ba | 802 | { |
tobyspark | 5:f8b285ca41ba | 803 | commsMode = commsOSC; |
tobyspark | 5:f8b285ca41ba | 804 | commsTypeString = "OSC: "; |
tobyspark | 1:f9fca21102e0 | 805 | |
tobyspark | 1:f9fca21102e0 | 806 | ethernet = new EthernetNetIf( |
tobyspark | 1:f9fca21102e0 | 807 | IpAddr(kOSCMbedIPAddress), |
tobyspark | 1:f9fca21102e0 | 808 | IpAddr(kOSCMbedSubnetMask), |
tobyspark | 1:f9fca21102e0 | 809 | IpAddr(kOSCMbedGateway), |
tobyspark | 1:f9fca21102e0 | 810 | IpAddr(kOSCMbedDNS) |
tobyspark | 1:f9fca21102e0 | 811 | ); |
tobyspark | 3:033d2b7768f3 | 812 | |
tobyspark | 1:f9fca21102e0 | 813 | EthernetErr ethError = ethernet->setup(); |
tobyspark | 1:f9fca21102e0 | 814 | if(ethError) |
tobyspark | 1:f9fca21102e0 | 815 | { |
tobyspark | 1:f9fca21102e0 | 816 | if (debug) debug->printf("Ethernet setup error, %d", ethError); |
tobyspark | 26:0299f8760715 | 817 | snprintf(commsStatusBuffer, kStringBufferLength, "Ethernet setup failed"); |
tobyspark | 5:f8b285ca41ba | 818 | commsMenu = commsNone; |
tobyspark | 1:f9fca21102e0 | 819 | // break out of here. this setup should be a function that returns a boolean |
tobyspark | 1:f9fca21102e0 | 820 | } |
tobyspark | 1:f9fca21102e0 | 821 | |
tobyspark | 1:f9fca21102e0 | 822 | osc = new OSCClass(); |
tobyspark | 3:033d2b7768f3 | 823 | osc->setReceiveMessage(&recMessage); |
tobyspark | 1:f9fca21102e0 | 824 | osc->begin(kOSCMbedPort); |
tobyspark | 1:f9fca21102e0 | 825 | |
tobyspark | 26:0299f8760715 | 826 | snprintf(commsStatusBuffer, kStringBufferLength, "Listening on %i", kOSCMbedPort); |
tobyspark | 1:f9fca21102e0 | 827 | } |
tobyspark | 23:909928cafb95 | 828 | else if (commsMenu.selectedItem().payload.command[0] == commsArtNet) |
tobyspark | 1:f9fca21102e0 | 829 | { |
tobyspark | 5:f8b285ca41ba | 830 | commsMode = commsArtNet; |
tobyspark | 5:f8b285ca41ba | 831 | commsTypeString = "ArtNet: "; |
tobyspark | 3:033d2b7768f3 | 832 | |
tobyspark | 3:033d2b7768f3 | 833 | artNet = new DmxArtNet(); |
tobyspark | 1:f9fca21102e0 | 834 | |
tobyspark | 3:033d2b7768f3 | 835 | artNet->BindIpAddress = IpAddr(kArtNetBindIPAddress); |
tobyspark | 3:033d2b7768f3 | 836 | artNet->BCastAddress = IpAddr(kArtNetBroadcastAddress); |
tobyspark | 3:033d2b7768f3 | 837 | |
tobyspark | 3:033d2b7768f3 | 838 | artNet->InitArtPollReplyDefaults(); |
tobyspark | 3:033d2b7768f3 | 839 | |
tobyspark | 3:033d2b7768f3 | 840 | artNet->ArtPollReply.PortType[0] = 128; // output |
tobyspark | 3:033d2b7768f3 | 841 | artNet->ArtPollReply.PortType[2] = 64; // input |
tobyspark | 3:033d2b7768f3 | 842 | artNet->ArtPollReply.GoodInput[2] = 4; |
tobyspark | 3:033d2b7768f3 | 843 | |
tobyspark | 3:033d2b7768f3 | 844 | artNet->Init(); |
tobyspark | 3:033d2b7768f3 | 845 | artNet->SendArtPollReply(); // announce to art-net nodes |
tobyspark | 3:033d2b7768f3 | 846 | |
tobyspark | 26:0299f8760715 | 847 | snprintf(commsStatusBuffer, kStringBufferLength, "Listening"); |
tobyspark | 1:f9fca21102e0 | 848 | } |
tobyspark | 23:909928cafb95 | 849 | else if (commsMenu.selectedItem().payload.command[0] == commsDMXIn) |
tobyspark | 1:f9fca21102e0 | 850 | { |
tobyspark | 5:f8b285ca41ba | 851 | commsMode = commsDMXIn; |
tobyspark | 5:f8b285ca41ba | 852 | commsTypeString = "DMX In: "; |
tobyspark | 1:f9fca21102e0 | 853 | |
tobyspark | 5:f8b285ca41ba | 854 | dmxDirectionDOUT = 0; |
tobyspark | 5:f8b285ca41ba | 855 | |
tobyspark | 5:f8b285ca41ba | 856 | dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX); |
tobyspark | 1:f9fca21102e0 | 857 | } |
tobyspark | 23:909928cafb95 | 858 | else if (commsMenu.selectedItem().payload.command[0] == commsDMXOut) |
tobyspark | 5:f8b285ca41ba | 859 | { |
tobyspark | 5:f8b285ca41ba | 860 | commsMode = commsDMXOut; |
tobyspark | 5:f8b285ca41ba | 861 | commsTypeString = "DMX Out: "; |
tobyspark | 5:f8b285ca41ba | 862 | |
tobyspark | 5:f8b285ca41ba | 863 | dmxDirectionDOUT = 1; |
tobyspark | 5:f8b285ca41ba | 864 | |
tobyspark | 5:f8b285ca41ba | 865 | dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX); |
tobyspark | 5:f8b285ca41ba | 866 | } |
tobyspark | 5:f8b285ca41ba | 867 | |
tobyspark | 1:f9fca21102e0 | 868 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 25:3b519ef70341 | 869 | screen.textToBuffer(commsTypeString + commsStatusBuffer, kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 870 | } |
tobyspark | 12:c270870bdd23 | 871 | else if (selectedMenu == &advancedMenu) |
tobyspark | 12:c270870bdd23 | 872 | { |
tobyspark | 23:909928cafb95 | 873 | if (advancedMenu.selectedItem().payload.command[0] == advancedHDCPOff) |
tobyspark | 12:c270870bdd23 | 874 | { |
tobyspark | 12:c270870bdd23 | 875 | bool ok = false; |
tobyspark | 12:c270870bdd23 | 876 | |
tobyspark | 15:4b394c64b461 | 877 | ok = tvOne.setHDCPOn(false); |
tobyspark | 12:c270870bdd23 | 878 | |
tobyspark | 12:c270870bdd23 | 879 | std::string sendOK = ok ? "Sent: HDCP Off" : "Send Error: HDCP Off"; |
tobyspark | 12:c270870bdd23 | 880 | |
tobyspark | 12:c270870bdd23 | 881 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 12:c270870bdd23 | 882 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 12:c270870bdd23 | 883 | } |
tobyspark | 23:909928cafb95 | 884 | else if (advancedMenu.selectedItem().payload.command[0] == advancedHDCPOn) |
tobyspark | 15:4b394c64b461 | 885 | { |
tobyspark | 15:4b394c64b461 | 886 | bool ok = false; |
tobyspark | 15:4b394c64b461 | 887 | |
tobyspark | 15:4b394c64b461 | 888 | ok = tvOne.setHDCPOn(true); |
tobyspark | 15:4b394c64b461 | 889 | |
tobyspark | 15:4b394c64b461 | 890 | std::string sendOK = ok ? "Sent: HDCP On" : "Send Error: HDCP On"; |
tobyspark | 15:4b394c64b461 | 891 | |
tobyspark | 15:4b394c64b461 | 892 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 15:4b394c64b461 | 893 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 15:4b394c64b461 | 894 | } |
tobyspark | 29:95a7efe30527 | 895 | else if (advancedMenu.selectedItem().payload.command[0] == advancedMixModeSafe) |
tobyspark | 29:95a7efe30527 | 896 | { |
tobyspark | 29:95a7efe30527 | 897 | mixMode = mixSafe; |
tobyspark | 29:95a7efe30527 | 898 | |
tobyspark | 29:95a7efe30527 | 899 | actionMixMode(); |
tobyspark | 29:95a7efe30527 | 900 | } |
tobyspark | 23:909928cafb95 | 901 | else if (advancedMenu.selectedItem().payload.command[0] == advancedConformProcessor) |
tobyspark | 17:fc68d40b8b1f | 902 | { |
tobyspark | 20:8b92d7922c48 | 903 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 20:8b92d7922c48 | 904 | screen.textToBuffer("Conforming...", kTVOneStatusLine); |
tobyspark | 20:8b92d7922c48 | 905 | screen.sendBuffer(); |
tobyspark | 20:8b92d7922c48 | 906 | |
tobyspark | 17:fc68d40b8b1f | 907 | bool ok = conformProcessor(); |
tobyspark | 17:fc68d40b8b1f | 908 | |
tobyspark | 17:fc68d40b8b1f | 909 | std::string sendOK = ok ? "Conform success" : "Send Error: Conform"; |
tobyspark | 17:fc68d40b8b1f | 910 | |
tobyspark | 17:fc68d40b8b1f | 911 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 17:fc68d40b8b1f | 912 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 17:fc68d40b8b1f | 913 | } |
tobyspark | 23:909928cafb95 | 914 | else if (advancedMenu.selectedItem().payload.command[0] == advancedLoadDefaults) |
tobyspark | 16:52484666b323 | 915 | { |
tobyspark | 16:52484666b323 | 916 | settings.loadDefaults(); |
tobyspark | 27:27851d3d2bba | 917 | setMixModeMenuItems(); |
tobyspark | 27:27851d3d2bba | 918 | setResolutionMenuItems(); |
tobyspark | 16:52484666b323 | 919 | |
tobyspark | 16:52484666b323 | 920 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 16:52484666b323 | 921 | screen.textToBuffer("Controller reverted", kTVOneStatusLine); |
tobyspark | 16:52484666b323 | 922 | } |
tobyspark | 23:909928cafb95 | 923 | else if (advancedMenu.selectedItem().payload.command[0] == advancedSelfTest) |
tobyspark | 15:4b394c64b461 | 924 | { |
tobyspark | 17:fc68d40b8b1f | 925 | selfTest(); |
tobyspark | 15:4b394c64b461 | 926 | } |
tobyspark | 23:909928cafb95 | 927 | else if (advancedMenu.selectedItem().payload.command[0] == advancedSetResolutions) |
tobyspark | 21:f9d63cb7cedb | 928 | { |
tobyspark | 21:f9d63cb7cedb | 929 | bool ok; |
tobyspark | 21:f9d63cb7cedb | 930 | ok = tvOne.setCustomResolutions(); |
tobyspark | 21:f9d63cb7cedb | 931 | |
tobyspark | 21:f9d63cb7cedb | 932 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 21:f9d63cb7cedb | 933 | screen.textToBuffer(ok ? "Resolutions set" : "Res' could not be set", kTVOneStatusLine); |
tobyspark | 21:f9d63cb7cedb | 934 | } |
tobyspark | 12:c270870bdd23 | 935 | } |
tobyspark | 0:87aab40d5806 | 936 | else |
tobyspark | 0:87aab40d5806 | 937 | { |
tobyspark | 0:87aab40d5806 | 938 | if (debug) { debug->printf("Warning: No action identified"); } |
tobyspark | 0:87aab40d5806 | 939 | } |
tobyspark | 0:87aab40d5806 | 940 | } |
tobyspark | 0:87aab40d5806 | 941 | |
tobyspark | 2:50043054e4f7 | 942 | // Send any updates to the display |
tobyspark | 2:50043054e4f7 | 943 | screen.sendBuffer(); |
tobyspark | 5:f8b285ca41ba | 944 | |
tobyspark | 0:87aab40d5806 | 945 | |
tobyspark | 5:f8b285ca41ba | 946 | //// MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIXMIX MIX MIXMIX MIX MIX MIX MIX MIXMIX MIX MIX |
tobyspark | 0:87aab40d5806 | 947 | |
tobyspark | 0:87aab40d5806 | 948 | bool updateFade = false; |
tobyspark | 3:033d2b7768f3 | 949 | float xFade = 0; |
tobyspark | 3:033d2b7768f3 | 950 | float fadeUp = 1; |
tobyspark | 3:033d2b7768f3 | 951 | |
tobyspark | 3:033d2b7768f3 | 952 | //// TASK: Process control surface |
tobyspark | 3:033d2b7768f3 | 953 | |
tobyspark | 0:87aab40d5806 | 954 | // Get new states of tap buttons, remembering at end of loop() assign these current values to the previous variables |
tobyspark | 5:f8b285ca41ba | 955 | const bool tapLeft = !tapLeftDIN; |
tobyspark | 5:f8b285ca41ba | 956 | const bool tapRight = !tapRightDIN; |
tobyspark | 0:87aab40d5806 | 957 | |
tobyspark | 17:fc68d40b8b1f | 958 | // We're taking a further median of the AINs on top of mbed libs v29. |
tobyspark | 17:fc68d40b8b1f | 959 | // This takes some values from last passes and most from now. With debug off, seem to need median size > 5 |
tobyspark | 17:fc68d40b8b1f | 960 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 961 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 962 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 963 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 964 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 965 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 966 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 967 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 968 | const float xFadeAINCached = xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 969 | const float fadeUpAINCached = fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 0:87aab40d5806 | 970 | |
tobyspark | 0:87aab40d5806 | 971 | // When a tap is depressed, we can ignore any move of the crossfader but not fade to black |
tobyspark | 0:87aab40d5806 | 972 | if (tapLeft || tapRight) |
tobyspark | 0:87aab40d5806 | 973 | { |
tobyspark | 5:f8b285ca41ba | 974 | // If both are pressed, take to the one that is new, ie. not the first pressed. |
tobyspark | 0:87aab40d5806 | 975 | if (tapLeft && tapRight) |
tobyspark | 0:87aab40d5806 | 976 | { |
tobyspark | 5:f8b285ca41ba | 977 | xFade = tapLeftWasFirstPressed ? 1 : 0; |
tobyspark | 0:87aab40d5806 | 978 | } |
tobyspark | 5:f8b285ca41ba | 979 | // If just one is pressed, take to that and remember which is pressed |
tobyspark | 5:f8b285ca41ba | 980 | else if (tapLeft) |
tobyspark | 5:f8b285ca41ba | 981 | { |
tobyspark | 5:f8b285ca41ba | 982 | xFade = 0; |
tobyspark | 5:f8b285ca41ba | 983 | tapLeftWasFirstPressed = 1; |
tobyspark | 5:f8b285ca41ba | 984 | } |
tobyspark | 5:f8b285ca41ba | 985 | else if (tapRight) |
tobyspark | 5:f8b285ca41ba | 986 | { |
tobyspark | 5:f8b285ca41ba | 987 | xFade = 1; |
tobyspark | 5:f8b285ca41ba | 988 | tapLeftWasFirstPressed = 0; |
tobyspark | 5:f8b285ca41ba | 989 | } |
tobyspark | 5:f8b285ca41ba | 990 | } |
tobyspark | 18:ebe5da639a6a | 991 | else xFade = 1.0 - fadeCalc(xFadeAINCached, xFadeTolerance); |
tobyspark | 0:87aab40d5806 | 992 | |
tobyspark | 0:87aab40d5806 | 993 | fadeUp = 1.0 - fadeCalc(fadeUpAINCached, fadeUpTolerance); |
tobyspark | 0:87aab40d5806 | 994 | |
tobyspark | 3:033d2b7768f3 | 995 | //// TASK: Process Network Comms |
tobyspark | 5:f8b285ca41ba | 996 | if (commsMode == commsOSC) |
tobyspark | 3:033d2b7768f3 | 997 | { |
tobyspark | 3:033d2b7768f3 | 998 | if (osc->newMessage) |
tobyspark | 3:033d2b7768f3 | 999 | { |
tobyspark | 3:033d2b7768f3 | 1000 | osc->newMessage = false; // fixme! |
tobyspark | 3:033d2b7768f3 | 1001 | processOSC(xFade, fadeUp); |
tobyspark | 3:033d2b7768f3 | 1002 | } |
tobyspark | 3:033d2b7768f3 | 1003 | } |
tobyspark | 3:033d2b7768f3 | 1004 | |
tobyspark | 5:f8b285ca41ba | 1005 | if (commsMode == commsArtNet) |
tobyspark | 3:033d2b7768f3 | 1006 | { |
tobyspark | 3:033d2b7768f3 | 1007 | if (artNet->Work()) processArtNet(xFade, fadeUp); |
tobyspark | 3:033d2b7768f3 | 1008 | } |
tobyspark | 3:033d2b7768f3 | 1009 | |
tobyspark | 5:f8b285ca41ba | 1010 | if (commsMode == commsDMXIn) |
tobyspark | 5:f8b285ca41ba | 1011 | { |
tobyspark | 5:f8b285ca41ba | 1012 | processDMXIn(xFade, fadeUp); |
tobyspark | 5:f8b285ca41ba | 1013 | } |
tobyspark | 5:f8b285ca41ba | 1014 | |
tobyspark | 5:f8b285ca41ba | 1015 | if (commsMode == commsDMXOut) |
tobyspark | 5:f8b285ca41ba | 1016 | { |
tobyspark | 5:f8b285ca41ba | 1017 | processDMXOut(xFade, fadeUp); |
tobyspark | 5:f8b285ca41ba | 1018 | } |
tobyspark | 0:87aab40d5806 | 1019 | |
tobyspark | 0:87aab40d5806 | 1020 | // Calculate new A&B fade percents |
tobyspark | 0:87aab40d5806 | 1021 | int newFadeAPercent = 0; |
tobyspark | 0:87aab40d5806 | 1022 | int newFadeBPercent = 0; |
tobyspark | 0:87aab40d5806 | 1023 | |
tobyspark | 29:95a7efe30527 | 1024 | if (mixMode == mixSafe) |
tobyspark | 11:0783cfbeb746 | 1025 | { |
tobyspark | 29:95a7efe30527 | 1026 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 29:95a7efe30527 | 1027 | newFadeBPercent = xFade * fadeUp * 100.0; |
tobyspark | 29:95a7efe30527 | 1028 | } |
tobyspark | 29:95a7efe30527 | 1029 | else if (mixMode == mixBlend) |
tobyspark | 29:95a7efe30527 | 1030 | { |
tobyspark | 29:95a7efe30527 | 1031 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 29:95a7efe30527 | 1032 | newFadeBPercent = fadeUp * 100.0; |
tobyspark | 11:0783cfbeb746 | 1033 | } |
tobyspark | 15:4b394c64b461 | 1034 | else if (mixMode == mixAdditive) |
tobyspark | 11:0783cfbeb746 | 1035 | { |
tobyspark | 22:90054fe6d86c | 1036 | // we need to set fade level of both windows according to the fade curve profile |
tobyspark | 22:90054fe6d86c | 1037 | float newFadeA = (1.0-xFade) * (1.0 + fadeCurve); |
tobyspark | 22:90054fe6d86c | 1038 | float newFadeB = xFade * (1 + fadeCurve); |
tobyspark | 22:90054fe6d86c | 1039 | if (newFadeA > 1.0) newFadeA = 1.0; |
tobyspark | 22:90054fe6d86c | 1040 | if (newFadeB > 1.0) newFadeB = 1.0; |
tobyspark | 22:90054fe6d86c | 1041 | |
tobyspark | 22:90054fe6d86c | 1042 | newFadeAPercent = newFadeA * fadeUp * 100.0; |
tobyspark | 22:90054fe6d86c | 1043 | newFadeBPercent = newFadeB * fadeUp * 100.0; |
tobyspark | 11:0783cfbeb746 | 1044 | } |
tobyspark | 15:4b394c64b461 | 1045 | else if (mixMode >= mixKey) |
tobyspark | 11:0783cfbeb746 | 1046 | { |
tobyspark | 0:87aab40d5806 | 1047 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 1048 | newFadeBPercent = fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 1049 | } |
tobyspark | 0:87aab40d5806 | 1050 | |
tobyspark | 17:fc68d40b8b1f | 1051 | //// TASK: Send to TVOne if percents have changed |
tobyspark | 17:fc68d40b8b1f | 1052 | |
tobyspark | 17:fc68d40b8b1f | 1053 | // No amount of median filtering is stopping flipflopping between two adjacent percents, so... |
tobyspark | 17:fc68d40b8b1f | 1054 | bool fadeAPercentHasChanged; |
tobyspark | 17:fc68d40b8b1f | 1055 | bool fadeBPercentHasChanged; |
tobyspark | 17:fc68d40b8b1f | 1056 | if (oldFadeAPercent == newFadeAPercent && (newFadeAPercent == fadeAPercent - 1 || newFadeAPercent == fadeAPercent + 1)) |
tobyspark | 17:fc68d40b8b1f | 1057 | fadeAPercentHasChanged = false; |
tobyspark | 17:fc68d40b8b1f | 1058 | else |
tobyspark | 17:fc68d40b8b1f | 1059 | fadeAPercentHasChanged = newFadeAPercent != fadeAPercent; |
tobyspark | 17:fc68d40b8b1f | 1060 | if (oldFadeBPercent == newFadeBPercent && (newFadeBPercent == fadeBPercent - 1 || newFadeBPercent == fadeBPercent + 1)) |
tobyspark | 17:fc68d40b8b1f | 1061 | fadeBPercentHasChanged = false; |
tobyspark | 17:fc68d40b8b1f | 1062 | else |
tobyspark | 17:fc68d40b8b1f | 1063 | fadeBPercentHasChanged = newFadeBPercent != fadeBPercent; |
tobyspark | 17:fc68d40b8b1f | 1064 | |
tobyspark | 9:f83eadd8917a | 1065 | // We want to send the higher first, otherwise black flashes can happen on taps |
tobyspark | 17:fc68d40b8b1f | 1066 | if (fadeAPercentHasChanged && newFadeAPercent >= newFadeBPercent) |
tobyspark | 8:d46cc49f0f37 | 1067 | { |
tobyspark | 17:fc68d40b8b1f | 1068 | oldFadeAPercent = fadeAPercent; |
tobyspark | 0:87aab40d5806 | 1069 | fadeAPercent = newFadeAPercent; |
tobyspark | 0:87aab40d5806 | 1070 | updateFade = true; |
tobyspark | 0:87aab40d5806 | 1071 | |
tobyspark | 0:87aab40d5806 | 1072 | fadeAPO = fadeAPercent / 100.0; |
tobyspark | 0:87aab40d5806 | 1073 | tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent); |
tobyspark | 0:87aab40d5806 | 1074 | } |
tobyspark | 17:fc68d40b8b1f | 1075 | if (fadeBPercentHasChanged) |
tobyspark | 8:d46cc49f0f37 | 1076 | { |
tobyspark | 17:fc68d40b8b1f | 1077 | oldFadeBPercent = fadeBPercent; |
tobyspark | 0:87aab40d5806 | 1078 | fadeBPercent = newFadeBPercent; |
tobyspark | 0:87aab40d5806 | 1079 | updateFade = true; |
tobyspark | 0:87aab40d5806 | 1080 | |
tobyspark | 0:87aab40d5806 | 1081 | fadeBPO = fadeBPercent / 100.0; |
tobyspark | 0:87aab40d5806 | 1082 | tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent); |
tobyspark | 0:87aab40d5806 | 1083 | } |
tobyspark | 17:fc68d40b8b1f | 1084 | if (fadeAPercentHasChanged && newFadeAPercent < newFadeBPercent) |
tobyspark | 9:f83eadd8917a | 1085 | { |
tobyspark | 17:fc68d40b8b1f | 1086 | oldFadeAPercent = fadeAPercent; |
tobyspark | 9:f83eadd8917a | 1087 | fadeAPercent = newFadeAPercent; |
tobyspark | 9:f83eadd8917a | 1088 | updateFade = true; |
tobyspark | 9:f83eadd8917a | 1089 | |
tobyspark | 9:f83eadd8917a | 1090 | fadeAPO = fadeAPercent / 100.0; |
tobyspark | 9:f83eadd8917a | 1091 | tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent); |
tobyspark | 9:f83eadd8917a | 1092 | } |
tobyspark | 8:d46cc49f0f37 | 1093 | if (updateFade && debug) |
tobyspark | 8:d46cc49f0f37 | 1094 | { |
tobyspark | 0:87aab40d5806 | 1095 | //debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAIN.read(), fadeUpAIN.read()); |
tobyspark | 0:87aab40d5806 | 1096 | debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAINCached, fadeUpAINCached); |
tobyspark | 0:87aab40d5806 | 1097 | debug->printf("xFade = %3f fadeUp = %3f fadeA% = %i fadeB% = %i \r\n", xFade, fadeUp, fadeAPercent, fadeBPercent); |
tobyspark | 18:ebe5da639a6a | 1098 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 1099 | } |
tobyspark | 0:87aab40d5806 | 1100 | } |
tobyspark | 0:87aab40d5806 | 1101 | } |