annotate testavr.c @ 43:51e7458d2e76

Init lastdata same as lastheat/coolon/off otherwise we won't handle thing properly early on (ie if now < lastdata/lastheat/coolon/off)
author darius@inchoate.localdomain
date Sun, 06 Jul 2008 22:42:32 +0930
parents 5898fba6593c
children 13a68734348b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
1 /*
9
7ed10c59ba06 Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents: 7
diff changeset
2 * Test various AVR bits and pieces
7ed10c59ba06 Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents: 7
diff changeset
3 *
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
4 * Copyright (c) 2008
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
6 *
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
9 * are met:
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
15 *
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
26 * SUCH DAMAGE.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
27 */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
28
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
29 #include <avr/io.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
30 #include <avr/interrupt.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
31 #include <avr/pgmspace.h>
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
32 #include <stdio.h>
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
33 #include <string.h>
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
34 #include <ctype.h>
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
35 #include <stdlib.h>
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
36 #include <util/delay.h>
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
37
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
38 #include "cons.h"
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
39 #include "1wire.h"
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
40 #ifdef WITHUSB
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
41 #include "usb.h"
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
42 #endif
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
43 #include "tempctrl.h"
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
44
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
45 void process_cmd(void);
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
46
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
47 int
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
48 main(void) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
49 /* Disable interrupts while we frob stuff */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
50 cli();
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
51
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
52 #if 0
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
53 /* Disable JTAG (yes twice) */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
54 MCUCSR |= _BV(JTD);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
55 MCUCSR |= _BV(JTD);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
56 #endif
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
57
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
58 #ifdef WITHUSB
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
59 /* USB data bus (7:0) */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
60 DDRA = 0x00;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
61 PORTA = 0x00;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
62
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
63 /* USB control (4:0) */
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
64 DDRB = 0x0d;
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
65 PORTB = 0x00;
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
66 #else
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
67 DDRA = 0xff;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
68 PORTA = 0x00;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
69 #endif
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
70 /* GPIO (0:7) */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
71 DDRC = 0xff;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
72 PORTC = 0x00;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
73
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
74 /* USART (0:1), IDBus (2:5), 485 (6:6), GPIO (7:7) */
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
75 DDRD = 0xf7;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
76 PORTD = 0xf7;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
77
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
78 /* Set up the one wire stuff */
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
79 OWInit();
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
80
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
81 /* Init UART */
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
82 cons_init();
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
83
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
84 printf_P(PSTR("\r\n\r\n===============\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
85 "Inited!\r\n\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
86
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
87 tempctrl_init();
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
88
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
89 /* Ready to go! */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
90 sei();
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
91
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
92 #if 0
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
93 DDRA = 0xff;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
94 DDRC = 0xff;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
95 while (1) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
96 printf_P(PSTR("1\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
97 PORTA = 0xff;
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
98 printf_P(PSTR("2\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
99 PORTC = 0x00;
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
100 printf_P(PSTR("3\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
101 _delay_us(1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
102 printf_P(PSTR("4\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
103 PORTA = 0x80;
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
104 printf_P(PSTR("5\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
105 PORTC = 0xff;
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
106 printf_P(PSTR("6\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
107 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
108 #endif
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
109
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
110 #ifdef WITHUSB
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
111 printf_P(PSTR("Calling usb_init\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
112 usb_init();
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
113 printf_P(PSTR("done\r\n"));
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
114 _delay_us(1000);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
115 #endif
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
116 printf_P(PSTR("> "));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
117 cmd.state = 0;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
118
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
119 /* Wait for user input or an "interrupt" */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
120 while (1) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
121 tempctrl_update();
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
122
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
123 if (cmd.state == 255) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
124 process_cmd();
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
125 printf_P(PSTR("> "));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
126 /* Allow new characters to be processed */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
127 cmd.state = 0;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
128 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
129
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
130 #ifdef WITHUSB
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
131 if (!(PDICTL & _BV(PDIINT)))
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
132 usb_intr();
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
133 #endif
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
134 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
135 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
136
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
137 void
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
138 process_cmd(void) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
139 uint8_t ROM[8];
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
140 int8_t i, arg;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
141 uint8_t crc, buf[9];
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
142 int8_t temp;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
143 uint16_t tfrac;
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
144
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
145 /* User just pressed enter */
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
146 if (cmd.len == 0)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
147 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
148
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
149 if (cmd.buf[0] == '?') {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
150 printf_P(PSTR("rs Reset and check for presence\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
151 "sr Search the bus for ROMs\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
152 "re Read a bit\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
153 "rb Read a byte\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
154 "wr bit Write a bit\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
155 "wb byte Write a byte (hex)\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
156 "wc cmd [ROMID] Write command\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
157 "te ROMID Read the temperature from a DS1820\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
158 "in port Read from a port\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
159 "out port val Write to a port\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
160 "ddr port [val] Read/write DDR for a port\r\n"
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
161 "tc ... Temperature control related (tc help for more)\r\n"));
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
162
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
163 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
164 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
165
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
166 i = strlen((char *)cmd.buf);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
167 if (cmd.len < 2)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
168 goto badcmd;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
169
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
170 if (cmd.buf[0] == 'r' && cmd.buf[1] == 's') {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
171 printf_P(PSTR("Resetting... "));
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
172
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
173 if (OWTouchReset() == 1)
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
174 printf_P(PSTR("No presence pulse found\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
175 else
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
176 printf_P(PSTR("Presence pulse found\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
177 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'e') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
178 if (OWReadBit())
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
179 printf_P(PSTR("Read a 1\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
180 else
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
181 printf_P(PSTR("Read a 0\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
182 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'b') {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
183 printf_P(PSTR("Read a 0x%02x\r\n"), OWReadByte());
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
184 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'r') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
185 arg = strtol((char *)cmd.buf + 3, (char **)NULL, 10);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
186 OWWriteBit(arg);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
187 printf_P(PSTR("Wrote a %c\r\n"), arg ? '1' : '0');
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
188 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'b') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
189 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
190 OWWriteByte(arg);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
191 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 't') {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
192 if (cmd.len < 26) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
193 printf_P(PSTR("Unable to parse ROM ID\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
194 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
195 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
196
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
197 if (OWTouchReset() != 0) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
198 printf_P(PSTR("No presence\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
199 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
200 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
201
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
202 for (i = 0; i < 8; i++)
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
203 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
204
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
205 if (ROM[0] != OW_FAMILY_ROM) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
206 printf_P(PSTR("ROM specified isn't a DS2502\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
207 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
208 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
209
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
210 if (OWTouchReset() != 0) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
211 printf_P(PSTR("No presence\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
212 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
213 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
214
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
215 crc = 0;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
216
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
217 OWCRC(OW_READ_STATUS, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
218 OWSendCmd(ROM, OW_READ_STATUS);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
219
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
220 OWWriteByte(0x00);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
221 OWCRC(0x00, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
222
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
223 OWWriteByte(0x00);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
224 OWCRC(0x00, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
225
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
226 if (crc != OWReadByte()) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
227 printf_P(PSTR("CRC mismatch on command & address\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
228 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
229 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
230
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
231 crc = 0;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
232 for (i = 0; i < 8; i++) {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
233 temp = OWReadByte();
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
234 printf_P(PSTR("%02x "), temp);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
235 OWCRC(temp, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
236 }
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
237 printf_P(PSTR("\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
238 if (crc != OWReadByte()) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
239 printf_P(PSTR("CRC mismatch on data\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
240 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
241 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
242 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'e') {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
243 if (cmd.len < 26) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
244 printf_P(PSTR("Unable to parse ROM ID\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
245 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
246 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
247
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
248 for (i = 0; i < 8; i++)
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
249 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
250
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
251 if (ROM[0] != OW_FAMILY_ROM) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
252 printf_P(PSTR("ROM specified isn't a ROM\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
253 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
254 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
255
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
256 buf[0] = (int)strtol((char *)cmd.buf + 27, (char **)NULL, 16); /* Address */
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
257 buf[1] = (int)strtol((char *)cmd.buf + 30, (char **)NULL, 16); /* Data .. */
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
258 buf[2] = (int)strtol((char *)cmd.buf + 33, (char **)NULL, 16);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
259
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
260 if (OWTouchReset() != 0) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
261 printf_P(PSTR("No presence\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
262 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
263 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
264
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
265 i = OWProgROM(ROM, buf[0], 2, &buf[1], 0, 0);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
266 printf_P(PSTR("OWProgROM returned %d\r\n"), i);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
267 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'r') {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
268 if (cmd.len < 26) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
269 printf_P(PSTR("Unable to parse ROM ID\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
270 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
271 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
272
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
273 for (i = 0; i < 8; i++)
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
274 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
275
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
276 if (ROM[0] != OW_FAMILY_ROM) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
277 printf_P(PSTR("ROM specified isn't a ROM\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
278 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
279 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
280
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
281 crc = 0;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
282 OWSendCmd(ROM, OW_READ_MEMORY);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
283 OWCRC(OW_READ_MEMORY, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
284
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
285 OWWriteByte(0x00);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
286 OWCRC(0x00, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
287
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
288 OWWriteByte(0x00);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
289 OWCRC(0x00, &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
290
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
291 if (crc != OWReadByte()) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
292 printf_P(PSTR("CRC mismatch on command & address\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
293 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
294 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
295
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
296 crc = 0;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
297 for (buf[0] = 0; buf[0] < 128; buf[0]++) {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
298 buf[1] = OWReadByte();
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
299 if (buf[0] > 0) {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
300 if (buf[0] % 16 != 0)
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
301 printf_P(PSTR(" "));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
302 else
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
303 printf_P(PSTR("\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
304 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
305
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
306 printf_P(PSTR("%02x"), buf[1]);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
307 OWCRC(buf[1], &crc);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
308 }
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
309 printf_P(PSTR("\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
310 if (crc != OWReadByte()) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
311 printf_P(PSTR("CRC mismatch on data\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
312 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
313 }
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
314
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
315 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'c') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
316 if (cmd.len < 5) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
317 printf_P(PSTR("No arguments\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
318 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
319 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
320
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
321 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
322 if (arg == 0) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
323 printf_P(PSTR("Unparseable command\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
324 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
325 }
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
326
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
327 if (i == 5) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
328 OWSendCmd(NULL, arg);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
329 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
330 }
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
331
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
332 if (i < 29) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
333 printf_P(PSTR("Can't parse ROM ID\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
334 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
335 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
336 for (i = 0; i < 8; i++)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
337 ROM[i] = (int)strtol((char *)cmd.buf + 6 + (3 * i), (char **)NULL, 16);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
338
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
339 OWSendCmd(ROM, arg);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
340 } else if (cmd.buf[0] == 't' && cmd.buf[1] == 'e') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
341 if (cmd.len < 26) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
342 printf_P(PSTR("Unable to parse ROM ID\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
343 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
344 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
345
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
346 for (i = 0; i < 8; i++)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
347 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
348
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
349 if (ROM[0] != OW_FAMILY_TEMP) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
350 printf_P(PSTR("ROM specified isn't a temperature sensor\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
351 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
352 }
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
353
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
354 OWSendCmd(ROM, OW_CONVERTT_CMD);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
355 i = 0;
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
356 /* Wait for the conversion */
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
357 while (OWReadBit() == 0)
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
358 i = 1;
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
359
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
360
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
361 OWSendCmd(ROM, OW_RD_SCR_CMD);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
362 crc = 0;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
363 for (i = 0; i < 9; i++) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
364 buf[i] = OWReadByte();
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
365 if (i < 8)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
366 OWCRC(buf[i], &crc);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
367 }
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
368
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
369 if (crc != buf[8]) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
370 printf_P(PSTR("CRC mismatch\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
371 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
372 }
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
373
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
374 /* 0 Temperature LSB
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
375 * 1 Temperature MSB
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
376 * 2 Th
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
377 * 3 Tl
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
378 * 4 Reserved
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
379 * 5 Reserved
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
380 * 6 Count Remain
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
381 * 7 Count per C
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
382 * 8 CRC
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
383 */
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
384 #if 0
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
385 for (i = 0; i < 9; i++)
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
386 printf_P(PSTR("%d\r\n"), buf[i]);
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
387 #endif
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
388 temp = buf[0];
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
389 if (buf[1] & 0x80)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
390 temp -= 256;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
391 temp >>= 1;
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
392
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
393 tfrac = buf[7] - buf[6];
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
394 tfrac *= (uint16_t)100;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
395 tfrac /= buf[7];
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
396 tfrac += 75;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
397 if (tfrac < 100) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
398 temp--;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
399 } else {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
400 tfrac -= 100;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
401 }
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
402
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
403 printf_P(PSTR("%d.%02d\r\n"), temp, tfrac);
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
404 } else if (cmd.buf[0] == 's' && cmd.buf[1] == 'r') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
405 memset(ROM, 0, 8);
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
406
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
407 i = OWFirst(ROM, 1, 0);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
408 do {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
409 switch (i) {
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
410 case OW_BADWIRE:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
411 printf_P(PSTR("Presence pulse, but no module found, bad module/cabling?\r\n"));
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
412 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
413
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
414 case OW_NOPRESENCE:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
415 printf_P(PSTR("No presence pulse found\r\n"));
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
416 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
417
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
418 case OW_BADCRC:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
419 printf_P(PSTR("Bad CRC\r\n"));
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
420 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
421
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
422 case OW_NOMODULES:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
423 case OW_FOUND:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
424 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
425
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
426 default:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
427 printf_P(PSTR("Unknown error from 1 wire library\r\n"));
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
428 break;
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
429 }
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
430
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
431 if (i != OW_FOUND)
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
432 break;
13
2c03ec600dbc Reduce object code size as much as possible.
darius
parents: 11
diff changeset
433
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
434 for (i = 0; i < 8; i++)
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
435 printf_P(PSTR("%02x%S"), ROM[i], i == 7 ? PSTR("\r\n") : PSTR(":"));
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
436
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
437 i = OWNext(ROM, 1, 0);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
438 } while (1);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
439 } else if (cmd.buf[0] == 'i' && cmd.buf[1] == 'n') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
440 switch (tolower(cmd.buf[3])) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
441 case 'a':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
442 crc = PINA;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
443 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
444
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
445 case 'b':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
446 crc = PINB;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
447 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
448
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
449 case 'c':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
450 crc = PINC;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
451 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
452
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
453 case 'd':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
454 crc = PIND;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
455 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
456
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
457 default:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
458 printf_P(PSTR("Unknown port\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
459 return;
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
460 }
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
461 printf_P(PSTR("0x%02x\r\n"), crc);
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
462 } else if (cmd.buf[0] == 'o' && cmd.buf[1] == 'u') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
463 crc = strtol((char *)cmd.buf + 8, (char **)NULL, 16);
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
464 switch (tolower(cmd.buf[4])) {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
465 case 'a':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
466 PORTA = crc;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
467 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
468
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
469 case 'b':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
470 PORTB = crc;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
471 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
472
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
473 case 'c':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
474 PORTC = crc;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
475 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
476
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
477 case 'd':
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
478 PORTD = crc;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
479 break;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
480
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
481 default:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
482 printf_P(PSTR("Unknown port\r\n"));
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
483 return;
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
484 }
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
485 printf_P(PSTR("PORT%c <= 0x%02x\r\n"), toupper(cmd.buf[4]), crc);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
486 } else if (cmd.buf[0] == 'd' && cmd.buf[1] == 'd') {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
487 crc = strtol((char *)cmd.buf + 8, (char **)NULL, 16);
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
488 switch (tolower(cmd.buf[4])) {
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
489 case 'a':
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
490 DDRA = crc;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
491 break;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
492
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
493 case 'b':
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
494 DDRB = crc;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
495 break;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
496
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
497 case 'c':
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
498 DDRC = crc;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
499 break;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
500
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
501 case 'd':
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
502 DDRD = crc;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
503 break;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
504
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
505 default:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
506 printf_P(PSTR("Unknown port\r\n"));
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
507 return;
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
508 }
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
509 printf_P(PSTR("0x%02x\r\n"), crc);
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
510 } else if (cmd.buf[0] == 't' && cmd.buf[1] == 'c') {
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
511 tempctrl_cmd((char *)cmd.buf);
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
512 #ifdef WITHUSB
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
513 } else if (cmd.buf[0] == 'u' && cmd.buf[1] == 's') {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
514 usb_gendata();
37
25fa387ef7e9 - Conditionalise USB support.
darius
parents: 30
diff changeset
515 #endif
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
516 } else {
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
517 badcmd:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 38
diff changeset
518 printf_P(PSTR("Unknown command, ? for a list\r\n"));
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
519 }
24
2b0ed085b95b - Change to 38400 baud.
darius
parents: 18
diff changeset
520 }
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
521
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
522