556 lines
16 KiB
C
556 lines
16 KiB
C
///*
|
|
// * UserIndication.c
|
|
// *
|
|
// * Created on: Jun 3, 2021
|
|
// * Author: zemon
|
|
// */
|
|
//
|
|
#include "UserIndication.h"
|
|
#include <SystemDelayInterface.h>
|
|
#include <CmsisRtosThreadUtils.h>
|
|
|
|
|
|
static void UserIndication_SetModeUveos(tUserIndication *env, tEraGlonassUveosStatus mode);
|
|
|
|
static void UserIndication_Update(tUserIndication *env);
|
|
|
|
void UserIndication_Init(
|
|
tUserIndication *env,
|
|
tDeviceModes initMode,
|
|
tBipLed *uiuLed,
|
|
tOnBoardLed *onBoardLeds
|
|
) {
|
|
env->timerIsBusy = SystemGetMs();
|
|
env->uiuLed = uiuLed;
|
|
env->onBoardLed = onBoardLeds;
|
|
env->mode = initMode;
|
|
|
|
env->uveosIndicator.env = env;
|
|
env->uveosIndicator.show = (void *) UserIndication_SetModeUveos;
|
|
|
|
InitThreadAtrStatic(&env->thread.attr, "Indication", env->thread.controlBlock, env->thread.stack, osPriorityNormal);
|
|
env->thread.id = 0;
|
|
env->bipPowerMode = true;
|
|
env->tmpDeviceModes = DEVICE_MODE_UVEOS_UNDEFINDET;
|
|
env->blincCount = 0;
|
|
}
|
|
|
|
void UserIndication_SetMode(tUserIndication *env, tDeviceModes mode) {
|
|
if (env->mode != mode) {
|
|
env->mode = mode;
|
|
}
|
|
}
|
|
|
|
|
|
#define UVEOS_TO_DEV_MODE(NAME) case UVEOS_STATUS_##NAME: UserIndication_SetMode(env, DEVICE_MODE_UVEOS_##NAME); return;
|
|
|
|
static void UserIndication_SetModeUveos(tUserIndication *env, tEraGlonassUveosStatus mode) {
|
|
switch (mode) {
|
|
UVEOS_TO_DEV_MODE(CALL_INITIATE)
|
|
UVEOS_TO_DEV_MODE(DIALING)
|
|
UVEOS_TO_DEV_MODE(MSD_TRANSMIT)
|
|
UVEOS_TO_DEV_MODE(SMS_TRANSMIT)
|
|
UVEOS_TO_DEV_MODE(CALL_ACTIVE)
|
|
UVEOS_TO_DEV_MODE(CALL_FAILURE)
|
|
UVEOS_TO_DEV_MODE(MANUAL_BEGIN)
|
|
UVEOS_TO_DEV_MODE(AUTOMATIC_BEGIN)
|
|
UVEOS_TO_DEV_MODE(TESTING_BEGIN)
|
|
UVEOS_TO_DEV_MODE(SYSTEM_STARTUP)
|
|
UVEOS_TO_DEV_MODE(UNDEFINDET)
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void UserIndication_fullBip(tUserIndication *env, uint8_t value) {
|
|
#if (AURUS_CAR_UI == 1)
|
|
if (value == UIU_GREEN) {
|
|
GpioPinSet(&env->onBoardLed->red2, true);
|
|
GpioPinSet(&env->uiuLed->green, false);
|
|
GpioPinSet(&env->uiuLed->red, true);
|
|
|
|
} else if (value == UIU_RED) {
|
|
GpioPinSet(&env->onBoardLed->green2, true);
|
|
GpioPinSet(&env->uiuLed->red, false);
|
|
GpioPinSet(&env->uiuLed->green, true);
|
|
|
|
} else if (value == UIU_OFF) {
|
|
GpioPinSet(&env->onBoardLed->green2, false);
|
|
GpioPinSet(&env->onBoardLed->red2, false);
|
|
|
|
GpioPinSet(&env->uiuLed->green, false);
|
|
GpioPinSet(&env->uiuLed->red, false);
|
|
} else if (value == UIU_ORANGE) {
|
|
|
|
}
|
|
#endif
|
|
#if (AURUS_CAR_UI == 0)
|
|
if (value == UIU_GREEN) {
|
|
GpioPinSet(&env->onBoardLed->green2, true);
|
|
|
|
GpioPinSet(&env->uiuLed->red, false);
|
|
GpioPinSet(&env->uiuLed->green, true);
|
|
|
|
} else if (value == UIU_RED) {
|
|
GpioPinSet(&env->onBoardLed->red2, true);
|
|
|
|
GpioPinSet(&env->uiuLed->green, false);
|
|
GpioPinSet(&env->uiuLed->red, true);
|
|
|
|
} else if (value == UIU_OFF) {
|
|
GpioPinSet(&env->onBoardLed->green2, false);
|
|
GpioPinSet(&env->onBoardLed->red2, false);
|
|
|
|
GpioPinSet(&env->uiuLed->green, false);
|
|
GpioPinSet(&env->uiuLed->red, false);
|
|
} else if (value == UIU_ORANGE) {
|
|
|
|
}
|
|
#endif
|
|
|
|
}
|
|
|
|
void UserIndication_doubleLineBip(tUserIndication *env, uint8_t value) {
|
|
if (value == UIU_GREEN) {
|
|
GpioPinSet(&env->onBoardLed->green2, true);
|
|
GpioPinSet(&env->uiuLed->ledsBip, false);
|
|
} else if (value == UIU_RED) {
|
|
GpioPinSet(&env->onBoardLed->red2, true);
|
|
GpioPinSet(&env->uiuLed->ledsBip, true);
|
|
|
|
} else if (value == UIU_OFF) {
|
|
GpioPinSet(&env->onBoardLed->green2, false);
|
|
GpioPinSet(&env->onBoardLed->red2, false);
|
|
|
|
} else if (value == UIU_ORANGE) {
|
|
|
|
}
|
|
}
|
|
|
|
void UserIndication_Uiu(tUserIndication *env, uint8_t value) {
|
|
if (env->bipPowerMode == true) {
|
|
UserIndication_fullBip(env, value);
|
|
}
|
|
}
|
|
|
|
void UserIndication_BlinkLed(tUserIndication *env, uint32_t timeOut, uint8_t indicatorFirst) {
|
|
env->tmpDeviceModes = env->mode;
|
|
uint32_t tmp = SystemGetMs() + timeOut;
|
|
UserIndication_Uiu(env, indicatorFirst);
|
|
while (tmp > SystemGetMs()) {
|
|
if (env->tmpDeviceModes != env->mode) {
|
|
return;
|
|
}
|
|
SystemDelayMs(1);
|
|
}
|
|
|
|
tmp = SystemGetMs() + timeOut;
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
while (tmp > SystemGetMs()) {
|
|
if (env->tmpDeviceModes != env->mode) {
|
|
return;
|
|
}
|
|
SystemDelayMs(1);
|
|
}
|
|
}
|
|
|
|
void UserIndication_ManualBeginCool(tUserIndication *env, uint32_t timeOut, uint8_t indicatorFirst, uint16_t blincCount) {
|
|
if(env->blincCount <= blincCount) {
|
|
env->tmpDeviceModes = env->mode;
|
|
uint32_t tmp = SystemGetMs() + timeOut;
|
|
UserIndication_Uiu(env, indicatorFirst);
|
|
while (tmp > SystemGetMs()) {
|
|
if (env->tmpDeviceModes != env->mode) {
|
|
return;
|
|
}
|
|
SystemDelayMs(1);
|
|
}
|
|
|
|
tmp = SystemGetMs() + timeOut;
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
while (tmp > SystemGetMs()) {
|
|
if (env->tmpDeviceModes != env->mode) {
|
|
return;
|
|
}
|
|
SystemDelayMs(1);
|
|
}
|
|
env->blincCount++;
|
|
}
|
|
}
|
|
void UserIndication_ManualInitCool(tUserIndication *env, uint32_t timeOut, uint8_t indicatorFirst) {
|
|
|
|
env->tmpDeviceModes = env->mode;
|
|
uint32_t tmp = SystemGetMs() + timeOut;
|
|
UserIndication_Uiu(env, indicatorFirst);
|
|
while (tmp > SystemGetMs()) {
|
|
if (env->tmpDeviceModes != env->mode) {
|
|
return;
|
|
}
|
|
SystemDelayMs(1);
|
|
}
|
|
|
|
tmp = SystemGetMs() + timeOut;
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
while (tmp > SystemGetMs()) {
|
|
if (env->tmpDeviceModes != env->mode) {
|
|
return;
|
|
}
|
|
SystemDelayMs(1);
|
|
}
|
|
env->blincCount++;
|
|
|
|
}
|
|
|
|
void UserIndication_BlinkLeds(
|
|
tUserIndication *env,
|
|
uint16_t timeOutFirst,
|
|
uint16_t timeOutSecond,
|
|
uint8_t indicatorFirst,
|
|
uint8_t indicatorSecond
|
|
) {
|
|
uint32_t endMs = SystemGetMs() + timeOutFirst;
|
|
while (endMs > SystemGetMs()) {
|
|
UserIndication_Uiu(env, indicatorFirst);
|
|
}
|
|
|
|
endMs = SystemGetMs() + timeOutFirst;
|
|
while (endMs > SystemGetMs()) {
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
}
|
|
|
|
endMs = SystemGetMs() + timeOutSecond;
|
|
while (endMs > SystemGetMs()) {
|
|
UserIndication_Uiu(env, indicatorSecond);
|
|
}
|
|
|
|
endMs = SystemGetMs() + timeOutSecond;
|
|
while (endMs > SystemGetMs()) {
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
}
|
|
}
|
|
|
|
|
|
//static void UserIndication_OnBoard(tUserIndication *env, uint8_t flags) {
|
|
// GpioPinSet(&env->onBoardLeds->red, flags & BOARD_RED);
|
|
// GpioPinSet(&env->onBoardLeds->green, flags & BOARD_GREEN);
|
|
// GpioPinSet(&env->onBoardLeds->blue, flags & BOARD_BLUE);
|
|
//}
|
|
//
|
|
//
|
|
//void UserIndication_UiuError(tUserIndication *env) {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
//}
|
|
|
|
tStringStatic teDeviceModesNames[] = {
|
|
StringStaticInit("Запуск"),
|
|
StringStaticInit("Тестирование"),
|
|
StringStaticInit("Ожидание загрузки GSM"),
|
|
|
|
StringStaticInit("Ошибка памяти"),
|
|
StringStaticInit("Ошибка GSM"),
|
|
StringStaticInit("Ошибка Кодека"),
|
|
|
|
StringStaticInit("Обнаружен сбой"),
|
|
StringStaticInit("Ошибка начального тестирования 1"),
|
|
StringStaticInit("Ошибка начального тестирования 2"),
|
|
|
|
StringStaticInit("ЭРА (нет ГНСС)"),
|
|
StringStaticInit("ЭРА"),
|
|
|
|
StringStaticInit("Экстренный вызов (подготовка)"),
|
|
StringStaticInit("Дозвон"),
|
|
StringStaticInit("Отправка МНД"),
|
|
StringStaticInit("Отправка SMS"),
|
|
StringStaticInit("Голосовое соединение"),
|
|
StringStaticInit("Ошибка соединения"),
|
|
|
|
StringStaticInit("Пассивный режим"),
|
|
StringStaticInit("Входящий вызов"),
|
|
StringStaticInit("Режим гараж"),
|
|
|
|
StringStaticInit("Экстренный вызов (ручной)"),
|
|
StringStaticInit("Экстренный вызов (автоматический)"),
|
|
StringStaticInit("Экстренный вызов (тестовый)"),
|
|
StringStaticInit("Зажигание включено, запуск устройства выполнен"),
|
|
StringStaticInit("Зажигание включено"),
|
|
StringStaticInit("Поиск сети"),
|
|
StringStaticInit(" "),
|
|
};
|
|
|
|
void UserIndicationIgngStarUp(tUserIndication *env) {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
SystemDelayMs(9500);
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
env->mode = DEVICE_MODE_UVEOS_UNDEFINDET;
|
|
}
|
|
|
|
void UserIndicationUpdateLed(tUserIndication *env) {
|
|
|
|
switch (env->mode) {
|
|
#if (AURUS_CAR_UI == 1)
|
|
// default: {
|
|
// UserIndication_BlinkLed(env, 2000,UIU_RED);
|
|
// UserIndication_BlinkLed(env, 2000,UIU_GREEN);
|
|
// break;
|
|
// }
|
|
case DEVICE_MODE_UVEOS_CALL_INITIATE: {
|
|
// UserIndication_BlinkLed(env, 2000,UIU_GREEN);
|
|
UserIndication_ManualInitCool(env, 2000,UIU_GREEN);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_MANUAL_BEGIN: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
UserIndication_ManualBeginCool(env, 2000,UIU_RED, 3);
|
|
break;
|
|
}
|
|
//
|
|
// case DEVICE_MODE_UVEOS_AUTOMATIC_BEGIN: {
|
|
// UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_MSD_TRANSMIT: {
|
|
// UserIndication_BlinkLed(env, 200 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_SMS_TRANSMIT: {
|
|
// UserIndication_BlinkLed(env, 200 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_CALL_ACTIVE: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_SYSTEM_STARTUP: {
|
|
// UserIndicationIgngStarUp(env);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_IGNITION_STATE: {
|
|
//// UserIndicationIgngStarUp(env);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_FAILURE: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_ERROR_ON_INIT_TEST1: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_ERROR_ON_INIT_TEST2: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_ERA_GNSS_READY: {
|
|
// UserIndication_Uiu(env, UIU_GREEN);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_ERA_WAIT_GNSS: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_PASSIVE: {
|
|
// UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_CALL_FAILURE: {
|
|
// UserIndication_BlinkLed(env, 500 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_GARAG: {
|
|
// UserIndication_BlinkLed(env, 1000 ,UIU_RED);
|
|
//// UserIndication_BlinkLeds(env, 500, 1500, UIU_GREEN, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_TESTING: {
|
|
// UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_IN_CALL: {
|
|
// UserIndication_Uiu(env, UIU_RED);
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_IGN_ON: {
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_UNDEFINDET: {
|
|
// break;
|
|
// }
|
|
//
|
|
// case DEVICE_MODE_UVEOS_WAIT_NETWORK: {
|
|
// UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
// break;
|
|
// }
|
|
#endif
|
|
|
|
#if (AURUS_CAR_UI == 0)
|
|
case DEVICE_MODE_UVEOS_CALL_INITIATE: {
|
|
UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_MANUAL_BEGIN: {
|
|
UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_AUTOMATIC_BEGIN: {
|
|
UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_MSD_TRANSMIT: {
|
|
UserIndication_BlinkLed(env, 200 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_SMS_TRANSMIT: {
|
|
UserIndication_BlinkLed(env, 200 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_CALL_ACTIVE: {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_SYSTEM_STARTUP: {
|
|
UserIndicationIgngStarUp(env);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_IGNITION_STATE: {
|
|
// UserIndicationIgngStarUp(env);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_FAILURE: {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_ERROR_ON_INIT_TEST1: {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_ERROR_ON_INIT_TEST2: {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_ERA_GNSS_READY: {
|
|
UserIndication_Uiu(env, UIU_GREEN);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_ERA_WAIT_GNSS: {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_PASSIVE: {
|
|
UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_CALL_FAILURE: {
|
|
UserIndication_BlinkLed(env, 500 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_GARAG: {
|
|
UserIndication_BlinkLed(env, 1000 ,UIU_RED);
|
|
// UserIndication_BlinkLeds(env, 500, 1500, UIU_GREEN, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_TESTING: {
|
|
UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_IN_CALL: {
|
|
UserIndication_Uiu(env, UIU_RED);
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_IGN_ON: {
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_UNDEFINDET: {
|
|
break;
|
|
}
|
|
|
|
case DEVICE_MODE_UVEOS_WAIT_NETWORK: {
|
|
UserIndication_BlinkLed(env, 800 ,UIU_RED);
|
|
break;
|
|
}
|
|
|
|
default: {
|
|
UserIndication_Uiu(env, UIU_OFF);
|
|
GpioPinSet(&env->onBoardLed->red1, false);
|
|
GpioPinSet(&env->onBoardLed->green1, false);
|
|
break;
|
|
}
|
|
#endif
|
|
case DEVICE_MODE_WAIT_GSM_BOOT:
|
|
break;
|
|
case DEVICE_MODE_ERROR_FLASH:
|
|
break;
|
|
case DEVICE_MODE_ERROR_GSM:
|
|
break;
|
|
case DEVICE_MODE_ERROR_CODEC:
|
|
break;
|
|
case DEVICE_MODE_UVEOS_DIALING:
|
|
break;
|
|
case DEVICE_MODE_UVEOS_TESTING_BEGIN:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void UserIndication_Update(tUserIndication *env) {
|
|
env->currentModeName = StringStaticGetLink(&teDeviceModesNames[env->mode]);
|
|
UserIndicationUpdateLed(env);
|
|
env->tick = ((env->tick + 1) % 10);
|
|
}
|
|
|
|
static _Noreturn void UserIndication_Thread(tUserIndication *env) {
|
|
for (;;) {
|
|
UserIndication_Update(env);
|
|
SystemDelayMs(4);
|
|
}
|
|
}
|
|
|
|
void UserIndication_StartThread(tUserIndication *env) {
|
|
if (!env->thread.id) {
|
|
env->thread.id = osThreadNew((osThreadFunc_t) (UserIndication_Thread), (void *) (env), &env->thread.attr);
|
|
} else {
|
|
osThreadResume(env->thread.id);
|
|
}
|
|
}
|
|
|
|
void UserIndication_StopThread(tUserIndication *env) {
|
|
if (env->thread.id) {
|
|
osThreadSuspend(env->thread.id);
|
|
}
|
|
}
|