commit 0c4bf0371ccd67c89b8331b2ab8f639bcbea4e5e Author: cfif Date: Tue Sep 23 17:12:43 2025 +0300 Начало diff --git a/Indication.c b/Indication.c new file mode 100644 index 0000000..f719e98 --- /dev/null +++ b/Indication.c @@ -0,0 +1,57 @@ +// +// Created by cfif on 11.10.23. +// +#include "Indication.h" +#include +#include + +tStringStatic eDeviceModesNames[] = { + StringStaticInit("Запуск"), + StringStaticInit("Работа") +}; + +static void Indication_Update(tIndication *env) { + env->currentModeName = StringStaticGetLink(&eDeviceModesNames[env->mode]); + + env->tick = ((env->tick + 1) % 10); +} + +void Indication_Init( + tIndication *env, + eHvacDevModes initMode +) { + + env->mode = initMode; + Indication_Update(env); + + InitThreadAtrStatic(&env->thread.attr, "Indication", env->thread.controlBlock, env->thread.stack, osPriorityNormal); + env->thread.id = 0; +} + +void Indication_SetMode(tIndication *env, eHvacDevModes mode) { + if (env->mode != mode) { + env->mode = mode; + Indication_Update(env); + } +} + +static _Noreturn void Indication_Thread(tIndication *env) { + for (;;) { + Indication_Update(env); + SystemDelayMs(100); + } +} + +void Indication_StartThread(tIndication *env) { + if (!env->thread.id) { + env->thread.id = osThreadNew((osThreadFunc_t) (Indication_Thread), (void *) (env), &env->thread.attr); + } else { + osThreadResume(env->thread.id); + } +} + +void Indication_StopThread(tIndication *env) { + if (env->thread.id) { + osThreadSuspend(env->thread.id); + } +} \ No newline at end of file diff --git a/Indication.h b/Indication.h new file mode 100644 index 0000000..862b83a --- /dev/null +++ b/Indication.h @@ -0,0 +1,35 @@ +// +// Created by cfif on 11.10.23. +// + +#ifndef ERA_ELEMENT_2_INDICATION_H +#define ERA_ELEMENT_2_INDICATION_H + +#include +#include + +typedef enum { + HVAC_DEV_MODE_STARTUP = 0, + HVAC_DEV_MODE_RUN = 1 +} eHvacDevModes; + +typedef struct { + eHvacDevModes mode; + tStringLink currentModeName; + + uint16_t tick; + + struct { + osThreadId_t id; + uint32_t stack[128]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; +} tIndication; + +void Indication_Init(tIndication *env, eHvacDevModes initMode); +void Indication_SetMode(tIndication *env, eHvacDevModes mode); +void Indication_StartThread(tIndication *env); +void Indication_StopThread(tIndication *env); + +#endif //ERA_ELEMENT_2_INDICATION_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..0dd1901 --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file