diff --git a/README.md b/README.md index 9cd7d10..3027136 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.2 geän # Change Log + ## Version 3.1.3 (23.04.2023) +- [Issue 069](https://github.com/tonuino/TonUINO-TNG/issues/69): Enhance serial input as command source to jump into menu entries - [Issue 075](https://github.com/tonuino/TonUINO-TNG/issues/75): Optimize Memory (RAM and FLASH) usage - [Issue 082](https://github.com/tonuino/TonUINO-TNG/issues/82): Speed up VolumeUp/Down when using longpress - [Issue 070](https://github.com/tonuino/TonUINO-TNG/issues/70): Revise modification cards diff --git a/TonUINO-TNG.ino b/TonUINO-TNG.ino index a8aa07b..aff1ef7 100644 --- a/TonUINO-TNG.ino +++ b/TonUINO-TNG.ino @@ -35,7 +35,7 @@ void setup() LOG(init_log, s_error, F("TonUINO Version 3.1 - refactored by Boerge1\n")); LOG(init_log, s_error, F("created by Thorsten Voß and licensed under GNU/GPL.")); LOG(init_log, s_error, F("Information and contribution at https://tonuino.de.\n")); - LOG(init_log, s_error, F("V3.1.3 23.04.23 III\n")); + LOG(init_log, s_error, F("V3.1.3 23.04.23 IV\n")); Tonuino::getTonuino().setup(); } diff --git a/src/commands.cpp b/src/commands.cpp index 80134a4..39240e6 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -5,33 +5,36 @@ const command cmd_table[][4] PROGMEM = { /* raw commands adm idle/pause play play_invert */ -/* none, */ { command::none , command::none , command::none , command::none }, -/* start, */ { command::none , command::start , command::none , command::none }, -/* allLong, */ { command::none , command::admin , command::admin , command::admin }, -/* pause, */ { command::select , command::pause , command::pause , command::pause }, -/* pauseLong, */ { command::adm_end , command::shutdown , command::track , command::track }, +/* none, */ { command::none , command::none , command::none , command::none } +/* start, */ ,{ command::none , command::start , command::none , command::none } +/* allLong, */ ,{ command::none , command::admin , command::admin , command::admin } +/* pause, */ ,{ command::select , command::pause , command::pause , command::pause } +/* pauseLong, */ ,{ command::adm_end , command::shutdown , command::track , command::track } #ifdef FIVEBUTTONS -/* up, */ { command::next , command::none , command::next , command::none }, -/* upLong, */ { command::next10 , command::shortcut2, command::next10 , command::none }, -/* upLongRepeat, */ { command::none , command::none , command::none , command::none }, -/* down, */ { command::previous , command::none , command::previous , command::none }, -/* downLong, */ { command::previous10, command::shortcut3, command::previous10 , command::none }, -/* downLongRepeat, */ { command::none , command::none , command::none , command::none }, -/* updownLong, */ { command::none , command::shortcut1, command::none , command::none }, -/* four, */ { command::next , command::none , command::volume_up , command::none }, -/* fourLong, */ { command::next10 , command::none , command::volume_up , command::none }, -/* fourLongRepeat, */ { command::none , command::none , command::volume_up , command::none }, -/* five, */ { command::previous , command::none , command::volume_down, command::none }, -/* fiveLong, */ { command::previous10, command::none , command::volume_down, command::none }, -/* fiveLongRepeat, */ { command::none , command::none , command::volume_down, command::none } +/* up, */ ,{ command::next , command::none , command::next , command::none } +/* upLong, */ ,{ command::next10 , command::shortcut2, command::next10 , command::none } +/* upLongRepeat, */ ,{ command::none , command::none , command::none , command::none } +/* down, */ ,{ command::previous , command::none , command::previous , command::none } +/* downLong, */ ,{ command::previous10, command::shortcut3, command::previous10 , command::none } +/* downLongRepeat, */ ,{ command::none , command::none , command::none , command::none } +/* updownLong, */ ,{ command::none , command::shortcut1, command::none , command::none } +/* four, */ ,{ command::next , command::none , command::volume_up , command::none } +/* fourLong, */ ,{ command::next10 , command::none , command::volume_up , command::none } +/* fourLongRepeat, */ ,{ command::none , command::none , command::volume_up , command::none } +/* five, */ ,{ command::previous , command::none , command::volume_down, command::none } +/* fiveLong, */ ,{ command::previous10, command::none , command::volume_down, command::none } +/* fiveLongRepeat, */ ,{ command::none , command::none , command::volume_down, command::none } #else // Three Button -/* up, */ { command::next , command::none , command::next , command::volume_up }, -/* upLong, */ { command::next10 , command::shortcut2, command::volume_up , command::next }, -/* upLongRepeat, */ { command::none , command::none , command::volume_up , command::none }, -/* down, */ { command::previous , command::none , command::previous , command::volume_down }, -/* downLong, */ { command::previous10, command::shortcut3, command::volume_down, command::previous }, -/* downLongRepeat, */ { command::none , command::none , command::volume_down, command::none }, -/* updownLong, */ { command::none , command::shortcut1, command::none , command::none } +/* up, */ ,{ command::next , command::none , command::next , command::volume_up } +/* upLong, */ ,{ command::next10 , command::shortcut2, command::volume_up , command::next } +/* upLongRepeat, */ ,{ command::none , command::none , command::volume_up , command::none } +/* down, */ ,{ command::previous , command::none , command::previous , command::volume_down } +/* downLong, */ ,{ command::previous10, command::shortcut3, command::volume_down, command::previous } +/* downLongRepeat, */ ,{ command::none , command::none , command::volume_down, command::none } +/* updownLong, */ ,{ command::none , command::shortcut1, command::none , command::none } +#endif +#ifdef SerialInputAsCommand +/* menu_jump , */ ,{ command::menu_jump , command::none , command::none , command::none } #endif }; Commands::Commands(const Settings& settings, CommandSource* source1, CommandSource* source2, CommandSource* source3) diff --git a/src/commands.hpp b/src/commands.hpp index d27dfca..931a50d 100644 --- a/src/commands.hpp +++ b/src/commands.hpp @@ -60,6 +60,9 @@ enum class commandRaw: uint8_t { five, fiveLong, fiveLongRepeat, +#endif +#ifdef SerialInputAsCommand + menu_jump, #endif cmd_end, #ifdef BUTTONS3X3 @@ -88,6 +91,9 @@ enum class command: uint8_t { previous10, // adm select, +#ifdef SerialInputAsCommand + menu_jump, +#endif adm_end, #ifdef BUTTONS3X3 ext_begin = buttonExtSC_begin, @@ -116,6 +122,14 @@ class Commands { commandRaw getCommandRaw(); command getCommand (commandRaw b, state_for_command s); + static bool isSelect(command cmd) { + return cmd == command::select +#ifdef SerialInputAsCommand + || cmd == command::menu_jump +#endif + ; + } + static uint8_t getButtonCode(commandRaw b); #ifdef BUTTONS3X3 static bool isExtButton(command c); diff --git a/src/constants.hpp b/src/constants.hpp index 734d8d5..8600426 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -15,10 +15,11 @@ // uncomment the below line to enable serial input as additional command source // um den Serial Monitor als zusätzliche Kommandoquelle zu haben bitte in der nächste Zeile den Kommentar entfernen -//#define SerialInputAsCommand -// 7: 8: up 9: upLong -// 4: allLong 5: pause 6: pauseLong -// 1: 2: down 3: downLong +#define SerialInputAsCommand +// -7: -8: up -9: upLong +// -4: allLong -5: pause -6: pauseLong +// -1: up/downLong -2: down -3: downLong +// number n > 0: Springe im Voice Menü zum n-ten Eintrag und selektiere ihn // uncomment the below line if you have support for the 3x3Buttons // um die Unterstützung für die 3x3 Buttons zu haben bitte in der nächste Zeile den Kommentar entfernen diff --git a/src/serial_input.cpp b/src/serial_input.cpp index 51988b7..f109d6f 100644 --- a/src/serial_input.cpp +++ b/src/serial_input.cpp @@ -3,6 +3,7 @@ #include "constants.hpp" #include "logger.hpp" +#ifdef SerialInputAsCommand SerialInput::SerialInput() : CommandSource() { @@ -11,18 +12,25 @@ SerialInput::SerialInput() commandRaw SerialInput::getCommandRaw() { commandRaw ret = commandRaw::none; if (Serial.available() > 0) { - int optionSerial = Serial.parseInt(); + long optionSerial = Serial.parseInt(); switch (optionSerial) { - case 2: ret = commandRaw::down ; break; - case 8: ret = commandRaw::up ; break; - case 3: ret = commandRaw::downLong ; break; - case 9: ret = commandRaw::upLong ; break; - case 5: ret = commandRaw::pause ; break; - case 6: ret = commandRaw::pauseLong; break; - case 4: ret = commandRaw::allLong ; break; - default: break; + case -2: ret = commandRaw::down ; break; + case -8: ret = commandRaw::up ; break; + case -3: ret = commandRaw::downLong ; break; + case -9: ret = commandRaw::upLong ; break; + case -5: ret = commandRaw::pause ; break; + case -6: ret = commandRaw::pauseLong ; break; + case -4: ret = commandRaw::allLong ; break; + case -1: ret = commandRaw::updownLong; break; + default: + if (optionSerial > 0) { + ret = commandRaw::menu_jump; + menu_jump = optionSerial; + } + break; } } return ret; } +#endif diff --git a/src/serial_input.hpp b/src/serial_input.hpp index dbebb28..95de0a8 100644 --- a/src/serial_input.hpp +++ b/src/serial_input.hpp @@ -11,6 +11,10 @@ class SerialInput: public CommandSource { SerialInput(); commandRaw getCommandRaw() override; + + uint8_t get_menu_jump() const { return menu_jump; } +private: + uint8_t menu_jump; }; #endif /* SRC_SERIAL_INPUT_HPP_ */ diff --git a/src/state_machine.cpp b/src/state_machine.cpp index bc1a910..6bcc973 100644 --- a/src/state_machine.cpp +++ b/src/state_machine.cpp @@ -107,6 +107,14 @@ void VoiceMenu::react(command cmd) { currentValue = max(currentValue - 1, 1); playCurrentValue(); break; + +#ifdef SerialInputAsCommand + case command::menu_jump: + currentValue = min(max(this->tonuino.getMenuJump(), 1),numberOfOptions); + playCurrentValue(); + break; +#endif + default: break; } @@ -139,7 +147,7 @@ void ChMode::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { folder.mode = static_cast(currentValue); LOG(state_log, s_info, str_ChMode(), F(": "), currentValue); if (folder.mode == pmode_t::admin) { @@ -184,7 +192,7 @@ void ChFolder::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { folder.folder = currentValue; LOG(state_log, s_info, str_ChFolder(), F(": "), currentValue); if (folder.mode == pmode_t::einzel) { @@ -227,7 +235,7 @@ void ChTrack::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { folder.special = currentValue; LOG(state_log, s_info, str_ChTrack(), F(": "), currentValue); transit(); @@ -260,7 +268,7 @@ void ChFirstTrack::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { folder.special = currentValue; LOG(state_log, s_info, str_ChFirstTrack(), F(": "), currentValue); transit(); @@ -295,7 +303,7 @@ void ChLastTrack::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { folder.special2 = currentValue; LOG(state_log, s_info, str_ChLastTrack(), F(": "), currentValue); transit(); @@ -786,7 +794,7 @@ void Admin_Allow::react(command_e const &cmd_e) { // case get_match_c : // VoiceMenu::react(b); // const command cmd = commands.getCommand(cmd_e.cmd_raw, state_for_command::admin); -// if ((cmd == command::select) && (currentValue != 0)) { +// if (Commands::isSelect(cmd) && (currentValue != 0)) { // if (current_subState == cv) // current_subState = allow; // else @@ -850,7 +858,7 @@ void Admin_Entry::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { lastCurrentValue = currentValue; switch (currentValue) { case 0: break; @@ -1009,7 +1017,7 @@ void Admin_SimpleSetting::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { switch (type) { case maxVolume : settings.maxVolume = currentValue + settings.minVolume ; break; case minVolume : settings.minVolume = currentValue ; break; @@ -1088,7 +1096,7 @@ void Admin_ModCard::react(command_e const &cmd_e) { } return; } - else if ((cmd == command::select) && (currentValue != 0)) { + else if (Commands::isSelect(cmd) && (currentValue != 0)) { if (mode == pmode_t::none) { mode = static_cast(currentValue); if (mode != pmode_t::sleep_timer) { @@ -1137,7 +1145,7 @@ void Admin_ShortCut::react(command_e const &cmd_e) { return; if (shortcut == 0) { - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { shortcut = currentValue; current_subState = start_setupCard; } @@ -1203,7 +1211,7 @@ void Admin_StandbyTimer::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { switch (currentValue) { case 1: settings.standbyTimer = 5; break; case 2: settings.standbyTimer = 15; break; @@ -1325,7 +1333,7 @@ void Admin_InvButtons::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { switch (currentValue) { case 1: settings.invertVolumeButtons = false; break; case 2: settings.invertVolumeButtons = true ; break; @@ -1379,7 +1387,7 @@ void Admin_LockAdmin::react(command_e const &cmd_e) { switch(current_subState) { case get_mode: VoiceMenu::react(cmd); - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { settings.adminMenuLocked = currentValue-1; if (settings.adminMenuLocked == 2) { current_subState = get_pin; @@ -1434,7 +1442,7 @@ void Admin_PauseIfCardRemoved::react(command_e const &cmd_e) { if (isAbort(cmd)) return; - if ((cmd == command::select) && (currentValue != 0)) { + if (Commands::isSelect(cmd) && (currentValue != 0)) { switch (currentValue) { case 1: settings.pauseWhenCardRemoved = false; break; case 2: settings.pauseWhenCardRemoved = true ; break; diff --git a/src/tonuino.hpp b/src/tonuino.hpp index cf533a0..ee41a02 100644 --- a/src/tonuino.hpp +++ b/src/tonuino.hpp @@ -42,6 +42,10 @@ class Tonuino { Chip_card& getChipCard() { return chip_card; } static uint32_t generateRamdomSeed(); +#ifdef SerialInputAsCommand + uint8_t getMenuJump() const { return serialInput.get_menu_jump(); } +#endif + void shutdown(); private: