Skip to content

Commit 40dc700

Browse files
committed
round temperature
1 parent cd817c5 commit 40dc700

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/com/eschava/ht2000/usb/HT2000State.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public class HT2000State {
1313
private static final long TIMESTAMP_SHIFT = 0x77797DA0; // TODO: magic constant
14-
private static final double TEMPERATURE_SHIFT = 11.2; // TODO: magic constant
14+
private static final int TEMPERATURE_SHIFT = 112; // TODO: magic constant
1515

1616
private final Date time;
1717
private final double temperature;
@@ -25,11 +25,19 @@ public HT2000State(ByteBuffer buffer) {
2525
if (timestamp > TIMESTAMP_SHIFT)
2626
timestamp -= TIMESTAMP_SHIFT;
2727
time = new Date(timestamp * 1000);
28-
temperature = TEMPERATURE_SHIFT + /*Byte.*/toUnsignedInt(buffer.get(8)) / 10.0;
28+
temperature = (TEMPERATURE_SHIFT + /*Byte.*/toUnsignedInt(buffer.get(8))) / 10.0;
2929
humidity = buffer.getShort(9) / 10.0;
3030
co2 = buffer.getShort(24);
3131
}
3232

33+
private static long toUnsignedLong(int x) {
34+
return ((long) x) & 0xffffffffL;
35+
}
36+
37+
private static int toUnsignedInt(byte x) {
38+
return ((int) x) & 0xff;
39+
}
40+
3341
public Date getTime() {
3442
return time;
3543
}
@@ -55,12 +63,4 @@ public String toString() {
5563
", CO2=" + co2 +
5664
'}';
5765
}
58-
59-
private static long toUnsignedLong(int x) {
60-
return ((long) x) & 0xffffffffL;
61-
}
62-
63-
private static int toUnsignedInt(byte x) {
64-
return ((int) x) & 0xff;
65-
}
6666
}

0 commit comments

Comments
 (0)