Skip to content

Commit

Permalink
1st working version with changing colors
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Sep 7, 2024
1 parent 92baf20 commit ee9da79
Show file tree
Hide file tree
Showing 2 changed files with 290 additions and 14 deletions.
259 changes: 259 additions & 0 deletions lib/ledspitask/ColorTo3Byte.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
uint8_t colorTo3Byte[256][3]=
{
{/*00*/0b10010010,0b01001001,0b00100100,},
{/*01*/0b10010010,0b01001001,0b00100110,},
{/*02*/0b10010010,0b01001001,0b00110100,},
{/*03*/0b10010010,0b01001001,0b00110110,},
{/*04*/0b10010010,0b01001001,0b10100100,},
{/*05*/0b10010010,0b01001001,0b10100110,},
{/*06*/0b10010010,0b01001001,0b10110100,},
{/*07*/0b10010010,0b01001001,0b10110110,},
{/*08*/0b10010010,0b01001101,0b00100100,},
{/*09*/0b10010010,0b01001101,0b00100110,},
{/*10*/0b10010010,0b01001101,0b00110100,},
{/*11*/0b10010010,0b01001101,0b00110110,},
{/*12*/0b10010010,0b01001101,0b10100100,},
{/*13*/0b10010010,0b01001101,0b10100110,},
{/*14*/0b10010010,0b01001101,0b10110100,},
{/*15*/0b10010010,0b01001101,0b10110110,},
{/*16*/0b10010010,0b01101001,0b00100100,},
{/*17*/0b10010010,0b01101001,0b00100110,},
{/*18*/0b10010010,0b01101001,0b00110100,},
{/*19*/0b10010010,0b01101001,0b00110110,},
{/*20*/0b10010010,0b01101001,0b10100100,},
{/*21*/0b10010010,0b01101001,0b10100110,},
{/*22*/0b10010010,0b01101001,0b10110100,},
{/*23*/0b10010010,0b01101001,0b10110110,},
{/*24*/0b10010010,0b01101101,0b00100100,},
{/*25*/0b10010010,0b01101101,0b00100110,},
{/*26*/0b10010010,0b01101101,0b00110100,},
{/*27*/0b10010010,0b01101101,0b00110110,},
{/*28*/0b10010010,0b01101101,0b10100100,},
{/*29*/0b10010010,0b01101101,0b10100110,},
{/*30*/0b10010010,0b01101101,0b10110100,},
{/*31*/0b10010010,0b01101101,0b10110110,},
{/*32*/0b10010011,0b01001001,0b00100100,},
{/*33*/0b10010011,0b01001001,0b00100110,},
{/*34*/0b10010011,0b01001001,0b00110100,},
{/*35*/0b10010011,0b01001001,0b00110110,},
{/*36*/0b10010011,0b01001001,0b10100100,},
{/*37*/0b10010011,0b01001001,0b10100110,},
{/*38*/0b10010011,0b01001001,0b10110100,},
{/*39*/0b10010011,0b01001001,0b10110110,},
{/*40*/0b10010011,0b01001101,0b00100100,},
{/*41*/0b10010011,0b01001101,0b00100110,},
{/*42*/0b10010011,0b01001101,0b00110100,},
{/*43*/0b10010011,0b01001101,0b00110110,},
{/*44*/0b10010011,0b01001101,0b10100100,},
{/*45*/0b10010011,0b01001101,0b10100110,},
{/*46*/0b10010011,0b01001101,0b10110100,},
{/*47*/0b10010011,0b01001101,0b10110110,},
{/*48*/0b10010011,0b01101001,0b00100100,},
{/*49*/0b10010011,0b01101001,0b00100110,},
{/*50*/0b10010011,0b01101001,0b00110100,},
{/*51*/0b10010011,0b01101001,0b00110110,},
{/*52*/0b10010011,0b01101001,0b10100100,},
{/*53*/0b10010011,0b01101001,0b10100110,},
{/*54*/0b10010011,0b01101001,0b10110100,},
{/*55*/0b10010011,0b01101001,0b10110110,},
{/*56*/0b10010011,0b01101101,0b00100100,},
{/*57*/0b10010011,0b01101101,0b00100110,},
{/*58*/0b10010011,0b01101101,0b00110100,},
{/*59*/0b10010011,0b01101101,0b00110110,},
{/*60*/0b10010011,0b01101101,0b10100100,},
{/*61*/0b10010011,0b01101101,0b10100110,},
{/*62*/0b10010011,0b01101101,0b10110100,},
{/*63*/0b10010011,0b01101101,0b10110110,},
{/*64*/0b10011010,0b01001001,0b00100100,},
{/*65*/0b10011010,0b01001001,0b00100110,},
{/*66*/0b10011010,0b01001001,0b00110100,},
{/*67*/0b10011010,0b01001001,0b00110110,},
{/*68*/0b10011010,0b01001001,0b10100100,},
{/*69*/0b10011010,0b01001001,0b10100110,},
{/*70*/0b10011010,0b01001001,0b10110100,},
{/*71*/0b10011010,0b01001001,0b10110110,},
{/*72*/0b10011010,0b01001101,0b00100100,},
{/*73*/0b10011010,0b01001101,0b00100110,},
{/*74*/0b10011010,0b01001101,0b00110100,},
{/*75*/0b10011010,0b01001101,0b00110110,},
{/*76*/0b10011010,0b01001101,0b10100100,},
{/*77*/0b10011010,0b01001101,0b10100110,},
{/*78*/0b10011010,0b01001101,0b10110100,},
{/*79*/0b10011010,0b01001101,0b10110110,},
{/*80*/0b10011010,0b01101001,0b00100100,},
{/*81*/0b10011010,0b01101001,0b00100110,},
{/*82*/0b10011010,0b01101001,0b00110100,},
{/*83*/0b10011010,0b01101001,0b00110110,},
{/*84*/0b10011010,0b01101001,0b10100100,},
{/*85*/0b10011010,0b01101001,0b10100110,},
{/*86*/0b10011010,0b01101001,0b10110100,},
{/*87*/0b10011010,0b01101001,0b10110110,},
{/*88*/0b10011010,0b01101101,0b00100100,},
{/*89*/0b10011010,0b01101101,0b00100110,},
{/*90*/0b10011010,0b01101101,0b00110100,},
{/*91*/0b10011010,0b01101101,0b00110110,},
{/*92*/0b10011010,0b01101101,0b10100100,},
{/*93*/0b10011010,0b01101101,0b10100110,},
{/*94*/0b10011010,0b01101101,0b10110100,},
{/*95*/0b10011010,0b01101101,0b10110110,},
{/*96*/0b10011011,0b01001001,0b00100100,},
{/*97*/0b10011011,0b01001001,0b00100110,},
{/*98*/0b10011011,0b01001001,0b00110100,},
{/*99*/0b10011011,0b01001001,0b00110110,},
{/*100*/0b10011011,0b01001001,0b10100100,},
{/*101*/0b10011011,0b01001001,0b10100110,},
{/*102*/0b10011011,0b01001001,0b10110100,},
{/*103*/0b10011011,0b01001001,0b10110110,},
{/*104*/0b10011011,0b01001101,0b00100100,},
{/*105*/0b10011011,0b01001101,0b00100110,},
{/*106*/0b10011011,0b01001101,0b00110100,},
{/*107*/0b10011011,0b01001101,0b00110110,},
{/*108*/0b10011011,0b01001101,0b10100100,},
{/*109*/0b10011011,0b01001101,0b10100110,},
{/*110*/0b10011011,0b01001101,0b10110100,},
{/*111*/0b10011011,0b01001101,0b10110110,},
{/*112*/0b10011011,0b01101001,0b00100100,},
{/*113*/0b10011011,0b01101001,0b00100110,},
{/*114*/0b10011011,0b01101001,0b00110100,},
{/*115*/0b10011011,0b01101001,0b00110110,},
{/*116*/0b10011011,0b01101001,0b10100100,},
{/*117*/0b10011011,0b01101001,0b10100110,},
{/*118*/0b10011011,0b01101001,0b10110100,},
{/*119*/0b10011011,0b01101001,0b10110110,},
{/*120*/0b10011011,0b01101101,0b00100100,},
{/*121*/0b10011011,0b01101101,0b00100110,},
{/*122*/0b10011011,0b01101101,0b00110100,},
{/*123*/0b10011011,0b01101101,0b00110110,},
{/*124*/0b10011011,0b01101101,0b10100100,},
{/*125*/0b10011011,0b01101101,0b10100110,},
{/*126*/0b10011011,0b01101101,0b10110100,},
{/*127*/0b10011011,0b01101101,0b10110110,},
{/*128*/0b11010010,0b01001001,0b00100100,},
{/*129*/0b11010010,0b01001001,0b00100110,},
{/*130*/0b11010010,0b01001001,0b00110100,},
{/*131*/0b11010010,0b01001001,0b00110110,},
{/*132*/0b11010010,0b01001001,0b10100100,},
{/*133*/0b11010010,0b01001001,0b10100110,},
{/*134*/0b11010010,0b01001001,0b10110100,},
{/*135*/0b11010010,0b01001001,0b10110110,},
{/*136*/0b11010010,0b01001101,0b00100100,},
{/*137*/0b11010010,0b01001101,0b00100110,},
{/*138*/0b11010010,0b01001101,0b00110100,},
{/*139*/0b11010010,0b01001101,0b00110110,},
{/*140*/0b11010010,0b01001101,0b10100100,},
{/*141*/0b11010010,0b01001101,0b10100110,},
{/*142*/0b11010010,0b01001101,0b10110100,},
{/*143*/0b11010010,0b01001101,0b10110110,},
{/*144*/0b11010010,0b01101001,0b00100100,},
{/*145*/0b11010010,0b01101001,0b00100110,},
{/*146*/0b11010010,0b01101001,0b00110100,},
{/*147*/0b11010010,0b01101001,0b00110110,},
{/*148*/0b11010010,0b01101001,0b10100100,},
{/*149*/0b11010010,0b01101001,0b10100110,},
{/*150*/0b11010010,0b01101001,0b10110100,},
{/*151*/0b11010010,0b01101001,0b10110110,},
{/*152*/0b11010010,0b01101101,0b00100100,},
{/*153*/0b11010010,0b01101101,0b00100110,},
{/*154*/0b11010010,0b01101101,0b00110100,},
{/*155*/0b11010010,0b01101101,0b00110110,},
{/*156*/0b11010010,0b01101101,0b10100100,},
{/*157*/0b11010010,0b01101101,0b10100110,},
{/*158*/0b11010010,0b01101101,0b10110100,},
{/*159*/0b11010010,0b01101101,0b10110110,},
{/*160*/0b11010011,0b01001001,0b00100100,},
{/*161*/0b11010011,0b01001001,0b00100110,},
{/*162*/0b11010011,0b01001001,0b00110100,},
{/*163*/0b11010011,0b01001001,0b00110110,},
{/*164*/0b11010011,0b01001001,0b10100100,},
{/*165*/0b11010011,0b01001001,0b10100110,},
{/*166*/0b11010011,0b01001001,0b10110100,},
{/*167*/0b11010011,0b01001001,0b10110110,},
{/*168*/0b11010011,0b01001101,0b00100100,},
{/*169*/0b11010011,0b01001101,0b00100110,},
{/*170*/0b11010011,0b01001101,0b00110100,},
{/*171*/0b11010011,0b01001101,0b00110110,},
{/*172*/0b11010011,0b01001101,0b10100100,},
{/*173*/0b11010011,0b01001101,0b10100110,},
{/*174*/0b11010011,0b01001101,0b10110100,},
{/*175*/0b11010011,0b01001101,0b10110110,},
{/*176*/0b11010011,0b01101001,0b00100100,},
{/*177*/0b11010011,0b01101001,0b00100110,},
{/*178*/0b11010011,0b01101001,0b00110100,},
{/*179*/0b11010011,0b01101001,0b00110110,},
{/*180*/0b11010011,0b01101001,0b10100100,},
{/*181*/0b11010011,0b01101001,0b10100110,},
{/*182*/0b11010011,0b01101001,0b10110100,},
{/*183*/0b11010011,0b01101001,0b10110110,},
{/*184*/0b11010011,0b01101101,0b00100100,},
{/*185*/0b11010011,0b01101101,0b00100110,},
{/*186*/0b11010011,0b01101101,0b00110100,},
{/*187*/0b11010011,0b01101101,0b00110110,},
{/*188*/0b11010011,0b01101101,0b10100100,},
{/*189*/0b11010011,0b01101101,0b10100110,},
{/*190*/0b11010011,0b01101101,0b10110100,},
{/*191*/0b11010011,0b01101101,0b10110110,},
{/*192*/0b11011010,0b01001001,0b00100100,},
{/*193*/0b11011010,0b01001001,0b00100110,},
{/*194*/0b11011010,0b01001001,0b00110100,},
{/*195*/0b11011010,0b01001001,0b00110110,},
{/*196*/0b11011010,0b01001001,0b10100100,},
{/*197*/0b11011010,0b01001001,0b10100110,},
{/*198*/0b11011010,0b01001001,0b10110100,},
{/*199*/0b11011010,0b01001001,0b10110110,},
{/*200*/0b11011010,0b01001101,0b00100100,},
{/*201*/0b11011010,0b01001101,0b00100110,},
{/*202*/0b11011010,0b01001101,0b00110100,},
{/*203*/0b11011010,0b01001101,0b00110110,},
{/*204*/0b11011010,0b01001101,0b10100100,},
{/*205*/0b11011010,0b01001101,0b10100110,},
{/*206*/0b11011010,0b01001101,0b10110100,},
{/*207*/0b11011010,0b01001101,0b10110110,},
{/*208*/0b11011010,0b01101001,0b00100100,},
{/*209*/0b11011010,0b01101001,0b00100110,},
{/*210*/0b11011010,0b01101001,0b00110100,},
{/*211*/0b11011010,0b01101001,0b00110110,},
{/*212*/0b11011010,0b01101001,0b10100100,},
{/*213*/0b11011010,0b01101001,0b10100110,},
{/*214*/0b11011010,0b01101001,0b10110100,},
{/*215*/0b11011010,0b01101001,0b10110110,},
{/*216*/0b11011010,0b01101101,0b00100100,},
{/*217*/0b11011010,0b01101101,0b00100110,},
{/*218*/0b11011010,0b01101101,0b00110100,},
{/*219*/0b11011010,0b01101101,0b00110110,},
{/*220*/0b11011010,0b01101101,0b10100100,},
{/*221*/0b11011010,0b01101101,0b10100110,},
{/*222*/0b11011010,0b01101101,0b10110100,},
{/*223*/0b11011010,0b01101101,0b10110110,},
{/*224*/0b11011011,0b01001001,0b00100100,},
{/*225*/0b11011011,0b01001001,0b00100110,},
{/*226*/0b11011011,0b01001001,0b00110100,},
{/*227*/0b11011011,0b01001001,0b00110110,},
{/*228*/0b11011011,0b01001001,0b10100100,},
{/*229*/0b11011011,0b01001001,0b10100110,},
{/*230*/0b11011011,0b01001001,0b10110100,},
{/*231*/0b11011011,0b01001001,0b10110110,},
{/*232*/0b11011011,0b01001101,0b00100100,},
{/*233*/0b11011011,0b01001101,0b00100110,},
{/*234*/0b11011011,0b01001101,0b00110100,},
{/*235*/0b11011011,0b01001101,0b00110110,},
{/*236*/0b11011011,0b01001101,0b10100100,},
{/*237*/0b11011011,0b01001101,0b10100110,},
{/*238*/0b11011011,0b01001101,0b10110100,},
{/*239*/0b11011011,0b01001101,0b10110110,},
{/*240*/0b11011011,0b01101001,0b00100100,},
{/*241*/0b11011011,0b01101001,0b00100110,},
{/*242*/0b11011011,0b01101001,0b00110100,},
{/*243*/0b11011011,0b01101001,0b00110110,},
{/*244*/0b11011011,0b01101001,0b10100100,},
{/*245*/0b11011011,0b01101001,0b10100110,},
{/*246*/0b11011011,0b01101001,0b10110100,},
{/*247*/0b11011011,0b01101001,0b10110110,},
{/*248*/0b11011011,0b01101101,0b00100100,},
{/*249*/0b11011011,0b01101101,0b00100110,},
{/*250*/0b11011011,0b01101101,0b00110100,},
{/*251*/0b11011011,0b01101101,0b00110110,},
{/*252*/0b11011011,0b01101101,0b10100100,},
{/*253*/0b11011011,0b01101101,0b10100110,},
{/*254*/0b11011011,0b01101101,0b10110100,},
{/*255*/0b11011011,0b01101101,0b10110110,}
};
45 changes: 31 additions & 14 deletions lib/ledspitask/GwLedSpiTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "GwHardware.h"
#include "GwApi.h"
#include <driver/spi_master.h>
#include "ColorTo3Byte.h"

/*
controlling some WS2812 using SPI
Expand Down Expand Up @@ -82,25 +83,19 @@ static Color colorFromMode(GwLedMode cmode){


static void colorCompTo3Byte(uint8_t comp,uint8_t *buffer){
//test: we assume comp to be 0x7f
//meaning 1 0 bit (100) and 7 1 bits (110)
/*
*buffer= 0b10011011;
*(buffer+1)=0b01101101;
*(buffer+2)=0b10110110;
*/
*buffer= 0b10010010;
*(buffer+1)=0b01001001;
*(buffer+2)=0b10110110;
for (int i=0;i<3;i++){
*(buffer+i)=colorTo3Byte[comp][i];
}
}

//depending on LED strip - handle color order
static size_t ledsToBuffer(int numLeds,const Color *leds,uint8_t *buffer){
uint8_t *p=buffer;
for (int i=0;i<numLeds;i++){
colorCompTo3Byte(leds[i].g,p);
p+=3;
colorCompTo3Byte(leds[i].r,p);
p+=3;
colorCompTo3Byte(leds[i].g,p);
p+=3;
colorCompTo3Byte(leds[i].b,p);
p+=3;
}
Expand Down Expand Up @@ -185,12 +180,23 @@ void handleSpiLeds(GwApi *api){
GwLedMode currentMode=LED_GREEN;
bool first=true;
int apiResult=0;
int count=0;
int seccount=0;
int modeIndex=0;
GwLedMode modes[4]={LED_WHITE,LED_GREEN,LED_RED,LED_BLUE};
while (true)
{
delay(50);
count++;
if (count > 20){ //1s repeat
first=true;
count=0;
seccount++;
}
GwLedMode newMode = currentMode;
/*
IButtonTask buttonState = api->taskInterfaces()->get<IButtonTask>(apiResult);
if (apiResult >= 0)
if (apiResult >= 0 )
{
switch (buttonState.state)
{
Expand All @@ -209,10 +215,19 @@ void handleSpiLeds(GwApi *api){
{
newMode = LED_WHITE;
}
*/
if (seccount > 5){
newMode=modes[modeIndex];
modeIndex++;
if (modeIndex >= 4) modeIndex=0;
seccount=0;
first=true;
}
if (newMode != currentMode || first)
{
first=false;
leds[0] = setBrightness(colorFromMode(newMode),brightness);
LOG_DEBUG(GwLog::DEBUG,"(%d) mode=%d,setting color g=%d,r=%d,b=%d",modeIndex,(int)newMode,leds[0].g,leds[0].r,leds[0].b);
ledsToBuffer(NUMLEDS,leds,outbuffer);
struct spi_transaction_t ta = {
.flags = 0,
Expand All @@ -222,12 +237,14 @@ void handleSpiLeds(GwApi *api){
.rxlength = 0,
.tx_buffer = outbuffer
};
int64_t now=esp_timer_get_time();
esp_err_t ret = spi_device_transmit(device, &ta);
int64_t end=esp_timer_get_time();
if (ret != ESP_OK){
LOG_DEBUG(GwLog::ERROR,"unable to send led data: %d",(int)ret);
}
else{
LOG_DEBUG(GwLog::DEBUG,"successfully send led data for %d leds",NUMLEDS);
LOG_DEBUG(GwLog::DEBUG,"successfully send led data for %d leds, %lld us",NUMLEDS,end-now);
}
currentMode = newMode;
}
Expand Down

0 comments on commit ee9da79

Please sign in to comment.