Browse Source

Merge branch 'main' of https://github.com/mmakaay/esphome-yeelight_bs2 into main

pull/1/head
Maurice Makaay 3 years ago
parent
commit
5b8de77a12
10 changed files with 142 additions and 5 deletions
  1. +3
    -0
      .gitignore
  2. BIN
      doc/ESP32 pinout.xcf
  3. BIN
      doc/IC connected to I2C on GPIO 17+18.xcf
  4. +139
    -0
      doc/RGB_mapping.py
  5. BIN
      doc/Trace bottom right.xcf
  6. BIN
      doc/Trace for IC connected to I2C on GPIO 17+18.xcf
  7. BIN
      doc/Trace front panel connector.xcf
  8. BIN
      doc/Trace top right.xcf
  9. BIN
      doc/Yeelight GPIO measurements.xlsx
  10. +0
    -5
      yeelight_bs2.h

+ 3
- 0
.gitignore View File

@ -17,3 +17,6 @@ Sessionx.vim
tags
# Persistent undo
[._]*.un~
# OpenOffice temp files
**/.~*

BIN
doc/ESP32 pinout.xcf View File


BIN
doc/IC connected to I2C on GPIO 17+18.xcf View File


+ 139
- 0
doc/RGB_mapping.py View File

@ -0,0 +1,139 @@
#!/usr/bin/env python3
#
# This script was used to work out how to map the RGB/brightness input
# data to GPIO pinout voltages.
maxV = 3.27
requirements = [
# Input # Expected output
(0, 0, 0, 1.00, False, None, None, None),
(255, 255, 255, 0.00, False, None, None, None),
(255, 0, 0, 0.01, True, 2.95, maxV, maxV),
(255, 0, 0, 1.00, True, 1.82, 3.27, 3.27),
(255, 255, 0, 0.01, True, 3.04, 2.86, 3.17),
(255, 255, 0, 1.00, True, 2.56, 1.77, 3.15),
(255, 255, 255, 0.01, True, 3.04, 2.86, 3.07),
(255, 255, 255, 1.00, True, 2.56, 1.77, 2.73),
(0, 255, 0, 0.01, True, 3.27, 2.95, 3.27),
(0, 255, 0, 1.00, True, 3.27, 1.82, 3.27),
(0, 255, 255, 0.01, True, 3.13, 2.86, 3.07),
(0, 255, 255, 1.00, True, 2.97, 1.76, 2.71),
(0, 0, 255, 0.01, True, 3.27, 3.27, 2.95),
(0, 0, 255, 1.00, True, 3.27, 3.27, 1.82),
(255, 0, 255, 0.01, True, 2.88, 3.12, 2.86),
(255, 0, 255, 1.00, True, 1.85, 2.92, 1.77),
(255, 128, 0, 0.01, True, 2.86, 2.93, 3.17),
(255, 128, 0, 1.00, True, 1.77, 2.10, 3.15),
(255, 0 ,128, 0.01, True, 2.86, 3.12, 3.10),
(255, 0 ,128, 1.00, True, 1.77, 2.94, 2.84),
(255, 128, 128, 0.01, True, 2.86, 2.93, 3.10),
(255, 128, 128, 1.00, True, 1.77, 2.10, 2.86),
(128, 255, 0, 0.01, True, 3.11, 2.86, 3.17),
(128, 255, 0, 1.00, True, 2.87, 1.76, 3.15),
(255, 128, 255, 0.01, True, 2.86, 2.93, 2.87),
(255, 128, 255, 1.00, True, 1.76, 2.06, 1.80),
]
def get_red(r, g, b, brightness):
if r == 0:
if g == 1 and b == 1:
return round(3.13 - (brightness * 100 - 1) * (3.13 - 2.97)/99, 2)
else:
return maxV;
if g == 1:
if r == 1:
return round((3.04 - (brightness * 100 - 1) * (3.04 - 2.56)/99), 2)
elif r > 0:
return round((3.11 - (brightness * 100 - 1) * (3.11 - 2.87)/99), 2)
elif g > 0:
if b == 1:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.76)/99), 2)
else:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.77)/99), 2)
elif b == 1:
return round((2.88 - (brightness * 100 - 1) * (2.88 - 1.85)/99), 2)
elif b > 0:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.77)/99), 2)
else:
return round((2.95 - (brightness * 100 - 1) * (2.95 - 1.82)/99), 2)
raise Exception("Shouldn't get here")
def get_green(r, g, b, brightness):
if g == 0:
if r == 1 and b == 1:
return round(3.12 - (brightness * 100 - 1) * (3.12 - 2.92)/99, 2)
elif r == 1 and b > 0:
return round(3.12 - (brightness * 100 - 1) * (3.12 - 2.94)/99, 2)
else:
return maxV;
if r == 1 and g == 1:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.77)/99), 2)
elif r == 1:
if b == 1:
return round((2.93 - (brightness * 100 - 1) * (2.93 - 2.06)/99), 2)
else:
return round((2.93 - (brightness * 100 - 1) * (2.93 - 2.10)/99), 2)
elif r > 0:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.76)/99), 2)
elif r == 0 and b == 1:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.76)/99), 2)
else:
return round((2.95 - (brightness * 100 - 1) * (2.95 - 1.82)/99), 2)
raise Exception("Shouldn't get here")
def get_blue(r, g, b, brightness):
if b == 0:
if r > 0 and g > 0:
return round((3.17 - (brightness * 100 - 1) * (3.17 - 3.15)/99), 2)
else:
return maxV;
if r == 1 and g == 1:
return round((3.07 - (brightness * 100 - 1) * (3.07 - 2.73)/99), 2)
elif r == 1 and g == 0:
if b == 1:
return round((2.86 - (brightness * 100 - 1) * (2.86 - 1.77)/99), 2)
elif b > 0:
return round((3.10 - (brightness * 100 - 1) * (3.10 - 2.84)/99), 2)
elif r == 1 and g > 0:
if b == 1:
return round((2.87 - (brightness * 100 - 1) * (2.87 - 1.80)/99), 2)
else:
return round((3.10 - (brightness * 100 - 1) * (3.10 - 2.86)/99), 2)
elif r == 0 and g == 1:
return round((3.07 - (brightness * 100 - 1) * (3.07 - 2.71)/99), 2)
else:
return round((2.95 - (brightness * 100 - 1) * (2.95 - 1.82)/99), 2)
raise Exception("Shouldn't get here")
def make_rgb_fractions(r, g, b):
""" These ought to be 0 to 1 on input already, but it won't
hurt to make sure they are."""
m = max(r, g, b)
r = r/m
g = g/m
b = b/m
return (r, g, b)
for r,g,b,brightness,stateExpected, rVexpected, gVexpected, bVexpected in requirements:
print(f"IN: {r}, {g}, {b} at {brightness} / ", end="")
print(f"EXP: ({stateExpected}) {rVexpected},{gVexpected},{bVexpected} ", end="")
state = True
if r + g + b == 0 or brightness == 0:
state = False
rV = None
gV = None
bV = None
else:
r, g, b = make_rgb_fractions(r, g, b)
rV = get_red(r, g, b, brightness)
gV = get_green(r, g, b, brightness)
bV = get_blue(r, g, b, brightness)
print(f"OUT: ({state}) {rV},{gV},{bV} ", end="")
if rV == rVexpected and gV == gVexpected and bV == bVexpected and state == stateExpected:
print(" [PASS]");
else:
print()

BIN
doc/Trace bottom right.xcf View File


BIN
doc/Trace for IC connected to I2C on GPIO 17+18.xcf View File


BIN
doc/Trace front panel connector.xcf View File


BIN
doc/Trace top right.xcf View File


BIN
doc/Yeelight GPIO measurements.xlsx View File


+ 0
- 5
yeelight_bs2.h View File

@ -92,11 +92,6 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput
{
ESP_LOGD("custom", "Activate RGB %f, %f, %f, BRIGHTNESS %f", red, green, blue, brightness);
// This tunes the power for the red channel a bit, to bring
// the red=1, green=1, blue=1 color more towards white.
// (on my lamps, there is a faint hint of red in the color)
red = red * 0.93f;
// Compensate for brightness.
red = red * brightness;
green = green * brightness;


Loading…
Cancel
Save