ds2438 test code works

This commit is contained in:
Empire 2021-02-16 21:35:46 +01:00
parent 6843a58228
commit ae18a25c69
2 changed files with 28 additions and 37 deletions

View File

@ -46,8 +46,8 @@ void DS2438::begin(){
if (validAddress(searchDeviceAddress)) { if (validAddress(searchDeviceAddress)) {
if (validFamily(searchDeviceAddress)) { if (validFamily(searchDeviceAddress)) {
memcpy(_address,searchDeviceAddress,8); memcpy(_address,searchDeviceAddress,8);
//DEFAULT_PAGE0(defaultConfig); DEFAULT_PAGE0(defaultConfig);
//writePage(0, defaultConfig); writePage(0, defaultConfig);
deviceFound = true; deviceFound = true;
} }
} }
@ -156,40 +156,31 @@ void DS2438::update() {
Serial.println(data[7],16); Serial.println(data[7],16);
Serial.println("-"); Serial.println("-");
uint16_t ICA = 0;
if (readPage(1, data)){
PageOne_t *pOne = (PageOne_t *) data;
Serial.println(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; int16_t CCA = pSeven->CCA0 | ((int16_t) pSeven->CCA1) << 8;
int16_t DCA = pSeven->DCA0 | ((int16_t) pSeven->DCA1) << 8; int16_t DCA = pSeven->DCA0 | ((int16_t) pSeven->DCA1) << 8;
Serial.println("ICA, DCA, CCA");
Serial.print(ICA);
Serial.printf("DCA: %d. CCA: %d\n", DCA, CCA); Serial.print(", ");
} Serial.print(DCA);
Serial.print(", ");
if (readPage(1, data)){ Serial.println(CCA);
PageOne_t *pSeven = (PageOne_t *) data;
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(pSeven->ICA);
float Ah = pSeven->ICA / (2048.0f * _currentShunt);
Serial.println(Ah);
Serial.println("=");
} }
} }

View File

@ -114,9 +114,9 @@ void setup() {
void loop() { void loop() {
whatever = !whatever; whatever = !whatever;
digitalWrite(OUTPUT_PUMP, whatever?HIGH:LOW); digitalWrite(OUTPUT_PUMP, HIGH);
delay(2000); delay(500);
digitalWrite(OUTPUT_PUMP0, HIGH); digitalWrite(OUTPUT_PUMP6, HIGH);
for(int j=0; j < 5 && temp.getDeviceCount() == 0; j++) { for(int j=0; j < 5 && temp.getDeviceCount() == 0; j++) {
delay(10); delay(10);
@ -131,9 +131,9 @@ void loop() {
battery.update(); battery.update();
} }
battery.update(); battery.update();
Serial.print(battery.getVoltage(0)); Serial.print(battery.getVoltage(0)); //use define here, solar
Serial.print("\t"); Serial.print("\t");
Serial.print(battery.getVoltage(1)); Serial.print(battery.getVoltage(1)); //use define here, battery
Serial.print("\t"); Serial.print("\t");
Serial.print(battery.getCurrent()); Serial.print(battery.getCurrent());
Serial.print("\t"); Serial.print("\t");