Define basic structure for primary state machine and update TODOs

This commit is contained in:
2024-09-16 00:49:36 +02:00
parent c3d5a83ebd
commit 851e456ea5

View File

@@ -6,17 +6,31 @@
#include <avr/interrupt.h>
// TODO: Implement primary state machine for update loop.
// TODO: Migrate to ATMega 1284P-PU for 2nd 16-bit timer.
// TODO: Keep persistent TEMP and DEWP targets in EEPROM.
// TODO: Check thermistor conversion results /w thermometer.
// TODO: Implement optional CRC8 sensor measurement check.
// TODO: Either implement software PWM for the FAN03 timer
// (which will be quite complicated) or pick a chip with
// more than two 16-bit PWM outputs like the ATmega328PB.
// https://www.mikrocontroller.net/articles/Soft-PWM
// TODO: Check if FAN02 is receiving the right frequency.
// TODO: Use 18.432MHz quarz crystal, burn required fuses.
// TODO: Write an improved command parser (low priority).
// TODO: Proper error handling and recovery (after testing).
enum state_e
{
S_IDLE,
S_HEAT_UP,
S_COOL_DOWN,
S_DEHUMIDIFY
};
static enum state_e state;
static float temp, temp_target;
static float dewp, dewp_target;
static int Init(void)
{
state = S_IDLE;
// MOSFETS control things like the heating element
// so they are the highest priority to initialize
// to a default state via MOS_Init().
@@ -96,32 +110,46 @@ static int Init(void)
static void Update(void)
{
float temp[3], rh[3];
float t[3], rh[3];
float adct[3];
Info("Reading sensor values...");
I2C_SetChannel(AHT01);
I2C_AHT20_Read(&temp[0], &rh[0]);
I2C_AHT20_Read(&t[0], &rh[0]);
I2C_SetChannel(AHT02);
I2C_AHT20_Read(&temp[1], &rh[1]);
I2C_AHT20_Read(&t[1], &rh[1]);
I2C_SetChannel(AHT03);
I2C_AHT20_Read(&temp[2], &rh[2]);
I2C_AHT20_Read(&t[2], &rh[2]);
adct[0] = I2C_ADS1115_ReadThermistor(ADS01);
adct[1] = I2C_ADS1115_ReadThermistor(ADS02);
adct[2] = I2C_ADS1115_ReadThermistor(ADS03);
Info("TEMP1=%.2fC, RH1=%.2f%% ADCT1=%.2fC", temp[0], rh[0], adct[0]);
Info("TEMP2=%.2fC, RH2=%.2f%% ADCT2=%.2fC", temp[1], rh[1], adct[1]);
Info("TEMP3=%.2fC, RH3=%.2f%% ADCT3=%.2fC", temp[2], rh[2], adct[2]);
Info("T1=%.2fC, RH1=%.2f%%, ADCT1=%.2fC", t[0], rh[0], adct[0]);
Info("T2=%.2fC, RH2=%.2f%%, ADCT2=%.2fC", t[1], rh[1], adct[1]);
Info("T3=%.2fC, RH3=%.2f%%, ADCT3=%.2fC", t[2], rh[2], adct[2]);
// TODO: Implement state machine
// TODO: Handle serial commands
// Inputs: TEMP, DEWP
// States: IDLE, DEHUMIDIFY, HEATUP, COOLDOWN
switch (state) {
case S_IDLE:
break;
case S_HEAT_UP:
break;
case S_COOL_DOWN:
break;
case S_DEHUMIDIFY:
break;
}
UNUSED(temp);
UNUSED(dewp);
UNUSED(temp_target);
UNUSED(dewp_target);
}
int main(void)