Skip to content

Commit

Permalink
Update cmd_newLEDDriver.c
Browse files Browse the repository at this point in the history
  • Loading branch information
rogere66 authored Dec 13, 2022
1 parent ef0fc31 commit 698feb4
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions src/cmnds/cmd_newLEDDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,25 @@ void LED_RunQuickColorLerp(int deltaMS) {
}
#endif
}

int exponential_mode = 2;

/* exponential mode command handler, usage: led_expoMode <0|1|2|3|4>
exponential modes: 0 = Off
1 = 1% min brightness with moderate exponential
2 = 1% min brightness with full exponential
3 = 0.1% min brightness with moderate exponential
4 = 0.1% min brightness with full exponential
*/
static commandResult_t exponentialMode (const void *context, const char *cmd, const char *args, int cmdFlags) {
int mode = atoi (args);
if((mode >= 0) && (mode <= 4)) {
exponential_mode = mode;
apply_smart_light ();
}
return CMD_RES_OK;
}

void apply_smart_light() {
int i;
int firstChannelIndex;
Expand Down Expand Up @@ -329,11 +348,32 @@ void apply_smart_light() {
float raw, final;

raw = baseColors[i];
final = 0.0f;

if(g_lightEnableAll) {
final = raw * g_brightness;
} else {
final = 0;
// make brightness exponential:
if (exponential_mode == 0) {
final = raw * g_brightness;
} else if (g_brightness == 0.0f) {
final = 0.0f;
} else {
float expo_base;
float expo_factor;
float expo_offset = 0.0;
if ((exponential_mode == 1) || (exponential_mode == 2)) {
expo_offset = 0.009f;
}
if ((exponential_mode == 1) || (exponential_mode == 3)) {
expo_base = 1.2f; // moderate exponential
expo_factor = 15.32f;
expo_offset -= 0.06609f;
} else {
expo_base = 1.06f; // full exponential
expo_factor = 74.115f;
expo_offset -= 0.013f;
}
final = raw * (pow(expo_base, g_brightness * expo_factor) / expo_factor + expo_offset);
}
}
if(g_lightMode == Light_Temperature) {
// skip channels 0, 1, 2
Expand All @@ -354,13 +394,16 @@ void apply_smart_light() {
finalColors[i] = final;
finalRGBCW[i] = final;

int chVal = (int)(final * g_cfg_colorScaleToChannel);
if (chVal > 100)
chVal = 100;

channelToUse = firstChannelIndex + i;

// log printf with %f crashes N platform?
//ADDLOG_INFO(LOG_FEATURE_CMD, "apply_smart_light: ch %i raw is %f, bright %f, final %f, enableAll is %i",
// channelToUse,raw,g_brightness,final,g_lightEnableAll);

float chVal = final * g_cfg_colorScaleToChannel;
if(CFG_HasFlag(OBK_FLAG_LED_SMOOTH_TRANSITIONS) == false) {
if(isCWMode()) {
// in CW mode, we have only set two channels
Expand Down Expand Up @@ -1193,6 +1236,11 @@ void NewLED_InitCommands(){
//cmddetail:"fn":"lerpSpeed","file":"cmnds/cmd_newLEDDriver.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("led_lerpSpeed", "", lerpSpeed, NULL, NULL);
//cmddetail:{"name":"led_expoMode","args":"",
//cmddetail:"descr":"set brightness exponential mode 0..4",
//cmddetail:"fn":"exponentialMode","file":"cmnds/cmd_newLEDDriver.c","requires":"",
//cmddetail:"examples":"led_expoMode 4"}
CMD_RegisterCommand("led_expoMode", "", exponentialMode, NULL, NULL);

// HSBColor 360,100,100 - red
// HSBColor 90,100,100 - green
Expand Down

0 comments on commit 698feb4

Please sign in to comment.