From 201125907961d0e7c800f42682dab84a3b424ed3 Mon Sep 17 00:00:00 2001 From: unicod Date: Thu, 8 Dec 2022 06:41:50 +0100 Subject: [PATCH] TODO relay handling --- XAirMixerControl.ino | 16 +++++++++++++++- ui.cpp | 6 +----- ui.h | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/XAirMixerControl.ino b/XAirMixerControl.ino index d93ec61..f61012c 100644 --- a/XAirMixerControl.ino +++ b/XAirMixerControl.ino @@ -63,6 +63,13 @@ const uint8_t pinGndChOn2 = 10; const uint8_t pinLedChOn2 = 11; const uint8_t pinBtnChOn2 = 12; +/***************************************************************************//** +* @brief Relay +*******************************************************************************/ +const uint8_t pinRelay1 = 13; +const uint8_t pinRelay2 = A7; +TimedPin RelayMute(pinRelay2); + /***************************************************************************//** * @brief LED *******************************************************************************/ @@ -80,7 +87,7 @@ bool MidiCfgTxOnly; /// duplex or only tx configuration (without MIDI rx lin MixerMuteState AirMutes[2] = { MixerMuteState(22, &LedChOn1, BTN_CH_ON1, EV_UI_RX_MUTE_CH1_ON, EV_UI_RX_MUTE_CH1_OFF), - MixerMuteState(23, &LedChOn2, BTN_CH_ON2, EV_UI_RX_MUTE_CH2_ON, EV_UI_RX_MUTE_CH2_OFF) + MixerMuteStateRly(23, &LedChOn2, &RelayMute, BTN_CH_ON2, EV_UI_RX_MUTE_CH2_ON, EV_UI_RX_MUTE_CH2_OFF) }; MixerFaderState AirFaders[2] = { @@ -133,11 +140,16 @@ void setup() { pinMode(pinBtnChOn1, INPUT_PULLUP); pinMode(pinBtnChOn2, INPUT_PULLUP); + pinMode(pinRelay1, OUTPUT); + pinMode(pinRelay2, OUTPUT); pinMode(pinGndDec1, OUTPUT); pinMode(pinGndInc2, OUTPUT); pinMode(pinGndDec2, OUTPUT); pinMode(pinGndChOn1, OUTPUT); pinMode(pinGndChOn2, OUTPUT); + + digitalWrite(pinRelay1, LOW); + digitalWrite(pinRelay2, LOW); digitalWrite(pinGndDec1, LOW); digitalWrite(pinGndInc2, LOW); digitalWrite(pinGndDec2, LOW); @@ -151,6 +163,7 @@ void setup() { LedDec1.begin(); LedInc2.begin(); LedDec2.begin(); + RelayMute.begin(); MIDI.setHandleControlChange(MidiCCHandler); MIDI.begin(MIDI_CHANNEL_OMNI); // Initiate MIDI communications, listen to all channels @@ -212,6 +225,7 @@ void loop() { LedDec1.update(); LedInc2.update(); LedDec2.update(); + RelayMute.update(); } // execute every 100ms ****************************************************** if (Tmr100ms.Check(t)) { diff --git a/ui.cpp b/ui.cpp index 9e647a8..0923da4 100644 --- a/ui.cpp +++ b/ui.cpp @@ -170,11 +170,7 @@ void UiSt_Home(UI_SM* const me, uint16_t event) { for (uint_fast8_t i=0; iBlink(t_on, t_off); + mute.ToggleState(); MIDI.sendControlChange(mute.MidiCtrlNr, mute.MuteLocal ? 127 : 0, 2); } } diff --git a/ui.h b/ui.h index 6183846..a4e8d30 100644 --- a/ui.h +++ b/ui.h @@ -63,6 +63,24 @@ struct MixerMuteState { MixerMuteState(uint8_t ctrl_nr, TimedPin* led, BTN_CODES button = BTN_MAX, uint16_t uieventon = EV_NO_EVENT, uint16_t uieventoff = EV_NO_EVENT) : MuteMixer(false), MuteLocal(false), MidiCtrlNr(ctrl_nr), UiButton(button), UiEventOn(uieventon), UiEventOff(uieventoff), Led(led) { } + void ToggleState() { + MuteLocal = !MuteLocal; + uint16_t t_on = 950; + uint16_t t_off = 50; + if (MuteLocal) { t_on = 50; t_off = 950; } + Led->Blink(t_on, t_off); + } +}; + +struct MixerMuteStateRly : MixerMuteState { + MixerMuteStateRly(uint8_t ctrl_nr, TimedPin* led, TimedPin* relay, BTN_CODES button = BTN_MAX, uint16_t uieventon = EV_NO_EVENT, uint16_t uieventoff = EV_NO_EVENT) : + MixerMuteState(ctrl_nr, led, button, uieventon, uieventoff), Relay(relay) { } + void ToggleState() { + MixerMuteState::ToggleState(); + Relay->Set(MuteLocal); + } + + TimedPin* Relay; }; /***************************************************************************//**