Only show temp if sensor is attached. Added common functions to get temp and vcc

This commit is contained in:
Gunnar Skjold
2020-02-14 21:48:03 +01:00
parent f484f3eb0e
commit eff00f1fe0
7 changed files with 118 additions and 49 deletions

32
src/HwTools.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef _HWTOOLS_H
#define _HWTOOLS_H
#include "Arduino.h"
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif
#include <DallasTemperature.h>
#include <OneWire.h>
class HwTools {
public:
static double getVcc();
static double getTemperature();
HwTools() {
#if defined TEMP_SENSOR_PIN
oneWire = new OneWire(TEMP_SENSOR_PIN);
tempSensor = new DallasTemperature(this->oneWire);
#endif
};
private:
bool tempSensorInit, hasTempSensor;
OneWire *oneWire;
DallasTemperature *tempSensor;
};
#endif