#include "sensor.h"
#include "switch.h"
#include "fsm.h"
#include <why-timer.h>
#include <why-irq.h>
#include <why-time.h>
#include <print>
int main()
{
Why::init();
Sensor sensor("/tmp/plant/temperature");
Switch cooling_switch("/tmp/plant/cooling");
Switch soft_alarm("/tmp/plant/soft-alarm");
Switch hard_alarm("/tmp/plant/hard-alarm");
const long LOW_TEMP = 20;
const long HIGH_TEMP = 500'000;
const long SOFT_ALARM_TEMP = 1'000'000;
const int SENSOR_BURNING_IRQ = 7;
const int OPERATOR_BUTTON_IRQ = 42;
std::println("* Thermostat lo: {}", LOW_TEMP);
std::println("* Thermostat hi: {}", HIGH_TEMP);
std::println("* Soft critical: {}", SOFT_ALARM_TEMP);
std::println("* Cooling switch: {}", cooling_switch.path());
std::println("* Soft alarm: {}", soft_alarm.path());
std::println("* Hard alarm: {}", hard_alarm.path());
std::println("* Sensor burning IRQ: {}", SENSOR_BURNING_IRQ);
std::println("* Operator button IRQ: {}", OPERATOR_BUTTON_IRQ);
FSM fsm(
Why::TimeSpec(0, 1'000'000), // <-- 1ms update interval
SENSOR_BURNING_IRQ, hard_alarm, // <-- "sensor-burning" irq, and associated alarm
SOFT_ALARM_TEMP, soft_alarm, // <-- "a little too high", and associated alarm
OPERATOR_BUTTON_IRQ, // <-- "operator button pressed" irq
sensor, cooling_switch, // <-- thermostat operation
LOW_TEMP, HIGH_TEMP // <-- thermostat operation
);
fsm.start(); // <-- activate interrupts, timer, ...
Why::pause(); // <-- sit idle
return 0;
}