Browse Source

light: mireds as another input value

color temperature applies to input values as and / or
- rgb channels scale, when cct mode is enabled w/ color
- white channel(s), moving between warm and cold

remove two rgb scalers applied one after the other in favour of two
distinct variants - we either subtract common value from rgb or use
mireds as a scale for both rgb and ww+cw
restore brightness control as well
pull/2558/head
Maxim Prokhorov 1 year ago
parent
commit
441454d931
4 changed files with 446 additions and 345 deletions
  1. +1
    -1
      code/espurna/config/version.h
  2. +2
    -1
      code/espurna/homeassistant.cpp
  3. +421
    -330
      code/espurna/light.cpp
  4. +22
    -13
      code/espurna/light.h

+ 1
- 1
code/espurna/config/version.h View File

@ -21,5 +21,5 @@
#endif
#ifndef CFG_VERSION
#define CFG_VERSION 12
#define CFG_VERSION 13
#endif

+ 2
- 1
code/espurna/homeassistant.cpp View File

@ -644,7 +644,8 @@ void receiveLightJson(StringView payload) {
}
if (root.containsKey("color_temp")) {
lightMireds(root["color_temp"].as<long>());
const auto mireds = root["color_temp"].as<long>();
lightTemperature(light::Mireds{ .value = mireds });
}
if (root.containsKey("brightness")) {


+ 421
- 330
code/espurna/light.cpp
File diff suppressed because it is too large
View File


+ 22
- 13
code/espurna/light.h View File

@ -114,21 +114,21 @@ struct Rgb {
Rgb& operator=(const Rgb&) = default;
Rgb& operator=(Rgb&&) = default;
Rgb(long red, long green, long blue) :
constexpr Rgb(long red, long green, long blue) noexcept :
_red(std::clamp(red, Min, Max)),
_green(std::clamp(green, Min, Max)),
_blue(std::clamp(blue, Min, Max))
{}
long red() const {
constexpr long red() const {
return _red;
}
long green() const {
constexpr long green() const {
return _green;
}
long blue() const {
constexpr long blue() const {
return _blue;
}
@ -138,24 +138,32 @@ private:
long _blue { Min };
};
struct MiredsRange {
constexpr MiredsRange() = default;
MiredsRange(long cold, long warm) :
struct Mireds {
long value;
};
struct Kelvin {
long value;
};
struct TemperatureRange {
TemperatureRange() = delete;
constexpr TemperatureRange(long cold, long warm) noexcept :
_cold(cold),
_warm(warm)
{}
long cold() const {
constexpr long cold() const {
return _cold;
}
long warm() const {
constexpr long warm() const {
return _warm;
}
private:
long _cold { MiredsCold };
long _warm { MiredsWarm };
long _cold;
long _warm;
};
} // namespace light
@ -212,8 +220,9 @@ espurna::light::Hsv lightHsv();
void lightHs(long hue, long saturation);
void lightHsv(espurna::light::Hsv);
void lightMireds(long mireds);
espurna::light::MiredsRange lightMiredsRange();
void lightTemperature(espurna::light::Kelvin);
void lightTemperature(espurna::light::Mireds);
espurna::light::TemperatureRange lightMiredsRange();
void lightRed(long value);
long lightRed();


Loading…
Cancel
Save