add timeout menu
This commit is contained in:
parent
d5ae799100
commit
1db10e1f07
|
@ -104,11 +104,13 @@ static void board_supplement_init(void)
|
||||||
HAL_GPIO_Init(BUTTON2_PORT, &GPIO_InitStruct);
|
HAL_GPIO_Init(BUTTON2_PORT, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t board_button1_read(void) {
|
uint32_t board_button1_read(void)
|
||||||
|
{
|
||||||
return BUTTON1_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON1_PORT, BUTTON1_PIN);
|
return BUTTON1_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON1_PORT, BUTTON1_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t board_button2_read(void) {
|
uint32_t board_button2_read(void)
|
||||||
|
{
|
||||||
return BUTTON2_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON2_PORT, BUTTON2_PIN);
|
return BUTTON2_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON2_PORT, BUTTON2_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +190,8 @@ int main(void)
|
||||||
tud_task(); // tinyusb device task
|
tud_task(); // tinyusb device task
|
||||||
|
|
||||||
// check for credential timeout
|
// check for credential timeout
|
||||||
const uint32_t minutes = board_millis() / 1000 / 60;
|
const uint32_t minutes = board_millis();
|
||||||
if (credentials && ((minutes > entered_when + config.timeout_global) || (minutes > entered_when + TIMEOUT_GLOBAL))) {
|
if (credentials && ((minutes > entered_when + config.timeout_global * 1000 * 60) || (minutes > entered_when + TIMEOUT_GLOBAL * 1000 * 60))) {
|
||||||
const char str[] = "global timeout reached, clearing cedentials\r\n";
|
const char str[] = "global timeout reached, clearing cedentials\r\n";
|
||||||
tud_cdc_write_str(str);
|
tud_cdc_write_str(str);
|
||||||
tud_cdc_write_flush();
|
tud_cdc_write_flush();
|
||||||
|
@ -201,7 +203,7 @@ int main(void)
|
||||||
pasted_when = 0;
|
pasted_when = 0;
|
||||||
entered_when = 0;
|
entered_when = 0;
|
||||||
}
|
}
|
||||||
if (credentials && ((minutes > pasted_when + config.timeout_repeat) || (minutes > pasted_when + TIMEOUT_REPEAT))) {
|
if (credentials && ((minutes > pasted_when + config.timeout_repeat * 1000 * 60) || (minutes > pasted_when + TIMEOUT_REPEAT * 1000 * 60))) {
|
||||||
const char str[] = "repeat timeout reached, clearing cedentials\r\n";
|
const char str[] = "repeat timeout reached, clearing cedentials\r\n";
|
||||||
tud_cdc_write_str(str);
|
tud_cdc_write_str(str);
|
||||||
tud_cdc_write_flush();
|
tud_cdc_write_flush();
|
||||||
|
@ -256,6 +258,8 @@ void tud_resume_cb(void)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
void cdc_task(void)
|
void cdc_task(void)
|
||||||
{
|
{
|
||||||
|
static char tmp[64];
|
||||||
|
|
||||||
// connected() check for DTR bit
|
// connected() check for DTR bit
|
||||||
// Most but not all terminal client set this when making connection
|
// Most but not all terminal client set this when making connection
|
||||||
// if ( tud_cdc_connected() )
|
// if ( tud_cdc_connected() )
|
||||||
|
@ -285,6 +289,16 @@ void cdc_task(void)
|
||||||
str = "\r\nbuttons swapped\r\n";
|
str = "\r\nbuttons swapped\r\n";
|
||||||
save_config();
|
save_config();
|
||||||
break;
|
break;
|
||||||
|
case 'g': // set global timeout
|
||||||
|
i = 0; // reset index
|
||||||
|
menu = MENU_TIMEOUT_GLOBAL;
|
||||||
|
str = "\r\nenter global timeout in minutes: ";
|
||||||
|
break;
|
||||||
|
case 'r': // set repeat timeout
|
||||||
|
i = 0; // reset index
|
||||||
|
menu = MENU_TIMEOUT_REPEAT;
|
||||||
|
str = "\r\nenter repeat timeout in minutes: ";
|
||||||
|
break;
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
break; // nothing to do
|
break; // nothing to do
|
||||||
|
@ -293,7 +307,10 @@ void cdc_task(void)
|
||||||
str = "\r\npress key to enter menu\r\n" \
|
str = "\r\npress key to enter menu\r\n" \
|
||||||
"h help\r\n" \
|
"h help\r\n" \
|
||||||
"c enter credentials\r\n" \
|
"c enter credentials\r\n" \
|
||||||
"b swap buttons\r\n";
|
"b swap buttons\r\n" \
|
||||||
|
"r set repeat timeout\r\n" \
|
||||||
|
"g set global timeout\r\n" \
|
||||||
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MENU_USER:
|
case MENU_USER:
|
||||||
|
@ -336,6 +353,54 @@ void cdc_task(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MENU_TIMEOUT_GLOBAL:
|
||||||
|
for (uint16_t j = 0; j < count; j++) {
|
||||||
|
if ('\r' == buf[0] || '\n' == buf[0]) { // 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;
|
||||||
|
}
|
||||||
|
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
|
||||||
|
str = "\r\nlimit reached\r\n";
|
||||||
|
} else {
|
||||||
|
tmp[i++] = buf[j]; // save password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MENU_TIMEOUT_REPEAT:
|
||||||
|
for (uint16_t j = 0; j < count; j++) {
|
||||||
|
if ('\r' == buf[0] || '\n' == buf[0]) { // 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;
|
||||||
|
}
|
||||||
|
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
|
||||||
|
str = "\r\nlimit reached\r\n";
|
||||||
|
} else {
|
||||||
|
tmp[i++] = buf[j]; // save password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: // unknown menu
|
default: // unknown menu
|
||||||
menu = MENU_HOME; // revert to home
|
menu = MENU_HOME; // revert to home
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue