UveosOnNation_VEGA_UserInput/Src/UserInput.c

45 lines
1.2 KiB
C

/*
* UserInput.c
*
* Created on: Jun 3, 2021
* Author: zemon
*/
#include "UserInput.h"
#include <SystemDelayInterface.h>
#include <CmsisRtosThreadUtils.h>
void UserInput_Init(
tUserInput *env,
tUserInputPins *pins
) {
UserInputButtonWatcher_InitStatic(&env->watcher, env->mem.watches, 128);
UserInputButtonWatcher_Add(&env->watcher, pins->emergency, UI_BUTTON_EMERGENCY);
UserInputButtonWatcher_Add(&env->watcher, pins->additional, UI_BUTTON_ADDITIONAL);
env->buttonsInterface = UserInputButtonWatcher_GetInterface(&env->watcher);
InitThreadAtrStatic(&env->thread.attr, "UserInput", env->thread.controlBlock, env->thread.stack, osPriorityNormal);
env->thread.id = 0;
}
static _Noreturn void UserInput_Thread(tUserInput *env) {
for (;;) {
UserInputButtonWatcher_Check(&env->watcher);
SystemDelayMs(5);
}
}
void UserInput_StartThread(tUserInput *env) {
if (!env->thread.id) {
env->thread.id = osThreadNew((osThreadFunc_t) (UserInput_Thread), (void *) (env), &env->thread.attr);
} else {
osThreadResume(env->thread.id);
}
}
void UserInput_Suspend(tUserInput *env) {
if (env->thread.id) {
osThreadSuspend(env->thread.id);
}
}