TODO commit

master
unicod 3 years ago
parent 2011259079
commit 98423ac38a

@ -7,9 +7,15 @@ TimedPin::TimedPin(uint8_t pin_id, bool inverted) {
OnTime = 0;
OffTime = 0;
}
TimedPin::TimedPin() {
PinId = 0xFF;
TPinMode = TPM_OFF;
OnTime = 0;
OffTime = 0;
}
void TimedPin::begin() {
pinMode(PinId, OUTPUT);
if (PinId < 0xFF) pinMode(PinId, OUTPUT);
PinOff();
}
@ -103,10 +109,10 @@ void TimedPin::Off() {
void TimedPin::PinOn() {
PinState = true;
digitalWrite(PinId, PinInvert ? LOW : HIGH);
if (PinId < 0xFF) digitalWrite(PinId, PinInvert ? LOW : HIGH);
}
void TimedPin::PinOff() {
PinState = false;
digitalWrite(PinId, PinInvert ? HIGH : LOW);
if (PinId < 0xFF) digitalWrite(PinId, PinInvert ? HIGH : LOW);
}

@ -26,6 +26,7 @@ class TimedPin {
void PinOff(); /// set pin to "off" (internal function)
public:
TimedPin();
TimedPin(uint8_t pin, bool inverted = false);
void begin();
void update();

@ -68,12 +68,15 @@ const uint8_t pinBtnChOn2 = 12;
*******************************************************************************/
const uint8_t pinRelay1 = 13;
const uint8_t pinRelay2 = A7;
TimedPin RelayMute(pinRelay2);
//TimedPin RelayMute(pinRelay2);
TimedPin RelayMute(LED_BUILTIN);
/***************************************************************************//**
* @brief LED
*******************************************************************************/
TimedPin LedBoard(LED_BUILTIN);
//TimedPin LedBoard(LED_BUILTIN);
TimedPin LedBoard(pinRelay2);
TimedPin LedChOn1(pinLedChOn1);
TimedPin LedChOn2(pinLedChOn2);
TimedPin LedInc1(pinLedInc1);
@ -86,8 +89,8 @@ TimedPin LedDec2(pinLedDec2);
bool MidiCfgTxOnly; /// duplex or only tx configuration (without MIDI rx line)
MixerMuteState AirMutes[2] = {
MixerMuteState(22, &LedChOn1, BTN_CH_ON1, EV_UI_RX_MUTE_CH1_ON, EV_UI_RX_MUTE_CH1_OFF),
MixerMuteStateRly(23, &LedChOn2, &RelayMute, BTN_CH_ON2, EV_UI_RX_MUTE_CH2_ON, EV_UI_RX_MUTE_CH2_OFF)
MixerMuteState(22, &LedChOn1, &RelayMute, 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)
};
MixerFaderState AirFaders[2] = {
@ -96,9 +99,6 @@ MixerFaderState AirFaders[2] = {
};
#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
HardwareSerial& Serial1; // Unused code, workaround for Intellisense bug
#endif
/***************************************************************************//**
* @brief MIDI instance (serial port)
*******************************************************************************/
@ -111,6 +111,7 @@ void MidiCCHandler(byte channel, byte ctrl_no, byte val) {
MixerFaderState& fader = AirFaders[i];
if (ctrl_no == fader.MidiCtrlNr) {
fader.VolumeReceived(val);
UI_EventProc(EV_UI_RX_MIDI);
}
}
}
@ -172,6 +173,12 @@ void setup() {
UI_Init(); // Start user interface (main state machine)
}
static uint8_t BtnPrev = 0x00;
uint8_t ButtonGetVal() { return BtnPrev; }
bool ButtonCheck(uint8_t btn) {
return (BtnPrev & (1 << btn)) ? true : false;
}
/***************************************************************************//**
* @brief Main loop
*******************************************************************************/
@ -181,7 +188,6 @@ void loop() {
uint32_t t = millis();
// execute every 10ms *******************************************************
if (Tmr10ms.Check(t)) {
static uint8_t BtnPrev = 0x00;
static uint8_t BtnNew = 0;
static uint8_t BtnRel = 0;
uint8_t btn = (digitalRead(pinBtnInc1) ? 0: (1 << BTN_INC1 ))

@ -30,7 +30,7 @@ extern MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<HardwareSerial>>
extern MixerMuteState AirMutes[2];
extern MixerFaderState AirFaders[2];
extern bool ButtonCheck(uint8_t btn);
// Typedefs ====================================================================
struct UI_SM {
@ -45,6 +45,7 @@ typedef void UI_STATE_FUNC(UI_SM* me, uint16_t event);
// Local variables =============================================================
static UI_SM UiSm;
#define DEFINE_MY_OBJECT() UI_SM* const me = &UiSm;
TimedPin DummyRelay;
const uint16_t ToutProg = 30; // [s]
@ -118,14 +119,15 @@ void UiSt_MixerStartup(UI_SM* const me, uint16_t event) {
case EV_STATE_ENTER: { //u MixerStartup: entry:
me->Timer = 0;
LedBoard.Blink(30, 270, 5);
LedChOn1.Blink(500, 500);
LedChOn2.Blink(500, 500);
LedInc1.Blink(500, 500);
LedDec1.Blink(500, 500);
LedChOn1.Blink(10, 1990);
LedChOn2.Blink(10, 1990);
LedInc1.Blink(10, 1990);
LedDec1.Blink(10, 1990);
}break;
case EV_STATE_EXIT: {
}break;
case EV_UI_RX_MIDI:
case EV_UI_RX_MUTE_CH1_ON:
case EV_UI_RX_MUTE_CH1_OFF:
case EV_UI_RX_MUTE_CH2_ON:
@ -134,12 +136,13 @@ void UiSt_MixerStartup(UI_SM* const me, uint16_t event) {
}break;
case EV_UI_TICK_1S: {
if ((me->Timer % 2) == 0) {
MixerFaderState& fader = AirFaders[0];
MIDI.sendControlChange(fader.MidiCtrlNr, fader.FaderStd - ((me->Timer >> 1) % 2), 1); // ping mixer with changing value (std, std-1, std,...)
}
if (++me->Timer == 15) {
SM_SET_STATE(&UiSt_Home); //u MixerStartup -left-> Home : timeout
}
//static uint8_t MuteVal = 0;
//MIDI.sendControlChange(21, MuteVal, 2); // Send Mute: CH2, 21-26: Aux1-6
//MuteVal = MuteVal ? 0 : 127;
}break;
}
}
@ -162,6 +165,19 @@ void UiSt_Home(UI_SM* const me, uint16_t event) {
switch (event) {
case EV_STATE_ENTER: {
LedBoard.Blink(30, 270, 5);
// initialize mixer
for (uint_fast8_t i=0; i<ELEMCNT(AirMutes); i++) {
MixerMuteState& mute = AirMutes[i];
mute.MuteLocal = false; // init value: not muted (channel enabled)
MIDI.sendControlChange(mute.MidiCtrlNr, mute.MuteLocal ? 127 : 0, 2);
mute.LedUpdate();
}
for (uint_fast8_t i=0; i<ELEMCNT(AirFaders); i++) {
MixerFaderState& fader = AirFaders[i];
fader.FaderLocal = fader.FaderStd; // init: set volume to standard
MIDI.sendControlChange(fader.MidiCtrlNr, fader.FaderLocal, 1);
fader.LedUpdate();
}
}break;
case EV_STATE_EXIT: {
}break;
@ -177,11 +193,21 @@ void UiSt_Home(UI_SM* const me, uint16_t event) {
for (uint_fast8_t i=0; i<ELEMCNT(AirFaders); i++) {
MixerFaderState& fader = AirFaders[i];
if (btn == fader.UiButtonInc) {
fader.VolumeInc();
if (ButtonCheck(fader.UiButtonDec)) { // inc+dec button together
fader.FaderLocal = fader.FaderStd;
fader.LedUpdate();
}else {
fader.VolumeInc();
}
MIDI.sendControlChange(fader.MidiCtrlNr, fader.FaderLocal, 1);
}
if (btn == fader.UiButtonDec) {
fader.VolumeDec();
if (ButtonCheck(fader.UiButtonInc)) { // inc+dec button together
fader.FaderLocal = fader.FaderStd;
fader.LedUpdate();
}else {
fader.VolumeDec();
}
MIDI.sendControlChange(fader.MidiCtrlNr, fader.FaderLocal, 1);
}
}

37
ui.h

@ -32,14 +32,11 @@ enum UI_EVENTS {
EV_UI_TICK_10MS = EV_USER_FIRST,
EV_UI_TICK_100MS,
EV_UI_TICK_1S,
EV_UI_RX_MIDI,
EV_UI_RX_MUTE_CH1_ON,
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,
@ -49,6 +46,8 @@ enum UI_EVENTS {
EV_NO_EVENT = 0xFFFF
};
extern TimedPin DummyRelay;
/***************************************************************************//**
* @brief Unit for mute switch from Air mixer
*******************************************************************************/
@ -60,27 +59,24 @@ struct MixerMuteState {
uint16_t UiEventOn; /// event to send to UI statemachine
uint16_t UiEventOff; /// event to send to UI statemachine
TimedPin* Led;
TimedPin* Relay;
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) { }
MuteMixer(false), MuteLocal(false), MidiCtrlNr(ctrl_nr), UiButton(button), UiEventOn(uieventon), UiEventOff(uieventoff), Led(led), Relay(&DummyRelay) { }
MixerMuteState(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) :
MuteMixer(false), MuteLocal(false), MidiCtrlNr(ctrl_nr), UiButton(button), UiEventOn(uieventon), UiEventOff(uieventoff), Led(led), Relay(relay) { }
void ToggleState() {
MuteLocal = !MuteLocal;
uint16_t t_on = 950;
uint16_t t_on = 1950;
uint16_t t_off = 50;
if (MuteLocal) { t_on = 50; t_off = 950; }
if (MuteLocal) { t_on = 50; t_off = 1950; }
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;
void LedUpdate() {
Led->Set(!MuteLocal);
}
};
/***************************************************************************//**
@ -136,11 +132,14 @@ struct MixerFaderState {
}
LedDec->Blink(t_on, t_off);
}
void LedUpdate() {
LedInc->Set((FaderLocal > FaderStd));
LedDec->Set((FaderLocal < FaderStd));
}
void VolumeReceived(uint8_t vol) {
FaderMixer = vol;
FaderLocal = vol;
LedInc->Set((vol > FaderStd));
LedDec->Set((vol < FaderStd));
LedUpdate();
}
bool VolumeInc() {
if (FaderLocal < FaderMax) {

Loading…
Cancel
Save