Skip to content

Commit

Permalink
Created functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMacas committed Nov 1, 2024
1 parent 0903396 commit 1762a6b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
@Controller("/thermistor")
public class ThermistorController {
private final ThermistorHelper thermistorHelper;
// Finalize (Still gathering my thoughts about this)
public ThermistorController(@Named("thermistor-input") DigitalInput sensorInput, @Named("thermistor-output") DigitalOutput sensorOutput){

public ThermistorController(@Named("thermistor-input") DigitalInput sensorInput, @Named("thermistor-output") DigitalOutput sensorOutput) {
this.thermistorHelper = new ThermistorHelper(sensorInput, sensorOutput);
}

@Get("/value")
public int getThermistorValue(){
return thermistorHelper.getThermistorValue();
@Get("/celsius")
public double getTemperatureCelsius() {
return thermistorHelper.getTemperatureCelsius();
}

@Get("/fahrenheit")
public double getTemperatureFahrenheit() {
return thermistorHelper.getTemperatureFahrenheit();
}
}

8 changes: 8 additions & 0 deletions components/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pi4j:
name: Thermistor Input
address: 18
provider: pigpio-digital-input
pull: PULL_DOWN
debounce: 2000
# end::digitalInput[]

# tag::digitalOutput[]
Expand Down Expand Up @@ -165,6 +167,12 @@ pi4j:
shutdown: LOW
initial: LOW
provider: pigpio-digital-output
thermistor-output:
name: Thermistor Output
address: 18
provider: pigpio-digital-output
initial: LOW
shutdown: LOW
# end::digitalOutput[]

# tag::multiInput[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,37 @@

public class ThermistorHelper {
private static final Logger log = LoggerFactory.getLogger(ThermistorHelper.class);
private String helperName;
private int globalValue;
private DigitalInput sensorInput;
private DigitalOutput sensorOutput;

public ThermistorHelper(DigitalInput sensorInput, DigitalOutput sensorOutput){
//Finalize (I'm still gathering my thoughts about how to handle this)
public ThermistorHelper(DigitalInput sensorInput, DigitalOutput sensorOutput) {
this.sensorInput = sensorInput;
this.sensorOutput = sensorOutput;
}

public int getThermistorValue() {
public double getTemperatureCelsius() {
int rawValue = getThermistorValue();
return convertRawToCelsius(rawValue);
}

public double getTemperatureFahrenheit() {
double celsius = getTemperatureCelsius();
return celsius * 9.0 / 5.0 + 32;
}

private double convertRawToCelsius(int rawValue) {
double resistance = calculateResistance(rawValue);
double tempCelsius = 1.0 / (0.001129148 + (0.000234125 * Math.log(resistance)) + (0.0000000876741 * Math.pow(Math.log(resistance), 3))) - 273.15;
return tempCelsius;
}

private double calculateResistance(int rawValue) {
double Vout = (rawValue / 1023.0) * 3.3;
return (10_000 * Vout) / (3.3 - Vout);
}

private int getThermistorValue() {
return 1;
}
}

0 comments on commit 1762a6b

Please sign in to comment.