This commit is contained in:
cfif 2025-06-02 13:26:40 +03:00
commit d4756ea10c
3 changed files with 701 additions and 0 deletions

124
Inc/UserIndication.h Normal file
View File

@ -0,0 +1,124 @@
/*
* UserIndication.h
*
* Created on: Oct 29, 2022
* Author: xemon
*/
#ifndef USER_INDICATION_INC_USERINDICATION_H_
#define USER_INDICATION_INC_USERINDICATION_H_
#include <cmsis_os.h>
#include <BaseTypes.h>
#include <GpioPinInterface.h>
#include <EraGlonassUveos_Indicatior.h>
#include "AudioPlayerInterface.h"
#define USE_POLAR_DEPENDENT_BIP 0
typedef struct {
tGpioPin ledsBip;
tGpioPin red;
tGpioPin green;
} tBipLed;
typedef struct {
tGpioPin red1;
tGpioPin green1;
tGpioPin red2;
tGpioPin green2;
} tOnBoardLed;
typedef enum {
DEVICE_MODE_UVEOS_SYSTEM_STARTUP = 0,
DEVICE_MODE_TESTING = 1,
DEVICE_MODE_WAIT_GSM_BOOT = 2,
DEVICE_MODE_ERROR_FLASH = 3,
DEVICE_MODE_ERROR_GSM = 4,
DEVICE_MODE_ERROR_CODEC = 5,
DEVICE_MODE_FAILURE = 6,
DEVICE_MODE_ERROR_ON_INIT_TEST1 = 7,
DEVICE_MODE_ERROR_ON_INIT_TEST2 = 8,
DEVICE_MODE_UVEOS_ERA_WAIT_GNSS = 9,
DEVICE_MODE_UVEOS_ERA_GNSS_READY = 10,
DEVICE_MODE_UVEOS_CALL_INITIATE = 11,
DEVICE_MODE_UVEOS_DIALING = 12,
DEVICE_MODE_UVEOS_MSD_TRANSMIT = 13,
DEVICE_MODE_UVEOS_SMS_TRANSMIT = 14,
DEVICE_MODE_UVEOS_CALL_ACTIVE = 15,
DEVICE_MODE_UVEOS_CALL_FAILURE = 16,
DEVICE_MODE_UVEOS_PASSIVE = 17,
DEVICE_MODE_UVEOS_IN_CALL = 18,
DEVICE_MODE_UVEOS_GARAG = 19,
DEVICE_MODE_UVEOS_MANUAL_BEGIN = 20,
DEVICE_MODE_UVEOS_AUTOMATIC_BEGIN = 21,
DEVICE_MODE_UVEOS_TESTING_BEGIN = 22,
DEVICE_MODE_UVEOS_IGNITION_STATE = 23,
DEVICE_MODE_UVEOS_IGN_ON = 24,
DEVICE_MODE_UVEOS_WAIT_NETWORK = 25,
DEVICE_MODE_UVEOS_UNDEFINDET = 26,
} tDeviceModes;
typedef struct {
tBipLed *uiuLed; //User Interface Unit (Блок интерфейса пользователя/БИП)
tOnBoardLed *onBoardLed;
tDeviceModes mode;
int32_t keepIgn;
tStringLink currentModeName;
tEraGlonassUveosIndicator uveosIndicator;
uint16_t tick;
bool bipPowerMode;
uint32_t timerIsBusy;
// tAudioPlayerInterface *audioPlayer;
struct {
osThreadId_t id;
uint32_t stack[128];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
tDeviceModes tmpDeviceModes;
uint16_t blincCount;
} tUserIndication;
void UserIndication_Init(
tUserIndication *env,
tDeviceModes initMode,
tBipLed *uiuLed,
tOnBoardLed *onBoardLed
);
void UserIndication_SetMode(tUserIndication *env, tDeviceModes mode);
void UserIndication_StartThread(tUserIndication *env);
void UserIndication_StopThread(tUserIndication *env);
static const uint8_t UIU_OFF = (0);
static const uint8_t UIU_RED = (0x1 << 0);
static const uint8_t UIU_GREEN = (0x1 << 1);
static const uint8_t UIU_START_SIGNAL = (0x1 << 2);
static const uint8_t UIU_ORANGE = UIU_GREEN | UIU_RED;
void UserIndication_Uiu(tUserIndication *env, uint8_t value);
void UserIndicationDevStarUp(tUserIndication *env);
#endif /* USER_INDICATION_INC_USERINDICATION_H_ */

555
Src/UserIndication.c Normal file
View File

@ -0,0 +1,555 @@
///*
// * 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);
}
}

22
modular.json Normal file
View File

@ -0,0 +1,22 @@
{
"dep": [
{
"type": "git",
"provider": "Smart_Components_Aurus",
"repo": "Rtc_ARTERY_AT32F435_437"
},
{
"type": "git",
"provider": "Smart_Components_Aurus",
"repo": "BaseTypes"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}