aboutsummaryrefslogtreecommitdiff
path: root/misc/temper/temper-1.0.diff
blob: 4f9943aad09a641680730cbeab186c669bbf0b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--- temper-1.0/temper.c	2009-10-17 08:26:46.000000000 +0100
+++ temper-1.0.new/temper.c	2011-02-06 16:49:24.511084503 +0000
@@ -49,7 +49,7 @@
 
 	t = calloc(1, sizeof(*t));
 	t->device = dev;
-	t->debug = debug;
+	t->debug = 0;
 	t->timeout = timeout;
 	t->handle = usb_open(t->device);
 	if(!t->handle) {
@@ -190,7 +190,7 @@
 int
 TemperGetTemperatureInC(Temper *t, float *tempC)
 {
-	char buf[256];
+	unsigned char buf[256];
 	int ret, temperature, i;
 
 	TemperSendCommand(t, 10, 11, 12, 13, 0, 0, 2, 0);
@@ -204,9 +204,7 @@
 		return -1;
 	}
 
-	temperature = (buf[1] & 0xFF) + (buf[0] << 8);	
-	temperature += 1152;			// calibration value
-	*tempC = temperature * (125.0 / 32000.0);
+	*tempC=buf[0]+((float)buf[1])/256;
 	return 0;
 }
 
@@ -253,29 +251,15 @@
 	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
 */
 
-	bzero(buf, 256);
-	ret = TemperGetOtherStuff(t, buf, 256);
-	printf("Other Stuff (%d bytes):\n", ret);
-	for(i = 0; i < ret; i++) {
-		printf(" %02x", buf[i] & 0xFF);
-		if(i % 16 == 15) {
-			printf("\n");
-		}
-	}
-	printf("\n");
-
-	for(;;) {
-		float tempc;
-
-		if(TemperGetTemperatureInC(t, &tempc) < 0) {
-			perror("TemperGetTemperatureInC");
-			exit(1);
-		}
-		printf("temperature %.2fF %.2fC\n", (9.0 / 5.0 * tempc + 32.0),
-		       tempc);
-		sleep(10);
-	}
-	return 0;
+	float tempc;
+
+	if(TemperGetTemperatureInC(t, &tempc) < 0) {
+		perror("TemperGetTemperatureInC");
+		exit(1);
+	}
+	printf("temperature %.2fF %.2fC\n", (9.0 / 5.0 * tempc + 32.0),
+		tempc);
+    fflush(stdout); /* flush the stdout buffer */
 }
 
 #endif