-
Notifications
You must be signed in to change notification settings - Fork 7
/
moat_console.c
94 lines (84 loc) · 1.89 KB
/
moat_console.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
/*
* 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 the console buffer via 1wire.
*/
#include "moat_internal.h"
#include "dev_data.h"
#include "debug.h"
#include "onewire.h"
#include "console.h"
#ifdef N_CONSOLE
static uint8_t sent;
uint8_t read_console_len(uint8_t chan)
{
uint8_t len;
len = console_buf_len();
if(chan == 1) {
if (len>MAXBUF)
len=MAXBUF;
} else if (!chan) {
if (len) len = 2;
else len = 0;
} else
next_idle('W');
sent = len;
return len;
}
void read_console(uint8_t chan, uint8_t *buf)
{
if (chan) {
if (chan != 1)
next_idle('W');
console_buf_read(buf,sent);
} else { // list of channels and their length
uint8_t len = console_buf_len();
buf[0] = 1;
buf[1] = len;
}
}
void read_console_done(uint8_t chan)
{
if (chan)
console_buf_done(sent);
}
char alert_console_check()
{
return console_alert();
}
void alert_console_fill(uint8_t *buf)
{
if(console_alert())
buf[0]=1;
}
#ifdef CONSOLE_WRITE
void write_console_check(uint8_t chan, uint8_t *buf, uint8_t len)
{
if (chan != 1)
next_idle('w');
if ((len==0) || (len>MAXBUF))
next_idle('u');
}
void write_console(uint8_t chan, uint8_t *buf, uint8_t len)
{
buf[len] = 0;
#if CONSOLE_WRITE>1
if(len==1 && buf[0]=='?') {
console_puts_P("Hello.");
} else
#endif
DBG_S((char *)buf);
}
#endif // console_write
#endif