diff main.c @ 13:96c345d304af default tip

Add 1wire code. 1wire.c, 1wire.h and 1wire-config.h are copied avr-lib.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 08 Feb 2012 10:37:22 +1030
parents 093bc0c3b1cc
children
line wrap: on
line diff
--- a/main.c	Mon Feb 06 23:55:53 2012 +1030
+++ b/main.c	Wed Feb 08 10:37:22 2012 +1030
@@ -9,6 +9,7 @@
 
 #include "stm32f10x.h"
 
+#include "1wire.h"
 #include "comm.h"
 #include "delay.h"
 #include "flash.h"
@@ -243,6 +244,72 @@
 		    GPIO_ResetBits(GPIOE, GPIO_Pin_3);
 		    _usleep16(60000);
 		}
+	    } else if (!strncmp("rs", cmd.buf, 2)) {
+		printf("Reset got %d\r\n", OWTouchReset());
+	    } else if (!strncmp("sr", cmd.buf, 2)) {
+		uint8_t	ROM[8];
+		int8_t	i;
+	
+		memset(ROM, 0, 8);
+
+		i = OWFirst(ROM, 1, 0);
+		do {
+		    switch (i) {
+			case OW_NOMODULES:
+			case OW_FOUND:
+			    break;
+		    
+			case OW_BADWIRE:
+			case OW_NOPRESENCE:
+			case OW_BADCRC:
+			default:
+			    printf("Err %d\r\n", i);
+			    break;
+		    }
+		
+		    if (i != OW_FOUND)
+			break;
+
+		    for (i = 0; i < 8; i++)
+			printf("%02x%s", ROM[i], i == 7 ? "\r\n" : ":");
+
+		    i = OWNext(ROM, 1, 0);
+		} while (1);
+	    } else if (!strncmp("rb", cmd.buf, 2)) {
+		printf("Read bit returned %d\r\n", OWReadBit());
+	    } else if (!strncmp("wb ", cmd.buf, 3)) {
+		x = atoi(cmd.buf + 3);
+		OWWriteBit(x);
+		printf("Wrote %d\r\n", x);
+	    } else if (!strncasecmp(cmd.buf, "te ", 3)) {
+		uint8_t	ROM[8];
+		int16_t	res;
+	
+		if (sscanf(cmd.buf, "te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 
+			   &ROM[0], &ROM[1], &ROM[2], &ROM[3],
+			   &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) {
+		    printf("Unable to parse ROM ID\r\n");
+		    goto out;
+		}
+
+		res = OWGetTemp(ROM);
+		switch (res) {
+		    case OW_TEMP_WRONG_FAM:
+			printf("ROM specified isn't a temperature sensor\r\n");
+			break;
+
+		    case OW_TEMP_CRC_ERR:
+			printf("CRC mismatch\r\n");
+			break;
+
+		    case OW_TEMP_NO_ROM:
+			printf("No ROM found\r\n");
+			break;
+
+		    default:
+			printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res));
+			break;
+		}
 	    } else if (!strncmp("zz", cmd.buf, 2)) {
 		NVIC_SystemReset();
 	    } else {