Mercurial > ~darius > hgwebdir.cgi > sprink
annotate sprink.c @ 3:e75ecd162da3
Add watering logic ressurected from 2013.
Handles basic "water all regions for X minutes in X minutes time"
Tolerates power failures.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 27 Jan 2015 23:40:01 +1030 |
parents | be930b34fcd3 |
children | 1188042ddc2f |
rev | line source |
---|---|
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 /* |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 * Sprinkler relay control |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 * |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 * Copyright (c) 2009 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 * |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 * modification, are permitted provided that the following conditions |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 * are met: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 * 1. Redistributions of source code must retain the above copyright |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 * notice, this list of conditions and the following disclaimer. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 * notice, this list of conditions and the following disclaimer in the |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 * documentation and/or other materials provided with the distribution. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 * |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 * SUCH DAMAGE. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 #include <avr/io.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 #include <avr/interrupt.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 #include <avr/pgmspace.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 #include <stdio.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 #include <string.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 #include <ctype.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 #include <stdlib.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 #include <util/delay.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 #include <avr/wdt.h> |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 #include "bitstring.h" |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 #include "cons.h" |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 #include "ds1307.h" |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 #include "1wire.h" |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
43 #include "water.h" |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 /* |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 ** Fuse bits should be set as follows |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 ** |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 ** EFUSE - BOD 4.3V -> xxxxx100 -> 0xfc |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 ** HFUSE - SPIEN, EESAVE |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 ** BOOTSZ1/0 -> 11010001 -> 0xd1 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 ** LFUSE - SUT1, CKSEL1 (low XTAL) -> 11011101 -> 0xdd |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 ** |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 ** http://www.engbedded.com/fusecalc/ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 ** |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 ** From Ateml the fuses were.. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 ** EFUSE - 0xff - 11111111 - BOD disabled |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 ** HFUSE - 0x99 - 10011001 - OCD disabled, JTAG enabled, SPI enabled, WDT disabled, |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 ** - EESAVE off, BOOTSZ0/1, BOOTRST off |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 ** LFUSE - 0x62 - 01100010 - CLKDIV8, no CKOUT, long SUT, CKSEL3/2/0 (internal 8Mhz) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 /* |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 * Mirror of the MCUCSR register, taken early during startup. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 uint8_t mcucsr __attribute__((section(".noinit"))); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 void process_cmd(void); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 /* |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 * Read out and reset MCUCSR early during startup. |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 void handle_mcucsr(void) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 __attribute__((section(".init3"))) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 __attribute__((naked)); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 void handle_mcucsr(void) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
76 wdt_disable(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
77 #ifdef MCUSR |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 mcucsr = MCUSR; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
79 MCUSR = 0; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 #else |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 mcucsr = MCUCSR; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 MCUCSR = 0; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 #endif |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 consbuf_t cmd; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
87 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 int |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 main(void) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 /* Disable interrupts while we frob stuff */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
91 cli(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 /* Init UART */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
94 cons_init(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 /* Init TWI etc */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 ds1307_init(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 /* Set up the one wire stuff */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 OWInit(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
102 /* Init water control state machine */ |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
103 water_init(); |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
104 |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 /* Analogue input is PA0:7 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 DDRA = 0x00; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
107 PORTA = 0x00; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
108 DIDR0 = 0xff; /* Disable digital input buffers */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
109 #ifdef PRR |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
110 PRR &= ~_BV(PRADC); /* Power ADC on - note that the |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 * datasheet says this is already 0 at |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 * power on.. */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 #endif |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
115 /* PB0 Used for 1-wire bus |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 * PB4:7 Used for relay board */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 DDRB = 0xf0; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 PORTB = 0x00; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 /* TWI (0:1) */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 DDRC = 0x03; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
122 PORTC = 0x03; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
123 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 /* USART (0:1) */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 DDRD = 0x03; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 PORTD = 0x03; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 printf_P(PSTR("\r\n\r\n===============\r\n" |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
129 "Inited!\r\n\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 if ((mcucsr & _BV(PORF)) == _BV(PORF)) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
132 printf_P(PSTR("Power on\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 if ((mcucsr & _BV(EXTRF)) == _BV(EXTRF)) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 printf_P(PSTR("External\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
137 if ((mcucsr & _BV(BORF)) == _BV(BORF)) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
138 printf_P(PSTR("Brown-out\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
140 if ((mcucsr & _BV(WDRF)) == _BV(WDRF)) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
141 printf_P(PSTR("Watchdog\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
142 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
143 #ifdef JTRF |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
144 if ((mcucsr & _BV(JTRF)) == _BV(JTRF)) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
145 printf_P(PSTR("JTAG\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
146 #endif |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
147 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
148 /* Ready to go! */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
149 sei(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
150 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
151 /* |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
152 * Enable the watchdog with the largest prescaler. Will cause a |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
153 * watchdog reset after approximately 2 s @ Vcc = 5 V |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
154 * |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
155 * Gets reset in the loop below and in the tempctrl.c timer IRQ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
156 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
157 wdt_enable(WDTO_2S); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
158 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
159 printf_P(PSTR("> ")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
160 cmd.state = 0; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
161 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 /* Wait for user input or an "interrupt" */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 while (1) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
164 wdt_reset(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
165 |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
166 water_update(); |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
167 |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
168 if (cmd.state == 255) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
169 process_cmd(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
170 printf_P(PSTR("> ")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
171 /* Allow new characters to be processed */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
172 cmd.state = 0; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
173 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
174 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
175 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
176 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
177 void |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
178 process_cmd(void) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
179 /* User just pressed enter */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
180 if (cmd.len == 0) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
181 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
182 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
183 if (!strcasecmp_P((char *)cmd.buf, PSTR("?")) || |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
184 !strcasecmp_P((char *)cmd.buf, PSTR("help"))) { |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
185 puts_P(PSTR("help This help\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
186 "wa dly time Water for time minutes after dly minutes\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
187 "gc Get time of day\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
188 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
189 "in port Read from a port\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
190 "ou port val Write to a port (val in hex)\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
191 "dd port val Set DDR on port\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
192 "an pin Sample from pin\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
193 "sr Search for 1-wire devices\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
194 "te ID Sample temperature from ID\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
195 "re Reset 1-wire bus\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
196 "rb Read bit from 1-wire bus\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
197 "rc Read byte from 1-wire bus\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
198 "wb bit Write bit to 1-wire bus\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
199 "wc byte Write byte to 1-wire bus\r\n" |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
200 "zz Reset micro\r\n")); |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
201 return; |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
202 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wa"), 2)) { |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
203 water_cmd((char *)cmd.buf); |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
204 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) { |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
205 ds1307_printnow(PSTR(""), PSTR("\r\n")); |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
206 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
207 if (cmd.len < 17) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
208 printf_P(PSTR("Invalid TOD\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
209 } else { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
210 if (ds1307_settod((char *)cmd.buf + 3) != 1) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
211 printf_P(PSTR("Unable to set TOD\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
212 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
213 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("in"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
214 uint8_t inp; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
215 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
216 switch (tolower(cmd.buf[3])) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
217 case 'a': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
218 inp = PINA; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
219 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
220 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
221 case 'b': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
222 inp = PINB; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
223 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
224 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
225 case 'c': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
226 inp = PINC; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
227 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
228 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 case 'd': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 inp = PIND; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
231 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
232 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
233 default: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
234 printf_P(PSTR("Unknown port\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
235 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
236 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
237 printf_P(PSTR("PORT %c <= 0x%02x\r\n"), toupper(cmd.buf[3]), inp); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
238 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("an"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
239 uint16_t res; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
240 int pin; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
241 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
242 if (sscanf_P((char *)cmd.buf, PSTR("an %d"), &pin) != 1) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
243 printf_P(PSTR("Unable to parse\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
244 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
246 if (pin < 0 || pin > 7) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
247 printf_P(PSTR("Unknown pin\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
248 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 |
1
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
251 /* Select desired pin, use AVREF */ |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
252 ADMUX = _BV(pin); |
be930b34fcd3
Make it compile, no testing yet.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
253 |
0
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
254 /* Enable ADC, start conversion, set divisor to 64 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
255 * (8e6 / 64 => 125kHz (max is 200kHz) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
256 */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADPS2) | _BV(ADPS1); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
259 /* Spin waiting for result */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
260 while ((ADCSRA & _BV(ADIF)) == 0) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
261 ; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
262 res = ADCL | (ADCH << 8); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
263 printf_P(PSTR("Pin %d <= %hhd\r\n"), pin, res); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
264 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
265 /* Disable ADC */ |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
266 ADCSRA = 0; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
267 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("ou"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
268 char port; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
269 int val; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
270 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
271 if (sscanf_P((char *)cmd.buf, PSTR("ou %c %x"), &port, &val) != 2) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
272 printf_P(PSTR("Unable to parse\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
273 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
274 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
275 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
276 switch (port) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
277 case 'a': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
278 PORTA = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
279 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
280 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
281 case 'b': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
282 PORTB = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
283 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
284 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
285 case 'c': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
286 PORTC = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
287 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
288 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
289 case 'd': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
290 PORTD = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
291 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
292 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
293 default: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
294 printf_P(PSTR("Unknown port\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
295 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
296 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
297 printf_P(PSTR("PORT%c <= 0x%02x\r\n"), toupper(port), val); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
298 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("dd"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
299 char port; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
300 uint8_t val; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
301 int num; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
302 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
303 num = sscanf_P((char *)cmd.buf, PSTR("dd %c %x"), &port, &val); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
304 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
305 if (num != 1 && num != 2) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
306 printf_P(PSTR("Unable to parse dd arguments\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
307 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
308 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
309 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
310 if (num == 1) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
311 switch (port) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
312 case 'a': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
313 DDRA = val; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
314 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
315 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
316 case 'b': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
317 DDRB = val; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
318 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
319 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
320 case 'c': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
321 DDRC = val; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
322 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
323 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
324 case 'd': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
325 DDRD = val; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
326 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
327 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
328 default: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
329 printf_P(PSTR("Unknown port\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
330 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
331 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
332 printf_P(PSTR("DDR%c => 0x%02x\r\n"), toupper(port), val); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
333 } else { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
334 switch (port) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
335 case 'a': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
336 DDRA = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
337 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
338 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
339 case 'b': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
340 DDRB = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
341 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
342 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
343 case 'c': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
344 DDRC = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
345 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
346 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
347 case 'd': |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
348 DDRD = val & 0xff; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
349 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
350 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
351 default: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
352 printf_P(PSTR("Unknown port\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
353 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
354 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
355 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(port), val); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
356 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
357 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
358 cli(); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
359 wdt_enable(WDTO_15MS); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
360 for (;;) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
361 ; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
362 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sr"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
363 uint8_t ROM[8]; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
364 int8_t i; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
365 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
366 memset(ROM, 0, 8); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
367 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
368 i = OWFirst(ROM, 1, 0); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
369 do { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
370 switch (i) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
371 case OW_NOMODULES: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
372 case OW_FOUND: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
373 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
374 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
375 case OW_BADWIRE: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
376 case OW_NOPRESENCE: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
377 case OW_BADCRC: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
378 default: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
379 printf_P(PSTR("Err %d\r\n"), i); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
380 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
381 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
382 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
383 if (i != OW_FOUND) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
384 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
385 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
386 for (i = 0; i < 8; i++) |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
387 printf_P(PSTR("%02x%S"), ROM[i], i == 7 ? PSTR("\r\n") : PSTR(":")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
388 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
389 i = OWNext(ROM, 1, 0); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
390 } while (1); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
391 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("te"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
392 uint8_t ROM[8]; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
393 int16_t t; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
394 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
395 if (sscanf_P((char *)cmd.buf, PSTR("te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
396 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
397 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
398 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
399 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
400 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
401 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
402 t = OWGetTemp(ROM); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
403 switch (t) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
404 case OW_TEMP_WRONG_FAM: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
405 printf_P(PSTR("ROM specified isn't a temperature sensor\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
406 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
407 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
408 case OW_TEMP_CRC_ERR: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
409 printf_P(PSTR("CRC mismatch\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
410 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
411 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
412 case OW_TEMP_NO_ROM: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
413 printf_P(PSTR("No ROM found\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
414 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
415 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
416 default: |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
417 printf_P(PSTR("%d.%02d\r\n"), GETWHOLE(t), GETFRAC(t)); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
418 break; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
419 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
420 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("re"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
421 printf_P(PSTR("Reset = %d\r\n"), OWTouchReset()); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
422 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rb"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
423 printf_P(PSTR("Read %d\r\n"), OWReadBit()); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
424 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rc"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
425 printf_P(PSTR("Read 0x%02x\r\n"), OWReadByte()); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
426 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wb"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
427 uint8_t d; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
428 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
429 if (sscanf_P((char *)cmd.buf, PSTR("wb %hhu"), &d) != 1) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
430 printf_P(PSTR("Can't parse bit\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
431 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
432 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
433 OWWriteBit(d); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
434 printf_P(PSTR("Wrote %d\r\n"), d); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
435 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wc"), 2)) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
436 uint8_t d; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
437 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
438 if (sscanf_P((char *)cmd.buf, PSTR("wc %hhx"), &d) != 1) { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
439 printf_P(PSTR("Can't parse byte\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
440 return; |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
441 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
442 |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
443 OWWriteByte(d); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
444 printf_P(PSTR("Wrote 0x%02x\r\n"), d); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
445 } else { |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
446 printf_P(PSTR("Unknown command, help for a list\r\n")); |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
447 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
448 } |
93d4ddff7dd0
Jumbo commit since I appear to have forgotten to do this before..
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
449 |