summaryrefslogtreecommitdiff
path: root/firmware/s1224/src/common/status.c
blob: ca4df5c69aec8a1158f68cc603be13dfaa5aece8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Status from PTT + dual sense; texts from INI.
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include "status.h"
#include "config.h"
#include "display.h"
#include "ptt.h"
#include "sense.h"
#include <stdio.h>

static s1224_state_t g_state = S1224_STATE_STARTING;

const char *s1224_state_string(s1224_state_t st)
{
    const s1224_config_t *cfg = config_get();
    switch (st) {
    case S1224_STATE_STARTING:
        return cfg->starting;
    case S1224_STATE_READY:
        return cfg->ready;
    case S1224_STATE_FAULT:
        return cfg->fault;
    case S1224_STATE_SENDING:
        return cfg->sending;
    case S1224_STATE_SIGNAL:
        return cfg->signal;
    case S1224_STATE_PACKET:
        return cfg->packet;
    default:
        return cfg->fault;
    }
}

void status_set(s1224_state_t st)
{
    g_state = st;
}

s1224_state_t status_get(void)
{
    return g_state;
}

void status_publish(void)
{
    const char *s = s1224_state_string(g_state);
    if (config_unsolicited_ok()) {
        printf("STATUS %s\r\n", s);
    }
    display_update();
}

void status_tick(void)
{
    if (g_state == S1224_STATE_FAULT || g_state == S1224_STATE_STARTING) {
        display_update();
        return;
    }

    s1224_state_t next;
    if (ptt_get()) {
        next = S1224_STATE_SENDING;
    } else if (sense_packet_active()) {
        next = S1224_STATE_PACKET;
    } else if (sense_signal_active()) {
        next = S1224_STATE_SIGNAL;
    } else {
        next = S1224_STATE_READY;
    }

    if (next != g_state) {
        g_state = next;
        status_publish();
    } else {
        display_update();
    }
}
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com