Skip to content

Commit a60e04b

Browse files
authored
Merge pull request #83 from Legion2/documentation
Improve the API Documentation
2 parents b57087e + dbeab2a commit a60e04b

28 files changed

+611
-186
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ Then the third argument of the `scale` function is `144`.
126126
For both functions it's **important**, that the CRGB arrays have at least the length of the physical LED strip.
127127
This means if your LED channel from iCUE has 50 LEDs and you use the `repeat` function to control 100 physical LEDs you MUST declare the CRGB array at least with a length of 100.
128128

129+
# License
130+
This project is licensed under the Apache 2.0 License.
131+
129132
# DISCLAIMERS
130133
This is a DO IT YOURSELF project, use at your own risk!
131134

examples/CommanderPRO/PWMFan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PWMFan::PWMFan(uint8_t pwmPin, uint16_t minRPM ,uint16_t maxRPM) : pwmPin(pwmPin
2323
case TIMER0B:/* 3 */
2424
#ifdef DEBUG
2525
Serial.println(F("Pin not supported as PWM fan pin"));
26-
Serial.println(F("We don't want to mess up arduino time functions"));
26+
Serial.println(F("We don't want to mess up Arduino time functions"));
2727
#endif // DEBUG
2828
break;
2929
case TIMER3A:/* 5 */

examples/CommanderPRO/PWMFan.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919

2020
class PWMFan {
2121
public:
22-
// minRPM should be the rpm value at 0% power and maxRPM at 100% power
23-
// These values are used to map speed to power using linear interpolation
22+
/**
23+
* PWM fan which maps speed to power using linear interpolation.
24+
* This fan does not read the real RPM values. The Arduino timer for the given pin will be set to higher speed.
25+
*
26+
* @param pwmPin the Arduino pwm pin for this fan. Not all PWM pins are supported.
27+
* @param minRPM the speed in RPM at 0% power
28+
* @param maxRPM the speed in RPM at 100% power
29+
*/
2430
PWMFan(uint8_t pwmPin, uint16_t minRPM, uint16_t maxRPM);
2531
virtual void setPower(uint8_t percentage);
2632
virtual uint8_t calculatePowerFromSpeed(uint16_t rpm);

examples/CommanderPRO/SimpleFanController.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ bool SimpleFanController::updateFans()
4545
long currentUpdateNumber = currentUpdate / updateRate;
4646
lastUpdate = currentUpdate;
4747
if (lastUpdateNumber < currentUpdateNumber) {
48-
if (trigger_save) {
49-
trigger_save = false;
48+
if (triggerSave) {
49+
triggerSave = false;
5050
save();
5151
}
5252

@@ -106,7 +106,7 @@ void SimpleFanController::setFanSpeed(uint8_t fan, uint16_t speed)
106106
fanData[fan].speed = speed;
107107
fanData[fan].mode = FAN_CONTROL_MODE_FIXED_RPM;
108108
fanData[fan].power = fans[fan] != nullptr ? fans[fan]->calculatePowerFromSpeed(speed) : 0;
109-
trigger_save = true;
109+
triggerSave = true;
110110
}
111111

112112
uint8_t SimpleFanController::getFanPower(uint8_t fan)
@@ -119,15 +119,15 @@ void SimpleFanController::setFanPower(uint8_t fan, uint8_t percentage)
119119
fanData[fan].power = percentage;
120120
fanData[fan].mode = FAN_CONTROL_MODE_FIXED_POWER;
121121
fanData[fan].speed = fans[fan] != nullptr ? fans[fan]->calculateSpeedFromPower(percentage) : 0;
122-
trigger_save = true;
122+
triggerSave = true;
123123
}
124124

125125
void SimpleFanController::setFanCurve(uint8_t fan, uint8_t group, FanCurve& fanCurve)
126126
{
127127
fanData[fan].fanCurve = fanCurve;
128128
fanData[fan].tempGroup = group;
129129
fanData[fan].mode = FAN_CONTROL_MODE_CURVE;
130-
trigger_save = true;
130+
triggerSave = true;
131131
}
132132

133133
void SimpleFanController::setFanExternalTemperature(uint8_t fan, uint16_t temp)
@@ -140,16 +140,16 @@ void SimpleFanController::setFanForce3PinMode(bool flag)
140140
force3PinMode = flag;
141141
}
142142

143-
uint8_t SimpleFanController::getFanDetectionType(uint8_t fan)
143+
FanDetectionType SimpleFanController::getFanDetectionType(uint8_t fan)
144144
{
145145
return fanData[fan].detectionType;
146146
}
147147

148-
void SimpleFanController::setFanDetectionType(uint8_t fan, uint8_t type)
148+
void SimpleFanController::setFanDetectionType(uint8_t fan, FanDetectionType type)
149149
{
150150
if (fanData[fan].detectionType != type) {
151151
fanData[fan].detectionType = type;
152-
trigger_save = true;
152+
triggerSave = true;
153153
}
154154
}
155155

examples/CommanderPRO/SimpleFanController.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,35 @@ struct FanData {
2828
uint8_t mode = FAN_CONTROL_MODE_FIXED_POWER;
2929
uint8_t power = 0;
3030
uint16_t speed = 0;
31-
uint8_t detectionType = FAN_DETECTION_TYPE_DISCONNECTED;
31+
FanDetectionType detectionType = FanDetectionType::Disconnected;
3232
uint8_t tempGroup;
3333
FanCurve fanCurve;
3434
};
3535

36-
// This simple Fan Controller implementation does not implement all features of a Fan Controller.
37-
// It should only demonstrate how to implement your own Fan Controller.
36+
/**
37+
* This simple Fan Controller implementation does not implement all features of a Fan Controller.
38+
* It should only demonstrate how to implement your own Fan Controller.
39+
*/
3840
class SimpleFanController : public FanController {
3941
public:
40-
// Fan Contorller must use the EEPROM else on startup the fans can't be controlled
41-
// updateRate it the time between fan speed updates in ms
42+
/**
43+
* Fan Controller must use the EEPROM else on startup the fans can't be controlled
44+
*
45+
* @param temperatureController the TemperatureController used to get the temperature to control the fans
46+
* @param updateRate is the time between fan speed updates in ms
47+
* @param eEPROMAdress the address where the data is stored in EEPROM
48+
*/
4249
SimpleFanController(TemperatureController* temperatureController, uint16_t updateRate, uint16_t eEPROMAdress);
50+
/**
51+
* Add a fan to the Controller.
52+
*
53+
* @param index the index of the fan
54+
* @param fan the fan object
55+
*/
4356
void addFan(uint8_t index, PWMFan* fan);
57+
/**
58+
* Update the fan speeds based on the temperature and commands.
59+
*/
4460
virtual bool updateFans();
4561
protected:
4662
virtual uint16_t getFanSpeed(uint8_t fan) override;
@@ -50,8 +66,8 @@ class SimpleFanController : public FanController {
5066
virtual void setFanCurve(uint8_t fan, uint8_t group, FanCurve& fanCurve) override;
5167
virtual void setFanExternalTemperature(uint8_t fan, uint16_t temp) override;
5268
virtual void setFanForce3PinMode(bool flag) override;
53-
virtual uint8_t getFanDetectionType(uint8_t fan) override;
54-
virtual void setFanDetectionType(uint8_t fan, uint8_t type) override;
69+
virtual FanDetectionType getFanDetectionType(uint8_t fan) override;
70+
virtual void setFanDetectionType(uint8_t fan, FanDetectionType type) override;
5571
bool load();
5672
bool save();
5773

@@ -62,6 +78,9 @@ class SimpleFanController : public FanController {
6278
uint16_t externalTemp[FAN_NUM];
6379
uint16_t updateRate;
6480
uint16_t eEPROMAdress;
65-
bool trigger_save = false;
81+
/**
82+
* Indicates that the configuration of the fans has been changed and should be saved.
83+
*/
84+
bool triggerSave = false;
6685
long lastUpdate = 0;
6786
};

examples/CommanderPRO/ThermistorTemperatureController.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@
1616
#pragma once
1717

1818
#include "TemperatureController.h"
19-
/*
20-
Thermistor Schematic :
21-
| ---- [10k - Resistor] ----- | ----- [Thermistor] ---- |
22-
| | |
23-
[Ground] Analog Pin [+5v]
24-
*/
19+
/**
20+
* This TemperatureController uses Thermistors and Resistors to messure the temperature. It does not implement the voltage rail measurements.
21+
*
22+
* Thermistor Schematic:
23+
* <pre>
24+
* | ---- [10k - Resistor] ---- | ---- [Thermistor] ---- |
25+
* | | |
26+
* [Ground] Analog Pin [+5v]
27+
* </pre>
28+
*/
2529
class ThermistorTemperatureController : public TemperatureController {
2630
public:
31+
/**
32+
* Add a Sensor to the TemperatureController using an Arduino analog pin connected as shown in {@link ThermistorTemperatureController}.
33+
*
34+
* @param index the index of the sensorPins
35+
* @param pin the Arduino analog pin
36+
*/
2737
void addSensor(uint8_t index, uint8_t pin);
2838
protected:
2939
virtual uint16_t getTemperatureValue(uint8_t temperatureSensor) override;

examples/SingleStripLightingNodePRO/SingleStripLightingNodePRO.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// The number of LEDs per channel.
2020
#define CHANNEL_LED_COUNT 50
2121

22-
// Total count of LEDs on all channels, the value is calculated based on the leds per channel.
22+
// Total count of LEDs on all channels, the value is calculated based on the LEDs per channel.
2323
#define NUM_LEDS (CHANNEL_LED_COUNT * 2)
2424

2525
// The Arduino pin where the physical LEDs are connected.

src/CLPUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace CLP
5858
bool isResetID(const uint8_t* deviceId);
5959

6060
/**
61-
* This will disable the RX and TX built in leds on Arduino Leonardo, Micro and Pro Micro.
61+
* This will disable the RX and TX built in LEDs on Arduino Leonardo, Micro and Pro Micro.
6262
*/
6363
void disableBuildInLEDs();
6464

src/CorsairLightingNodePRO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Arduino.h"
1919
#include "CorsairLightingFirmware.h"
2020
#include "FastLEDController.h"
21-
#include "CorsairLightingProtocol.h"
21+
#include "CorsairLightingProtocolController.h"
2222
#include "CorsairLightingProtocolHID.h"
2323
#include <FastLED.h>
2424

src/CorsairLightingProtocol.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
#pragma once
1717

18-
// central include file for CorsairLightingProtocolController
18+
/**
19+
* @file
20+
* The central include file for CorsairLightingProtocol.
21+
*/
1922
#include "CorsairLightingFirmware.h"
2023
#include "CorsairLightingNodePRO.h"
2124
#include "CorsairLightingProtocolConstants.h"

src/CorsairLightingProtocolController.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ class CorsairLightingProtocolController
3232
{
3333
public:
3434
/**
35-
* The constructor used to create a Lighting Node PRO.
36-
*
35+
* The constructor used to create a Lighting only device.
36+
*
3737
* @param l The LEDController which should be used to control the LEDs of the created Lighting Node PRO
3838
* @param c The CorsairLightingFirmware used to handle Firmware related commands
3939
*/
4040
CorsairLightingProtocolController(ILEDController* l, CorsairLightingFirmware* c);
4141
/**
42-
* The constructor used to create a Commander PRO.
43-
*
42+
* The constructor used to create a device with lighting, temperature and fan controller functionality (Commander PRO).
43+
*
4444
* @param l The LEDController which should be used to control the LEDs of the created Commander PRO
4545
* @param t The TemperatureController which used to messure the temperature of the created Commander PRO
4646
* @param f The FanController used to control the fans of the created Commander PRO
4747
* @param c The CorsairLightingFirmware used to handle Firmware related commands
4848
*/
4949
CorsairLightingProtocolController(ILEDController* l, ITemperatureController* t, IFanController* f, CorsairLightingFirmware* c);
5050
/**
51-
* The only public function of the CorsairLightingProtocolController. It must be called to process a command with was received from iCUE. This
52-
* function is normaly called by CorsairLightingProtocolHID and CorsairLightingProtocolSerial adapters.
53-
*
51+
* The only public function of the CorsairLightingProtocolController. It must be called to process a command which was received from iCUE.
52+
* This function is normally called by CorsairLightingProtocolHID and CorsairLightingProtocolSerial adapters.
53+
*
5454
* @param command The command received from iCUE
5555
* @param response The response callback which can be called to response to the command
5656
*/

src/CorsairLightingProtocolHID.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ bool printCommand = PRINT_COMMAND;
2727
bool printResponse = PRINT_RESPONSE;
2828
#endif
2929

30-
CorsairLightingProtocolHID::CorsairLightingProtocolHID(CorsairLightingProtocolController* cLP) : cLP(cLP)
30+
CorsairLightingProtocolHID::CorsairLightingProtocolHID(CorsairLightingProtocolController* controller) : controller(controller)
3131
{
3232
RawHID.begin(rawhidData, sizeof(rawhidData));
3333
}
3434

35-
CorsairLightingProtocolHID::CorsairLightingProtocolHID(CorsairLightingProtocolController* cLP, const char* serialNumber) : CorsairLightingProtocolHID(cLP)
35+
CorsairLightingProtocolHID::CorsairLightingProtocolHID(CorsairLightingProtocolController* controller, const char* serialNumber) : CorsairLightingProtocolHID(controller)
3636
{
3737
RawHID.setSerialNumber(serialNumber);
3838
}
@@ -43,7 +43,7 @@ void CorsairLightingProtocolHID::update()
4343
{
4444
Command command;
4545
getCommand(command);
46-
cLP->handleCommand(command, this);
46+
controller->handleCommand(command, this);
4747
}
4848
}
4949

src/CorsairLightingProtocolHID.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,34 @@ extern bool printCommand;
2828
extern bool printResponse;
2929
#endif
3030

31+
/**
32+
* The HID Adapter for CorsairLightingProtocolController. This adapter uses the USB HID interface
33+
* directly to mimic a corsair device. This adapter can only be used when the USB interface is
34+
* accessable by the sketch.
35+
*/
3136
class CorsairLightingProtocolHID : CorsairLightingProtocolResponse {
3237
public:
33-
CorsairLightingProtocolHID(CorsairLightingProtocolController* cLP);
34-
CorsairLightingProtocolHID(CorsairLightingProtocolController* cLP, const char* serialNumber);
38+
/**
39+
* Create a new adapter for CorsairLightingProtocolController using the default Serial Number.
40+
*
41+
* @param controller the CorsairLightingProtocolController
42+
*/
43+
CorsairLightingProtocolHID(CorsairLightingProtocolController* controller);
44+
/**
45+
* Create a new adapter for using the given Serial Number for the usb interface.
46+
*
47+
* @param controller the CorsairLightingProtocolController
48+
* @param serialNumber the Serial Number used for the USB interface
49+
*/
50+
CorsairLightingProtocolHID(CorsairLightingProtocolController* controller, const char* serialNumber);
51+
/**
52+
* Read commands form HID interface and pass them to the contoller.
53+
* This function must be called in loop.
54+
*/
3555
void update();
3656
protected:
3757
uint8_t rawhidData[COMMAND_SIZE];
38-
CorsairLightingProtocolController* const cLP;
58+
CorsairLightingProtocolController* const controller;
3959

4060
bool available() const;
4161
void getCommand(Command& command);

src/CorsairLightingProtocolResponse.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,29 @@
1919

2020
class CorsairLightingProtocolResponse {
2121
public:
22+
/**
23+
* Send 64 bytes via the CorsairLightingProtocol. All unset bytes will be filled with zeros.
24+
*
25+
* @param data the array with the data
26+
* @param size the length of the array
27+
*/
2228
virtual void send(const uint8_t* data, size_t size) const;
29+
/**
30+
* Send an error.
31+
*/
2332
virtual void sendError() const;
33+
/**
34+
* Send data from program memory.
35+
*
36+
* @param data the array with the data, the pointer must point to program memory
37+
* @param size the length of the array which should be send.
38+
*/
2439
virtual void send_P(const uint8_t* data, size_t size) const;
25-
// Send x byte data via the CorsairLightingProtocol.
40+
/**
41+
* Send some bytes data via the CorsairLightingProtocol.
42+
*
43+
* @param data the array with the data
44+
* @param x the length of the array which should be send.
45+
*/
2646
virtual void sendX(const uint8_t* data, const size_t x) const = 0;
2747
};

src/CorsairLightingProtocolSerial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
#include "CorsairLightingProtocolSerial.h"
1717

18-
CorsairLightingProtocolSerial::CorsairLightingProtocolSerial(CorsairLightingProtocolController* cLP) : cLP(cLP) {}
18+
CorsairLightingProtocolSerial::CorsairLightingProtocolSerial(CorsairLightingProtocolController* controller) : controller(controller) {}
1919

2020
void CorsairLightingProtocolSerial::setup()
2121
{
@@ -30,7 +30,7 @@ void CorsairLightingProtocolSerial::update()
3030
{
3131
Command command;
3232
memcpy(command.raw, rawCommand, sizeof(command.raw));
33-
cLP->handleCommand(command, this);
33+
controller->handleCommand(command, this);
3434
}
3535
}
3636

0 commit comments

Comments
 (0)