forked from M-o-a-T/owslave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moat_status.c
100 lines (86 loc) · 1.92 KB
/
moat_status.c
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright © 2014-2015, Matthias Urlichs <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License (included; see the file LICENSE)
* for more details.
*/
/* This code implements reading port pins via 1wire.
*/
#include <string.h> // memset
#include "moat_internal.h"
#include "dev_data.h"
#include "debug.h"
#include "onewire.h"
#include "status.h"
#include "timer.h"
#include "_status.h"
#ifdef N_STATUS
#if N_STATUS>1 && defined(IS_BOOTLOADER)
static const char buildv[] __attribute__ ((progmem)) = BUILDVER;
#endif
uint8_t read_status_len(uint8_t chan)
{
switch (chan) {
case 0:
return 1;
case S_reboot:
return 1;
#if N_STATUS>1 && defined(IS_BOOTLOADER)
case S_loader:
return strlen(BUILDVER);
#endif
default:
next_idle('s');
}
}
void read_status(uint8_t chan, uint8_t *buf)
{
switch(chan) {
case 0:
*buf = ((1<<(STATUS_MAX-1))-1)
#if N_STATUS < 2 || !defined(IS_BOOTLOADER)
& ~(1<<(S_loader-1))
#endif
;
break;
case S_reboot:
*buf = status_boot;
#ifdef CONDITIONAL_SEARCH
init_msg &=~ (1<<(S_reboot-1));
#endif
break;
#if N_STATUS>1 && defined(WITH_BOOTLOADER)
case S_loader:
const char *v = buildv;
while ((*buf = pgm_read_byte(v))) {
buf++;
v++;
}
break;
#endif
default:
next_idle('s');
}
}
#ifdef CONDITIONAL_SEARCH
char alert_status_check(void)
{
if (init_msg)
return 1;
return 0;
}
void alert_status_fill(uint8_t *buf)
{
memset(buf,0,(STATUS_MAX+7)>>3);
*buf = init_msg;
}
#endif // conditional
#endif // N_STATUS