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.
158 lines
4.3 KiB
C++
158 lines
4.3 KiB
C++
/***************************************************************************//**
|
|
* @file ui.cpp
|
|
*******************************************************************************/
|
|
|
|
#include <Arduino.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <avr/pgmspace.h>
|
|
#include <avr/eeprom.h>
|
|
|
|
//#include "gitinfo.h"
|
|
#include "MIDI.h"
|
|
#include "TimedPin.h"
|
|
#include "ui.h"
|
|
|
|
|
|
#define ELEMCNT(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
|
|
|
|
// Extern variables ============================================================
|
|
extern TimedPin LedBoard;
|
|
|
|
extern MIDI_NAMESPACE::SerialMIDI<HardwareSerial> serialMIDI;
|
|
extern MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<HardwareSerial>> MIDI;
|
|
|
|
|
|
// Typedefs ====================================================================
|
|
struct UI_SM {
|
|
STATE_MACHINE sm;
|
|
uint32_t Events;
|
|
uint16_t Timer;
|
|
uint16_t KeyTimer;
|
|
};
|
|
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;
|
|
|
|
|
|
const uint16_t ToutProg = 30; // [s]
|
|
|
|
// Local function declarations =================================================
|
|
static void UiSt_MixerStartup(UI_SM* me, uint16_t event);
|
|
static void UiSt_Home(UI_SM* me, uint16_t event);
|
|
|
|
|
|
// Function definitions ========================================================
|
|
|
|
|
|
//u @startuml
|
|
//u skinparam defaultTextAlignment left
|
|
//u state UserInterface {
|
|
|
|
/***************************************************************************//**
|
|
* @brief Initialize state machine for user interface
|
|
*******************************************************************************/
|
|
void UI_Init() {
|
|
DEFINE_MY_OBJECT();
|
|
me->Events = 0;
|
|
StateMachineInit(&me->sm, (SM_STATE_FUNC*)&UiSt_MixerStartup); //u [*] -> MixerStartup
|
|
}
|
|
|
|
/***************************************************************************//**
|
|
* @brief Execute event handler
|
|
*******************************************************************************/
|
|
void UI_EventProc(uint16_t event) {
|
|
DEFINE_MY_OBJECT();
|
|
StateMachine((STATE_MACHINE*)me, event);
|
|
}
|
|
|
|
/***************************************************************************//**
|
|
* @brief Check and execute asynchron event (from event buffer)
|
|
*******************************************************************************/
|
|
void UI_CheckEvent() {
|
|
DEFINE_MY_OBJECT();
|
|
|
|
if (me->Events) {
|
|
uint32_t mask = 1;
|
|
uint8_t ev;
|
|
for (ev = 0; ev < 32; ev++) {
|
|
if (me->Events & mask) {
|
|
me->Events &= ~mask;
|
|
StateMachine((STATE_MACHINE*)me, ev);
|
|
break;
|
|
}
|
|
mask <<= 1; // shift left
|
|
}
|
|
}
|
|
}
|
|
|
|
/***************************************************************************//**
|
|
* @brief Send (asynchron) event to state machine to process it later
|
|
*******************************************************************************/
|
|
static inline void EventSend(UI_SM* const me, uint16_t event) {
|
|
me->Events |= (1 << event);
|
|
}
|
|
|
|
|
|
// State definitions ===========================================================
|
|
|
|
|
|
//u state MixerStartup {
|
|
/***************************************************************************//**
|
|
* @brief MixerStartup
|
|
*******************************************************************************/
|
|
void UiSt_MixerStartup(UI_SM* const me, uint16_t event) {
|
|
switch (event) {
|
|
case EV_STATE_ENTER: { //u MixerStartup: entry:
|
|
me->Timer = 0;
|
|
LedBoard.Blink(50, 450);
|
|
}break;
|
|
case EV_STATE_EXIT: {
|
|
}break;
|
|
|
|
case EV_UI_TICK_100MS: {
|
|
}break;
|
|
|
|
case EV_UI_TICK_1S: {
|
|
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;
|
|
}
|
|
}
|
|
//u }
|
|
|
|
|
|
//u state Home {
|
|
/***************************************************************************//**
|
|
* @brief Standby (home) state
|
|
*******************************************************************************/
|
|
void UiSt_Home(UI_SM* const me, uint16_t event) {
|
|
switch (event) {
|
|
case EV_STATE_ENTER: {
|
|
LedBoard.Blink(1900, 100);
|
|
}break;
|
|
case EV_STATE_EXIT: {
|
|
}break;
|
|
|
|
case EV_UI_TICK_10MS: {
|
|
}break;
|
|
}
|
|
}
|
|
//u }
|
|
|
|
|
|
|
|
|
|
//u }
|
|
|
|
//u @enduml
|