Skip to content

Commit f6730f7

Browse files
authored
Merge pull request #59 from Legion2/documentation-and-renaming
Refactorings
2 parents f7e256a + 86d0c5d commit f6730f7

19 files changed

+143
-106
lines changed

examples/CommanderPRO/CommanderPRO.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
#include "SimpleFanController.h"
1717
#include "ThermistorTemperatureController.h"
18-
#include <CorsairLightingFirmware.h>
1918
#include <CorsairLightingProtocol.h>
20-
#include <CorsairLightingProtocolHID.h>
21-
#include <FastLEDController.h>
2219
#include <FastLED.h>
2320

2421
#define DATA_PIN_CHANNEL_1 2
@@ -39,7 +36,7 @@ CorsairLightingFirmware firmware = corsairCommanderPROFirmware();
3936
ThermistorTemperatureController temperatureController;
4037
FastLEDController ledController(&temperatureController, true);
4138
SimpleFanController fanController(&temperatureController, FAN_UPDATE_RATE, EEPROM_ADDRESS + ledController.getEEPROMSize());
42-
CorsairLightingProtocol cLP(&ledController, &temperatureController, &fanController, &firmware);
39+
CorsairLightingProtocolController cLP(&ledController, &temperatureController, &fanController, &firmware);
4340
CorsairLightingProtocolHID cHID(&cLP);
4441

4542
CRGB ledsChannel1[CHANNEL_LED_COUNT];

examples/DebugSketch/DebugSketch.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <CorsairLightingFirmware.h>
17-
#include <FastLEDController.h>
1816
#include <CorsairLightingProtocol.h>
19-
#include <CorsairLightingProtocolHID.h>
2017
#include <FastLED.h>
2118
#include <EEPROM.h>
2219

@@ -27,7 +24,7 @@
2724

2825
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
2926
FastLEDController ledController(true);
30-
CorsairLightingProtocol cLP(&ledController, &firmware);
27+
CorsairLightingProtocolController cLP(&ledController, &firmware);
3128
CorsairLightingProtocolHID cLPS(&cLP);
3229

3330
CRGB ledsChannel1[CHANNEL_LED_COUNT];
@@ -65,7 +62,7 @@ void processCommand(String& cmd) {
6562
if (cmd == F("print DeviceID")) {
6663
byte DeviceId[4];
6764
EEPROM.get(EEPROM_ADDRESS_DEVICE_ID, DeviceId);
68-
printDeviceID(DeviceId);
65+
CLP::printDeviceID(DeviceId);
6966
Serial.println();
7067
}
7168
#ifdef VERBOSE

examples/HoodLoader2UnoMegaController/HoodLoader2UnoMegaController.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <CorsairLightingFirmware.h>
17-
#include <FastLEDController.h>
1816
#include <CorsairLightingProtocol.h>
19-
#include <CorsairLightingProtocolSerial.h>
2017
#include <FastLED.h>
2118

2219
#define CHANNEL_LED_COUNT 96
@@ -26,7 +23,7 @@
2623

2724
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
2825
FastLEDController ledController(true);
29-
CorsairLightingProtocol cLP(&ledController, &firmware);
26+
CorsairLightingProtocolController cLP(&ledController, &firmware);
3027
CorsairLightingProtocolSerial cLPS(&cLP);
3128

3229
CRGB ledsChannel1[CHANNEL_LED_COUNT];

examples/RepeatAndScale/RepeatAndScale.ino

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <CorsairLightingFirmware.h>
17-
#include <FastLEDController.h>
1816
#include <CorsairLightingProtocol.h>
19-
#include <CorsairLightingProtocolHID.h>
20-
#include <FastLEDControllerUtils.h>
2117
#include <FastLED.h>
2218

2319
#define DATA_PIN_CHANNEL_1 2
@@ -28,7 +24,7 @@ CRGB ledsChannel2[144];
2824

2925
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
3026
FastLEDController ledController(true);
31-
CorsairLightingProtocol cLP(&ledController, &firmware);
27+
CorsairLightingProtocolController cLP(&ledController, &firmware);
3228
CorsairLightingProtocolHID cHID(&cLP);
3329

3430
void setup() {

examples/SingleStripLightingNodePRO/SingleStripLightingNodePRO.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <CorsairLightingFirmware.h>
17-
#include <FastLEDController.h>
1816
#include <CorsairLightingProtocol.h>
19-
#include <CorsairLightingProtocolHID.h>
2017
#include <FastLED.h>
2118

2219
// The number of LEDs per channel.
@@ -32,7 +29,7 @@
3229

3330
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
3431
FastLEDController ledController(true);
35-
CorsairLightingProtocol cLP(&ledController, &firmware);
32+
CorsairLightingProtocolController cLP(&ledController, &firmware);
3633
CorsairLightingProtocolHID cHID(&cLP);
3734

3835
// This array conatins all RGB values for the LEDs of the both channels.

examples/TransformLLFansFormatToStrip/TransformLLFansFormatToStrip.ino

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <CorsairLightingFirmware.h>
17-
#include <FastLEDController.h>
1816
#include <CorsairLightingProtocol.h>
19-
#include <CorsairLightingProtocolHID.h>
20-
#include <FastLEDControllerUtils.h>
2117
#include <FastLED.h>
2218

2319
#define DATA_PIN_CHANNEL_1 2
@@ -28,7 +24,7 @@ CRGB ledsChannel2[60];
2824

2925
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
3026
FastLEDController ledController(true);
31-
CorsairLightingProtocol cLP(&ledController, &firmware);
27+
CorsairLightingProtocolController cLP(&ledController, &firmware);
3228
CorsairLightingProtocolHID cHID(&cLP);
3329

3430
void setup() {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=The library mimics a Lighting Node PRO and can be controlled as such i
77
category=Device Control
88
url=https://github.com/Legion2/CorsairLightingProtocol
99
architectures=*
10-
includes=CorsairLightingProtocol.h,LEDController.h
10+
includes=CorsairLightingProtocol.h

src/CorsairLightingNodePRO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CorsairLightingNodePRO {
3636
CRGB ledsChannel2[CHANNEL_LED_COUNT_DEFAULT];
3737
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
3838
FastLEDController ledController;
39-
CorsairLightingProtocol cLP;
39+
CorsairLightingProtocolController cLP;
4040
CorsairLightingProtocolHID connectionAdapter;
4141
};
4242

src/CorsairLightingProtocol.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,20 @@
1515
*/
1616
#pragma once
1717

18-
#include "Arduino.h"
19-
18+
// central include file for CorsairLightingProtocolController
2019
#include "CorsairLightingFirmware.h"
20+
#include "CorsairLightingNodePRO.h"
2121
#include "CorsairLightingProtocolConstants.h"
22+
#include "CorsairLightingProtocolController.h"
23+
#include "CorsairLightingProtocolHID.h"
2224
#include "CorsairLightingProtocolResponse.h"
25+
#include "CorsairLightingProtocolSerial.h"
2326
#include "IFanController.h"
27+
#include "FanController.h"
2428
#include "ILEDController.h"
29+
#include "LEDController.h"
30+
#include "FastLEDController.h"
2531
#include "ITemperatureController.h"
26-
27-
class CorsairLightingProtocol
28-
{
29-
public:
30-
CorsairLightingProtocol(ILEDController* l, CorsairLightingFirmware* c);
31-
CorsairLightingProtocol(ILEDController* l, ITemperatureController* t, IFanController* f, CorsairLightingFirmware* c);
32-
void handleCommand(const Command& command, CorsairLightingProtocolResponse* response);
33-
private:
34-
CorsairLightingFirmware* const corsairLightingFirmware;
35-
ILEDController* const ledController;
36-
ITemperatureController* const temperatureController;
37-
IFanController* const fanController;
38-
};
32+
#include "TemperatureController.h"
33+
#include "FastLEDControllerUtils.h"
34+
#include "CLPUtils.h"

src/CorsairLightingProtocol.cpp renamed to src/CorsairLightingProtocolController.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include "CorsairLightingProtocol.h"
16+
#include "CorsairLightingProtocolController.h"
1717
#include "LEDController.h"
1818

19-
CorsairLightingProtocol::CorsairLightingProtocol(ILEDController* aLEDController, CorsairLightingFirmware* corsairLightingFirmware) : corsairLightingFirmware(corsairLightingFirmware), ledController(aLEDController), temperatureController(nullptr), fanController(nullptr) {}
19+
CorsairLightingProtocolController::CorsairLightingProtocolController(ILEDController* aLEDController, CorsairLightingFirmware* corsairLightingFirmware) : corsairLightingFirmware(corsairLightingFirmware), ledController(aLEDController), temperatureController(nullptr), fanController(nullptr) {}
2020

21-
CorsairLightingProtocol::CorsairLightingProtocol(ILEDController* aLEDController, ITemperatureController* temperatureController, IFanController* fanController, CorsairLightingFirmware* corsairLightingFirmware) : corsairLightingFirmware(corsairLightingFirmware), ledController(aLEDController), temperatureController(temperatureController), fanController(fanController) {}
21+
CorsairLightingProtocolController::CorsairLightingProtocolController(ILEDController* aLEDController, ITemperatureController* temperatureController, IFanController* fanController, CorsairLightingFirmware* corsairLightingFirmware) : corsairLightingFirmware(corsairLightingFirmware), ledController(aLEDController), temperatureController(temperatureController), fanController(fanController) {}
2222

23-
void CorsairLightingProtocol::handleCommand(const Command& command, CorsairLightingProtocolResponse* response)
23+
void CorsairLightingProtocolController::handleCommand(const Command& command, CorsairLightingProtocolResponse* response)
2424
{
2525
if (command.command < 0x10) {
2626
corsairLightingFirmware->handleFirmwareCommand(command, response);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
20+
#include "CorsairLightingFirmware.h"
21+
#include "CorsairLightingProtocolConstants.h"
22+
#include "CorsairLightingProtocolResponse.h"
23+
#include "IFanController.h"
24+
#include "ILEDController.h"
25+
#include "ITemperatureController.h"
26+
27+
/**
28+
* The central Controller which integrates all components. The main components of the CorsairLightingProtocolController are the CorsairLightingFirmware
29+
* and the LEDController. There can also be an optional TemperatureController and FanController which are required if the device should be an Commander PRO.
30+
*/
31+
class CorsairLightingProtocolController
32+
{
33+
public:
34+
/**
35+
* The constructor used to create a Lighting Node PRO.
36+
*
37+
* @param l The LEDController which should be used to control the LEDs of the created Lighting Node PRO
38+
* @param c The CorsairLightingFirmware used to handle Firmware related commands
39+
*/
40+
CorsairLightingProtocolController(ILEDController* l, CorsairLightingFirmware* c);
41+
/**
42+
* The constructor used to create an Commander PRO.
43+
*
44+
* @param l The LEDController which should be used to control the LEDs of the created Commander PRO
45+
* @param t The TemperatureController which used to messure the temperature of the created Commander PRO
46+
* @param f The FanController used to control the fans of the created Commander PRO
47+
* @param c The CorsairLightingFirmware used to handle Firmware related commands
48+
*/
49+
CorsairLightingProtocolController(ILEDController* l, ITemperatureController* t, IFanController* f, CorsairLightingFirmware* c);
50+
/**
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+
*
54+
* @param command The command received from iCUE
55+
* @param response The response callback which can be called to response to the command
56+
*/
57+
void handleCommand(const Command& command, CorsairLightingProtocolResponse* response);
58+
private:
59+
CorsairLightingFirmware* const corsairLightingFirmware;
60+
ILEDController* const ledController;
61+
ITemperatureController* const temperatureController;
62+
IFanController* const fanController;
63+
};

src/CorsairLightingProtocolHID.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool printCommand = PRINT_COMMAND;
2727
bool printResponse = PRINT_RESPONSE;
2828
#endif
2929

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

src/CorsairLightingProtocolHID.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "Arduino.h"
1919

20-
#include "CorsairLightingProtocol.h"
20+
#include "CorsairLightingProtocolController.h"
2121
#include "CorsairLightingProtocolResponse.h"
2222
#include "CorsairLightingProtocolConstants.h"
2323

@@ -30,11 +30,11 @@ extern bool printResponse;
3030

3131
class CorsairLightingProtocolHID : CorsairLightingProtocolResponse {
3232
public:
33-
CorsairLightingProtocolHID(CorsairLightingProtocol* cLP);
33+
CorsairLightingProtocolHID(CorsairLightingProtocolController* cLP);
3434
void update();
3535
protected:
3636
uint8_t rawhidData[COMMAND_SIZE];
37-
CorsairLightingProtocol* const cLP;
37+
CorsairLightingProtocolController* const cLP;
3838

3939
bool available() const;
4040
void getCommand(Command& command);

src/CorsairLightingProtocolSerial.cpp

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

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

2020
void CorsairLightingProtocolSerial::setup()
2121
{

src/CorsairLightingProtocolSerial.h

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

18-
#include <CorsairLightingProtocol.h>
18+
#include <CorsairLightingProtocolController.h>
1919
#include <CorsairLightingProtocolConstants.h>
2020
#include <CorsairLightingProtocolResponse.h>
2121

@@ -25,12 +25,12 @@
2525

2626
class CorsairLightingProtocolSerial : CorsairLightingProtocolResponse {
2727
public:
28-
CorsairLightingProtocolSerial(CorsairLightingProtocol* cLP);
28+
CorsairLightingProtocolSerial(CorsairLightingProtocolController* cLP);
2929
void setup();
3030
void update();
3131
private:
3232
byte rawCommand[COMMAND_SIZE];
33-
CorsairLightingProtocol* const cLP;
33+
CorsairLightingProtocolController* const cLP;
3434

3535
bool handleSerial();
3636
void sendX(const uint8_t* data, const size_t x) const override;

src/FanController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "Arduino.h"
1919

20-
#include "CorsairLightingProtocol.h"
2120
#include "IFanController.h"
2221

2322
#define FAN_NUM 6

0 commit comments

Comments
 (0)