recuperator fan control with esp32
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
esp-recuperator/main/fancontrol.h

100 lines
2.4 KiB

//
// Created by MightyPork on 2022/08/20.
//
#ifndef FANCTL_FANCONTROL_H
#define FANCTL_FANCONTROL_H
#include <stdint.h>
#include "actuators.h"
void fancontrol_init();
/** this is bit-based: IN:OUT:BLIND */
enum ventilation_mode {
VENT_MODE_OFF = 0,
VENT_MODE_FREE = 1,
VENT_MODE_OUT = 3,
VENT_MODE_IN = 5,
VENT_MODE_RECUP = 7,
};
enum recup_mode {
/** stricly time based recuperation switching */
RECUP_MODE_TIME = 0,
/** Temperature-based recuperation switching
* (switch direction when further blowing won't save energy) */
RECUP_MODE_TEMP = 1,
};
struct FanControlState {
/**
* Power requested trough register or as the default value.
* This value stays unchanged even if stopped, unlike gAct.power which reflects the actual output.
*/
perc_t set_power;
/**
* rezim ventilace. Use fan_set_vent_mode() to change it!
*/
enum ventilation_mode set_vent_mode;
/** Status for the register */
enum ventilation_mode instantaneous_vent_mode;
/* sensors */
bool valid_t_indoor;
bool valid_t_outdoor;
bool valid_t_inflow;
bool valid_t_exhaust;
bool valid_t_actual_in;
bool valid_t_actual_out;
cels_t t_indoor;
cels_t t_outdoor;
cels_t t_inflow;
cels_t t_exhaust;
uint16_t lastTempsSerial;
cels_t t_actual_in;
cels_t t_actual_out;
secs_t real_recup_time_in;
secs_t real_recup_time_out;
// Private
/**
* like vent_mode, but if power is 0, becomes OFF
*/
enum ventilation_mode effective_vent_mode;
/**
* skutecny aktualni pohyb motoru (zustava stejny, dokud ramp time nedosahne nuly)
*/
enum motor_direction real_direction;
/**
* Poloha roletky, 0<->blind_time, inkrement/dekrement 1 za sekundu.
* Pri zmene blind_time se musi hodnota aktualizovat, pokud je na doraze nebo za.
*/
secs_t blind_position;
/**
* Cas chodu motoru v aktualnim smeru, inkrement 1 za sekundu.
*/
secs_t run_time;
/**
* "stav chodu motoru". 0=stop, ramp_time = jede.
*/
secs_t ramp;
// helper counters that increment hour counters when overflow
secs_t uptime_secs;
hours_t motor_secs;
secs_t uptime_hours;
hours_t motor_hours;
};
extern struct FanControlState gState;
void fan_set_vent_mode(enum ventilation_mode mode);
void fan_set_power(perc_t power);
#endif //FANCTL_FANCONTROL_H