1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.chabala.brick.controllab.sensor;
20
21
22
23
24 public class TemperatureSensor implements SensorValue {
25
26 private SensorValue sensorValue;
27
28 public TemperatureSensor(SensorValue sensorValue) {
29 this.sensorValue = sensorValue;
30 }
31
32 @Override
33 public int getAnalogValue() {
34 return sensorValue.getAnalogValue();
35 }
36
37 @Override
38 public int getStatusCode() {
39 return sensorValue.getStatusCode();
40 }
41
42 public String temperatureValue() {
43 if (isPassive() && isEngaged()) {
44 double degreesF = (760 - getAnalogValue()) / 4.4 + 32;
45 return String.format("%.2f", degreesF);
46 } else {
47 return "";
48 }
49 }
50
51 @Override
52 public String toString() {
53 return "TemperatureSensor{" +
54 "value=" + String.format("0x%02X", getAnalogValue()) +
55 ", status=" + getStatusCode() +
56 ", temp=" + temperatureValue() +
57 '}';
58 }
59 }