From 90ca4840efc46187b203849d50da024566e6750f Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 26 Apr 2020 13:01:59 +0200 Subject: [PATCH] add menu system --- .../mixercontroller_w5100_pio/src/main.cpp | 145 +++++++++++++++--- 1 file changed, 126 insertions(+), 19 deletions(-) diff --git a/controller/mixercontroller_w5100_pio/src/main.cpp b/controller/mixercontroller_w5100_pio/src/main.cpp index f876016..796cfcd 100644 --- a/controller/mixercontroller_w5100_pio/src/main.cpp +++ b/controller/mixercontroller_w5100_pio/src/main.cpp @@ -59,6 +59,8 @@ unsigned long last_mqttreconnectattempt=0; long last_serialdebug=0; #define INTERVAL_SERIALDEBUG 200 + + //Inputs #include "button.h" @@ -134,6 +136,14 @@ long last_potidifferenceLow=0; //error boolean motorerror=false; +//Menu system +uint8_t menu_mode=0; //0= volume set mode, 1=mute output selection, 2=output group selection +uint8_t menu_selectedChannel=0; +#define MENU_MAXCHANNEL 7 + +long last_ledupdate=0; +#define INTERVAL_LEDUPDATE 50 + void setup() { pinMode(PIN_BUTTON,INPUT_PULLUP); button_knob = Button(); @@ -270,19 +280,52 @@ void loop() { button_knob.update(millis(),!digitalRead(PIN_BUTTON)); //Update routine + - if (button_knob.buttonPressed()){ - Serial.println("Button Pressed"); - }else if(button_knob.buttonHold()){ - Serial.println("Button hold"); + + + if (button_knob.buttonPressed()){ //short press + switch(menu_mode) { + case 0: //volume + //TODO: implement someting here, muting maybe? + break; + + case 1: //mute + if (menu_selectedChannel<=MENU_MAXCHANNEL) { //inside valid range + setMuteChannel(menu_selectedChannel,!getMute(menu_selectedChannel)); // mute/unmute menu_selectedChannel + }else{ //nothing selected + menu_mode = 0; //return to volume mode + } + break; + + case 2: //group selection + if (menu_selectedChannel<=MENU_MAXCHANNEL) { //inside valid range + setSelectionChannel(menu_selectedChannel,!getSelection(menu_selectedChannel)); // toggle selection menu_selectedChannel + }else{ //nothing selected + menu_mode = 0; //return to volume mode + } + break; + } + }else if(button_knob.buttonHold()){ //long press + switch(menu_mode) { + case 0: //volume + menu_mode = 1; //change to mute select mode + break; + + case 1: //mute + menu_mode = 2; //change to output group select mode. (hold button a second time) + break; + + case 2: //group selection + menu_mode = 1; //change back to mute select mode + break; + } + } - - - //Read Encoder to velocity "volEncVel" int volEncVel=0; int _volEnc=volEnc.read(); @@ -294,10 +337,29 @@ void loop() { //Input Handling if (volEncVel!=0){ //knob moved - poti_set+=volEncVel*encoderMultiplier; //change poti set value - poti_set=constrain(poti_set, POT_MIN,POT_MAX); - poti_reachedposition=false; - publishCurrentSetVolume(); + switch(menu_mode) { + case 0: //volume + poti_set+=volEncVel*encoderMultiplier; //change poti set value + poti_set=constrain(poti_set, POT_MIN,POT_MAX); + poti_reachedposition=false; + publishCurrentSetVolume(); + break; + + case 1: case 2: //mute or group selection + menu_selectedChannel+=127; //offset to compensate negative values + menu_selectedChannel+=volEncVel; + if (menu_selectedChannel<127){ + menu_selectedChannel=127; //lower limit (0) + }else if (menu_selectedChannel > MENU_MAXCHANNEL+1) { //max channel and one extra for "nothing selected" + menu_selectedChannel=127+MENU_MAXCHANNEL+1; //upper limit + } + + menu_selectedChannel-=127; //take out offset + + + break; + } + } @@ -355,6 +417,58 @@ void loop() { } + + if ( loopmillis > last_ledupdate+INTERVAL_LEDUPDATE){ + last_ledupdate=loopmillis; + + switch(menu_mode) { + case 0: //volume + for(uint8_t i=0;i last_serialdebug+INTERVAL_SERIALDEBUG){ @@ -372,16 +486,9 @@ void loop() { Serial.print("!"); } Serial.println(""); - - for(uint8_t i=0;i