Skip to content

Commit

Permalink
round temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
eschava committed Mar 29, 2016
1 parent cd817c5 commit 40dc700
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/com/eschava/ht2000/usb/HT2000State.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class HT2000State {
private static final long TIMESTAMP_SHIFT = 0x77797DA0; // TODO: magic constant
private static final double TEMPERATURE_SHIFT = 11.2; // TODO: magic constant
private static final int TEMPERATURE_SHIFT = 112; // TODO: magic constant

private final Date time;
private final double temperature;
Expand All @@ -25,11 +25,19 @@ public HT2000State(ByteBuffer buffer) {
if (timestamp > TIMESTAMP_SHIFT)
timestamp -= TIMESTAMP_SHIFT;
time = new Date(timestamp * 1000);
temperature = TEMPERATURE_SHIFT + /*Byte.*/toUnsignedInt(buffer.get(8)) / 10.0;
temperature = (TEMPERATURE_SHIFT + /*Byte.*/toUnsignedInt(buffer.get(8))) / 10.0;
humidity = buffer.getShort(9) / 10.0;
co2 = buffer.getShort(24);
}

private static long toUnsignedLong(int x) {
return ((long) x) & 0xffffffffL;
}

private static int toUnsignedInt(byte x) {
return ((int) x) & 0xff;
}

public Date getTime() {
return time;
}
Expand All @@ -55,12 +63,4 @@ public String toString() {
", CO2=" + co2 +
'}';
}

private static long toUnsignedLong(int x) {
return ((long) x) & 0xffffffffL;
}

private static int toUnsignedInt(byte x) {
return ((int) x) & 0xff;
}
}

0 comments on commit 40dc700

Please sign in to comment.