|
|
|
@ -12,9 +12,11 @@ |
|
|
|
|
struct FanControlState gState = {}; |
|
|
|
|
|
|
|
|
|
static void timerCallback(TimerHandle_t xTimer); |
|
|
|
|
|
|
|
|
|
static void invalidate_temps(); |
|
|
|
|
|
|
|
|
|
void settings_blind_time_set(uint16_t blind_time) { |
|
|
|
|
void settings_blind_time_set(uint16_t blind_time) |
|
|
|
|
{ |
|
|
|
|
bool nadoraz = (gState.blind_position >= gSettings.blind_time) || (gState.blind_position >= blind_time); |
|
|
|
|
|
|
|
|
|
gSettings.blind_time = blind_time; |
|
|
|
@ -26,7 +28,8 @@ void settings_blind_time_set(uint16_t blind_time) { |
|
|
|
|
settings_persist(SETTINGS_blind_time); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fancontrol_init() { |
|
|
|
|
void fancontrol_init() |
|
|
|
|
{ |
|
|
|
|
gState.set_vent_mode = gSettings.initial_mode; |
|
|
|
|
gState.set_power = gSettings.initial_power; |
|
|
|
|
|
|
|
|
@ -38,7 +41,8 @@ void fancontrol_init() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void timerCallback(TimerHandle_t xTimer) { |
|
|
|
|
static void timerCallback(TimerHandle_t xTimer) |
|
|
|
|
{ |
|
|
|
|
// posun rolety
|
|
|
|
|
if (gAct.blind) { |
|
|
|
|
if (gState.blind_position < gSettings.blind_time) { |
|
|
|
@ -119,26 +123,22 @@ static void timerCallback(TimerHandle_t xTimer) { |
|
|
|
|
do_switch = true; |
|
|
|
|
} else { |
|
|
|
|
// temp-based switching - magic(tm)
|
|
|
|
|
// Delta = IN - OUT
|
|
|
|
|
const int16_t ideal_delta = gState.t_indoor - gState.t_outdoor; |
|
|
|
|
int16_t delta, stop_delta; |
|
|
|
|
int16_t stop_delta = ((int32_t) ideal_delta |
|
|
|
|
* (int32_t) (100 - gSettings.recup_factor)) / 100; |
|
|
|
|
int16_t delta; |
|
|
|
|
bool allow_temp_switch = false; |
|
|
|
|
|
|
|
|
|
if (gState.real_direction == MOTOR_DIR_OUT) { |
|
|
|
|
delta = gState.t_indoor - gState.t_exhaust; |
|
|
|
|
// 100% factor = nadoraz
|
|
|
|
|
stop_delta = ((int32_t)ideal_delta |
|
|
|
|
* (int32_t)(100 - gSettings.recup_factor)) / 100; |
|
|
|
|
// Delta = IN - OUT
|
|
|
|
|
if (gState.valid_t_indoor && gState.valid_t_exhaust && gState.valid_t_outdoor) { |
|
|
|
|
delta = gState.t_indoor - gState.t_exhaust; |
|
|
|
|
allow_temp_switch = true; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// IN
|
|
|
|
|
delta = gState.t_inflow - gState.t_outdoor; |
|
|
|
|
// 100% factor = nadoraz
|
|
|
|
|
stop_delta = ((int32_t)ideal_delta |
|
|
|
|
* (int32_t)(gSettings.recup_factor)) / 100; |
|
|
|
|
// Delta = IN - OUT
|
|
|
|
|
if (gState.valid_t_intake && gState.valid_t_indoor && gState.valid_t_outdoor) { |
|
|
|
|
if (gState.valid_t_inflow && gState.valid_t_indoor && gState.valid_t_outdoor) { |
|
|
|
|
delta = gState.t_inflow - gState.t_outdoor; |
|
|
|
|
allow_temp_switch = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -188,13 +188,13 @@ static void timerCallback(TimerHandle_t xTimer) { |
|
|
|
|
|
|
|
|
|
if (end_temp_meas) { |
|
|
|
|
if (gState.t_aggr_cnt > 0) { |
|
|
|
|
uint16_t t1 = (uint16_t) (gState.t1_aggr / gState.t_aggr_cnt); |
|
|
|
|
uint16_t t2 = (uint16_t) (gState.t2_aggr / gState.t_aggr_cnt); |
|
|
|
|
int16_t t1 = (int16_t) (gState.t1_aggr / (int32_t)gState.t_aggr_cnt); |
|
|
|
|
int16_t t2 = (int16_t) (gState.t2_aggr / (int32_t)gState.t_aggr_cnt); |
|
|
|
|
switch (gState.real_direction) { |
|
|
|
|
case MOTOR_DIR_IN: |
|
|
|
|
gState.t_outdoor = t2; |
|
|
|
|
gState.t_inflow = t1; |
|
|
|
|
gState.valid_t_outdoor = gState.valid_t_intake = true; |
|
|
|
|
gState.valid_t_outdoor = gState.valid_t_inflow = true; |
|
|
|
|
if (gState.effective_vent_mode == VENT_MODE_IN) { |
|
|
|
|
gState.valid_t_indoor = gState.valid_t_exhaust = false; |
|
|
|
|
} |
|
|
|
@ -204,20 +204,21 @@ static void timerCallback(TimerHandle_t xTimer) { |
|
|
|
|
gState.t_exhaust = t2; |
|
|
|
|
gState.valid_t_indoor = gState.valid_t_exhaust = true; |
|
|
|
|
if (gState.effective_vent_mode == VENT_MODE_OUT) { |
|
|
|
|
gState.valid_t_outdoor = gState.valid_t_intake = false; |
|
|
|
|
gState.valid_t_outdoor = gState.valid_t_inflow = false; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
gState.t1_aggr = gState.t2_aggr = gState.t_aggr_cnt = 0; |
|
|
|
|
gState.t1_aggr = gState.t2_aggr = 0; |
|
|
|
|
gState.t_aggr_cnt = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (gState.effective_vent_mode == VENT_MODE_IN |
|
|
|
|
|| gState.effective_vent_mode == VENT_MODE_OUT |
|
|
|
|
|| gState.effective_vent_mode == VENT_MODE_RECUP) { |
|
|
|
|
// Measure temperatures
|
|
|
|
|
int16_t t1 = 200; |
|
|
|
|
int16_t t2 = 190; // TODO
|
|
|
|
|
int16_t t1 = act_temp_in(); |
|
|
|
|
int16_t t2 = act_temp_out(); |
|
|
|
|
|
|
|
|
|
gState.t_actual_1 = t1; |
|
|
|
|
gState.t_actual_2 = t2; |
|
|
|
@ -225,7 +226,8 @@ static void timerCallback(TimerHandle_t xTimer) { |
|
|
|
|
gState.valid_t_actual_1 = gState.valid_t_actual_2 = true; |
|
|
|
|
|
|
|
|
|
if (gAct.dir == gState.real_direction |
|
|
|
|
&& gState.ramp >= gSettings.ramp_time) { |
|
|
|
|
&& gState.ramp >= gSettings.ramp_time) |
|
|
|
|
{ |
|
|
|
|
gState.t1_aggr += t1; |
|
|
|
|
gState.t2_aggr += t2; |
|
|
|
|
gState.t_aggr_cnt++; |
|
|
|
@ -235,7 +237,8 @@ static void timerCallback(TimerHandle_t xTimer) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fan_set_vent_mode(enum ventilation_mode mode) { |
|
|
|
|
void fan_set_vent_mode(enum ventilation_mode mode) |
|
|
|
|
{ |
|
|
|
|
if (mode == gState.set_vent_mode) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -253,16 +256,18 @@ void fan_set_vent_mode(enum ventilation_mode mode) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void invalidate_temps() { |
|
|
|
|
static void invalidate_temps() |
|
|
|
|
{ |
|
|
|
|
gState.valid_t_indoor = false; |
|
|
|
|
gState.valid_t_outdoor = false; |
|
|
|
|
gState.valid_t_intake = false; |
|
|
|
|
gState.valid_t_inflow = false; |
|
|
|
|
gState.valid_t_exhaust = false; |
|
|
|
|
gState.valid_t_actual_1 = false; |
|
|
|
|
gState.valid_t_actual_2 = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fan_set_power(uint16_t power) { |
|
|
|
|
void fan_set_power(uint16_t power) |
|
|
|
|
{ |
|
|
|
|
gState.set_power = power; |
|
|
|
|
if (power == 0) { |
|
|
|
|
gState.effective_vent_mode = VENT_MODE_OFF; |
|
|
|
@ -270,4 +275,4 @@ void fan_set_power(uint16_t power) { |
|
|
|
|
} else { |
|
|
|
|
gState.effective_vent_mode = gState.set_vent_mode; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|