global: make user_input_get blocking

This commit is contained in:
King Kévin 2018-01-24 22:25:12 +01:00
parent a9b0ad9f62
commit 5f10bc3424
2 changed files with 3 additions and 6 deletions

View File

@ -166,9 +166,8 @@ void sys_tick_handler(void)
char user_input_get(void)
{
// this is prone to error if user input is stored meanwhile (e.g. by interrupts)
if (!user_input_used) { // no user input available
return 0;
while (!user_input_available) { // wait for user input
__WFI(); // go to sleep
}
volatile char to_return = user_input_buffer[user_input_i]; // get the next available character
user_input_i = (user_input_i+1)%LENGTH(user_input_buffer); // update used buffer
@ -191,9 +190,6 @@ void user_input_store(char c)
bool wait_space(void)
{
while (!user_input_available) { // wait for user input
__WFI(); // go to sleep
}
if (' '==user_input_get()) { // space entered
return true;
} else { // something else entered

View File

@ -419,6 +419,7 @@ void sleep_ms(uint32_t duration);
/** get user input
* @note verify availability using user_input_available
* @warning blocks and sleeps until user input is available
* @return user input character
*/
char user_input_get(void);