-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting all colors differently
- Loading branch information
Showing
7 changed files
with
199 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "Message.h" | ||
|
||
#include "HSBColor.h" | ||
|
||
namespace RGBStrip { | ||
|
||
class ColorArrayMessage : public Message { | ||
public: | ||
static const uint8_t Type = 0x02; | ||
|
||
static uint16_t size(uint16_t count) { | ||
return sizeof(ColorArrayMessage) + sizeof(HSBColor) * count; | ||
} | ||
|
||
public: | ||
uint16_t offset; | ||
uint16_t count; | ||
|
||
HSBColor colors[0]; | ||
|
||
void fillHeader(uint16_t count) { | ||
header.identifier = Identifier; | ||
header.type = Type; | ||
header.length = size(count); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "Message.h" | ||
|
||
#include "HSBColor.h" | ||
|
||
namespace RGBStrip { | ||
|
||
class ColorMessage : public Message { | ||
public: | ||
static const uint8_t Type = 0x01; | ||
|
||
static uint16_t size() { | ||
return sizeof(ColorMessage); | ||
} | ||
|
||
public: | ||
uint16_t offset; | ||
uint16_t count; | ||
|
||
HSBColor color; | ||
|
||
void fillHeader() { | ||
header.identifier = Identifier; | ||
header.type = Type; | ||
header.length = size(); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
namespace RGBStrip { | ||
|
||
class Message { | ||
public: | ||
static const uint16_t MaxLength = 520; | ||
|
||
static const uint8_t Identifier = 0x42; | ||
|
||
struct Header { | ||
uint8_t identifier; | ||
uint8_t type; | ||
|
||
uint16_t checksum; | ||
uint16_t length; | ||
uint16_t code; | ||
}; | ||
|
||
public: | ||
Header header; | ||
unsigned char data[0]; | ||
|
||
public: | ||
uint16_t calcChecksum() const { | ||
const uint16_t length = header.length - sizeof(header); | ||
|
||
uint16_t checksum = header.type; | ||
for(uint16_t index = 0; index < length; ++index) | ||
{ | ||
checksum += data[index]; | ||
} | ||
|
||
return checksum; | ||
} | ||
|
||
void fillChecksum() | ||
{ | ||
header.checksum = calcChecksum(); | ||
} | ||
|
||
bool validateChecksum() const | ||
{ | ||
if(header.identifier != Identifier) | ||
{ | ||
return false; | ||
} | ||
|
||
if(header.checksum != calcChecksum()) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.