Mercurial > ~darius > hgwebdir.cgi > tempctrl
annotate main.c @ 73:56165caf744b
Missed some USB related crud + copyright updates.
author | darius@Inchoate |
---|---|
date | Wed, 21 Jan 2009 18:01:17 +1030 |
parents | 13f8e6eb5c01 |
children |
rev | line source |
---|---|
0 | 1 /* |
73
56165caf744b
Missed some USB related crud + copyright updates.
darius@Inchoate
parents:
72
diff
changeset
|
2 * Monitor fermenter temperature and control it by switching cooler & heater. |
9
7ed10c59ba06
Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents:
7
diff
changeset
|
3 * |
73
56165caf744b
Missed some USB related crud + copyright updates.
darius@Inchoate
parents:
72
diff
changeset
|
4 * Copyright (c) 2009 |
0 | 5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
6 * | |
7 * Redistribution and use in source and binary forms, with or without | |
8 * modification, are permitted provided that the following conditions | |
9 * are met: | |
10 * 1. Redistributions of source code must retain the above copyright | |
11 * notice, this list of conditions and the following disclaimer. | |
12 * 2. Redistributions in binary form must reproduce the above copyright | |
13 * notice, this list of conditions and the following disclaimer in the | |
14 * documentation and/or other materials provided with the distribution. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 * SUCH DAMAGE. | |
27 */ | |
28 | |
29 #include <avr/io.h> | |
30 #include <avr/interrupt.h> | |
31 #include <avr/pgmspace.h> | |
41 | 32 #include <stdio.h> |
0 | 33 #include <string.h> |
4 | 34 #include <ctype.h> |
13 | 35 #include <stdlib.h> |
24 | 36 #include <util/delay.h> |
47 | 37 #include <avr/wdt.h> |
0 | 38 |
41 | 39 #include "cons.h" |
0 | 40 #include "1wire.h" |
41 | 41 #include "tempctrl.h" |
60
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
42 #include "ds1307.h" |
24 | 43 |
47 | 44 /* |
45 * Mirror of the MCUCSR register, taken early during startup. | |
46 */ | |
47 uint8_t mcucsr __attribute__((section(".noinit"))); | |
48 | |
24 | 49 void process_cmd(void); |
0 | 50 |
47 | 51 /* |
52 * Read out and reset MCUCSR early during startup. | |
53 */ | |
54 void handle_mcucsr(void) | |
55 __attribute__((section(".init3"))) | |
56 __attribute__((naked)); | |
57 void handle_mcucsr(void) { | |
53
98b5a43fc748
Disable WDT in reset just in case we take too long (eg after reset when the
darius@Inchoate
parents:
52
diff
changeset
|
58 wdt_disable(); |
47 | 59 mcucsr = MCUCSR; |
60 MCUCSR = 0; | |
61 } | |
62 | |
24 | 63 int |
64 main(void) { | |
65 /* Disable interrupts while we frob stuff */ | |
66 cli(); | |
67 | |
41 | 68 #if 0 |
24 | 69 /* Disable JTAG (yes twice) */ |
70 MCUCSR |= _BV(JTD); | |
71 MCUCSR |= _BV(JTD); | |
37 | 72 #endif |
73 | |
74 DDRA = 0xff; | |
75 PORTA = 0x00; | |
54
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
76 |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
77 DDRB = 0x00; |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
78 PORTB = 0x00; |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
79 |
24 | 80 /* GPIO (0:7) */ |
81 DDRC = 0xff; | |
82 PORTC = 0x00; | |
83 | |
37 | 84 /* USART (0:1), IDBus (2:5), 485 (6:6), GPIO (7:7) */ |
85 DDRD = 0xf7; | |
86 PORTD = 0xf7; | |
87 | |
54
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
88 /* Beep |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
89 * |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
90 * Fpwm = Fclk / (N * 510) |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
91 * = 16e6 / (8 * 510) |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
92 * = 3921Hz |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
93 * |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
94 * Behind ifndef because PB3 is A0 on PDI chip |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
95 * |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
96 * Phase correct PWM, non-inverted output, divide by 8 */ |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
97 TCCR0 = _BV(WGM00) | _BV(WGM11) | _BV(COM00) | _BV(COM01) | _BV(CS01); |
56 | 98 OCR0 = 128; |
54
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
99 |
37 | 100 /* Set up the one wire stuff */ |
101 OWInit(); | |
24 | 102 |
60
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
103 /* Setup IIC */ |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
104 ds1307_init(); |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
105 |
24 | 106 /* Init UART */ |
41 | 107 cons_init(); |
24 | 108 |
60
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
109 /* Init temperature control stuff */ |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
110 tempctrl_init(); |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
111 |
41 | 112 printf_P(PSTR("\r\n\r\n===============\r\n" |
113 "Inited!\r\n\r\n")); | |
24 | 114 |
47 | 115 if ((mcucsr & _BV(PORF)) == _BV(PORF)) |
116 printf_P(PSTR("Power on reset\r\n")); | |
117 | |
118 if ((mcucsr & _BV(EXTRF)) == _BV(EXTRF)) | |
119 printf_P(PSTR("External reset\r\n")); | |
120 | |
121 if ((mcucsr & _BV(BORF)) == _BV(BORF)) | |
122 printf_P(PSTR("Brown-out reset\r\n")); | |
123 | |
124 if ((mcucsr & _BV(WDRF)) == _BV(WDRF)) | |
125 printf_P(PSTR("Watchdog reset\r\n")); | |
126 | |
127 if ((mcucsr & _BV(JTRF)) == _BV(JTRF)) | |
128 printf_P(PSTR("JTAG reset\r\n")); | |
129 | |
24 | 130 /* Ready to go! */ |
131 sei(); | |
132 | |
47 | 133 /* |
134 * Enable the watchdog with the largest prescaler. Will cause a | |
135 * watchdog reset after approximately 2 s @ Vcc = 5 V | |
136 * | |
137 * Gets reset in the loop below and in the tempctrl.c timer IRQ | |
138 */ | |
139 wdt_enable(WDTO_2S); | |
140 | |
41 | 141 printf_P(PSTR("> ")); |
24 | 142 cmd.state = 0; |
143 | |
144 /* Wait for user input or an "interrupt" */ | |
145 while (1) { | |
47 | 146 wdt_reset(); |
147 | |
41 | 148 tempctrl_update(); |
149 | |
24 | 150 if (cmd.state == 255) { |
151 process_cmd(); | |
41 | 152 printf_P(PSTR("> ")); |
24 | 153 /* Allow new characters to be processed */ |
154 cmd.state = 0; | |
155 } | |
156 } | |
157 } | |
158 | |
159 void | |
160 process_cmd(void) { | |
52
3217e93b28a3
Missed variable declaration changes from previous commit.
darius@Inchoate
parents:
51
diff
changeset
|
161 uint8_t ROM[8], crc, buf[9], temp; |
24 | 162 int8_t i, arg; |
52
3217e93b28a3
Missed variable declaration changes from previous commit.
darius@Inchoate
parents:
51
diff
changeset
|
163 int16_t t; |
0 | 164 |
24 | 165 /* User just pressed enter */ |
166 if (cmd.len == 0) | |
167 return; | |
168 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
169 if (!strcasecmp_P((char *)cmd.buf, PSTR("?")) || |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
170 !strcasecmp_P((char *)cmd.buf, PSTR("help"))) { |
41 | 171 printf_P(PSTR("rs Reset and check for presence\r\n" |
172 "sr Search the bus for ROMs\r\n" | |
173 "re Read a bit\r\n" | |
174 "rb Read a byte\r\n" | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
175 "wr bit Write a bit\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
176 "wb byte Write a byte (hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
177 "wc cmd [ROMID] Write command\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
178 "te ROMID Read the temperature from a DS1820\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
179 "in port Read from a port\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
180 "ou port val Write to a port (val in hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
181 "dd port [val] Read/write DDR for a port (val in hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
182 "rt ROMID Read DS2502 status page\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
183 "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
184 "rr ROMID Read DS2502 PROM\r\n" |
65 | 185 "zz Reset MCU\r\n" |
60
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
186 "gc Get time of day\r\n" |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
187 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n" |
63 | 188 "tc ... Temperature control related (tc help for more)\r\n")); |
41 | 189 |
24 | 190 return; |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
191 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
192 cli(); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
193 wdt_enable(WDTO_15MS); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
194 for (;;) |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
195 ; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
196 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rs"), 2)) { |
41 | 197 printf_P(PSTR("Resetting... ")); |
4 | 198 |
24 | 199 if (OWTouchReset() == 1) |
41 | 200 printf_P(PSTR("No presence pulse found\r\n")); |
24 | 201 else |
41 | 202 printf_P(PSTR("Presence pulse found\r\n")); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
203 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("re"), 2)) { |
24 | 204 if (OWReadBit()) |
41 | 205 printf_P(PSTR("Read a 1\r\n")); |
24 | 206 else |
41 | 207 printf_P(PSTR("Read a 0\r\n")); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
208 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rb"), 2)) { |
41 | 209 printf_P(PSTR("Read a 0x%02x\r\n"), OWReadByte()); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
210 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wr"), 2)) { |
24 | 211 arg = strtol((char *)cmd.buf + 3, (char **)NULL, 10); |
212 OWWriteBit(arg); | |
41 | 213 printf_P(PSTR("Wrote a %c\r\n"), arg ? '1' : '0'); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
214 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wb"), 2)) { |
24 | 215 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16); |
216 OWWriteByte(arg); | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
217 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rt"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
218 if (sscanf_P((char *)cmd.buf, PSTR("rt %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
219 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
220 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
41 | 221 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
37 | 222 return; |
223 } | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
224 |
37 | 225 if (ROM[0] != OW_FAMILY_ROM) { |
41 | 226 printf_P(PSTR("ROM specified isn't a DS2502\r\n")); |
37 | 227 return; |
228 } | |
229 | |
230 if (OWTouchReset() != 0) { | |
41 | 231 printf_P(PSTR("No presence\r\n")); |
37 | 232 return; |
233 } | |
234 | |
235 crc = 0; | |
236 | |
237 OWCRC(OW_READ_STATUS, &crc); | |
238 OWSendCmd(ROM, OW_READ_STATUS); | |
239 | |
240 OWWriteByte(0x00); | |
241 OWCRC(0x00, &crc); | |
242 | |
243 OWWriteByte(0x00); | |
244 OWCRC(0x00, &crc); | |
245 | |
246 if (crc != OWReadByte()) { | |
41 | 247 printf_P(PSTR("CRC mismatch on command & address\r\n")); |
37 | 248 return; |
249 } | |
250 | |
251 crc = 0; | |
252 for (i = 0; i < 8; i++) { | |
253 temp = OWReadByte(); | |
41 | 254 printf_P(PSTR("%02x "), temp); |
37 | 255 OWCRC(temp, &crc); |
256 } | |
41 | 257 printf_P(PSTR("\r\n")); |
37 | 258 if (crc != OWReadByte()) { |
41 | 259 printf_P(PSTR("CRC mismatch on data\r\n")); |
37 | 260 return; |
261 } | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
262 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("we"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
263 uint8_t adr, data; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
264 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
265 if (sscanf_P((char *)cmd.buf, PSTR("we %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhx %hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
266 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
267 &ROM[4], &ROM[5], &ROM[6], &ROM[7], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
268 &adr, &data) != 10) { |
41 | 269 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
37 | 270 return; |
271 } | |
272 | |
273 if (ROM[0] != OW_FAMILY_ROM) { | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
274 printf_P(PSTR("ID specified isn't a ROM\r\n")); |
37 | 275 return; |
276 } | |
277 | |
278 if (OWTouchReset() != 0) { | |
41 | 279 printf_P(PSTR("No presence\r\n")); |
37 | 280 return; |
281 } | |
282 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
283 printf_P(PSTR("OWProgROM returned %S\r\n"), OWProgROM_Status[OWProgROM(ROM, buf[0], 2, &buf[1], 0, 0)]); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
284 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rr"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
285 if (sscanf_P((char *)cmd.buf, PSTR("rr %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
286 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
287 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
41 | 288 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
37 | 289 return; |
290 } | |
291 | |
292 if (ROM[0] != OW_FAMILY_ROM) { | |
41 | 293 printf_P(PSTR("ROM specified isn't a ROM\r\n")); |
37 | 294 return; |
295 } | |
296 | |
297 crc = 0; | |
298 OWSendCmd(ROM, OW_READ_MEMORY); | |
299 OWCRC(OW_READ_MEMORY, &crc); | |
300 | |
301 OWWriteByte(0x00); | |
302 OWCRC(0x00, &crc); | |
303 | |
304 OWWriteByte(0x00); | |
305 OWCRC(0x00, &crc); | |
306 | |
307 if (crc != OWReadByte()) { | |
41 | 308 printf_P(PSTR("CRC mismatch on command & address\r\n")); |
37 | 309 return; |
310 } | |
311 | |
312 crc = 0; | |
313 for (buf[0] = 0; buf[0] < 128; buf[0]++) { | |
314 buf[1] = OWReadByte(); | |
315 if (buf[0] > 0) { | |
316 if (buf[0] % 16 != 0) | |
41 | 317 printf_P(PSTR(" ")); |
37 | 318 else |
41 | 319 printf_P(PSTR("\r\n")); |
37 | 320 } |
321 | |
41 | 322 printf_P(PSTR("%02x"), buf[1]); |
37 | 323 OWCRC(buf[1], &crc); |
324 } | |
41 | 325 printf_P(PSTR("\r\n")); |
37 | 326 if (crc != OWReadByte()) { |
41 | 327 printf_P(PSTR("CRC mismatch on data\r\n")); |
37 | 328 return; |
329 } | |
330 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
331 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wc"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
332 uint8_t c; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
333 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
334 i = sscanf_P((char *)cmd.buf, PSTR("wc %hhx %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
335 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
336 &ROM[4], &ROM[5], &ROM[6], &ROM[7], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
337 &c); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
338 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
339 if (i != 1 && i != 9) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
340 printf_P(PSTR("Incorrect usage\r\n")); |
24 | 341 return; |
342 } | |
343 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
344 if (i == 1) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
345 OWSendCmd(i == 1 ? NULL : ROM, c); |
24 | 346 return; |
347 } | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
348 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("te"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
349 if (sscanf_P((char *)cmd.buf, PSTR("te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
350 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
351 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
41 | 352 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
24 | 353 return; |
354 } | |
355 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
356 t = OWGetTemp(ROM); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
357 switch (t) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
358 case OW_TEMP_WRONG_FAM: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
359 printf_P(PSTR("ROM specified isn't a temperature sensor\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
360 break; |
24 | 361 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
362 case OW_TEMP_CRC_ERR: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
363 printf_P(PSTR("CRC mismatch\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
364 break; |
41 | 365 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
366 case OW_TEMP_NO_ROM: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
367 printf_P(PSTR("No ROM found\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
368 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
369 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
370 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
371 printf_P(PSTR("%d.%02d\r\n"), GETWHOLE(t), GETFRAC(t)); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
372 break; |
24 | 373 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
374 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sr"), 2)) { |
24 | 375 memset(ROM, 0, 8); |
10 | 376 |
24 | 377 i = OWFirst(ROM, 1, 0); |
378 do { | |
379 switch (i) { | |
10 | 380 case OW_BADWIRE: |
41 | 381 printf_P(PSTR("Presence pulse, but no module found, bad module/cabling?\r\n")); |
10 | 382 break; |
383 | |
384 case OW_NOPRESENCE: | |
41 | 385 printf_P(PSTR("No presence pulse found\r\n")); |
10 | 386 break; |
387 | |
388 case OW_BADCRC: | |
41 | 389 printf_P(PSTR("Bad CRC\r\n")); |
10 | 390 break; |
391 | |
392 case OW_NOMODULES: | |
393 case OW_FOUND: | |
394 break; | |
395 | |
396 default: | |
41 | 397 printf_P(PSTR("Unknown error from 1 wire library\r\n")); |
10 | 398 break; |
24 | 399 } |
10 | 400 |
24 | 401 if (i != OW_FOUND) |
402 break; | |
13 | 403 |
41 | 404 for (i = 0; i < 8; i++) |
405 printf_P(PSTR("%02x%S"), ROM[i], i == 7 ? PSTR("\r\n") : PSTR(":")); | |
10 | 406 |
24 | 407 i = OWNext(ROM, 1, 0); |
408 } while (1); | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
409 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("in"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
410 uint8_t inp; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
411 |
24 | 412 switch (tolower(cmd.buf[3])) { |
413 case 'a': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
414 inp = PINA; |
24 | 415 break; |
416 | |
417 case 'b': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
418 inp = PINB; |
24 | 419 break; |
420 | |
421 case 'c': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
422 inp = PINC; |
24 | 423 break; |
424 | |
425 case 'd': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
426 inp = PIND; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
427 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
428 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
429 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
430 printf_P(PSTR("Unknown port\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
431 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
432 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
433 printf_P(PSTR("0x%02x\r\n"), inp); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
434 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("ou"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
435 char port; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
436 int val; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
437 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
438 if (sscanf_P((char *)cmd.buf, PSTR("ou %c %x"), &port, &val) != 2) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
439 printf_P(PSTR("Unable to parse ou arguments\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
440 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
441 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
442 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
443 switch (port) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
444 case 'a': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
445 PORTA = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
446 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
447 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
448 case 'b': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
449 PORTB = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
450 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
451 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
452 case 'c': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
453 PORTC = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
454 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
455 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
456 case 'd': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
457 PORTD = val & 0xff; |
24 | 458 break; |
459 | |
460 default: | |
41 | 461 printf_P(PSTR("Unknown port\r\n")); |
24 | 462 return; |
0 | 463 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
464 printf_P(PSTR("PORT%c <= 0x%02x\r\n"), toupper(port), val); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
465 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("dd"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
466 char port; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
467 uint8_t val; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
468 int num; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
469 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
470 num = sscanf_P((char *)cmd.buf, PSTR("dd %c %x"), &port, &val); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
471 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
472 if (num != 2 && num != 3) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
473 printf_P(PSTR("Unable to parse dd arguments\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
474 return; |
24 | 475 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
476 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
477 if (num == 2) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
478 switch (port) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
479 case 'a': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
480 val = DDRA; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
481 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
482 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
483 case 'b': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
484 val = DDRB; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
485 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
486 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
487 case 'c': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
488 val = DDRC; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
489 break; |
63 | 490 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
491 case 'd': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
492 val = DDRD; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
493 break; |
37 | 494 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
495 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
496 printf_P(PSTR("Unknown port\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
497 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
498 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
499 printf_P(PSTR("DDR%c => 0x%02x\r\n"), toupper(port), val); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
500 } else { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
501 switch (port) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
502 case 'a': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
503 DDRA = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
504 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
505 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
506 case 'b': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
507 DDRB = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
508 break; |
37 | 509 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
510 case 'c': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
511 DDRC = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
512 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
513 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
514 case 'd': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
515 DDRD = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
516 break; |
37 | 517 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
518 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
519 printf_P(PSTR("Unknown port\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
520 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
521 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
522 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(port), val); |
37 | 523 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
524 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("tc"), 2)) { |
41 | 525 tempctrl_cmd((char *)cmd.buf); |
60
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
526 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) { |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
527 ds1307_printtime(PSTR(""), PSTR("\r\n")); |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
528 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) { |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
529 if (cmd.len < 17) { |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
530 printf_P(PSTR("Command not long enough\r\n")); |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
531 } else { |
63 | 532 if (ds1307_settod((char *)cmd.buf + 3) != 1) |
60
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
533 printf_P(PSTR("Unable to set time of day\r\n")); |
50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
darius@Inchoate
parents:
56
diff
changeset
|
534 } |
24 | 535 } else { |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
536 printf_P(PSTR("Unknown command, help for a list\r\n")); |
0 | 537 } |
24 | 538 } |
0 | 539 |