306 lines
9.6 KiB
C
306 lines
9.6 KiB
C
//
|
|
// Created by ilya on 04.04.24.
|
|
//
|
|
|
|
#include "UserInput.h"
|
|
#include "ext_telematica.h"
|
|
#include <SystemDelayInterface.h>
|
|
#include <CmsisRtosThreadUtils.h>
|
|
|
|
#pragma GCC push_options
|
|
#pragma GCC optimize ("O0")
|
|
|
|
bool UserInputButtonWatcher_CustomEnv(tUserInputButtonWatcherCustomAdcEnv *env){
|
|
uint16_t volts = AdcGet(env->adcIo ,40);
|
|
if( (env->lowLevel<volts) && (volts < env->HightLevel) ){
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
bool currentValue = 0;
|
|
bool prevValue = 0;
|
|
bool UserInputGetAntiRattlePin(tGpioPin *pin){
|
|
prevValue = false;
|
|
currentValue = false;
|
|
prevValue = GpioPinGet(pin);
|
|
|
|
if (prevValue == true) {
|
|
uint32_t tm = SystemGetMs() + 100;
|
|
while (tm > SystemGetMs()){
|
|
currentValue = GpioPinGet(pin);
|
|
if (prevValue == currentValue) {
|
|
currentValue = true;
|
|
} else {
|
|
currentValue = false;
|
|
}
|
|
}
|
|
}
|
|
return currentValue;
|
|
}
|
|
|
|
uint32_t tm = 0;
|
|
bool UserInputButtonWatcher_CustomTestModeEnv(tUserInputButtonWatcherCustomEnvTestMode *env){
|
|
#if (AURUS_CAR_UI == 1)
|
|
bool res = false;
|
|
|
|
if(UserInputGetAntiRattlePin(&env->userInputPins->emergency)) {
|
|
res = true;
|
|
env->buttonWaitPresTime = SystemGetMs() + env->waitPresTime;
|
|
env->flIsPreset = true;
|
|
} else {
|
|
res = false;
|
|
}
|
|
|
|
if( res == true ){
|
|
env->presCounter++;
|
|
} else {
|
|
tm = SystemGetMs();
|
|
if((tm > env->buttonWaitPresTime) && (env->flIsPreset == true)){
|
|
env->flIsPreset = false;
|
|
env->presCounter = 0;
|
|
env->buttonWaitPresTime = 0;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if(env->presCounter == env->presLimit){
|
|
env->flIsPreset = false;
|
|
env->presCounter = 0;
|
|
env->buttonWaitPresTime = 0;
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
#if (AURUS_CAR_UI == 0)
|
|
bool res = false;
|
|
if(
|
|
( GpioPinGet(&env->userInputPins->additional) ) &&
|
|
( GpioPinGet(&env->userInputPins->emergency ) )
|
|
){
|
|
res = true;
|
|
} else {
|
|
res = false;
|
|
}
|
|
|
|
///===============================================================================================
|
|
if( (res) && (env->flIsPreset == false) ){
|
|
env->buttonThisPresTime = SystemGetMs() + env->buttonWaitPresTime;
|
|
env->buttonThisPresTime = env->buttonThisPresTime;
|
|
env->flIsPreset = true;
|
|
}
|
|
|
|
if(
|
|
(!res) &&
|
|
(env->buttonThisPresTime > SystemGetMs())
|
|
){
|
|
if(env->flIsPreset == true){
|
|
env->flIsPreset = false;
|
|
}
|
|
}
|
|
|
|
if(
|
|
(res) &&
|
|
(env->buttonThisPresTime < SystemGetMs()) &&
|
|
(env->flIsPreset = true)
|
|
){
|
|
env->flIsPreset = false;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
bool UserInputButtonWatcher_CustomAddEnv(tUserInputButtonWatcherCustomSampleMode *env){
|
|
return UserInputGetAntiRattlePin(&env->userInputPins->additional);
|
|
}
|
|
|
|
bool UserInputButtonWatcher_CustomEmerEnv(tUserInputButtonWatcherCustomSampleMode *env){
|
|
return UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
}
|
|
|
|
bool res = false;
|
|
bool UserInputButtonWatcher_CustomEmerModeEnv(tUserInputButtonWatcherCustomEnvEmerMode *env){
|
|
#if (AURUS_CAR_UI == 1)
|
|
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
if( (res) && (env->flIsPreset == false) ){
|
|
env->buttonThisPresTime = SystemGetMs() + env->buttonWaitPresTime;
|
|
env->buttonThisPresTime = env->buttonThisPresTime;
|
|
env->flIsPreset = true;
|
|
}
|
|
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
if(
|
|
(!res) &&
|
|
(env->buttonThisPresTime > SystemGetMs())
|
|
){
|
|
if(env->flIsPreset == true){
|
|
env->flIsPreset = false;
|
|
}
|
|
}
|
|
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
if(
|
|
(res) &&
|
|
(env->buttonThisPresTime < SystemGetMs()) &&
|
|
(env->flIsPreset = true)
|
|
){
|
|
env->flIsPreset = false;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
#endif
|
|
#if (AURUS_CAR_UI == 0)
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->additional);
|
|
if(res) {
|
|
env->flIsPreset = false;
|
|
return false;
|
|
}
|
|
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
if( (res) && (env->flIsPreset == false) ){
|
|
env->buttonThisPresTime = SystemGetMs() + env->buttonWaitPresTime;
|
|
env->buttonThisPresTime = env->buttonThisPresTime;
|
|
env->flIsPreset = true;
|
|
}
|
|
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
if(
|
|
(!res) &&
|
|
(env->buttonThisPresTime > SystemGetMs())
|
|
){
|
|
if(env->flIsPreset == true){
|
|
env->flIsPreset = false;
|
|
}
|
|
}
|
|
|
|
res = UserInputGetAntiRattlePin(&env->userInputPins->emergency);
|
|
if(
|
|
(res) &&
|
|
(env->buttonThisPresTime < SystemGetMs()) &&
|
|
(env->flIsPreset = true)
|
|
){
|
|
env->flIsPreset = false;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
void UserInput_Init(
|
|
tUserInput *env,
|
|
tUserInputPins *pins,
|
|
const uint16_t *buttonPresTimeEmerMode,
|
|
const uint16_t *buttonPresTimeTestMode
|
|
) {
|
|
UserInputButtonWatcher_InitStatic(&env->watcher, env->mem.watches, 128);
|
|
|
|
env->CustomEnvTestMode = (tUserInputButtonWatcherCustomEnvTestMode) {
|
|
.userInputPins = pins,
|
|
.buttonWaitPresTime = *buttonPresTimeTestMode,
|
|
.buttonThisPresTime = 0,
|
|
.flIsPreset = false,
|
|
.waitPresTime = 6000,
|
|
.presCounter = 0,
|
|
.presLimit = 5
|
|
};
|
|
env->CustomEnvEmerMode.buttonWaitPresTime = env->CustomEnvEmerMode.buttonWaitPresTime-1000;
|
|
UserInputButtonWatcher_AddCustom(&env->watcher, &env->CustomEnvTestMode, UserInputButtonWatcher_CustomTestModeEnv,
|
|
UI_CUSTOM_BUTTON_TEST_MODE);
|
|
|
|
|
|
env->CustomEnvEmerMode = (tUserInputButtonWatcherCustomEnvEmerMode) {
|
|
.userInputPins = pins,
|
|
.buttonWaitPresTime = *buttonPresTimeEmerMode,
|
|
.buttonThisPresTime = 0,
|
|
.flIsPreset = false,
|
|
};
|
|
env->CustomEnvEmerMode.buttonWaitPresTime = env->CustomEnvEmerMode.buttonWaitPresTime-1000;
|
|
UserInputButtonWatcher_AddCustom(&env->watcher, &env->CustomEnvEmerMode, UserInputButtonWatcher_CustomEmerModeEnv,
|
|
UI_CUSTOM_BUTTON_EMERGENCY);
|
|
|
|
|
|
env->CustomEnvSampleAdd = (tUserInputButtonWatcherCustomSampleMode) {
|
|
.userInputPins = pins,
|
|
};
|
|
UserInputButtonWatcher_AddCustom(&env->watcher, &env->CustomEnvSampleAdd, UserInputButtonWatcher_CustomAddEnv,
|
|
UI_VIRT_BUTTON_ADDITIONAL);
|
|
|
|
|
|
env->CustomEnvSampleEmer = (tUserInputButtonWatcherCustomSampleMode) {
|
|
.userInputPins = pins,
|
|
};
|
|
UserInputButtonWatcher_AddCustom(&env->watcher, &env->CustomEnvSampleEmer, UserInputButtonWatcher_CustomEmerEnv,
|
|
UI_VIRT_BUTTON_EMERGENCY);
|
|
|
|
env->buttonsInterface = UserInputButtonWatcher_GetInterface(&env->watcher);
|
|
|
|
InitThreadAtrStatic(&env->thread.attr, "UserInput", env->thread.controlBlock, env->thread.stack, osPriorityNormal);
|
|
env->thread.id = 0;
|
|
}
|
|
|
|
bool state = false;
|
|
uint32_t timing = 0;
|
|
bool isPressedEmergencyButton = false;
|
|
bool isPressedTestButton = false;
|
|
static _Noreturn void UserInput_Thread(tUserInput *env) {
|
|
for (;;) {
|
|
UserInputButtonWatcher_Check(&env->watcher);
|
|
//начало-----------------Обновление счетчиков телематики (для отладки)--------------------------------------
|
|
|
|
isPressedEmergencyButton = UserInputGetAntiRattlePin(&env->CustomEnvSampleEmer.userInputPins->emergency);
|
|
if (isPressedEmergencyButton) {
|
|
if (EXT_ENV_ADR_TELE.META_EXT_ENV_TELE) {
|
|
EXT_ENV_ADR_TELE.tele_func(env, TELE_MODULE_COUNTER_1);
|
|
}
|
|
if(state == false){
|
|
timing = SystemGetMs();
|
|
state = true;
|
|
}
|
|
} else{
|
|
if(state == true){
|
|
timing = SystemGetMs() - timing;
|
|
if (EXT_ENV_ADR_TELE.META_EXT_ENV_TELE) {
|
|
EXT_ENV_ADR_TELE.tele_func(&timing, TELE_MODULE_COUNTER_5);
|
|
}
|
|
timing = 0;
|
|
state = false;
|
|
}
|
|
}
|
|
//конец------------------Обновление счетчиков телематики (для отладки)--------------------------------------
|
|
//начало-----------------Обновление счетчиков телематики (для отладки)--------------------------------------
|
|
// bool isPressedTestButton = GpioPinGet(&env->CustomEnvSampleEmer.userInputPins->additional);
|
|
isPressedTestButton = UserInputGetAntiRattlePin(&env->CustomEnvSampleEmer.userInputPins->additional);
|
|
if (isPressedTestButton) {
|
|
if (EXT_ENV_ADR_TELE.META_EXT_ENV_TELE) {
|
|
EXT_ENV_ADR_TELE.tele_func(env, TELE_MODULE_COUNTER_3);
|
|
}
|
|
}
|
|
|
|
//конец------------------Обновление счетчиков телематики (для отладки)--------------------------------------
|
|
SystemDelayMs(100);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
#pragma GCC pop_options |