improve timeout menus

This commit is contained in:
King Kévin 2024-04-15 07:24:42 +02:00
parent 8ca558ef30
commit ddb100570d
1 changed files with 42 additions and 14 deletions

View File

@ -352,12 +352,14 @@ void cdc_task(void)
case 'g': // set global timeout
i = 0; // reset index
menu = MENU_TIMEOUT_GLOBAL;
str = "\r\nenter global timeout in minutes: ";
snprintf(tmp, sizeof(tmp), "\r\nenter global timeout in minutes [%u]: ", config.timeout_global);
str = tmp;
break;
case 'r': // set repeat timeout
i = 0; // reset index
menu = MENU_TIMEOUT_REPEAT;
str = "\r\nenter repeat timeout in minutes: ";
snprintf(tmp, sizeof(tmp), "\r\nenter repeat timeout in minutes [%u]: ", config.timeout_repeat);
str = tmp;
break;
case 'k': // set user key
i = 0; // reset index
@ -566,21 +568,46 @@ void cdc_task(void)
}
}
break;
case MENU_LAYOUT:
for (uint16_t j = 0; j < count; j++) {
if ('\r' == buf[j] || '\n' == buf[j]) { // end received
tmp[i] = 0; // end time input
const uint16_t layout = atoi(tmp);
if (0 == strlen(tmp)) {
str = "\r\n"; // leave previous
} else if (layout > LENGTH(map_asciimap)) {
str = "\r\ninvalid entry\r\n";
} else {
config.layout = layout;
save_config();
str = "\r\nlayout set\r\n";
}
i = 0; // reset index
menu = MENU_HOME; // go to next menu
} else if (i >= sizeof(tmp) - 2) {
memset(tmp, 0, sizeof(tmp)); // clear password
str = "\r\nlimit reached\r\n";
} else {
tmp[i++] = buf[j]; // save user entry
}
}
break;
case MENU_TIMEOUT_GLOBAL:
for (uint16_t j = 0; j < count; j++) {
if ('\r' == buf[j] || '\n' == buf[j]) { // end received
tmp[i] = 0; // end time input
const uint16_t time = atoi(tmp);
if (strlen(tmp) > 0 && time > 0) {
config.timeout_global = time;
}
if (config.timeout_global > TIMEOUT_GLOBAL) {
config.timeout_global = TIMEOUT_GLOBAL;
if (0 == strlen(tmp)) {
str = "\r\n"; // leave previous
} else {
if (0 == time || config.timeout_global > TIMEOUT_GLOBAL) {
config.timeout_global = TIMEOUT_GLOBAL;
}
save_config();
}
snprintf(tmp, sizeof(tmp), "\r\nglobal timeout set to %u minutes\r\n", config.timeout_global);
str = tmp;
i = 0; // reset index
save_config();
menu = MENU_HOME; // go to next menu
} else if (i >= sizeof(tmp) - 2) {
memset(tmp, 0, sizeof(tmp)); // clear password
@ -595,16 +622,17 @@ void cdc_task(void)
if ('\r' == buf[j] || '\n' == buf[j]) { // end received
tmp[i] = 0; // end time input
const uint16_t time = atoi(tmp);
if (strlen(tmp) > 0 && time > 0) {
config.timeout_repeat = time;
}
if (config.timeout_repeat > TIMEOUT_REPEAT) {
config.timeout_repeat = TIMEOUT_REPEAT;
if (0 == strlen(tmp)) {
str = "\r\n"; // leave previous
} else {
if (0 == time || config.timeout_repeat > TIMEOUT_REPEAT) {
config.timeout_repeat = TIMEOUT_REPEAT;
}
save_config();
}
snprintf(tmp, sizeof(tmp), "\r\nrepeat timeout set to %u minutes\r\n", config.timeout_repeat);
str = tmp;
i = 0; // reset index
save_config();
menu = MENU_HOME; // go to next menu
} else if (i >= sizeof(tmp) - 2) {
memset(tmp, 0, sizeof(tmp)); // clear password