Skip to content

Commit

Permalink
Move to DS18B20 library
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Feb 23, 2020
1 parent 827080f commit 161ce81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
59 changes: 25 additions & 34 deletions src/bubbles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void Bubbles::update() { // Regular update loop, once per minute

// Store last values
single->lastBpm = single->getRawBpm();
single->lastAmb = single->getAmbientTemp();
single->lastVes = single->getVesselTemp();
single->lastAmb = single->getTemp(AMBSENSOR);
single->lastVes = single->getTemp(VESSENSOR);

// Push values to circular buffers
tempAmbAvg.push(single->lastAmb);
Expand Down Expand Up @@ -103,40 +103,31 @@ float Bubbles::getRawBpm() { // Return raw pulses per minute (resets counter)
return ppm; // Return pulses per minute
}

float Bubbles::getAmbientTemp() {
OneWire ambient(AMBSENSOR);
byte addrAmb[8];
float fAmbTemp = -100.0;
while (ambient.search(addrAmb)) { // Make sure we have a sensor
DallasTemperature sensorAmbient(&ambient);
sensorAmbient.begin();
sensorAmbient.requestTemperatures();

JsonConfig *config = JsonConfig::getInstance();
if (config->tempinf == true)
fAmbTemp = sensorAmbient.getTempFByIndex(0) + config->calAmbient;
else
fAmbTemp = sensorAmbient.getTempCByIndex(0) + config->calAmbient;
float Bubbles::getTemp(uint8_t pin) {
OneWire oneWire(pin);
DS18B20 sensor(&oneWire);
sensor.begin();
float retVal = -100.00;
sensor.setResolution(13);
sensor.requestTemperatures();
while (!sensor.isConversionComplete());

// Get Temps
JsonConfig *config = JsonConfig::getInstance();
if (config->tempinf) {
retVal = sensor.getTempC();
retVal = retVal * 9/5 + 32;
} else {
retVal = sensor.getTempC();
}
return fAmbTemp;
}

float Bubbles::getVesselTemp() {
OneWire vessel(VESSENSOR);
byte addrVes[8];
float fVesTemp = -100.0;
while (vessel.search(addrVes)) { // Make sure we have a sensor
DallasTemperature sensorVessel(&vessel);
sensorVessel.begin();
sensorVessel.requestTemperatures();

JsonConfig *config = JsonConfig::getInstance();
if (config->tempinf == true)
fVesTemp = sensorVessel.getTempFByIndex(0) + config->calVessel;
else
fVesTemp = sensorVessel.getTempCByIndex(0) + config->calVessel;
// Apply calibration
if (pin == AMBSENSOR) {
retVal = retVal + config->calAmbient;
} else if (pin == VESSENSOR) {
retVal = retVal + config->calVessel;
}
return fVesTemp;

return retVal;
}

float Bubbles::getAvgAmbient() {
Expand Down
7 changes: 3 additions & 4 deletions src/bubbles.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ SOFTWARE. */
#ifndef _BUBBLES_H
#define _BUBBLES_H

#include "main.h"
#include "config.h"
#include "jsonconfig.h"
#include "ntphandler.h"
#include "DallasTemperature.h"
#include "DS18B20.h"
#include "OneWire.h"
#include <ArduinoLog.h>
#include <CircularBuffer.h>
#include <Arduino.h>

Expand All @@ -50,8 +50,7 @@ class Bubbles {
float lastAmb;
float lastVes;
float getRawBpm();
float getAmbientTemp();
float getVesselTemp();
float getTemp(uint8_t);

public:
// Singleton Declarations
Expand Down

0 comments on commit 161ce81

Please sign in to comment.