summaryrefslogtreecommitdiff
path: root/firmware/c1224/src/common/status.c
blob: 8d09f224fa8d2fbc10e6ecb0c87f68f817a114cc (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 c1224_state_t g_state = C1224_STATE_STARTING;

const char *c1224_state_string(c1224_state_t st)
{
    const c1224_config_t *cfg = config_get();
    switch (st) {
    case C1224_STATE_STARTING:
        return cfg->starting;
    case C1224_STATE_READY:
        return cfg->ready;
    case C1224_STATE_FAULT:
        return cfg->fault;
    case C1224_STATE_SENDING:
        return cfg->sending;
    case C1224_STATE_SIGNAL:
        return cfg->signal;
    case C1224_STATE_PACKET:
        return cfg->packet;
    default:
        return cfg->fault;
    }
}

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

c1224_state_t status_get(void)
{
    return g_state;
}

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

void status_tick(void)
{
    if (g_state == C1224_STATE_FAULT || g_state == C1224_STATE_STARTING) {
        display_update();
        return;
    }

    c1224_state_t next;
    if (ptt_get()) {
        next = C1224_STATE_SENDING;
    } else if (sense_packet_active()) {
        next = C1224_STATE_PACKET;
    } else if (sense_signal_active()) {
        next = C1224_STATE_SIGNAL;
    } else {
        next = C1224_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