Removed setColorMap and replaced as second parameter to Pixel constructor

Provides for full backwards compatibility with previous constructor.
This commit is contained in:
Gregg 2024-02-25 17:21:52 -06:00
parent 0cf12f3331
commit a0bf2c8c8a
6 changed files with 33 additions and 31 deletions

View File

@ -52,7 +52,7 @@ void HAPClient::init(){
if(nvs_get_blob(srpNVS,"VERIFYDATA",NULL,&len)) // if Pair-Setup verification code data not found in NVS if(nvs_get_blob(srpNVS,"VERIFYDATA",NULL,&len)) // if Pair-Setup verification code data not found in NVS
homeSpan.setPairingCode(DEFAULT_SETUP_CODE); // create and save verification from using Pairing Setup Code homeSpan.setPairingCode(DEFAULT_SETUP_CODE); // create and save verification from using Pairing Setup Code
if(!strlen(homeSpan.qrID)){ // is Setup ID has not been specified in sketch if(!strlen(homeSpan.qrID)){ // if Setup ID has not been specified in sketch
if(!nvs_get_str(hapNVS,"SETUPID",NULL,&len)){ // check for saved value if(!nvs_get_str(hapNVS,"SETUPID",NULL,&len)){ // check for saved value
nvs_get_str(hapNVS,"SETUPID",homeSpan.qrID,&len); // retrieve data nvs_get_str(hapNVS,"SETUPID",homeSpan.qrID,&len); // retrieve data
} else { } else {

View File

@ -510,7 +510,7 @@ void Span::checkConnect(){
char setupHash[9]; char setupHash[9];
size_t len; size_t len;
memcpy(hashInput,qrID,4); // Create the Seup ID for use with optional QR Codes. This is an undocumented feature of HAP R2! memcpy(hashInput,qrID,4); // Create the Setup ID for use with optional QR Codes. This is an undocumented feature of HAP R2!
memcpy(hashInput+4,id,17); // Step 1: Concatenate 4-character Setup ID and 17-character Accessory ID into hashInput memcpy(hashInput+4,id,17); // Step 1: Concatenate 4-character Setup ID and 17-character Accessory ID into hashInput
mbedtls_sha512_ret(hashInput,21,hashOutput,0); // Step 2: Perform SHA-512 hash on combined 21-byte hashInput to create 64-byte hashOutput mbedtls_sha512_ret(hashInput,21,hashOutput,0); // Step 2: Perform SHA-512 hash on combined 21-byte hashInput to create 64-byte hashOutput
mbedtls_base64_encode((uint8_t *)setupHash,9,&len,hashOutput,4); // Step 3: Encode the first 4 bytes of hashOutput in base64, which results in an 8-character, null-terminated, setupHash mbedtls_base64_encode((uint8_t *)setupHash,9,&len,hashOutput,4); // Step 3: Encode the first 4 bytes of hashOutput in base64, which results in an 8-character, null-terminated, setupHash

View File

@ -33,7 +33,7 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.setLogLevel(1); homeSpan.setLogLevel(2);
homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL); homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL);
// homeSpan.enableWebLog(50,"pool.ntp.org","UTC","myStatus"); // homeSpan.enableWebLog(50,"pool.ntp.org","UTC","myStatus");
// homeSpan.enableWebLog(50,NULL,NULL,NULL); // homeSpan.enableWebLog(50,NULL,NULL,NULL);

View File

@ -35,19 +35,21 @@
// Single-Wire RGB/RGBW NeoPixels // // Single-Wire RGB/RGBW NeoPixels //
//////////////////////////////////////////// ////////////////////////////////////////////
Pixel::Pixel(int pin, boolean isRGBW){ //Pixel::Pixel(int pin, boolean isRGBW){
Pixel::Pixel(int pin, pixelType_t pixelType){
rf=new RFControl(pin,false,false); // set clock to 1/80 usec, no default driver rf=new RFControl(pin,false,false); // set clock to 1/80 usec, no default driver
if(!*rf) if(!*rf)
return; return;
if(isRGBW) map=pixelType;
this->bytesPerPixel=4;
if(map[3])
bytesPerPixel=4;
else else
this->bytesPerPixel=3; bytesPerPixel=3;
setTiming(0.32, 0.88, 0.64, 0.56, 80.0); // set default timing parameters (suitable for most SK68 and WS28 RGB pixels) setTiming(0.32, 0.88, 0.64, 0.56, 80.0); // set default timing parameters (suitable for most SK68 and WS28 RGB pixels)
setColorMap(ColorMap::GRB); // set default color mapping
rmt_isr_register(loadData,NULL,0,NULL); // set custom interrupt handler rmt_isr_register(loadData,NULL,0,NULL); // set custom interrupt handler
@ -75,13 +77,6 @@ void Pixel::setTiming(float high0, float low0, float high1, float low1, uint32_t
/////////////////// ///////////////////
void Pixel::setColorMap(const uint8_t *map){
this->map=map;
}
///////////////////
void Pixel::set(Color *c, int nPixels, boolean multiColor){ void Pixel::set(Color *c, int nPixels, boolean multiColor){
if(!*rf || nPixels==0) if(!*rf || nPixels==0)

View File

@ -37,14 +37,23 @@
[[maybe_unused]] static const char* PIXEL_TAG = "Pixel"; [[maybe_unused]] static const char* PIXEL_TAG = "Pixel";
namespace ColorMap { typedef const uint8_t pixelType_t[];
static const uint8_t RGB[4]={31,23,15,7}; namespace PixelType {
static const uint8_t RBG[4]={31,15,23,7};
static const uint8_t BRG[4]={23,15,31,7}; // const uint8_t RGB[4]={31,23,15,0};
static const uint8_t BGR[4]={15,23,31,7}; pixelType_t RGB={31,23,15,0};
static const uint8_t GBR[4]={15,31,23,7}; pixelType_t RBG={31,15,23,0};
static const uint8_t GRB[4]={23,31,15,7}; pixelType_t BRG={23,15,31,0};
pixelType_t BGR={15,23,31,0};
pixelType_t GBR={15,31,23,0};
pixelType_t GRB={23,31,15,0};
pixelType_t RGBW={31,23,15,7};
pixelType_t RBGW={31,15,23,7};
pixelType_t BRGW={23,15,31,7};
pixelType_t BGRW={15,23,31,7};
pixelType_t GBRW={15,31,23,7};
pixelType_t GRBW={23,31,15,7};
}; };
//////////////////////////////////////////// ////////////////////////////////////////////
@ -153,7 +162,9 @@ class Pixel : public Blinkable {
volatile static pixel_status_t status; // storage for volatile information modified in interupt handler volatile static pixel_status_t status; // storage for volatile information modified in interupt handler
public: public:
Pixel(int pin, boolean isRGBW=false); // creates addressable single-wire RGB (false) or RGBW (true) LED connected to pin (such as the SK68 or WS28)
Pixel(int pin, pixelType_t pixelType=PixelType::GRB); // creates addressable single-wire LED of pixelType connected to pin (such as the SK68 or WS28)
Pixel(int pin, boolean isRGBW):Pixel(pin,isRGBW?PixelType::GRBW:PixelType::GRB){}; // old-style constructor included for backwards compatibility
void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels
void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c
@ -162,7 +173,6 @@ class Pixel : public Blinkable {
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1 int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
void setTiming(float high0, float low0, float high1, float low1, uint32_t lowReset); // changes default timings for bit pulse - note parameters are in MICROSECONDS void setTiming(float high0, float low0, float high1, float low1, uint32_t lowReset); // changes default timings for bit pulse - note parameters are in MICROSECONDS
void setColorMap(const uint8_t *map); // changes the default color map from GRBW to an alternative mapping - controls order in which color bytes are transmitted
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
return(*rf); return(*rf);

View File

@ -27,12 +27,10 @@
#include "Pixel.h" #include "Pixel.h"
#define PIXEL_PIN 32 // set this to whatever pin you are using - note pin cannot be "input only" #define PIXEL_PIN 26 // set this to whatever pin you are using - note pin cannot be "input only"
#define NPIXELS 60 // set to number of pixels in strand #define NPIXELS 8 // set to number of pixels in strand
#define COLORMAP ColorMap::GRB // sets the order in which color bytes are transmitted
#define RGBW true // set to true if RGBW, else false if just RGB
Pixel testPixel(PIXEL_PIN,RGBW); Pixel testPixel(PIXEL_PIN);
void setup() { void setup() {
@ -40,7 +38,6 @@ void setup() {
delay(1000); delay(1000);
Serial.printf("\n\nPixel Test on pin %d with %d pixels\n\n",PIXEL_PIN,NPIXELS); Serial.printf("\n\nPixel Test on pin %d with %d pixels\n\n",PIXEL_PIN,NPIXELS);
testPixel.setColorMap(COLORMAP);
} }