diff --git a/.gitignore b/.gitignore index 19fa632..a674637 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ Sessionx.vim tags # Persistent undo [._]*.un~ + +# OpenOffice temp files +**/.~* diff --git a/doc/ESP32 pinout.xcf b/doc/ESP32 pinout.xcf new file mode 100644 index 0000000..418de6e Binary files /dev/null and b/doc/ESP32 pinout.xcf differ diff --git a/doc/IC connected to I2C on GPIO 17+18.xcf b/doc/IC connected to I2C on GPIO 17+18.xcf new file mode 100644 index 0000000..910f97f Binary files /dev/null and b/doc/IC connected to I2C on GPIO 17+18.xcf differ diff --git a/doc/RGB_mapping.py b/doc/RGB_mapping.py new file mode 100644 index 0000000..2b34306 --- /dev/null +++ b/doc/RGB_mapping.py @@ -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() + diff --git a/doc/Trace bottom right.xcf b/doc/Trace bottom right.xcf index a0706e5..b49e433 100644 Binary files a/doc/Trace bottom right.xcf and b/doc/Trace bottom right.xcf differ diff --git a/doc/Trace for IC connected to I2C on GPIO 17+18.xcf b/doc/Trace for IC connected to I2C on GPIO 17+18.xcf new file mode 100644 index 0000000..9e63b6c Binary files /dev/null and b/doc/Trace for IC connected to I2C on GPIO 17+18.xcf differ diff --git a/doc/Trace front panel connector.xcf b/doc/Trace front panel connector.xcf index 095d2cf..77ea49d 100644 Binary files a/doc/Trace front panel connector.xcf and b/doc/Trace front panel connector.xcf differ diff --git a/doc/Trace top right.xcf b/doc/Trace top right.xcf index de2485c..c28a7c0 100644 Binary files a/doc/Trace top right.xcf and b/doc/Trace top right.xcf differ diff --git a/doc/Yeelight GPIO measurements.xlsx b/doc/Yeelight GPIO measurements.xlsx index a04923c..276d508 100644 Binary files a/doc/Yeelight GPIO measurements.xlsx and b/doc/Yeelight GPIO measurements.xlsx differ diff --git a/yeelight_bs2.h b/yeelight_bs2.h index 031f6a5..72b2b31 100644 --- a/yeelight_bs2.h +++ b/yeelight_bs2.h @@ -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;