![](/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@26:0299f8760715, 2012-10-28 (annotated)
- Committer:
- tobyspark
- Date:
- Sun Oct 28 15:17:28 2012 +0000
- Revision:
- 26:0299f8760715
- Parent:
- 25:3b519ef70341
- Child:
- 27:27851d3d2bba
Buffer overrun safe version of sprintf
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 | 23:909928cafb95 | 117 | Serial *debug = new Serial(USBTX, USBRX); // For debugging via USB serial |
tobyspark | 23:909928cafb95 | 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 | 15:4b394c64b461 | 160 | enum { mixBlend, mixAdditive, mixKey }; // additive will require custom TVOne firmware. |
tobyspark | 15:4b394c64b461 | 161 | int mixMode = mixBlend; |
tobyspark | 24:49c6624119ae | 162 | float fadeCurve = 1.0f; // 0 = "X", ie. as per blend, 1 = "/\" <-- 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 | 21:f9d63cb7cedb | 169 | enum { advancedHDCPOn, advancedHDCPOff, 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 | 24:49c6624119ae | 331 | if (mixMode == mixBlend) |
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 | 0:87aab40d5806 | 509 | int main() |
tobyspark | 0:87aab40d5806 | 510 | { |
tobyspark | 0:87aab40d5806 | 511 | if (debug) |
tobyspark | 0:87aab40d5806 | 512 | { |
tobyspark | 0:87aab40d5806 | 513 | debug->printf("\r\n\r\n"); |
tobyspark | 0:87aab40d5806 | 514 | debug->printf("*spark d-fuser -----------\r\n"); |
tobyspark | 0:87aab40d5806 | 515 | debug->printf(" debug channel\r\n"); |
tobyspark | 0:87aab40d5806 | 516 | } |
tobyspark | 2:50043054e4f7 | 517 | |
tobyspark | 2:50043054e4f7 | 518 | // Set display font |
tobyspark | 2:50043054e4f7 | 519 | screen.fontStartCharacter = &characterBytesStartChar; |
tobyspark | 2:50043054e4f7 | 520 | screen.fontEndCharacter = &characterBytesEndChar; |
tobyspark | 2:50043054e4f7 | 521 | screen.fontCharacters = characterBytes; |
tobyspark | 2:50043054e4f7 | 522 | |
tobyspark | 0:87aab40d5806 | 523 | // Splash screen |
tobyspark | 2:50043054e4f7 | 524 | screen.imageToBuffer(spkDisplayLogo); |
tobyspark | 0:87aab40d5806 | 525 | screen.textToBuffer("SPK:D-Fuser",0); |
tobyspark | 13:3796bde6ba8f | 526 | screen.textToBuffer(string("SW ") + kSPKDFSoftwareVersion,1); |
tobyspark | 5:f8b285ca41ba | 527 | screen.sendBuffer(); |
tobyspark | 0:87aab40d5806 | 528 | |
tobyspark | 11:0783cfbeb746 | 529 | // Load saved settings |
tobyspark | 16:52484666b323 | 530 | bool settingsAreCustom = false; |
tobyspark | 13:3796bde6ba8f | 531 | /* CRAZY, see note in spk_settings.h |
tobyspark | 16:52484666b323 | 532 | settingsAreCustom = settings.load(kSPKDFSettingsFilename); |
tobyspark | 16:52484666b323 | 533 | if (settingsAreCustom) |
tobyspark | 13:3796bde6ba8f | 534 | {screen.textToBuffer("Settings Read",2); screen.sendBuffer();} |
tobyspark | 13:3796bde6ba8f | 535 | else |
tobyspark | 13:3796bde6ba8f | 536 | {screen.textToBuffer("Settings NOT Read",2); screen.sendBuffer();} |
tobyspark | 13:3796bde6ba8f | 537 | */ |
tobyspark | 0:87aab40d5806 | 538 | // Set menu structure |
tobyspark | 0:87aab40d5806 | 539 | mixModeMenu.title = "Mix Mode"; |
tobyspark | 23:909928cafb95 | 540 | mixModeMenu.addMenuItem(SPKMenuItem("Blend", mixBlend)); |
tobyspark | 24:49c6624119ae | 541 | if (true) mixModeMenu.addMenuItem(SPKMenuItem("Additive", &mixModeAdditiveMenu)); // TODO: Detect whether SPKDF custom firmware |
tobyspark | 11:0783cfbeb746 | 542 | for (int i=0; i < settings.keyerSetCount(); i++) |
tobyspark | 11:0783cfbeb746 | 543 | { |
tobyspark | 23:909928cafb95 | 544 | mixModeMenu.addMenuItem(SPKMenuItem(settings.keyerParamName(i), mixKey+i)); |
tobyspark | 11:0783cfbeb746 | 545 | } |
tobyspark | 24:49c6624119ae | 546 | mixModeMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 24:49c6624119ae | 547 | |
tobyspark | 24:49c6624119ae | 548 | mixModeAdditiveMenu.title = "Additive - adjust midpoint"; |
tobyspark | 24:49c6624119ae | 549 | mixModeAdditiveMenu.addMenuItem(SPKMenuItem("click to return", &mixModeMenu, true)); |
tobyspark | 0:87aab40d5806 | 550 | |
tobyspark | 0:87aab40d5806 | 551 | resolutionMenu.title = "Resolution"; |
tobyspark | 16:52484666b323 | 552 | for (int i=0; i < settings.resolutionsCount(); i++) |
tobyspark | 16:52484666b323 | 553 | { |
tobyspark | 23:909928cafb95 | 554 | resolutionMenu.addMenuItem(SPKMenuItem(settings.resolutionName(i), settings.resolutionIndex(i), settings.resolutionEDIDIndex(i))); |
tobyspark | 16:52484666b323 | 555 | } |
tobyspark | 24:49c6624119ae | 556 | resolutionMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 0:87aab40d5806 | 557 | |
tobyspark | 5:f8b285ca41ba | 558 | commsMenu.title = "Network Mode"; |
tobyspark | 23:909928cafb95 | 559 | // commsMenu is built in mixer's run loop, depending on RJ45 mode. |
tobyspark | 23:909928cafb95 | 560 | |
tobyspark | 15:4b394c64b461 | 561 | advancedMenu.title = "Troubleshooting"; |
tobyspark | 23:909928cafb95 | 562 | advancedMenu.addMenuItem(SPKMenuItem("HDCP Off", advancedHDCPOff)); |
tobyspark | 23:909928cafb95 | 563 | advancedMenu.addMenuItem(SPKMenuItem("HDCP On", advancedHDCPOn)); |
tobyspark | 23:909928cafb95 | 564 | advancedMenu.addMenuItem(SPKMenuItem("Conform Processor", advancedConformProcessor)); |
tobyspark | 23:909928cafb95 | 565 | if (settingsAreCustom) advancedMenu.addMenuItem(SPKMenuItem("Revert to defaults", advancedLoadDefaults)); |
tobyspark | 23:909928cafb95 | 566 | advancedMenu.addMenuItem(SPKMenuItem("Start Self-Test", advancedSelfTest)); |
tobyspark | 24:49c6624119ae | 567 | advancedMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 23:909928cafb95 | 568 | |
tobyspark | 0:87aab40d5806 | 569 | mainMenu.title = "Main Menu"; |
tobyspark | 24:49c6624119ae | 570 | mainMenu.addMenuItem(SPKMenuItem(mixModeMenu.title, &mixModeMenu)); |
tobyspark | 24:49c6624119ae | 571 | mainMenu.addMenuItem(SPKMenuItem(resolutionMenu.title, &resolutionMenu)); |
tobyspark | 24:49c6624119ae | 572 | mainMenu.addMenuItem(SPKMenuItem(commsMenu.title, &commsMenu)); |
tobyspark | 24:49c6624119ae | 573 | mainMenu.addMenuItem(SPKMenuItem(advancedMenu.title, &advancedMenu)); |
tobyspark | 23:909928cafb95 | 574 | |
tobyspark | 0:87aab40d5806 | 575 | selectedMenu = &mainMenu; |
tobyspark | 23:909928cafb95 | 576 | |
tobyspark | 0:87aab40d5806 | 577 | // Misc I/O stuff |
tobyspark | 0:87aab40d5806 | 578 | |
tobyspark | 0:87aab40d5806 | 579 | fadeAPO.period(0.001); |
tobyspark | 0:87aab40d5806 | 580 | fadeBPO.period(0.001); |
tobyspark | 0:87aab40d5806 | 581 | |
tobyspark | 20:8b92d7922c48 | 582 | // Test for TV One connectivity and determine unit type |
tobyspark | 21:f9d63cb7cedb | 583 | int32_t testConnectionPayload = 0; |
tobyspark | 21:f9d63cb7cedb | 584 | |
tobyspark | 21:f9d63cb7cedb | 585 | // kTV1FunctionReadSoftwareVersion |
tobyspark | 21:f9d63cb7cedb | 586 | // kTV1FunctionReadProductType |
tobyspark | 21:f9d63cb7cedb | 587 | // kTV1FunctionReadBoardType |
tobyspark | 21:f9d63cb7cedb | 588 | bool ok = tvOne.readCommand(0, kTV1WindowIDA, kTV1FunctionReadSoftwareVersion, testConnectionPayload); |
tobyspark | 21:f9d63cb7cedb | 589 | |
tobyspark | 21:f9d63cb7cedb | 590 | string tvOneDetectString = ok ? "TVOne link ok" : "TVOne link failed"; |
tobyspark | 21:f9d63cb7cedb | 591 | |
tobyspark | 21:f9d63cb7cedb | 592 | // TODO: Use software version to select resolution slots etc? |
tobyspark | 21:f9d63cb7cedb | 593 | // TODO: Use product / board type to select TVOne conform type? |
tobyspark | 23:909928cafb95 | 594 | |
tobyspark | 12:c270870bdd23 | 595 | // Display menu and framing lines |
tobyspark | 0:87aab40d5806 | 596 | screen.horizLineToBuffer(kMenuLine1*pixInPage - 1); |
tobyspark | 0:87aab40d5806 | 597 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 598 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 599 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 600 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 601 | screen.horizLineToBuffer(kMenuLine2*pixInPage + pixInPage); |
tobyspark | 1:f9fca21102e0 | 602 | screen.horizLineToBuffer(kCommsStatusLine*pixInPage - 1); |
tobyspark | 1:f9fca21102e0 | 603 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 21:f9d63cb7cedb | 604 | screen.textToBuffer(tvOneDetectString, kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 605 | screen.sendBuffer(); |
tobyspark | 0:87aab40d5806 | 606 | |
tobyspark | 0:87aab40d5806 | 607 | //// CONTROLS TEST |
tobyspark | 0:87aab40d5806 | 608 | |
tobyspark | 0:87aab40d5806 | 609 | while (0) { |
tobyspark | 0:87aab40d5806 | 610 | 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 | 611 | } |
tobyspark | 0:87aab40d5806 | 612 | |
tobyspark | 0:87aab40d5806 | 613 | //// MIXER RUN |
tobyspark | 0:87aab40d5806 | 614 | |
tobyspark | 8:d46cc49f0f37 | 615 | while (1) |
tobyspark | 8:d46cc49f0f37 | 616 | { |
tobyspark | 1:f9fca21102e0 | 617 | //// Task background things |
tobyspark | 5:f8b285ca41ba | 618 | if (ethernet && rj45Mode == rj45Ethernet) |
tobyspark | 5:f8b285ca41ba | 619 | { |
tobyspark | 5:f8b285ca41ba | 620 | Net::poll(); |
tobyspark | 5:f8b285ca41ba | 621 | } |
tobyspark | 5:f8b285ca41ba | 622 | |
tobyspark | 5:f8b285ca41ba | 623 | //// RJ45 SWITCH |
tobyspark | 5:f8b285ca41ba | 624 | |
tobyspark | 5:f8b285ca41ba | 625 | if (rj45ModeDIN != rj45Mode) |
tobyspark | 1:f9fca21102e0 | 626 | { |
tobyspark | 23:909928cafb95 | 627 | if (debug) debug->printf("Handling RJ45 mode change\r\n"); |
tobyspark | 5:f8b285ca41ba | 628 | // update state |
tobyspark | 5:f8b285ca41ba | 629 | rj45Mode = rj45ModeDIN; |
tobyspark | 23:909928cafb95 | 630 | if (rj45Mode == rj45Ethernet) |
tobyspark | 23:909928cafb95 | 631 | { |
tobyspark | 23:909928cafb95 | 632 | commsMenu.title = "Network Mode [Ethernet]"; |
tobyspark | 23:909928cafb95 | 633 | commsMenu.clearMenuItems(); |
tobyspark | 23:909928cafb95 | 634 | commsMenu.addMenuItem(SPKMenuItem("None", commsNone)); |
tobyspark | 23:909928cafb95 | 635 | commsMenu.addMenuItem(SPKMenuItem("OSC", commsOSC)); |
tobyspark | 23:909928cafb95 | 636 | commsMenu.addMenuItem(SPKMenuItem("ArtNet", commsArtNet)); |
tobyspark | 24:49c6624119ae | 637 | commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 23:909928cafb95 | 638 | } |
tobyspark | 23:909928cafb95 | 639 | if (rj45Mode == rj45DMX) |
tobyspark | 23:909928cafb95 | 640 | { |
tobyspark | 23:909928cafb95 | 641 | commsMenu.title = "Network Mode [DMX]"; |
tobyspark | 23:909928cafb95 | 642 | commsMenu.clearMenuItems(); |
tobyspark | 23:909928cafb95 | 643 | commsMenu.addMenuItem(SPKMenuItem("None", commsNone)); |
tobyspark | 23:909928cafb95 | 644 | commsMenu.addMenuItem(SPKMenuItem("DMX In", commsDMXIn)); |
tobyspark | 23:909928cafb95 | 645 | commsMenu.addMenuItem(SPKMenuItem("DMX Out", commsDMXOut)); |
tobyspark | 24:49c6624119ae | 646 | commsMenu.addMenuItem(SPKMenuItem("Back to Main Menu", &mainMenu)); |
tobyspark | 23:909928cafb95 | 647 | } |
tobyspark | 5:f8b285ca41ba | 648 | |
tobyspark | 5:f8b285ca41ba | 649 | // cancel old comms |
tobyspark | 5:f8b285ca41ba | 650 | commsMode = commsNone; |
tobyspark | 5:f8b285ca41ba | 651 | commsMenu = commsMode; |
tobyspark | 5:f8b285ca41ba | 652 | |
tobyspark | 5:f8b285ca41ba | 653 | // refresh display |
tobyspark | 23:909928cafb95 | 654 | if (selectedMenu == &commsMenu) |
tobyspark | 23:909928cafb95 | 655 | { |
tobyspark | 23:909928cafb95 | 656 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 23:909928cafb95 | 657 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 23:909928cafb95 | 658 | } |
tobyspark | 5:f8b285ca41ba | 659 | if (rj45Mode == rj45Ethernet) screen.textToBuffer("RJ45: Ethernet Engaged", kCommsStatusLine); |
tobyspark | 5:f8b285ca41ba | 660 | if (rj45Mode == rj45DMX) screen.textToBuffer("RJ45: DMX Engaged", kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 661 | } |
tobyspark | 1:f9fca21102e0 | 662 | |
tobyspark | 0:87aab40d5806 | 663 | //// MENU |
tobyspark | 0:87aab40d5806 | 664 | |
tobyspark | 0:87aab40d5806 | 665 | int menuChange = menuEnc.getChange(); |
tobyspark | 0:87aab40d5806 | 666 | |
tobyspark | 0:87aab40d5806 | 667 | // Update GUI |
tobyspark | 0:87aab40d5806 | 668 | if (menuChange != 0) |
tobyspark | 0:87aab40d5806 | 669 | { |
tobyspark | 24:49c6624119ae | 670 | if (selectedMenu->selectedItem().handlingControls) |
tobyspark | 24:49c6624119ae | 671 | { |
tobyspark | 24:49c6624119ae | 672 | if (selectedMenu == &mixModeAdditiveMenu) |
tobyspark | 24:49c6624119ae | 673 | { |
tobyspark | 24:49c6624119ae | 674 | fadeCurve += menuChange * 0.05; |
tobyspark | 24:49c6624119ae | 675 | if (fadeCurve > 1.0f) fadeCurve = 1.0f; |
tobyspark | 24:49c6624119ae | 676 | if (fadeCurve < 0.0f) fadeCurve = 0.0f; |
tobyspark | 25:3b519ef70341 | 677 | |
tobyspark | 26:0299f8760715 | 678 | char fadeCurveMessage[kStringBufferLength]; |
tobyspark | 26:0299f8760715 | 679 | snprintf(fadeCurveMessage, kStringBufferLength, "Blend < %1.2f > Additive", fadeCurve); |
tobyspark | 24:49c6624119ae | 680 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 25:3b519ef70341 | 681 | screen.textToBuffer(fadeCurveMessage, kMenuLine2); |
tobyspark | 24:49c6624119ae | 682 | |
tobyspark | 24:49c6624119ae | 683 | if (debug) debug->printf("Fade curve changed by %i to %f", menuChange, fadeCurve); |
tobyspark | 24:49c6624119ae | 684 | } |
tobyspark | 24:49c6624119ae | 685 | } |
tobyspark | 24:49c6624119ae | 686 | else |
tobyspark | 24:49c6624119ae | 687 | { |
tobyspark | 24:49c6624119ae | 688 | if (debug) debug->printf("Menu changed by %i\r\n", menuChange); |
tobyspark | 24:49c6624119ae | 689 | |
tobyspark | 24:49c6624119ae | 690 | *selectedMenu = selectedMenu->selectedIndex() + menuChange; |
tobyspark | 24:49c6624119ae | 691 | |
tobyspark | 24:49c6624119ae | 692 | // update OLED line 2 here |
tobyspark | 24:49c6624119ae | 693 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 24:49c6624119ae | 694 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 24:49c6624119ae | 695 | |
tobyspark | 24:49c6624119ae | 696 | if (debug) debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 24:49c6624119ae | 697 | } |
tobyspark | 0:87aab40d5806 | 698 | } |
tobyspark | 0:87aab40d5806 | 699 | |
tobyspark | 0:87aab40d5806 | 700 | // Action menu item |
tobyspark | 0:87aab40d5806 | 701 | if (menuEnc.hasPressed()) |
tobyspark | 0:87aab40d5806 | 702 | { |
tobyspark | 0:87aab40d5806 | 703 | if (debug) debug->printf("Action Menu Item!\r\n"); |
tobyspark | 21:f9d63cb7cedb | 704 | |
tobyspark | 0:87aab40d5806 | 705 | // Are we changing menus? |
tobyspark | 23:909928cafb95 | 706 | if (selectedMenu->selectedItem().type == SPKMenuItem::changesToMenu) |
tobyspark | 0:87aab40d5806 | 707 | { |
tobyspark | 0:87aab40d5806 | 708 | // point selected menu to the new menu |
tobyspark | 23:909928cafb95 | 709 | selectedMenu = selectedMenu->selectedItem().payload.menu; |
tobyspark | 0:87aab40d5806 | 710 | |
tobyspark | 0:87aab40d5806 | 711 | // update OLED lines 1&2 |
tobyspark | 0:87aab40d5806 | 712 | screen.clearBufferRow(kMenuLine1); |
tobyspark | 0:87aab40d5806 | 713 | screen.clearBufferRow(kMenuLine2); |
tobyspark | 0:87aab40d5806 | 714 | screen.textToBuffer(selectedMenu->title, kMenuLine1); |
tobyspark | 0:87aab40d5806 | 715 | screen.textToBuffer(selectedMenu->selectedString(), kMenuLine2); |
tobyspark | 0:87aab40d5806 | 716 | |
tobyspark | 0:87aab40d5806 | 717 | if (debug) |
tobyspark | 0:87aab40d5806 | 718 | { |
tobyspark | 0:87aab40d5806 | 719 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 720 | debug->printf("%s \r\n", selectedMenu->title.c_str()); |
tobyspark | 0:87aab40d5806 | 721 | debug->printf("%s \r\n", selectedMenu->selectedString().c_str()); |
tobyspark | 0:87aab40d5806 | 722 | } |
tobyspark | 24:49c6624119ae | 723 | |
tobyspark | 24:49c6624119ae | 724 | // Are we changing menus that should have a command attached? |
tobyspark | 24:49c6624119ae | 725 | if (selectedMenu == &mixModeAdditiveMenu) |
tobyspark | 24:49c6624119ae | 726 | { |
tobyspark | 24:49c6624119ae | 727 | mixMode = mixAdditive; |
tobyspark | 24:49c6624119ae | 728 | actionMixMode(); |
tobyspark | 24:49c6624119ae | 729 | } |
tobyspark | 0:87aab40d5806 | 730 | } |
tobyspark | 0:87aab40d5806 | 731 | // With that out of the way, we should be actioning a specific menu's payload? |
tobyspark | 0:87aab40d5806 | 732 | else if (selectedMenu == &mixModeMenu) |
tobyspark | 0:87aab40d5806 | 733 | { |
tobyspark | 23:909928cafb95 | 734 | mixMode = mixModeMenu.selectedItem().payload.command[0]; |
tobyspark | 24:49c6624119ae | 735 | actionMixMode(); |
tobyspark | 0:87aab40d5806 | 736 | } |
tobyspark | 0:87aab40d5806 | 737 | else if (selectedMenu == &resolutionMenu) |
tobyspark | 0:87aab40d5806 | 738 | { |
tobyspark | 9:f83eadd8917a | 739 | bool ok = true; |
tobyspark | 0:87aab40d5806 | 740 | |
tobyspark | 23:909928cafb95 | 741 | ok = tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustOutputsOutputResolution, resolutionMenu.selectedItem().payload.command[0]); |
tobyspark | 23:909928cafb95 | 742 | ok = ok && tvOne.command(kTV1SourceRGB1, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedItem().payload.command[1]); |
tobyspark | 23:909928cafb95 | 743 | ok = ok && tvOne.command(kTV1SourceRGB2, kTV1WindowIDA, kTV1FunctionAdjustSourceEDID, resolutionMenu.selectedItem().payload.command[1]); |
tobyspark | 0:87aab40d5806 | 744 | |
tobyspark | 25:3b519ef70341 | 745 | string sentOK; |
tobyspark | 0:87aab40d5806 | 746 | if (ok) sentOK = "Sent: "; |
tobyspark | 0:87aab40d5806 | 747 | else sentOK = "Send Error: "; |
tobyspark | 0:87aab40d5806 | 748 | |
tobyspark | 26:0299f8760715 | 749 | char sentMSGBuffer[kStringBufferLength]; |
tobyspark | 26:0299f8760715 | 750 | snprintf(sentMSGBuffer, kStringBufferLength,"Res %i, EDID %i", resolutionMenu.selectedItem().payload.command[0], resolutionMenu.selectedItem().payload.command[1]); |
tobyspark | 0:87aab40d5806 | 751 | |
tobyspark | 1:f9fca21102e0 | 752 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 25:3b519ef70341 | 753 | screen.textToBuffer(sentOK + sentMSGBuffer, kTVOneStatusLine); |
tobyspark | 0:87aab40d5806 | 754 | |
tobyspark | 0:87aab40d5806 | 755 | if (debug) { debug->printf("Changing resolution"); } |
tobyspark | 0:87aab40d5806 | 756 | } |
tobyspark | 1:f9fca21102e0 | 757 | else if (selectedMenu == &commsMenu) |
tobyspark | 1:f9fca21102e0 | 758 | { |
tobyspark | 26:0299f8760715 | 759 | string commsTypeString = "Network:"; |
tobyspark | 26:0299f8760715 | 760 | char commsStatusBuffer[kStringBufferLength] = "--"; |
tobyspark | 1:f9fca21102e0 | 761 | |
tobyspark | 1:f9fca21102e0 | 762 | // Tear down any existing comms |
tobyspark | 1:f9fca21102e0 | 763 | // This is the action of commsNone |
tobyspark | 1:f9fca21102e0 | 764 | // And also clears the way for other comms actions |
tobyspark | 26:0299f8760715 | 765 | commsMode = commsNone; |
tobyspark | 5:f8b285ca41ba | 766 | if (osc) {delete osc; osc = NULL;} |
tobyspark | 5:f8b285ca41ba | 767 | if (ethernet) {delete ethernet; ethernet = NULL;} |
tobyspark | 5:f8b285ca41ba | 768 | if (artNet) {delete artNet; artNet = NULL;} |
tobyspark | 5:f8b285ca41ba | 769 | if (dmx) {delete dmx; dmx = NULL;} |
tobyspark | 5:f8b285ca41ba | 770 | |
tobyspark | 5:f8b285ca41ba | 771 | // Ensure we can't change to comms modes the hardware isn't switched to |
tobyspark | 23:909928cafb95 | 772 | if (rj45Mode == rj45DMX && (commsMenu.selectedItem().payload.command[0] == commsOSC || commsMenu.selectedItem().payload.command[0] == commsArtNet)) |
tobyspark | 1:f9fca21102e0 | 773 | { |
tobyspark | 5:f8b285ca41ba | 774 | commsTypeString = "RJ45 not in Ethernet mode"; |
tobyspark | 5:f8b285ca41ba | 775 | } |
tobyspark | 23:909928cafb95 | 776 | else if (rj45Mode == rj45Ethernet && (commsMenu.selectedItem().payload.command[0] == commsDMXIn || commsMenu.selectedItem().payload.command[0] == commsDMXOut)) |
tobyspark | 5:f8b285ca41ba | 777 | { |
tobyspark | 5:f8b285ca41ba | 778 | commsTypeString = "RJ45 not in DMX mode"; |
tobyspark | 5:f8b285ca41ba | 779 | } |
tobyspark | 5:f8b285ca41ba | 780 | // Action! |
tobyspark | 23:909928cafb95 | 781 | else if (commsMenu.selectedItem().payload.command[0] == commsOSC) |
tobyspark | 5:f8b285ca41ba | 782 | { |
tobyspark | 5:f8b285ca41ba | 783 | commsMode = commsOSC; |
tobyspark | 5:f8b285ca41ba | 784 | commsTypeString = "OSC: "; |
tobyspark | 1:f9fca21102e0 | 785 | |
tobyspark | 1:f9fca21102e0 | 786 | ethernet = new EthernetNetIf( |
tobyspark | 1:f9fca21102e0 | 787 | IpAddr(kOSCMbedIPAddress), |
tobyspark | 1:f9fca21102e0 | 788 | IpAddr(kOSCMbedSubnetMask), |
tobyspark | 1:f9fca21102e0 | 789 | IpAddr(kOSCMbedGateway), |
tobyspark | 1:f9fca21102e0 | 790 | IpAddr(kOSCMbedDNS) |
tobyspark | 1:f9fca21102e0 | 791 | ); |
tobyspark | 3:033d2b7768f3 | 792 | |
tobyspark | 1:f9fca21102e0 | 793 | EthernetErr ethError = ethernet->setup(); |
tobyspark | 1:f9fca21102e0 | 794 | if(ethError) |
tobyspark | 1:f9fca21102e0 | 795 | { |
tobyspark | 1:f9fca21102e0 | 796 | if (debug) debug->printf("Ethernet setup error, %d", ethError); |
tobyspark | 26:0299f8760715 | 797 | snprintf(commsStatusBuffer, kStringBufferLength, "Ethernet setup failed"); |
tobyspark | 5:f8b285ca41ba | 798 | commsMenu = commsNone; |
tobyspark | 1:f9fca21102e0 | 799 | // break out of here. this setup should be a function that returns a boolean |
tobyspark | 1:f9fca21102e0 | 800 | } |
tobyspark | 1:f9fca21102e0 | 801 | |
tobyspark | 1:f9fca21102e0 | 802 | osc = new OSCClass(); |
tobyspark | 3:033d2b7768f3 | 803 | osc->setReceiveMessage(&recMessage); |
tobyspark | 1:f9fca21102e0 | 804 | osc->begin(kOSCMbedPort); |
tobyspark | 1:f9fca21102e0 | 805 | |
tobyspark | 26:0299f8760715 | 806 | snprintf(commsStatusBuffer, kStringBufferLength, "Listening on %i", kOSCMbedPort); |
tobyspark | 1:f9fca21102e0 | 807 | } |
tobyspark | 23:909928cafb95 | 808 | else if (commsMenu.selectedItem().payload.command[0] == commsArtNet) |
tobyspark | 1:f9fca21102e0 | 809 | { |
tobyspark | 5:f8b285ca41ba | 810 | commsMode = commsArtNet; |
tobyspark | 5:f8b285ca41ba | 811 | commsTypeString = "ArtNet: "; |
tobyspark | 3:033d2b7768f3 | 812 | |
tobyspark | 3:033d2b7768f3 | 813 | artNet = new DmxArtNet(); |
tobyspark | 1:f9fca21102e0 | 814 | |
tobyspark | 3:033d2b7768f3 | 815 | artNet->BindIpAddress = IpAddr(kArtNetBindIPAddress); |
tobyspark | 3:033d2b7768f3 | 816 | artNet->BCastAddress = IpAddr(kArtNetBroadcastAddress); |
tobyspark | 3:033d2b7768f3 | 817 | |
tobyspark | 3:033d2b7768f3 | 818 | artNet->InitArtPollReplyDefaults(); |
tobyspark | 3:033d2b7768f3 | 819 | |
tobyspark | 3:033d2b7768f3 | 820 | artNet->ArtPollReply.PortType[0] = 128; // output |
tobyspark | 3:033d2b7768f3 | 821 | artNet->ArtPollReply.PortType[2] = 64; // input |
tobyspark | 3:033d2b7768f3 | 822 | artNet->ArtPollReply.GoodInput[2] = 4; |
tobyspark | 3:033d2b7768f3 | 823 | |
tobyspark | 3:033d2b7768f3 | 824 | artNet->Init(); |
tobyspark | 3:033d2b7768f3 | 825 | artNet->SendArtPollReply(); // announce to art-net nodes |
tobyspark | 3:033d2b7768f3 | 826 | |
tobyspark | 26:0299f8760715 | 827 | snprintf(commsStatusBuffer, kStringBufferLength, "Listening"); |
tobyspark | 1:f9fca21102e0 | 828 | } |
tobyspark | 23:909928cafb95 | 829 | else if (commsMenu.selectedItem().payload.command[0] == commsDMXIn) |
tobyspark | 1:f9fca21102e0 | 830 | { |
tobyspark | 5:f8b285ca41ba | 831 | commsMode = commsDMXIn; |
tobyspark | 5:f8b285ca41ba | 832 | commsTypeString = "DMX In: "; |
tobyspark | 1:f9fca21102e0 | 833 | |
tobyspark | 5:f8b285ca41ba | 834 | dmxDirectionDOUT = 0; |
tobyspark | 5:f8b285ca41ba | 835 | |
tobyspark | 5:f8b285ca41ba | 836 | dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX); |
tobyspark | 1:f9fca21102e0 | 837 | } |
tobyspark | 23:909928cafb95 | 838 | else if (commsMenu.selectedItem().payload.command[0] == commsDMXOut) |
tobyspark | 5:f8b285ca41ba | 839 | { |
tobyspark | 5:f8b285ca41ba | 840 | commsMode = commsDMXOut; |
tobyspark | 5:f8b285ca41ba | 841 | commsTypeString = "DMX Out: "; |
tobyspark | 5:f8b285ca41ba | 842 | |
tobyspark | 5:f8b285ca41ba | 843 | dmxDirectionDOUT = 1; |
tobyspark | 5:f8b285ca41ba | 844 | |
tobyspark | 5:f8b285ca41ba | 845 | dmx = new DMX(kMBED_RS485_TTLTX, kMBED_RS485_TTLRX); |
tobyspark | 5:f8b285ca41ba | 846 | } |
tobyspark | 5:f8b285ca41ba | 847 | |
tobyspark | 1:f9fca21102e0 | 848 | screen.clearBufferRow(kCommsStatusLine); |
tobyspark | 25:3b519ef70341 | 849 | screen.textToBuffer(commsTypeString + commsStatusBuffer, kCommsStatusLine); |
tobyspark | 1:f9fca21102e0 | 850 | } |
tobyspark | 12:c270870bdd23 | 851 | else if (selectedMenu == &advancedMenu) |
tobyspark | 12:c270870bdd23 | 852 | { |
tobyspark | 23:909928cafb95 | 853 | if (advancedMenu.selectedItem().payload.command[0] == advancedHDCPOff) |
tobyspark | 12:c270870bdd23 | 854 | { |
tobyspark | 12:c270870bdd23 | 855 | bool ok = false; |
tobyspark | 12:c270870bdd23 | 856 | |
tobyspark | 15:4b394c64b461 | 857 | ok = tvOne.setHDCPOn(false); |
tobyspark | 12:c270870bdd23 | 858 | |
tobyspark | 12:c270870bdd23 | 859 | std::string sendOK = ok ? "Sent: HDCP Off" : "Send Error: HDCP Off"; |
tobyspark | 12:c270870bdd23 | 860 | |
tobyspark | 12:c270870bdd23 | 861 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 12:c270870bdd23 | 862 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 12:c270870bdd23 | 863 | } |
tobyspark | 23:909928cafb95 | 864 | else if (advancedMenu.selectedItem().payload.command[0] == advancedHDCPOn) |
tobyspark | 15:4b394c64b461 | 865 | { |
tobyspark | 15:4b394c64b461 | 866 | bool ok = false; |
tobyspark | 15:4b394c64b461 | 867 | |
tobyspark | 15:4b394c64b461 | 868 | ok = tvOne.setHDCPOn(true); |
tobyspark | 15:4b394c64b461 | 869 | |
tobyspark | 15:4b394c64b461 | 870 | std::string sendOK = ok ? "Sent: HDCP On" : "Send Error: HDCP On"; |
tobyspark | 15:4b394c64b461 | 871 | |
tobyspark | 15:4b394c64b461 | 872 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 15:4b394c64b461 | 873 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 15:4b394c64b461 | 874 | } |
tobyspark | 23:909928cafb95 | 875 | else if (advancedMenu.selectedItem().payload.command[0] == advancedConformProcessor) |
tobyspark | 17:fc68d40b8b1f | 876 | { |
tobyspark | 20:8b92d7922c48 | 877 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 20:8b92d7922c48 | 878 | screen.textToBuffer("Conforming...", kTVOneStatusLine); |
tobyspark | 20:8b92d7922c48 | 879 | screen.sendBuffer(); |
tobyspark | 20:8b92d7922c48 | 880 | |
tobyspark | 17:fc68d40b8b1f | 881 | bool ok = conformProcessor(); |
tobyspark | 17:fc68d40b8b1f | 882 | |
tobyspark | 17:fc68d40b8b1f | 883 | std::string sendOK = ok ? "Conform success" : "Send Error: Conform"; |
tobyspark | 17:fc68d40b8b1f | 884 | |
tobyspark | 17:fc68d40b8b1f | 885 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 17:fc68d40b8b1f | 886 | screen.textToBuffer(sendOK, kTVOneStatusLine); |
tobyspark | 17:fc68d40b8b1f | 887 | } |
tobyspark | 23:909928cafb95 | 888 | else if (advancedMenu.selectedItem().payload.command[0] == advancedLoadDefaults) |
tobyspark | 16:52484666b323 | 889 | { |
tobyspark | 16:52484666b323 | 890 | settings.loadDefaults(); |
tobyspark | 16:52484666b323 | 891 | |
tobyspark | 16:52484666b323 | 892 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 16:52484666b323 | 893 | screen.textToBuffer("Controller reverted", kTVOneStatusLine); |
tobyspark | 16:52484666b323 | 894 | } |
tobyspark | 23:909928cafb95 | 895 | else if (advancedMenu.selectedItem().payload.command[0] == advancedSelfTest) |
tobyspark | 15:4b394c64b461 | 896 | { |
tobyspark | 17:fc68d40b8b1f | 897 | selfTest(); |
tobyspark | 15:4b394c64b461 | 898 | } |
tobyspark | 23:909928cafb95 | 899 | else if (advancedMenu.selectedItem().payload.command[0] == advancedSetResolutions) |
tobyspark | 21:f9d63cb7cedb | 900 | { |
tobyspark | 21:f9d63cb7cedb | 901 | bool ok; |
tobyspark | 21:f9d63cb7cedb | 902 | ok = tvOne.setCustomResolutions(); |
tobyspark | 21:f9d63cb7cedb | 903 | |
tobyspark | 21:f9d63cb7cedb | 904 | screen.clearBufferRow(kTVOneStatusLine); |
tobyspark | 21:f9d63cb7cedb | 905 | screen.textToBuffer(ok ? "Resolutions set" : "Res' could not be set", kTVOneStatusLine); |
tobyspark | 21:f9d63cb7cedb | 906 | } |
tobyspark | 12:c270870bdd23 | 907 | } |
tobyspark | 0:87aab40d5806 | 908 | else |
tobyspark | 0:87aab40d5806 | 909 | { |
tobyspark | 0:87aab40d5806 | 910 | if (debug) { debug->printf("Warning: No action identified"); } |
tobyspark | 0:87aab40d5806 | 911 | } |
tobyspark | 0:87aab40d5806 | 912 | } |
tobyspark | 0:87aab40d5806 | 913 | |
tobyspark | 2:50043054e4f7 | 914 | // Send any updates to the display |
tobyspark | 2:50043054e4f7 | 915 | screen.sendBuffer(); |
tobyspark | 5:f8b285ca41ba | 916 | |
tobyspark | 0:87aab40d5806 | 917 | |
tobyspark | 5:f8b285ca41ba | 918 | //// MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIX MIXMIX MIX MIXMIX MIX MIX MIX MIX MIXMIX MIX MIX |
tobyspark | 0:87aab40d5806 | 919 | |
tobyspark | 0:87aab40d5806 | 920 | bool updateFade = false; |
tobyspark | 3:033d2b7768f3 | 921 | float xFade = 0; |
tobyspark | 3:033d2b7768f3 | 922 | float fadeUp = 1; |
tobyspark | 3:033d2b7768f3 | 923 | |
tobyspark | 3:033d2b7768f3 | 924 | //// TASK: Process control surface |
tobyspark | 3:033d2b7768f3 | 925 | |
tobyspark | 0:87aab40d5806 | 926 | // Get new states of tap buttons, remembering at end of loop() assign these current values to the previous variables |
tobyspark | 5:f8b285ca41ba | 927 | const bool tapLeft = !tapLeftDIN; |
tobyspark | 5:f8b285ca41ba | 928 | const bool tapRight = !tapRightDIN; |
tobyspark | 0:87aab40d5806 | 929 | |
tobyspark | 17:fc68d40b8b1f | 930 | // We're taking a further median of the AINs on top of mbed libs v29. |
tobyspark | 17:fc68d40b8b1f | 931 | // This takes some values from last passes and most from now. With debug off, seem to need median size > 5 |
tobyspark | 17:fc68d40b8b1f | 932 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 933 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 934 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 935 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 936 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 937 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 938 | xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 939 | fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 940 | const float xFadeAINCached = xFadeFilter.process(xFadeAIN.read()); |
tobyspark | 17:fc68d40b8b1f | 941 | const float fadeUpAINCached = fadeUpFilter.process(fadeUpAIN.read()); |
tobyspark | 0:87aab40d5806 | 942 | |
tobyspark | 0:87aab40d5806 | 943 | // When a tap is depressed, we can ignore any move of the crossfader but not fade to black |
tobyspark | 0:87aab40d5806 | 944 | if (tapLeft || tapRight) |
tobyspark | 0:87aab40d5806 | 945 | { |
tobyspark | 5:f8b285ca41ba | 946 | // If both are pressed, take to the one that is new, ie. not the first pressed. |
tobyspark | 0:87aab40d5806 | 947 | if (tapLeft && tapRight) |
tobyspark | 0:87aab40d5806 | 948 | { |
tobyspark | 5:f8b285ca41ba | 949 | xFade = tapLeftWasFirstPressed ? 1 : 0; |
tobyspark | 0:87aab40d5806 | 950 | } |
tobyspark | 5:f8b285ca41ba | 951 | // If just one is pressed, take to that and remember which is pressed |
tobyspark | 5:f8b285ca41ba | 952 | else if (tapLeft) |
tobyspark | 5:f8b285ca41ba | 953 | { |
tobyspark | 5:f8b285ca41ba | 954 | xFade = 0; |
tobyspark | 5:f8b285ca41ba | 955 | tapLeftWasFirstPressed = 1; |
tobyspark | 5:f8b285ca41ba | 956 | } |
tobyspark | 5:f8b285ca41ba | 957 | else if (tapRight) |
tobyspark | 5:f8b285ca41ba | 958 | { |
tobyspark | 5:f8b285ca41ba | 959 | xFade = 1; |
tobyspark | 5:f8b285ca41ba | 960 | tapLeftWasFirstPressed = 0; |
tobyspark | 5:f8b285ca41ba | 961 | } |
tobyspark | 5:f8b285ca41ba | 962 | } |
tobyspark | 18:ebe5da639a6a | 963 | else xFade = 1.0 - fadeCalc(xFadeAINCached, xFadeTolerance); |
tobyspark | 0:87aab40d5806 | 964 | |
tobyspark | 0:87aab40d5806 | 965 | fadeUp = 1.0 - fadeCalc(fadeUpAINCached, fadeUpTolerance); |
tobyspark | 0:87aab40d5806 | 966 | |
tobyspark | 3:033d2b7768f3 | 967 | //// TASK: Process Network Comms |
tobyspark | 5:f8b285ca41ba | 968 | if (commsMode == commsOSC) |
tobyspark | 3:033d2b7768f3 | 969 | { |
tobyspark | 3:033d2b7768f3 | 970 | if (osc->newMessage) |
tobyspark | 3:033d2b7768f3 | 971 | { |
tobyspark | 3:033d2b7768f3 | 972 | osc->newMessage = false; // fixme! |
tobyspark | 3:033d2b7768f3 | 973 | processOSC(xFade, fadeUp); |
tobyspark | 3:033d2b7768f3 | 974 | } |
tobyspark | 3:033d2b7768f3 | 975 | } |
tobyspark | 3:033d2b7768f3 | 976 | |
tobyspark | 5:f8b285ca41ba | 977 | if (commsMode == commsArtNet) |
tobyspark | 3:033d2b7768f3 | 978 | { |
tobyspark | 3:033d2b7768f3 | 979 | if (artNet->Work()) processArtNet(xFade, fadeUp); |
tobyspark | 3:033d2b7768f3 | 980 | } |
tobyspark | 3:033d2b7768f3 | 981 | |
tobyspark | 5:f8b285ca41ba | 982 | if (commsMode == commsDMXIn) |
tobyspark | 5:f8b285ca41ba | 983 | { |
tobyspark | 5:f8b285ca41ba | 984 | processDMXIn(xFade, fadeUp); |
tobyspark | 5:f8b285ca41ba | 985 | } |
tobyspark | 5:f8b285ca41ba | 986 | |
tobyspark | 5:f8b285ca41ba | 987 | if (commsMode == commsDMXOut) |
tobyspark | 5:f8b285ca41ba | 988 | { |
tobyspark | 5:f8b285ca41ba | 989 | processDMXOut(xFade, fadeUp); |
tobyspark | 5:f8b285ca41ba | 990 | } |
tobyspark | 0:87aab40d5806 | 991 | |
tobyspark | 0:87aab40d5806 | 992 | // Calculate new A&B fade percents |
tobyspark | 0:87aab40d5806 | 993 | int newFadeAPercent = 0; |
tobyspark | 0:87aab40d5806 | 994 | int newFadeBPercent = 0; |
tobyspark | 0:87aab40d5806 | 995 | |
tobyspark | 15:4b394c64b461 | 996 | if (mixMode == mixBlend) |
tobyspark | 11:0783cfbeb746 | 997 | { |
tobyspark | 22:90054fe6d86c | 998 | if (fadeUp < 1.0) // TODO: OR if a source is not valid |
tobyspark | 9:f83eadd8917a | 999 | { |
tobyspark | 9:f83eadd8917a | 1000 | // 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 | 1001 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 9:f83eadd8917a | 1002 | newFadeBPercent = xFade * fadeUp * 100.0; |
tobyspark | 9:f83eadd8917a | 1003 | } |
tobyspark | 9:f83eadd8917a | 1004 | else |
tobyspark | 9:f83eadd8917a | 1005 | { |
tobyspark | 9:f83eadd8917a | 1006 | // 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 | 1007 | newFadeAPercent = (1.0-xFade) * 100.0; |
tobyspark | 9:f83eadd8917a | 1008 | newFadeBPercent = 100.0; |
tobyspark | 9:f83eadd8917a | 1009 | } |
tobyspark | 11:0783cfbeb746 | 1010 | } |
tobyspark | 15:4b394c64b461 | 1011 | else if (mixMode == mixAdditive) |
tobyspark | 11:0783cfbeb746 | 1012 | { |
tobyspark | 22:90054fe6d86c | 1013 | // we need to set fade level of both windows according to the fade curve profile |
tobyspark | 22:90054fe6d86c | 1014 | float newFadeA = (1.0-xFade) * (1.0 + fadeCurve); |
tobyspark | 22:90054fe6d86c | 1015 | float newFadeB = xFade * (1 + fadeCurve); |
tobyspark | 22:90054fe6d86c | 1016 | if (newFadeA > 1.0) newFadeA = 1.0; |
tobyspark | 22:90054fe6d86c | 1017 | if (newFadeB > 1.0) newFadeB = 1.0; |
tobyspark | 22:90054fe6d86c | 1018 | |
tobyspark | 22:90054fe6d86c | 1019 | newFadeAPercent = newFadeA * fadeUp * 100.0; |
tobyspark | 22:90054fe6d86c | 1020 | newFadeBPercent = newFadeB * fadeUp * 100.0; |
tobyspark | 11:0783cfbeb746 | 1021 | } |
tobyspark | 15:4b394c64b461 | 1022 | else if (mixMode >= mixKey) |
tobyspark | 11:0783cfbeb746 | 1023 | { |
tobyspark | 0:87aab40d5806 | 1024 | newFadeAPercent = (1.0-xFade) * fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 1025 | newFadeBPercent = fadeUp * 100.0; |
tobyspark | 0:87aab40d5806 | 1026 | } |
tobyspark | 0:87aab40d5806 | 1027 | |
tobyspark | 17:fc68d40b8b1f | 1028 | //// TASK: Send to TVOne if percents have changed |
tobyspark | 17:fc68d40b8b1f | 1029 | |
tobyspark | 17:fc68d40b8b1f | 1030 | // No amount of median filtering is stopping flipflopping between two adjacent percents, so... |
tobyspark | 17:fc68d40b8b1f | 1031 | bool fadeAPercentHasChanged; |
tobyspark | 17:fc68d40b8b1f | 1032 | bool fadeBPercentHasChanged; |
tobyspark | 17:fc68d40b8b1f | 1033 | if (oldFadeAPercent == newFadeAPercent && (newFadeAPercent == fadeAPercent - 1 || newFadeAPercent == fadeAPercent + 1)) |
tobyspark | 17:fc68d40b8b1f | 1034 | fadeAPercentHasChanged = false; |
tobyspark | 17:fc68d40b8b1f | 1035 | else |
tobyspark | 17:fc68d40b8b1f | 1036 | fadeAPercentHasChanged = newFadeAPercent != fadeAPercent; |
tobyspark | 17:fc68d40b8b1f | 1037 | if (oldFadeBPercent == newFadeBPercent && (newFadeBPercent == fadeBPercent - 1 || newFadeBPercent == fadeBPercent + 1)) |
tobyspark | 17:fc68d40b8b1f | 1038 | fadeBPercentHasChanged = false; |
tobyspark | 17:fc68d40b8b1f | 1039 | else |
tobyspark | 17:fc68d40b8b1f | 1040 | fadeBPercentHasChanged = newFadeBPercent != fadeBPercent; |
tobyspark | 17:fc68d40b8b1f | 1041 | |
tobyspark | 9:f83eadd8917a | 1042 | // We want to send the higher first, otherwise black flashes can happen on taps |
tobyspark | 17:fc68d40b8b1f | 1043 | if (fadeAPercentHasChanged && newFadeAPercent >= newFadeBPercent) |
tobyspark | 8:d46cc49f0f37 | 1044 | { |
tobyspark | 17:fc68d40b8b1f | 1045 | oldFadeAPercent = fadeAPercent; |
tobyspark | 0:87aab40d5806 | 1046 | fadeAPercent = newFadeAPercent; |
tobyspark | 0:87aab40d5806 | 1047 | updateFade = true; |
tobyspark | 0:87aab40d5806 | 1048 | |
tobyspark | 0:87aab40d5806 | 1049 | fadeAPO = fadeAPercent / 100.0; |
tobyspark | 0:87aab40d5806 | 1050 | tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent); |
tobyspark | 0:87aab40d5806 | 1051 | } |
tobyspark | 17:fc68d40b8b1f | 1052 | if (fadeBPercentHasChanged) |
tobyspark | 8:d46cc49f0f37 | 1053 | { |
tobyspark | 17:fc68d40b8b1f | 1054 | oldFadeBPercent = fadeBPercent; |
tobyspark | 0:87aab40d5806 | 1055 | fadeBPercent = newFadeBPercent; |
tobyspark | 0:87aab40d5806 | 1056 | updateFade = true; |
tobyspark | 0:87aab40d5806 | 1057 | |
tobyspark | 0:87aab40d5806 | 1058 | fadeBPO = fadeBPercent / 100.0; |
tobyspark | 0:87aab40d5806 | 1059 | tvOne.command(0, kTV1WindowIDB, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeBPercent); |
tobyspark | 0:87aab40d5806 | 1060 | } |
tobyspark | 17:fc68d40b8b1f | 1061 | if (fadeAPercentHasChanged && newFadeAPercent < newFadeBPercent) |
tobyspark | 9:f83eadd8917a | 1062 | { |
tobyspark | 17:fc68d40b8b1f | 1063 | oldFadeAPercent = fadeAPercent; |
tobyspark | 9:f83eadd8917a | 1064 | fadeAPercent = newFadeAPercent; |
tobyspark | 9:f83eadd8917a | 1065 | updateFade = true; |
tobyspark | 9:f83eadd8917a | 1066 | |
tobyspark | 9:f83eadd8917a | 1067 | fadeAPO = fadeAPercent / 100.0; |
tobyspark | 9:f83eadd8917a | 1068 | tvOne.command(0, kTV1WindowIDA, kTV1FunctionAdjustWindowsMaxFadeLevel, fadeAPercent); |
tobyspark | 9:f83eadd8917a | 1069 | } |
tobyspark | 8:d46cc49f0f37 | 1070 | if (updateFade && debug) |
tobyspark | 8:d46cc49f0f37 | 1071 | { |
tobyspark | 0:87aab40d5806 | 1072 | //debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAIN.read(), fadeUpAIN.read()); |
tobyspark | 0:87aab40d5806 | 1073 | debug->printf("xFade = %3f fadeUp = %3f \r\n", xFadeAINCached, fadeUpAINCached); |
tobyspark | 0:87aab40d5806 | 1074 | debug->printf("xFade = %3f fadeUp = %3f fadeA% = %i fadeB% = %i \r\n", xFade, fadeUp, fadeAPercent, fadeBPercent); |
tobyspark | 18:ebe5da639a6a | 1075 | debug->printf("\r\n"); |
tobyspark | 0:87aab40d5806 | 1076 | } |
tobyspark | 0:87aab40d5806 | 1077 | } |
tobyspark | 0:87aab40d5806 | 1078 | } |