mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-13 23:45:25 +00:00
Added support for TMP236 analog temp sensor
This commit is contained in:
parent
e71f937856
commit
5d47105951
@ -126,6 +126,7 @@ void setup() {
|
||||
hw.setLed(config.getLedPin(), config.isLedInverted());
|
||||
hw.setLedRgb(config.getLedPinRed(), config.getLedPinGreen(), config.getLedPinBlue(), config.isLedRgbInverted());
|
||||
hw.setTempSensorPin(config.getTempSensorPin());
|
||||
hw.setTempAnalogSensorPin(config.getTempAnalogSensorPin());
|
||||
hw.setVccPin(config.getVccPin());
|
||||
hw.setVccMultiplier(config.getVccMultiplier());
|
||||
hw.setVccOffset(config.getVccOffset());
|
||||
|
||||
@ -92,8 +92,8 @@ bool HwTools::updateTemperatures() {
|
||||
DeviceAddress addr;
|
||||
sensorApi->requestTemperatures();
|
||||
int c = sensorApi->getDeviceCount();
|
||||
Serial.print("Sensors found: ");
|
||||
Serial.println(c);
|
||||
//Serial.print("Sensors found: ");
|
||||
//Serial.println(c);
|
||||
for(int i = 0; i < c; i++) {
|
||||
bool found = false;
|
||||
sensorApi->getAddress(addr, i);
|
||||
@ -150,6 +150,11 @@ bool HwTools::isSensorAddressEqual(uint8_t a[8], uint8_t b[8]) {
|
||||
double HwTools::getTemperature() {
|
||||
uint8_t c = 0;
|
||||
double ret = 0;
|
||||
double analogTemp = getTemperatureAnalog();
|
||||
if(analogTemp != DEVICE_DISCONNECTED_C) {
|
||||
ret += analogTemp;
|
||||
c++;
|
||||
}
|
||||
for(int x = 0; x < sensorCount; x++) {
|
||||
TempSensorData data = *tempSensors[x];
|
||||
if(data.common && data.lastValidRead > -85) {
|
||||
@ -159,6 +164,20 @@ double HwTools::getTemperature() {
|
||||
}
|
||||
return c == 0 ? DEVICE_DISCONNECTED_C : ret/c;
|
||||
}
|
||||
double HwTools::getTemperatureAnalog() {
|
||||
if(tempAnalogSensorPin != 0xFF) {
|
||||
float adcCalibrationFactor = 1.06587;
|
||||
int adcRead = analogRead(tempAnalogSensorPin);
|
||||
int volts;
|
||||
#if defined(ESP8266)
|
||||
volts = (analogRead(vccPin) / 1024.0) * 3.3;
|
||||
#elif defined(ESP32)
|
||||
volts = (analogRead(vccPin) / 4095.0) * 3.3;
|
||||
#endif
|
||||
return ((volts * adcCalibrationFactor) - 0.4) / 0.0195;
|
||||
}
|
||||
return DEVICE_DISCONNECTED_C;
|
||||
}
|
||||
|
||||
int HwTools::getWifiRssi() {
|
||||
int rssi = WiFi.RSSI();
|
||||
|
||||
@ -29,6 +29,7 @@ struct TempSensorData {
|
||||
class HwTools {
|
||||
public:
|
||||
void setTempSensorPin(int tempSensorPin);
|
||||
void setTempAnalogSensorPin(int tempAnalogSensorPin);
|
||||
void setVccPin(int vccPin);
|
||||
void setVccOffset(double vccOffset);
|
||||
void setVccMultiplier(double vccMultiplier);
|
||||
@ -38,6 +39,7 @@ public:
|
||||
TempSensorData* getTempSensorData(uint8_t i);
|
||||
bool updateTemperatures();
|
||||
double getTemperature();
|
||||
double getTemperature();
|
||||
double getTemperature(uint8_t address[8]);
|
||||
int getWifiRssi();
|
||||
void setLed(uint8_t ledPin, bool ledInverted);
|
||||
@ -48,7 +50,7 @@ public:
|
||||
|
||||
HwTools() {};
|
||||
private:
|
||||
uint8_t tempSensorPin = -1;
|
||||
uint8_t tempSensorPin = -1, tempAnalogSensorPin = -1;
|
||||
uint8_t vccPin = -1;
|
||||
uint8_t ledPin = -1, ledPinRed = -1, ledPinGreen = -1, ledPinBlue = -1;
|
||||
bool ledInverted, ledRgbInverted;
|
||||
|
||||
@ -929,6 +929,7 @@ void AmsWebServer::handleSave() {
|
||||
hw->setLed(config->getLedPin(), config->isLedInverted());
|
||||
hw->setLedRgb(config->getLedPinRed(), config->getLedPinGreen(), config->getLedPinBlue(), config->isLedRgbInverted());
|
||||
hw->setTempSensorPin(config->getTempSensorPin());
|
||||
hw->setTempAnalogSensorPin(config->getTempAnalogSensorPin());
|
||||
hw->setVccPin(config->getVccPin());
|
||||
hw->setVccOffset(config->getVccOffset());
|
||||
hw->setVccMultiplier(config->getVccMultiplier());
|
||||
|
||||
@ -217,8 +217,9 @@ var fetch = function() {
|
||||
|
||||
for(var id in json) {
|
||||
var str = json[id];
|
||||
if(typeof str === "object")
|
||||
if(typeof str === "object") {
|
||||
continue;
|
||||
}
|
||||
if(isNaN(str)) {
|
||||
$('#'+id).html(str);
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user