Skip to content

Gamma correction for Light Bulb Controller #1658

@Giorgi020

Description

@Giorgi020

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");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions