Skip to content

Commit

Permalink
Merge pull request #80: Issue 069: Enhance serial input as command so…
Browse files Browse the repository at this point in the history
…urce to jump into menu entries
  • Loading branch information
boerge1 authored Apr 23, 2023
2 parents 59b2146 + 4bed7e9 commit 83657dc
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 53 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TonUINO-TNG.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
53 changes: 28 additions & 25 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ enum class commandRaw: uint8_t {
five,
fiveLong,
fiveLongRepeat,
#endif
#ifdef SerialInputAsCommand
menu_jump,
#endif
cmd_end,
#ifdef BUTTONS3X3
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions src/serial_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "constants.hpp"
#include "logger.hpp"

#ifdef SerialInputAsCommand
SerialInput::SerialInput()
: CommandSource()
{
Expand All @@ -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

4 changes: 4 additions & 0 deletions src/serial_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
36 changes: 22 additions & 14 deletions src/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ void VoiceMenu<SMT>::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;
}
Expand Down Expand Up @@ -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<pmode_t>(currentValue);
LOG(state_log, s_info, str_ChMode(), F(": "), currentValue);
if (folder.mode == pmode_t::admin) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<finished>();
Expand Down Expand Up @@ -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<ChLastTrack>();
Expand Down Expand Up @@ -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<finished>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<pmode_t>(currentValue);
if (mode != pmode_t::sleep_timer) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/tonuino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 83657dc

Please sign in to comment.