ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
FanController.h
Go to the documentation of this file.
1/**
2 * @file FanController.h
3 * @brief Declares the FanController class for managing PWM-based fan speed control.
4 *
5 * This file defines the FanController class, which provides methods for initializing
6 * and controlling a fan using PWM signals, as well as setting speed as a ratio.
7 *
8 * @date 22/12/2024
9 * @author Coela Can't
10 */
11
12#pragma once
13
14#include <Arduino.h> // Include for Arduino compatibility.
15#include "../../Utils/Math/Mathematics.h" // Include for mathematical utilities.
16
17/**
18 * @class FanController
19 * @brief Manages PWM-based fan speed control.
20 *
21 * The FanController class provides functionality for initializing a fan, setting its
22 * speed using PWM signals, and retrieving the current PWM value.
23 */
25private:
26 uint8_t pin; ///< The pin number connected to the fan's PWM input.
27 uint8_t pwm; ///< The current PWM value (0-255).
28
29public:
30 /**
31 * @brief Constructs a FanController with the specified pin.
32 *
33 * @param pin The pin number connected to the fan's PWM input.
34 */
35 FanController(uint8_t pin);
36
37 /**
38 * @brief Initializes the fan controller by setting up the pin for PWM output.
39 */
40 void Initialize();
41
42 /**
43 * @brief Sets the PWM value to control the fan speed.
44 *
45 * @param pwm The PWM value (0-255) to set.
46 */
47 void SetPWM(uint8_t pwm);
48
49 /**
50 * @brief Sets the fan speed as a ratio of its maximum speed.
51 *
52 * @param ratio A float value between 0.0 and 1.0 representing the speed ratio.
53 */
54 void SetSpeed(float ratio);
55
56 /**
57 * @brief Retrieves the current PWM value.
58 *
59 * @return The current PWM value (0-255).
60 */
61 uint8_t GetPWM();
62};
Manages PWM-based fan speed control.
uint8_t GetPWM()
Retrieves the current PWM value.
void SetSpeed(float ratio)
Sets the fan speed as a ratio of its maximum speed.
void Initialize()
Initializes the fan controller by setting up the pin for PWM output.
uint8_t pwm
The current PWM value (0-255).
uint8_t pin
The pin number connected to the fan's PWM input.
void SetPWM(uint8_t pwm)
Sets the PWM value to control the fan speed.