Air Fader (volume) handling

* LED + INC/DEC button handling
master
unicod 3 years ago
parent 93a0eb3af6
commit a3f5922478

@ -38,30 +38,46 @@ Tmr Tmr1s = { .Period = 1000 };
* @brief Button - port assignment
*******************************************************************************/
const uint8_t pinBtnChOn1 = 2;
const uint8_t pinBtnChOn2 = 3;
const uint8_t pinLedChOn1 = 3;
const uint8_t pinBtnInc1 = 8;
const uint8_t pinBtnDec1 = 9;
const uint8_t pinBtnInc2 = 10;
const uint8_t pinBtnDec2 = 11;
const uint8_t pinBtnChOn2 = 4;
const uint8_t pinLedChOn2 = 5;
const uint8_t pinBtnInc1 = 6;
const uint8_t pinLedInc1 = 7;
const uint8_t pinBtnDec1 = 8;
const uint8_t pinLedDec1 = 9;
const uint8_t pinBtnInc2 = A0;
const uint8_t pinLedInc2 = A1;
const uint8_t pinBtnDec2 = A2;
const uint8_t pinLedDec2 = A3;
/***************************************************************************//**
* @brief LED
*******************************************************************************/
TimedPin LedBoard(LED_BUILTIN);
TimedPin LedChOn1(A0, true);
TimedPin LedChOn2(A1, true);
TimedPin LedChOn1(pinLedChOn1, true);
TimedPin LedChOn2(pinLedChOn2, true);
TimedPin LedInc1(pinLedInc1, true);
TimedPin LedDec1(pinLedDec1, true);
TimedPin LedInc2(pinLedInc2, true);
TimedPin LedDec2(pinLedDec2, true);
bool MidiCfgTxOnly; /// duplex or only tx configuration (without MIDI rx line)
MixerMuteState AirMutes[2] = {
//MixerMuteState(23, &LedBoard),
MixerMuteState(21, &LedChOn1, BTN_CH_ON1, EV_UI_RX_MUTE_CH1_ON, EV_UI_RX_MUTE_CH1_OFF),
MixerMuteState(22, &LedChOn2, BTN_CH_ON2, EV_UI_RX_MUTE_CH2_ON, EV_UI_RX_MUTE_CH2_OFF)
};
MixerFaderState AirFaders[2] = {
MixerFaderState(0, 90, 100, 110, &LedInc1, &LedDec1, BTN_INC1, BTN_DEC1),
MixerFaderState(1, 90, 100, 110, &LedInc2, &LedDec2, BTN_INC2, BTN_DEC2)
};
/***************************************************************************//**
* @brief MIDI instance (serial port)
*******************************************************************************/
@ -69,6 +85,15 @@ MIDI_CREATE_DEFAULT_INSTANCE();
// -----------------------------------------------------------------------------
void MidiCCHandler(byte channel, byte ctrl_no, byte val) {
if (channel == 1) { // Faders: ch=1
for (uint_fast8_t i=0; i<ELEMCNT(AirFaders); i++) {
MixerFaderState& fader = AirFaders[i];
if (ctrl_no == fader.MidiCtrlNr) {
fader.VolumeReceived(val);
}
}
}
if (channel == 2) { // Mutes: ch=2
for (uint_fast8_t i=0; i<ELEMCNT(AirMutes); i++) {
MixerMuteState& mute = AirMutes[i];
@ -97,6 +122,10 @@ void setup() {
LedBoard.begin();
LedChOn1.begin();
LedChOn2.begin();
LedInc1.begin();
LedDec1.begin();
LedInc2.begin();
LedDec2.begin();
MIDI.setHandleControlChange(MidiCCHandler);
MIDI.begin(MIDI_CHANNEL_OMNI); // Initiate MIDI communications, listen to all channels
@ -154,6 +183,10 @@ void loop() {
LedBoard.loop();
LedChOn1.loop();
LedChOn2.loop();
LedInc1.loop();
LedDec1.loop();
LedInc2.loop();
LedDec2.loop();
}
// execute every 100ms ******************************************************
if (Tmr100ms.Check(t)) {

@ -27,6 +27,7 @@ extern MIDI_NAMESPACE::SerialMIDI<HardwareSerial> serialMIDI;
extern MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<HardwareSerial>> MIDI;
extern MixerMuteState AirMutes[2];
extern MixerFaderState AirFaders[2];
// Typedefs ====================================================================
@ -173,6 +174,17 @@ void UiSt_Home(UI_SM* const me, uint16_t event) {
MIDI.sendControlChange(mute.MidiCtrlNr, mute.MuteLocal ? 0 : 127, 2);
}
}
for (uint_fast8_t i=0; i<ELEMCNT(AirFaders); i++) {
MixerFaderState& fader = AirFaders[i];
if (btn == fader.UiButtonInc) {
fader.VolumeInc();
MIDI.sendControlChange(fader.MidiCtrlNr, fader.FaderLocal, 1);
}
if (btn == fader.UiButtonDec) {
fader.VolumeDec();
MIDI.sendControlChange(fader.MidiCtrlNr, fader.FaderLocal, 1);
}
}
}break;
case EV_UI_TICK_10MS: {

81
ui.h

@ -36,6 +36,10 @@ enum UI_EVENTS {
EV_UI_RX_MUTE_CH1_OFF,
EV_UI_RX_MUTE_CH2_ON,
EV_UI_RX_MUTE_CH2_OFF,
EV_UI_RX_FADER_INC1,
EV_UI_RX_FADER_DEC1,
EV_UI_RX_FADER_INC2,
EV_UI_RX_FADER_DEC2,
EV_UI_KEY_PRESS = 0x0100,
EV_UI_KEY_PRESS_MAX = 0x01FF,
@ -61,6 +65,83 @@ struct MixerMuteState {
MuteMixer(false), MuteLocal(false), MidiCtrlNr(ctrl_nr), UiButton(button), UiEventOn(uieventon), UiEventOff(uieventoff), Led(led) { }
};
/***************************************************************************//**
* @brief Unit for fader from Air mixer
*******************************************************************************/
struct MixerFaderState {
uint8_t MidiCtrlNr; /// assign MIDI CC number to MUTE switch of Air mixer
uint8_t FaderMixer; /// volume received from mixer
uint8_t FaderLocal; /// local volume (sent to mixer)
uint8_t FaderMin; /// min volume
uint8_t FaderMax; /// max volume
uint8_t FaderStd; /// std volume
BTN_CODES UiButtonInc; /// assigned button
BTN_CODES UiButtonDec; /// assigned button
TimedPin* LedInc;
TimedPin* LedDec;
MixerFaderState(
uint8_t ctrl_nr,
uint8_t volmin,
uint8_t volstd,
uint8_t volmax,
TimedPin* ledinc,
TimedPin* leddec,
BTN_CODES btninc,
BTN_CODES btndec
) :
MidiCtrlNr(ctrl_nr),
FaderMixer(0),
FaderLocal(0),
FaderMin(volmin),
FaderStd(volstd),
FaderMax(volmax),
UiButtonInc(btninc),
UiButtonDec(btndec),
LedInc(ledinc),
LedDec(leddec)
{ }
void LedUpdateVolSent() {
uint16_t t_on = 50;
uint16_t t_off = 950;
if (FaderLocal > FaderStd) {
t_on = 950;
t_off = 50;
}
LedInc->Blink(t_on, t_off);
t_on = 950;
t_off = 50;
if (FaderLocal < FaderStd) {
t_on = 950;
t_off = 50;
}
LedDec->Blink(t_on, t_off);
}
void VolumeReceived(uint8_t vol) {
FaderMixer = vol;
FaderLocal = vol;
LedInc->Set((vol > FaderStd));
LedDec->Set((vol < FaderStd));
}
bool VolumeInc() {
if (FaderLocal < FaderMax) {
FaderLocal++;
LedUpdateVolSent();
return true;
}
return false;
}
bool VolumeDec() {
if (FaderLocal > FaderMin) {
FaderLocal--;
LedUpdateVolSent();
return true;
}
return false;
}
};
extern void UI_Init();

Loading…
Cancel
Save