You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.8 KiB
C

#ifndef __UI_H__
#define __UI_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
#include "statemachine.h"
#ifndef ELEMCNT
#define ELEMCNT(x) (sizeof(x) / sizeof((x)[0]))
#endif
/***************************************************************************//**
* @brief Button codes
*******************************************************************************/
enum BTN_CODES {
BTN_INC1 = 0,
BTN_DEC1,
BTN_INC2,
BTN_DEC2,
BTN_CH_ON1,
BTN_CH_ON2,
BTN_MAX
};
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_KEY_PRESS = 0x0100,
EV_UI_KEY_PRESS_MAX = 0x01FF,
EV_UI_KEY_REL = 0x0200,
EV_UI_KEY_REL_MAX = 0x02FF,
EV_NO_EVENT = 0xFFFF
};
extern TimedPin DummyRelay;
/***************************************************************************//**
* @brief Unit for mute switch from Air mixer
*******************************************************************************/
struct MixerMuteState {
bool MuteMixer; /// state received from mixer
bool MuteLocal; /// local state (sent to mixer)
uint8_t MuteInit; /// state after startup 0=not muted, 1=muted, 0xFF=no init
uint8_t MidiCtrlNr; /// assign MIDI CC number to MUTE switch of Air mixer
BTN_CODES UiButton; /// assigned button
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, uint8_t muteinit, BTN_CODES button = BTN_MAX, uint16_t uieventon = EV_NO_EVENT, uint16_t uieventoff = EV_NO_EVENT) :
MuteMixer(false), MuteLocal(false), MidiCtrlNr(ctrl_nr), MuteInit(muteinit), UiButton(button), UiEventOn(uieventon), UiEventOff(uieventoff), Led(led), Relay(&DummyRelay) { }
MixerMuteState(uint8_t ctrl_nr, TimedPin* led, TimedPin* relay, uint8_t muteinit, BTN_CODES button = BTN_MAX, uint16_t uieventon = EV_NO_EVENT, uint16_t uieventoff = EV_NO_EVENT) :
MuteMixer(false), MuteLocal(false), MidiCtrlNr(ctrl_nr), MuteInit(muteinit), UiButton(button), UiEventOn(uieventon), UiEventOff(uieventoff), Led(led), Relay(relay) { }
void ToggleState() {
MuteLocal = !MuteLocal;
uint16_t t_on = 1950;
uint16_t t_off = 50;
if (MuteLocal) { t_on = 50; t_off = 1950; }
Led->Blink(t_on, t_off);
Relay->Set(MuteLocal);
}
void LedUpdate() {
Led->Set(!MuteLocal);
}
};
/***************************************************************************//**
* @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 FaderStd; /// std volume
uint8_t FaderMax; /// max 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(volstd),
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 = 1950;
if (FaderLocal > FaderStd) {
t_on = 1950;
t_off = 50;
}
LedInc->Blink(t_on, t_off);
t_on = 50;
t_off = 1950;
if (FaderLocal < FaderStd) {
t_on = 1950;
t_off = 50;
}
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;
LedUpdate();
}
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();
extern void UI_EventProc(uint16_t event);
extern void UI_EventSend(uint16_t event);
extern void UI_CheckEvent();
#ifdef __cplusplus
}
#endif
#endif