pin fix
This commit is contained in:
parent
e7ac4210c1
commit
23beebc4be
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @file DS18B20.h
|
||||
* @author your name (you@domain.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2020-06-09
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
* Based on the LUA code from the ESP8266
|
||||
* --------------------------------------------------------------------------------
|
||||
* -- DS18B20 one wire module for NODEMCU
|
||||
* -- NODEMCU TEAM
|
||||
* -- LICENCE: http://opensource.org/licenses/MIT
|
||||
* -- Vowstar <vowstar@nodemcu.com>
|
||||
* -- 2015/02/14 sza2 <sza2trash@gmail.com> Fix for negative values
|
||||
* --------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef DS18B20_H
|
||||
#define DS18B20_H
|
||||
|
||||
#include <OneWire.h>
|
||||
|
||||
class Ds18B20
|
||||
{
|
||||
private:
|
||||
OneWire *mDs;
|
||||
int foundDevices;
|
||||
|
||||
public:
|
||||
Ds18B20(int pin)
|
||||
{
|
||||
this->mDs = new OneWire(pin);
|
||||
}
|
||||
|
||||
~Ds18B20()
|
||||
{
|
||||
delete this->mDs;
|
||||
}
|
||||
/**
|
||||
* @brief read amount sensots
|
||||
* check for available of DS18B20 sensors
|
||||
* @return amount of sensors
|
||||
*/
|
||||
int readDevices(void);
|
||||
|
||||
/**
|
||||
* @brief Read all temperatures in celsius
|
||||
*
|
||||
* @param pTemperatures array of float valuies
|
||||
* @param maxTemperatures size of the given array
|
||||
* @return int amount of read temperature values
|
||||
*/
|
||||
int readAllTemperatures(float *pTemperatures, int maxTemperatures);
|
||||
};
|
||||
#endif
|
@ -24,6 +24,7 @@ private:
|
||||
int mPinSensor = 0; /**< Pin of the moist sensor */
|
||||
int mPinPump = 0; /**< Pin of the pump */
|
||||
bool mConnected = false;
|
||||
int mPlantId = -1;
|
||||
|
||||
public:
|
||||
PlantSettings_t *mSetting;
|
||||
|
@ -1,103 +0,0 @@
|
||||
/**
|
||||
* @file DS18B20.cpp
|
||||
* @author your name (you@domain.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2020-06-09
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*/
|
||||
|
||||
#include "DS18B20.h"
|
||||
|
||||
#define STARTCONV 0x44
|
||||
#define READSCRATCH 0xBE // Read EEPROM
|
||||
#define TEMP_LSB 0
|
||||
#define TEMP_MSB 1
|
||||
#define SCRATCHPADSIZE 9
|
||||
#define OFFSET_CRC8 8 /**< 9th byte has the CRC of the complete data */
|
||||
|
||||
//Printf debugging
|
||||
//#define DS_DEBUG
|
||||
|
||||
int Ds18B20::readDevices()
|
||||
{
|
||||
byte addr[8];
|
||||
|
||||
int amount = -1;
|
||||
while (this->mDs->search(addr))
|
||||
{
|
||||
amount++;
|
||||
}
|
||||
this->mDs->reset_search();
|
||||
return amount;
|
||||
}
|
||||
|
||||
int Ds18B20::readAllTemperatures(float *pTemperatures, int maxTemperatures)
|
||||
{
|
||||
byte addr[8];
|
||||
uint8_t scratchPad[SCRATCHPADSIZE];
|
||||
int currentTemp = 0;
|
||||
|
||||
while (this->mDs->search(addr))
|
||||
{
|
||||
this->mDs->reset();
|
||||
this->mDs->select(addr);
|
||||
this->mDs->write(STARTCONV);
|
||||
}
|
||||
delay(750);
|
||||
|
||||
while (this->mDs->search(addr))
|
||||
{
|
||||
this->mDs->reset();
|
||||
this->mDs->select(addr);
|
||||
this->mDs->write(READSCRATCH);
|
||||
|
||||
// Read all registers in a simple loop
|
||||
// byte 0: temperature LSB
|
||||
// byte 1: temperature MSB
|
||||
// byte 2: high alarm temp
|
||||
// byte 3: low alarm temp
|
||||
// byte 4: DS18S20: store for crc
|
||||
// DS18B20 & DS1822: configuration register
|
||||
// byte 5: internal use & crc
|
||||
// byte 6: DS18S20: COUNT_REMAIN
|
||||
// DS18B20 & DS1822: store for crc
|
||||
// byte 7: DS18S20: COUNT_PER_C
|
||||
// DS18B20 & DS1822: store for crc
|
||||
// byte 8: SCRATCHPAD_CRC
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
scratchPad[i] = this->mDs->read();
|
||||
}
|
||||
uint8_t crc8 = this->mDs->crc8(scratchPad, 8);
|
||||
|
||||
/* Only work an valid data */
|
||||
if (crc8 == scratchPad[OFFSET_CRC8])
|
||||
{
|
||||
int16_t fpTemperature = (((int16_t)scratchPad[TEMP_MSB]) << 11) | (((int16_t)scratchPad[TEMP_LSB]) << 3);
|
||||
float celsius = (float)fpTemperature * 0.0078125;
|
||||
#ifdef DS_DEBUG
|
||||
Serial.printf("\r\nTemp%d %f °C (Raw: %d, %x =? %x)\r\n", (currentTemp + 1), celsius, fpTemperature, crc8, scratchPad[8]);
|
||||
#endif
|
||||
/* check, if the buffer as some space for our data */
|
||||
if (currentTemp < maxTemperatures)
|
||||
{
|
||||
pTemperatures[currentTemp] = celsius;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
currentTemp++;
|
||||
}
|
||||
this->mDs->reset();
|
||||
#ifdef DS_DEBUG
|
||||
Serial.println(" No more addresses.");
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
return currentTemp;
|
||||
}
|
@ -19,6 +19,7 @@ Plant::Plant(int pinSensor, int pinPump, int plantId, HomieNode *plant, PlantSet
|
||||
this->mPinPump = pinPump;
|
||||
this->mPlant = plant;
|
||||
this->mSetting = setting;
|
||||
this->mPlantId = plantId;
|
||||
}
|
||||
|
||||
void Plant::init(void)
|
||||
@ -53,6 +54,9 @@ void Plant::addSenseValue(void)
|
||||
int raw = analogRead(this->mPinSensor);
|
||||
if(raw < MOIST_SENSOR_MAX_ADC && raw > MOIST_SENSOR_MIN_ADC){
|
||||
this->moistureRaw.add(raw);
|
||||
} else {
|
||||
int plantId = this->mPlantId;
|
||||
Serial << "ignoring sensor " << plantId << " value due to being strange " << raw << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user