Skip to content

Commit

Permalink
Update custom colors on display when changed elswhere
Browse files Browse the repository at this point in the history
  • Loading branch information
CWempe committed Oct 18, 2018
1 parent b9d0415 commit d562db3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/SuperLEDstrip.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ bool halloweenFlickerState = false; // helper to save current state of flick
uint16_t halloweenFlashTimer = 1000; // initial flash timer value
bool halloweenFlashState = false; // helper to save current state of flashing; true = flashing on

bool updateDisplayRed = false;
bool updateDisplayGreen = false;
bool updateDisplayBlue = false;


/*
* Nextion display
Expand Down Expand Up @@ -237,4 +241,6 @@ void loop(void)

Homie.loop();

updateDisplayColors();

}
3 changes: 3 additions & 0 deletions src/led_custom_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void updateCustomColor() {

void updateCustomColorRed(uint8_t red, bool updateRGB = true) {
customColor.red = red;
updateDisplayRed = true;

// Send updated RGB values to mqtt and display.
// But only do so if you do not want to change other colors at the same time.
Expand All @@ -23,6 +24,7 @@ void updateCustomColorRed(uint8_t red, bool updateRGB = true) {

void updateCustomColorGreen(uint8_t green, bool updateRGB = true) {
customColor.green = green;
updateDisplayGreen = true;

// Send updated RGB values to mqtt and display.
// But only do so if you do not want to change other colors at the same time.
Expand All @@ -34,6 +36,7 @@ void updateCustomColorGreen(uint8_t green, bool updateRGB = true) {

void updateCustomColorBlue(uint8_t blue, bool updateRGB = true) {
customColor.blue = blue;
updateDisplayBlue = true;

// Send updated RGB values to mqtt and display.
// But only do so if you do not want to change other colors at the same time.
Expand Down
6 changes: 3 additions & 3 deletions src/nextion_declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ NexButton p09greenM = NexButton(8, 23, "p09greenM");
NexButton p09greenP = NexButton(8, 24, "p09greenP");
NexButton p09blueM = NexButton(8, 26, "p09blueM");
NexButton p09blueP = NexButton(8, 27, "p09blueP");
NexText red = NexText( 8, 18, "red");
NexText green = NexText( 8, 19, "green");
NexText blue = NexText( 8, 20, "blue");
NexText p09red = NexText( 8, 15, "p09red");
NexText p09green = NexText( 8, 22, "p09green");
NexText p09blue = NexText( 8, 25, "p09blue");
60 changes: 59 additions & 1 deletion src/nextion_functions.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

void setTextTitle()
{
title.setText(DISPLAY_TITLE);
Expand Down Expand Up @@ -110,4 +109,63 @@ void getBlue ()
if ( blue != 999) {
updateCustomColorBlue(blue);
}
}

void setRed ()
{
uint8_t red = customColor.red;

// set slider
delay (10); // a short delay to make the setValue work more stable
p09sliderRed.setValue(red);
delay (10);

// set value next to slider; needs to be converted to char
char sRed[4];
dtostrf(red, 3, 0, sRed);
p09red.setText(sRed);

updateDisplayRed = false;
}

void setGreen ()
{
uint8_t green = customColor.green;

// set slider
delay (10); // a short delay to make the setValue work more stable
p09sliderGreen.setValue(green);
delay (10);

// set value next to slider; needs to be converted to char
char sGreen[4];
dtostrf(green, 3, 0, sGreen);
p09green.setText(sGreen);

updateDisplayGreen = false;
}

void setBlue ()
{
uint8_t blue = customColor.blue;

// set slider
delay (10); // a short delay to make the setValue work more stable
p09sliderBlue.setValue(blue);
delay (10);

// set value next to slider; needs to be converted to char
char sBlue[4];
dtostrf(blue, 3, 0, sBlue);
p09blue.setText(sBlue);

updateDisplayBlue= false;
}

// this function is used because directly `setValue` in updateCustomColor* causes the program to crash
void updateDisplayColors ()
{
if ( updateDisplayRed == true ) { setRed(); delay(10);}
if ( updateDisplayGreen == true ) { setGreen(); delay(10);}
if ( updateDisplayBlue == true ) { setBlue(); }
}
6 changes: 3 additions & 3 deletions src/nextion_registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ NexTouch *nex_listen_list[] =

&p09, &p09title, &p09temp, &p09humid,
&p09settings, &p09power,
&red, &p09sliderRed, &p09redM, &p09redP,
&green, &p09sliderGreen, &p09greenM, &p09greenP,
&blue, &p09sliderBlue, &p09blueM, &p09blueP,
&p09red, &p09sliderRed, &p09redM, &p09redP,
&p09green, &p09sliderGreen, &p09greenM, &p09greenP,
&p09blue, &p09sliderBlue, &p09blueM, &p09blueP,
NULL
};

0 comments on commit d562db3

Please sign in to comment.