/* Copyright (c) 2025 Rodrigo Arias Mallo * SPDX-License-Identifier: GPL-3.0-or-later */ #include "thermostat.h" #define DELTA_LOW 1.0 #define DELTA_HIGH 1.0 void thermostat_set(struct thermostat *th, float temp_target) { if (th->st == THERMOSTAT_ON && th->temp_target == temp_target) return; th->st = THERMOSTAT_ON; th->temp_target = temp_target; th->temp_min = temp_target - DELTA_LOW; th->temp_max = temp_target + DELTA_HIGH; th->on = 1; } void thermostat_off(struct thermostat *th) { th->st = THERMOSTAT_OFF; th->on = 0; } int thermostat_state(struct thermostat *th, float temp) { if (th->st == THERMOSTAT_OFF) return 0; if (th->on && temp > th->temp_max) th->on = 0; else if (!th->on && temp < th->temp_min) th->on = 1; return th->on; }