Skip to content

Commit

Permalink
add special channel indexes for R, G, B access
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Feb 19, 2023
1 parent 8573a26 commit 008e1ae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/cmnds/cmd_newLEDDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,21 @@ OBK_Publish_Result sendColorChange() {

return MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_BASECOLOR_RGB,DEDUP_EXPIRE_TIME,"led_basecolor_rgb",s, 0);
}
void LED_SetBaseColorByIndex(int i, float f, bool bApply) {
if (i < 0 || i >= 5)
return;
baseColors[i] = f;
if (bApply) {
if (CFG_HasFlag(OBK_FLAG_LED_AUTOENABLE_ON_ANY_ACTION)) {
LED_SetEnableAll(true);
}

// set g_lightMode
SET_LightMode(Light_RGB);
sendColorChange();
apply_smart_light();
}
}
void LED_GetBaseColorString(char * s) {
byte c[3];

Expand Down
1 change: 1 addition & 0 deletions src/cmnds/cmd_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ bool LED_IsLEDRunning();
void LED_SetEnableAll(int bEnable);
int LED_GetEnableAll();
void LED_GetBaseColorString(char* s);
void LED_SetBaseColorByIndex(int i, float f, bool bApply);
int LED_GetMode();
float LED_GetHue();
float LED_GetSaturation();
Expand Down
4 changes: 4 additions & 0 deletions src/new_pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,10 @@ void CHANNEL_Set(int ch, int iVal, int iFlags) {
LED_SetTemperature(iVal, 1);
return;
}
if (ch >= SPECIAL_CHANNEL_BASECOLOR_FIRST && ch <= SPECIAL_CHANNEL_BASECOLOR_LAST) {
LED_SetBaseColorByIndex(ch - SPECIAL_CHANNEL_BASECOLOR_FIRST, iVal, 1);
return;
}
if (ch < 0 || ch >= CHANNEL_MAX) {
//if(bMustBeSilent==0) {
addLogAdv(LOG_ERROR, LOG_FEATURE_GENERAL, "CHANNEL_Set: Channel index %i is out of range <0,%i)\n\r", ch, CHANNEL_MAX);
Expand Down
21 changes: 17 additions & 4 deletions src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,23 @@ typedef enum {

#define CHANNEL_MAX 64

#define SPECIAL_CHANNEL_BRIGHTNESS 129
#define SPECIAL_CHANNEL_LEDPOWER 130
#define SPECIAL_CHANNEL_BASECOLOR 131
#define SPECIAL_CHANNEL_TEMPERATURE 132
// Special channel indexes
// They were created so we can have easy and seamless
// access to special variables internally.
// Futhermore, they can be very useful for scripting,
// because they can be plugged into "setChannel" command
#define SPECIAL_CHANNEL_BRIGHTNESS 129
#define SPECIAL_CHANNEL_LEDPOWER 130
#define SPECIAL_CHANNEL_BASECOLOR 131
#define SPECIAL_CHANNEL_TEMPERATURE 132
// RGBCW access (well, in reality, we just use RGB access and CW is derived from temp)
#define SPECIAL_CHANNEL_BASECOLOR_FIRST 133
#define SPECIAL_CHANNEL_BASECOLOR_RED 133
#define SPECIAL_CHANNEL_BASECOLOR_GREEN 134
#define SPECIAL_CHANNEL_BASECOLOR_BLUE 135
#define SPECIAL_CHANNEL_BASECOLOR_COOL 136
#define SPECIAL_CHANNEL_BASECOLOR_WARM 137
#define SPECIAL_CHANNEL_BASECOLOR_LAST 137

#if PLATFORM_W800

Expand Down

0 comments on commit 008e1ae

Please sign in to comment.