From a0bf2c8c8a82aa0dcdbb7c76dcd85695ee751fea Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 25 Feb 2024 17:21:52 -0600 Subject: [PATCH] Removed setColorMap and replaced as second parameter to Pixel constructor Provides for full backwards compatibility with previous constructor. --- src/HAP.cpp | 2 +- src/HomeSpan.cpp | 2 +- src/src.ino | 2 +- src/src/extras/Pixel.cpp | 19 +++++++------------ src/src/extras/Pixel.h | 30 ++++++++++++++++++++---------- src/src/extras/extras.ino | 9 +++------ 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/HAP.cpp b/src/HAP.cpp index 4f08076..d6ee651 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -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 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 nvs_get_str(hapNVS,"SETUPID",homeSpan.qrID,&len); // retrieve data } else { diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index fd8d50a..f521c18 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -510,7 +510,7 @@ void Span::checkConnect(){ char setupHash[9]; 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 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 diff --git a/src/src.ino b/src/src.ino index 43de092..1db723a 100644 --- a/src/src.ino +++ b/src/src.ino @@ -33,7 +33,7 @@ void setup() { Serial.begin(115200); - homeSpan.setLogLevel(1); + homeSpan.setLogLevel(2); homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL); // homeSpan.enableWebLog(50,"pool.ntp.org","UTC","myStatus"); // homeSpan.enableWebLog(50,NULL,NULL,NULL); diff --git a/src/src/extras/Pixel.cpp b/src/src/extras/Pixel.cpp index 8c423f6..e7aa55f 100644 --- a/src/src/extras/Pixel.cpp +++ b/src/src/extras/Pixel.cpp @@ -35,19 +35,21 @@ // 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 if(!*rf) return; - if(isRGBW) - this->bytesPerPixel=4; + map=pixelType; + + if(map[3]) + bytesPerPixel=4; 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) - setColorMap(ColorMap::GRB); // set default color mapping 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){ if(!*rf || nPixels==0) diff --git a/src/src/extras/Pixel.h b/src/src/extras/Pixel.h index 0a8ec75..921c928 100644 --- a/src/src/extras/Pixel.h +++ b/src/src/extras/Pixel.h @@ -37,14 +37,23 @@ [[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}; - static const uint8_t RBG[4]={31,15,23,7}; - static const uint8_t BRG[4]={23,15,31,7}; - static const uint8_t BGR[4]={15,23,31,7}; - static const uint8_t GBR[4]={15,31,23,7}; - static const uint8_t GRB[4]={23,31,15,7}; +namespace PixelType { + +// const uint8_t RGB[4]={31,23,15,0}; + pixelType_t RGB={31,23,15,0}; + pixelType_t RBG={31,15,23,0}; + 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}; }; //////////////////////////////////////////// @@ -53,7 +62,7 @@ namespace ColorMap { class Pixel : public Blinkable { - public: + public: struct Color { union{ struct { @@ -153,7 +162,9 @@ class Pixel : public Blinkable { volatile static pixel_status_t status; // storage for volatile information modified in interupt handler 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=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 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 return(*rf); diff --git a/src/src/extras/extras.ino b/src/src/extras/extras.ino index 9ac0d3f..14d5006 100644 --- a/src/src/extras/extras.ino +++ b/src/src/extras/extras.ino @@ -27,12 +27,10 @@ #include "Pixel.h" -#define PIXEL_PIN 32 // 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 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 +#define PIXEL_PIN 26 // set this to whatever pin you are using - note pin cannot be "input only" +#define NPIXELS 8 // set to number of pixels in strand -Pixel testPixel(PIXEL_PIN,RGBW); +Pixel testPixel(PIXEL_PIN); void setup() { @@ -40,7 +38,6 @@ void setup() { delay(1000); Serial.printf("\n\nPixel Test on pin %d with %d pixels\n\n",PIXEL_PIN,NPIXELS); - testPixel.setColorMap(COLORMAP); }