Permalink
Browse files

Change "temperatureDS1820Value" to be single fixed-point 2 decimal pl…

…ace.
  • Loading branch information...
1 parent 1388f64 commit 9f479e1c29319efc42c3f03a3eb77868642d7a50 @geekscape committed Jun 14, 2012
Showing with 5 additions and 8 deletions.
  1. +4 −6 aiko_devices/AikoDeviceTemperatureDS1820.cpp
  2. +1 −2 aiko_devices/AikoDeviceTemperatureDS1820.h
@@ -10,8 +10,7 @@ static const byte ONE_WIRE_DEVICE_18S20 = 0x10;
byte temperatureDS1820Initialized = false;
byte temperatureDS1820Ready = false;
-byte temperatureDS1820Whole = 0;
-byte temperatureDS1820Fraction = 0;
+int temperatureDS1820Value = 0; // fixed-point with 2 decimal places
byte address[8];
#endif
@@ -61,11 +60,10 @@ void temperatureDS1820Handler(void) { // total time: 19 or 33 milliseconds
int signBit = temperature & 0x8000;
if (signBit) temperature = (temperature ^ 0xffff) + 1; // 2's complement
- int tc_100 = (6 * temperature) + temperature / 4; // multiply by 100 * 0.0625
+ temperatureDS1820Value = (6 * temperature) + temperature / 4;
+ // multiply by 100 * 0.0625
- temperatureDS1820Whole = tc_100 / 100;
- temperatureDS1820Fraction = tc_100 % 100;
- if (signBit) temperatureDS1820Whole = - temperatureDS1820Whole;
+ if (signBit) temperatureDS1820Value = - temperatureDS1820Value;
temperatureDS1820Ready = true;
}
@@ -6,8 +6,7 @@
extern byte temperatureDS1820Ready;
-extern byte temperatureDS1820Whole;
-extern byte temperatureDS1820Fraction;
+extern int temperatureDS1820Value; // fixed-point with 2 decimal places
void temperatureDS1820Handler(void);

0 comments on commit 9f479e1

Please sign in to comment.