Register / Login | Desktop view |
// somewhere globally, define the variable
HardwareRotaryEncoder* secondEncoder;
void setuo() {
// other stuff...
setupMenu(); // Important! This must be before any usage of switches
// here we assume that menuVolume was defined in your menu project as an analog item
secondEncoder = new HardwareRotaryEncoder(pinA, pinB, [](int encoderValue) {
activeMenuItem = ... ???
switch(activeMenuItem) {
"menuvolume" : increase_or_decrease_volume(); // ???
break;
"menuchannel" : increase_or_decrease_channel();
break;
etc....
});
secondEncoder->changePrecision(menuVolume.getMaximumValue(), menuVolume.getCurrentValue());
switches.setEncoder(1, secondEncoder);
}
MenuItem* myItem = menuMgr.findCurrentActive();
setupMenu();
// code voor de 2e encoder
secondEncoder = new HardwareRotaryEncoder(PB8, PB9, [](int encoderValue) {
// do the action on the switch press
Serial.print("2nd encoder value change: ");
Serial.println(encoderValue);
// uitzoeken welk menupunt actief is
MenuItem* activeItem = menuMgr.findCurrentActive();
switch(activeItem->getId()) {
case 4: // menuCable, see STM32F401_eSPI_menu.cpp
if(encoderValue > 5) {
menuCable.setCurrentValue(menuCable.getCurrentValue() + 1);
} else {
menuCable.setCurrentValue(menuCable.getCurrentValue() - 1);
}
break;
case 5: // menuFrom
if(encoderValue > 5) {
menuFrom.setCurrentValue(menuFrom.getCurrentValue() + 1);
} else {
menuFrom.setCurrentValue(menuFrom.getCurrentValue() - 1);
}
break;
case 6: // menuTo
if(encoderValue > 5) {
menuTo.setCurrentValue(menuTo.getCurrentValue() + 1);
} else {
menuTo.setCurrentValue(menuTo.getCurrentValue() - 1);
}
break;
default: // niets gedefinieerd, doe niets.
break;
}
// value van encoder 2 weer terugzetten naar midden value
secondEncoder->setCurrentReading(5);
});
secondEncoder->changePrecision(10, 5); // max value, current value
switches.setEncoder(1, secondEncoder);