add menu system
This commit is contained in:
parent
28ae775fc3
commit
90ca4840ef
|
@ -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();
|
||||
|
@ -271,18 +281,51 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -356,6 +418,58 @@ void loop() {
|
|||
|
||||
|
||||
|
||||
if ( loopmillis > last_ledupdate+INTERVAL_LEDUPDATE){
|
||||
last_ledupdate=loopmillis;
|
||||
|
||||
switch(menu_mode) {
|
||||
case 0: //volume
|
||||
for(uint8_t i=0;i<leds.numPixels();i++){ //set color of all leds
|
||||
leds.setPixelColor(i, Wheel(wheelpos+i*10));
|
||||
}
|
||||
wheelpos+=1;
|
||||
break;
|
||||
|
||||
case 1: case 2: //group selection //mute
|
||||
//show selected channel
|
||||
leds.clear();
|
||||
uint8_t _r=0;
|
||||
uint8_t _g=0;
|
||||
uint8_t _b=0;
|
||||
|
||||
for(uint8_t i=0;i<leds.numPixels();i++){ //set color of all leds
|
||||
if (menu_mode==1) { //in mute mode
|
||||
if (!getMute(i)) { //not muted
|
||||
_r = 0; _g = 50; _b = 0;
|
||||
}else{ //muted
|
||||
_r = 50; _g = 0; _b = 50;
|
||||
}
|
||||
}else if(menu_mode==2) { //in selection mode
|
||||
if (!getSelection(i)) { //Selected A
|
||||
_r = 50; _g = 50; _b = 50;
|
||||
}else{ //Selected B
|
||||
_r = 50; _g = 0; _b = 0;
|
||||
}
|
||||
}
|
||||
if (menu_selectedChannel==i) { //this item is currently selected
|
||||
_r*=4; //make color brighter
|
||||
_g*=4;
|
||||
_b*=4;
|
||||
}
|
||||
if (menu_selectedChannel==MENU_MAXCHANNEL+1) { //nothing selected
|
||||
_r=50; _g=50; _b=50;
|
||||
}
|
||||
leds.setPixelColor(i, leds.Color(_r,_g,_b));
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
leds.show();
|
||||
}
|
||||
|
||||
|
||||
if ( loopmillis > last_serialdebug+INTERVAL_SERIALDEBUG){
|
||||
last_serialdebug=loopmillis;
|
||||
|
@ -372,16 +486,9 @@ void loop() {
|
|||
Serial.print("!");
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
for(uint8_t i=0;i<leds.numPixels();i++){ //set color of all leds
|
||||
leds.setPixelColor(i, Wheel(wheelpos+i*10));
|
||||
}
|
||||
wheelpos+=5;
|
||||
|
||||
leds.show();
|
||||
}
|
||||
|
||||
if (loopmillis%5001==0) {
|
||||
if (loopmillis%5001==0) { //TODO: remove when working
|
||||
Serial.println(loopmillis); //alive print. for debugging
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue