expose ica dcd ccd ah values

This commit is contained in:
Empire 2021-02-16 23:40:05 +01:00
parent f1f21027ed
commit d5fbd38762
3 changed files with 36 additions and 56 deletions

View File

@ -87,6 +87,10 @@ class DS2438 {
double getTemperature(); double getTemperature();
float getVoltage(int channel=DS2438_CHA); float getVoltage(int channel=DS2438_CHA);
float getCurrent(); float getCurrent();
long getICA();
long getCCA();
long getDCA();
float getAh();
boolean isError(); boolean isError();
boolean isFound(); boolean isFound();
private: private:
@ -102,6 +106,9 @@ class DS2438 {
float _voltageB; float _voltageB;
float _current; float _current;
float _currentShunt; float _currentShunt;
long _CCA;
long _DCA;
long _ICA;
boolean _error; boolean _error;
boolean startConversion(int channel, boolean doTemperature); boolean startConversion(int channel, boolean doTemperature);
boolean selectChannel(int channel); boolean selectChannel(int channel);

View File

@ -90,22 +90,6 @@ void DS2438::update() {
Serial.println("Error reading zero page ds2438 channel a"); Serial.println("Error reading zero page ds2438 channel a");
return; return;
} }
Serial.print(data[0],16);
Serial.print(" ");
Serial.print(data[1],16);
Serial.print(" ");
Serial.print(data[2],16);
Serial.print(" ");
Serial.print(data[3],16);
Serial.print(" ");
Serial.print(data[4],16);
Serial.print(" ");
Serial.print(data[5],16);
Serial.print(" ");
Serial.print(data[6],16);
Serial.print(" ");
Serial.println(data[7],16);
if (doTemperature) { if (doTemperature) {
_temperature = (double)(((((int16_t)data[2]) << 8) | (data[1] & 0x0ff)) >> 3) * 0.03125; _temperature = (double)(((((int16_t)data[2]) << 8) | (data[1] & 0x0ff)) >> 3) * 0.03125;
@ -139,48 +123,16 @@ void DS2438::update() {
float fullByteb = fullByte; float fullByteb = fullByte;
_current = (fullByteb) / ((4096.0f * _currentShunt)); _current = (fullByteb) / ((4096.0f * _currentShunt));
_error = false; _error = false;
Serial.print(data[0],16);
Serial.print(" ");
Serial.print(data[1],16);
Serial.print(" ");
Serial.print(data[2],16);
Serial.print(" ");
Serial.print(data[3],16);
Serial.print(" ");
Serial.print(data[4],16);
Serial.print(" ");
Serial.print(data[5],16);
Serial.print(" ");
Serial.print(data[6],16);
Serial.print(" ");
Serial.println(data[7],16);
Serial.println("-");
uint16_t ICA = 0;
if (readPage(1, data)){ if (readPage(1, data)){
PageOne_t *pOne = (PageOne_t *) data; PageOne_t *pOne = (PageOne_t *) data;
Serial.println(pOne->ICA); _ICA = pOne->ICA;
float Ah = pOne->ICA / (2048.0f * _currentShunt);
Serial.print("Ah=");
Serial.println(Ah);
ICA = pOne->ICA;
} }
if (readPage(7, data)){ if (readPage(7, data)){
PageSeven_t *pSeven = (PageSeven_t *) data; PageSeven_t *pSeven = (PageSeven_t *) data;
int16_t CCA = pSeven->CCA0 | ((int16_t) pSeven->CCA1) << 8; _CCA = pSeven->CCA0 | ((int16_t) pSeven->CCA1) << 8;
int16_t DCA = pSeven->DCA0 | ((int16_t) pSeven->DCA1) << 8; _DCA = pSeven->DCA0 | ((int16_t) pSeven->DCA1) << 8;
Serial.println("ICA, DCA, CCA");
Serial.print(ICA);
Serial.print(", ");
Serial.print(DCA);
Serial.print(", ");
Serial.println(CCA);
} }
} }
@ -189,6 +141,23 @@ double DS2438::getTemperature() {
return _temperature; return _temperature;
} }
float DS2438::getAh(){
return _ICA / (2048.0f * _currentShunt);
}
long DS2438::getICA(){
return _ICA;
}
long DS2438::getDCA(){
return _DCA;
}
long DS2438::getCCA(){
return _CCA;
}
float DS2438::getVoltage(int channel) { float DS2438::getVoltage(int channel) {
if (channel == DS2438_CHA) { if (channel == DS2438_CHA) {
return _voltageA; return _voltageA;

View File

@ -71,7 +71,7 @@ RTC_DATA_ATTR float rtcLastBatteryVoltage = 0.0f;
RTC_DATA_ATTR float rtcLastSolarVoltage = 0.0f; RTC_DATA_ATTR float rtcLastSolarVoltage = 0.0f;
RTC_DATA_ATTR int gBootCount = 0; RTC_DATA_ATTR int gBootCount = 0;
RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant needs water) */ RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant needs water) */
RTC_DATA_ATTR int rtcLipoTempIndex = -1; RTC_DATA_ATTR int rtcLipoTempIndex = 0; //FIXME use -1 and configure properly
RTC_DATA_ATTR int rtcWaterTempIndex = -1; RTC_DATA_ATTR int rtcWaterTempIndex = -1;
/****************************************************************************** /******************************************************************************
@ -185,7 +185,7 @@ void readSystemSensors()
{ {
sensors.begin(); sensors.begin();
battery.begin(); battery.begin();
sensorCount = sensors.getDeviceCount(); sensorCount = sensors.getDS18Count();
Serial << "Waitloop: One wire count: " << sensorCount << endl; Serial << "Waitloop: One wire count: " << sensorCount << endl;
delay(200); delay(200);
} }
@ -199,7 +199,7 @@ void readSystemSensors()
for (int i = 0; i < sensorCount; i++) for (int i = 0; i < sensorCount; i++)
{ {
Serial << "OnwWire sensor " << i << " has value " << sensors.getTempCByIndex(i) << endl; Serial << "OneWire sensor " << i << " has value " << sensors.getTempCByIndex(i) << endl;
} }
// Update battery chip data // Update battery chip data
@ -318,6 +318,10 @@ void mode2MQTT()
sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT)); sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT));
sensorLipo.setProperty("volt").send(String(mBatteryVoltage)); sensorLipo.setProperty("volt").send(String(mBatteryVoltage));
sensorLipo.setProperty("Ah").send(String(battery.getAh()));
sensorLipo.setProperty("ICA").send(String(battery.getICA()));
sensorLipo.setProperty("DCA").send(String(battery.getDCA()));
sensorLipo.setProperty("CCA").send(String(battery.getCCA()));
sensorSolar.setProperty("percent").send(String(100 * mSolarVoltage / VOLT_MAX_SOLAR)); sensorSolar.setProperty("percent").send(String(100 * mSolarVoltage / VOLT_MAX_SOLAR));
sensorSolar.setProperty("volt").send(String(mSolarVoltage)); sensorSolar.setProperty("volt").send(String(mSolarVoltage));
startupReason.setProperty("startupReason").send(String(wakeUpReason)); startupReason.setProperty("startupReason").send(String(wakeUpReason));
@ -453,7 +457,7 @@ void readDistance()
*/ */
int readTemp() { int readTemp() {
int readAgain = TEMP_SENSOR_MEASURE_SERIES; int readAgain = TEMP_SENSOR_MEASURE_SERIES;
int sensorCount = sensors.getDeviceCount(); int sensorCount = sensors.getDS18Count();
int leaveMode1 = 0; int leaveMode1 = 0;
while (readAgain > 0) while (readAgain > 0)
@ -844,7 +848,7 @@ void mode2()
*/ */
void setup() void setup()
{ {
Serial.begin(9600); Serial.begin(115200);
Serial.setTimeout(1000); // Set timeout of 1 second Serial.setTimeout(1000); // Set timeout of 1 second
Serial << endl Serial << endl
<< endl; << endl;