Update documentation and do some basic housekeeping
This commit is contained in:
62
src/main.c
62
src/main.c
@@ -76,17 +76,11 @@ static int Init(void)
|
||||
WDT_Enable();
|
||||
WDT_SetTimeoutFlag(WDT2000); // 2 seconds
|
||||
|
||||
// Test persistent settings from EEPROM. There must
|
||||
// be some sanity checking before these values are
|
||||
// used.
|
||||
// See if there are persistent target settings
|
||||
// stored in EEPROM and load them. Some sanity
|
||||
// checking must be done before using those.
|
||||
|
||||
// mem.temp = 20.50f;
|
||||
// mem.dewp = 10.25f;
|
||||
// MEM_Write(&mem);
|
||||
// MEM_Dump();
|
||||
// MEM_Free();
|
||||
|
||||
if (MEM_Read(&mem) == 0) {
|
||||
if (MEM_Read(&mem)) { // Any valid blocks found?
|
||||
Info("Found persistent configuration in EEPROM!");
|
||||
Info("Using targets TEMP=%.2fC, DEWP=%.2fC.",
|
||||
mem.temp, mem.dewp);
|
||||
@@ -95,6 +89,12 @@ static int Init(void)
|
||||
dewp_target = mem.dewp;
|
||||
}
|
||||
|
||||
// mem.temp = 20.50f;
|
||||
// mem.dewp = 10.25f;
|
||||
// MEM_Write(&mem);
|
||||
// MEM_Dump();
|
||||
// MEM_Free();
|
||||
|
||||
// There is a possiblity to use interrupt signals
|
||||
// for I2C communication but only as one large
|
||||
// branching routine for the whole I2C system.
|
||||
@@ -103,9 +103,9 @@ static int Init(void)
|
||||
I2C_Init();
|
||||
PWM_Init();
|
||||
|
||||
MOS_Enable(MOS03); // Lights
|
||||
// MOS_Enable(MOS01); // Peltier
|
||||
// MOS_Disable(MOS02); // Heating
|
||||
MOS_Enable(MOS03); // Lights
|
||||
// MOS_Enable(MOS01); // Peltier
|
||||
// MOS_Disable(MOS02); // Heating
|
||||
|
||||
// Only FAN01 and FAN02 are receiving the correct
|
||||
// frequency (25 KHz) right now. The 16-bit timer on
|
||||
@@ -117,9 +117,9 @@ static int Init(void)
|
||||
// complicated so it might be worth it to switch to
|
||||
// something like an ATmega328PB.
|
||||
|
||||
PWM_SetValue(FAN01, 50); // Fan Peltier Hot side
|
||||
PWM_SetValue(FAN02, 50); // Fan Peltier Cold Side
|
||||
// PWM_SetValue(FAN03, 20); // Fan Heating
|
||||
PWM_SetValue(FAN01, 50); // Fan Peltier Hot side
|
||||
PWM_SetValue(FAN02, 50); // Fan Peltier Cold Side
|
||||
// PWM_SetValue(FAN03, 20); // Fan Heating
|
||||
|
||||
// The I2C_SetChannel command changes the channel
|
||||
// setting of the PCA9546 I2C multiplexer. Any
|
||||
@@ -156,7 +156,7 @@ static void Update(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Get sensor values
|
||||
// Get latest sensor values
|
||||
FetchSensorValues();
|
||||
|
||||
// Handle state
|
||||
@@ -179,23 +179,25 @@ static void SetTarget(float t, float td)
|
||||
Print("\r\n");
|
||||
Info("Updating target configuration:");
|
||||
Info("Setting temperature to %.2fC.", t);
|
||||
Info("Setting new dewpoint to %.2fC.", td);
|
||||
Info("Setting dewpoint to %.2fC.", td);
|
||||
|
||||
if (MEM_Read(&mem) == 0) {
|
||||
// Even with level wearing there is a finite number
|
||||
// of EEPROM write cycles so we should always check
|
||||
// for redundant values. This could be handled by
|
||||
// the underlying memory implementation.
|
||||
|
||||
if (MEM_Read(&mem)) {
|
||||
if (t == mem.temp && td == mem.dewp) {
|
||||
return; // Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
mem.temp = t;
|
||||
mem.dewp = td;
|
||||
// Update current targets
|
||||
mem.temp = temp_target = t;
|
||||
mem.dewp = dewp_target = td;
|
||||
|
||||
// Keep in EEPROM
|
||||
// Store in EEPROM
|
||||
MEM_Write(&mem);
|
||||
|
||||
// Update state
|
||||
temp_target = t;
|
||||
dewp_target = td;
|
||||
}
|
||||
|
||||
static void FetchSensorValues(void)
|
||||
@@ -204,23 +206,19 @@ static void FetchSensorValues(void)
|
||||
float t[6], rh[3], td[3];
|
||||
|
||||
Print("\r\n");
|
||||
Info("Reading sensor values...");
|
||||
Info("Fetching sensor values...");
|
||||
|
||||
I2C_SetChannel(AHT01);
|
||||
I2C_AHT20_Read(&t[0], &rh[0]);
|
||||
|
||||
I2C_SetChannel(AHT02);
|
||||
I2C_AHT20_Read(&t[1], &rh[1]);
|
||||
|
||||
I2C_SetChannel(AHT03);
|
||||
I2C_AHT20_Read(&t[2], &rh[2]);
|
||||
|
||||
raw = I2C_ADS1115_ReadRaw(ADS01);
|
||||
t[3] = SteinhartHart(Resistance(raw));
|
||||
|
||||
raw = I2C_ADS1115_ReadRaw(ADS02);
|
||||
t[4] = SteinhartHart(Resistance(raw));
|
||||
|
||||
raw = I2C_ADS1115_ReadRaw(ADS03);
|
||||
t[5] = SteinhartHart(Resistance(raw));
|
||||
|
||||
@@ -230,7 +228,7 @@ static void FetchSensorValues(void)
|
||||
|
||||
temp = (t[0] + t[1] + t[2]) / 3;
|
||||
rhum = (rh[0] + rh[1] + rh[2]) / 3;
|
||||
dewp = Dewpoint(temp, rhum);
|
||||
dewp = (td[0] + td[1] + td[2]) / 3;
|
||||
|
||||
Info("T1=%.2fC, TD1=%.2fC, RH1=%.2f%%, NT1=%.2fC", t[0], td[0], rh[0], t[3]);
|
||||
Info("T2=%.2fC, TD2=%.2fC, RH2=%.2f%%, NT2=%.2fC", t[1], td[1], rh[1], t[4]);
|
||||
|
||||
Reference in New Issue
Block a user