The addition of a single-channel mode implied further modularisation of the component. This commit has broken the component down into the following modules to avoid a huge single source file and to make unit testing easier. The modules: - Separation of public and private code - *types and *defs - public relay_chn API - *adapter - *output - *run_info - *core - *ctl (control) - *tilt Closes #957.
74 lines
1.6 KiB
C
74 lines
1.6 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2025 Kozmotronik Tech
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "relay_chn_core.h"
|
|
#include "relay_chn_run_info.h"
|
|
|
|
|
|
#if RELAY_CHN_COUNT > 1
|
|
static relay_chn_run_info_t run_infos[RELAY_CHN_COUNT];
|
|
#else
|
|
static relay_chn_run_info_t run_info;
|
|
#endif
|
|
|
|
void relay_chn_run_info_init()
|
|
{
|
|
#if RELAY_CHN_COUNT > 1
|
|
for (int i = 0; i < RELAY_CHN_COUNT; i++) {
|
|
run_infos[i].last_run_cmd = RELAY_CHN_CMD_NONE;
|
|
run_infos[i].last_run_cmd_time_ms = 0;
|
|
}
|
|
#else
|
|
run_info.last_run_cmd = RELAY_CHN_CMD_NONE;
|
|
run_info.last_run_cmd_time_ms = 0;
|
|
#endif
|
|
}
|
|
|
|
#if RELAY_CHN_COUNT > 1
|
|
relay_chn_run_info_t *relay_chn_run_info_get(uint8_t chn_id)
|
|
{
|
|
if (!relay_chn_is_channel_id_valid(chn_id)) {
|
|
return NULL;
|
|
}
|
|
return &run_infos[chn_id];
|
|
}
|
|
|
|
relay_chn_run_info_t *relay_chn_run_info_get_all()
|
|
{
|
|
return run_infos;
|
|
}
|
|
#else
|
|
relay_chn_run_info_t *relay_chn_run_info_get()
|
|
{
|
|
return &run_info;
|
|
}
|
|
#endif // RELAY_CHN_COUNT > 1
|
|
|
|
relay_chn_cmd_t relay_chn_run_info_get_last_run_cmd(relay_chn_run_info_t *run_info)
|
|
{
|
|
return run_info == NULL ? RELAY_CHN_CMD_NONE : run_info->last_run_cmd;
|
|
}
|
|
|
|
void relay_chn_run_info_set_last_run_cmd(relay_chn_run_info_t *run_info, relay_chn_cmd_t cmd)
|
|
{
|
|
if (!run_info) {
|
|
return;
|
|
}
|
|
run_info->last_run_cmd = cmd;
|
|
}
|
|
|
|
uint32_t relay_chn_run_info_get_last_run_cmd_time_ms(relay_chn_run_info_t *run_info)
|
|
{
|
|
return run_info == NULL ? 0 : run_info->last_run_cmd_time_ms;
|
|
}
|
|
|
|
void relay_chn_run_info_set_last_run_cmd_time_ms(relay_chn_run_info_t *run_info, uint32_t time_ms)
|
|
{
|
|
if (!run_info) {
|
|
return;
|
|
}
|
|
run_info->last_run_cmd_time_ms = time_ms;
|
|
} |