Skip to content

Commit

Permalink
fix: make secondary analog measurement more generic in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
arcadien committed Dec 5, 2023
1 parent 68cefb8 commit 6f1362d
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#endif

#if defined(USE_DS18B20)
#if defined(AVR)
#include <avr/io.h>
#include <ds18b20.h>
#else
#warning Cannot use DS18B20 in native environment for now
#endif
#endif

#if defined(USE_LACROSSE)
Expand Down Expand Up @@ -115,7 +120,7 @@ int main(void) {
#endif

#if defined(USE_DS18B20)

#if defined(AVR)
ds18b20convert(&PORTA, &DDRA, &PINA, (1 << 3), nullptr);

// Delay (sensor needs time to perform conversion)
Expand All @@ -128,7 +133,7 @@ int main(void) {
if (readStatus == DS18B20_ERROR_OK) {
temperature = (temp / 16);
}

#endif
#endif

#if defined(BATTERY_VOLTAGE_X10_ID)
Expand Down Expand Up @@ -161,15 +166,16 @@ int main(void) {

#if defined(ANALOG1_X10_ID)

uint16_t rawSolar = hal.GetRawAnalogSensor();
SerialPrintInfo("Raw solar", rawSolar, ANALOG);
uint16_t analogMeasurement = hal.GetRawAnalogSensor();
SerialPrintInfo("Raw analog", analogMeasurement, ANALOG);

uint16_t solar_power = hal.ConvertAnalogValueToMv(rawSolar, vccMv);
SerialPrintInfo("Vsolar", solar_power, MILLIVOLT);
uint16_t analogVoltage =
hal.ConvertAnalogValueToMv(analogMeasurement, vccMv);
SerialPrintInfo("Analog voltage", analogVoltage, MILLIVOLT);

hal.LedOn();
x10encoder.RFXmeter(ANALOG1_X10_ID, 0x00,
ConversionTools::dec16ToHex(solar_power));
ConversionTools::dec16ToHex(analogVoltage));
hal.LedOff();
hal.Delay30ms();
#endif
Expand Down Expand Up @@ -234,18 +240,7 @@ int main(void) {
}
#endif

#if defined(USE_SERIAL_LOG)
// SerialPrintInfo("Going to sleep", (uint16_t)SLEEP_TIME_IN_SECONDS,
// SECOND);
#endif

hal.PowerOffSensors();
hal.Hibernate((uint16_t)SLEEP_TIME_IN_SECONDS);

#if defined(USE_SERIAL_LOG)
// swSerial.begin();
// swSerial.print("Wakeup!");
// swSerial.println();
#endif
}
}

0 comments on commit 6f1362d

Please sign in to comment.