-
Notifications
You must be signed in to change notification settings - Fork 145
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Hi, I think it would be nice to implement gamma correction for the light bulb controllers, to linearise the perceived brightness, since in the lower brightness range a variation of a few percentages is much more noticeable than in the higher range.
I think the best place to implement it would be in the UpdatePWM methods of the WhiteController, CCTController, and RGBWController
I could make a PR for an hardcoded version, but I think it would be nice to give the option to enable it or not from the UI, and I don't have the knowledge to implement that, but let me know if I can help.
const float gammaValue = 2.2f // Typical LED gamma value
bool gammaEnabled = true; // Placeholder for config option
// shelly_rgbw_controller.cpp
void RGBWController::UpdatePWM(const StateRGBW &state) {
float r = gammaEnabled ? powf(state.r, gammaValue) : state.r;
float g = gammaEnabled ? powf(state.g, gammaValue) : state.g;
float b = gammaEnabled ? powf(state.b, gammaValue) : state.b;
out_r_->SetStatePWM(r, "transition");
out_g_->SetStatePWM(g, "transition");
out_b_->SetStatePWM(b, "transition");
if (out_w_ != nullptr) {
float w = gammaEnabled ? powf(state.w, gammaValue) : state.w;
out_w_->SetStatePWM(state.w, "transition");
}
}
// shelly_cct_controller.cpp
void CCTController::UpdatePWM(const StateCCT &state) {
float ww = gammaEnabled ? powf(state.ww, gammaValue) : state.ww;
float cw = gammaEnabled ? powf(state.cw, gammaValue) : state.cw;
out_ww_->SetStatePWM(ww, "transition");
out_cw_->SetStatePWM(cw, "transition");
}
// shelly_white_controller.cpp
void WhiteController::UpdatePWM(const StateW &state) {
float w = gammaEnabled ? powf(state.w, gammaValue) : state.w;
out_w_->SetStatePWM(w, "transition");
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request