armchair_fw/main/fan.hpp
jonny_l480 be40a8c2d3 Rework fan control: single pin, more delay, config
- remove second fan instance since both fans are controlled via one pin
  now
- more config options so fans turn on less at short movements
  => less noise and less relay cycles
2023-08-15 19:39:37 +02:00

50 lines
1.0 KiB
C++

#pragma once
extern "C"
{
#include "driver/gpio.h"
}
#include "motorctl.hpp"
//struct with all config parameters for a fan
typedef struct fan_config_t {
gpio_num_t gpio_fan;
float dutyThreshold;
uint32_t minOnMs;
uint32_t minOffMs;
uint32_t turnOffDelayMs;
} fan_config;
//==================================
//====== controlledFan class =======
//==================================
class controlledFan {
public:
//--- constructor ---
controlledFan (fan_config_t config_f, controlledMotor* motor1_f, controlledMotor* motor2_f );
//--- functions ---
void handle();
private:
//--- variables ---
bool fanRunning = false;
bool needsCooling = false;
uint32_t timestamp_needsCoolingSet;
uint32_t timestamp_lastThreshold = 0;
uint32_t timestamp_turnedOn = 0;
uint32_t timestamp_turnedOff = 0;
fan_config_t config;
controlledMotor * motor1;
controlledMotor * motor2;
motorCommand_t motor1Status;
motorCommand_t motor2Status;
};