Corsair Lighting Protocol  0.15.0
Control LEDs connected to an Arduino with iCUE
SimpleFanController.h
1 /*
2  Copyright 2019 Leon Kiefer
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 #pragma once
17 
18 #include "Arduino.h"
19 #include "FanController.h"
20 #include "PWMFan.h"
21 #include "TemperatureController.h"
22 
23 #define FAN_CONTROL_MODE_FIXED_POWER 0
24 #define FAN_CONTROL_MODE_FIXED_RPM 1
25 #define FAN_CONTROL_MODE_CURVE 2
26 
27 struct FanData {
28  uint8_t mode = FAN_CONTROL_MODE_FIXED_POWER;
29  uint8_t power = 0;
30  uint16_t speed = 0;
32  uint8_t tempGroup;
33  FanCurve fanCurve;
34 };
35 
41 public:
49  SimpleFanController(TemperatureController* temperatureController, uint16_t updateRate, uint16_t eEPROMAdress);
56  void addFan(uint8_t index, PWMFan* fan);
60  virtual bool updateFans();
61 
62 protected:
63  virtual uint16_t getFanSpeed(uint8_t fan) override;
64  virtual void setFanSpeed(uint8_t fan, uint16_t speed) override;
65  virtual uint8_t getFanPower(uint8_t fan) override;
66  virtual void setFanPower(uint8_t fan, uint8_t percentage) override;
67  virtual void setFanCurve(uint8_t fan, uint8_t group, FanCurve& fanCurve) override;
68  virtual void setFanExternalTemperature(uint8_t fan, uint16_t temp) override;
69  virtual void setFanForce3PinMode(bool flag) override;
70  virtual FanDetectionType getFanDetectionType(uint8_t fan) override;
71  virtual void setFanDetectionType(uint8_t fan, FanDetectionType type) override;
72  bool load();
73  bool save();
74 
75  TemperatureController* const temperatureController;
76  PWMFan* fans[FAN_NUM] = {nullptr};
77  bool force3PinMode = false;
78  FanData fanData[FAN_NUM];
79  uint16_t externalTemp[FAN_NUM];
80  uint16_t updateRate;
81  uint16_t eEPROMAdress;
85  bool triggerSave = false;
86  unsigned long lastUpdate = 0;
87 };
FanDetectionType
Definition: FanController.h:49
Definition: FanController.h:88
Definition: PWMFan.h:20
Definition: SimpleFanController.h:40
virtual bool updateFans()
Definition: SimpleFanController.cpp:41
virtual void setFanForce3PinMode(bool flag) override
Definition: SimpleFanController.cpp:129
SimpleFanController(TemperatureController *temperatureController, uint16_t updateRate, uint16_t eEPROMAdress)
Definition: SimpleFanController.cpp:20
virtual FanDetectionType getFanDetectionType(uint8_t fan) override
Definition: SimpleFanController.cpp:133
virtual void setFanSpeed(uint8_t fan, uint16_t speed) override
Definition: SimpleFanController.cpp:100
bool triggerSave
Definition: SimpleFanController.h:85
virtual void setFanExternalTemperature(uint8_t fan, uint16_t temp) override
Definition: SimpleFanController.cpp:125
virtual uint16_t getFanSpeed(uint8_t fan) override
Definition: SimpleFanController.cpp:96
void addFan(uint8_t index, PWMFan *fan)
Definition: SimpleFanController.cpp:26
virtual void setFanPower(uint8_t fan, uint8_t percentage) override
Definition: SimpleFanController.cpp:111
virtual uint8_t getFanPower(uint8_t fan) override
Definition: SimpleFanController.cpp:107
virtual void setFanDetectionType(uint8_t fan, FanDetectionType type) override
Definition: SimpleFanController.cpp:137
virtual void setFanCurve(uint8_t fan, uint8_t group, FanCurve &fanCurve) override
Definition: SimpleFanController.cpp:118
Definition: TemperatureController.h:38
Definition: FanController.h:73
Definition: SimpleFanController.h:27