From 3cfae4ccceff06f14d9f821aa12f88a9981a9373 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 4 Nov 2021 19:29:06 +0100 Subject: [PATCH] Support for DisplayDimmer for Core2 with Berry drivers --- tasmota/berry/drivers/i2c_axp192_M5StackCore2.be | 16 +++++++++++++++- tasmota/xdrv_13_display.ino | 8 ++++++++ tasmota/xdsp_18_berry_display.ino | 10 +++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tasmota/berry/drivers/i2c_axp192_M5StackCore2.be b/tasmota/berry/drivers/i2c_axp192_M5StackCore2.be index 057c3d4e1..79e6ee7f6 100644 --- a/tasmota/berry/drivers/i2c_axp192_M5StackCore2.be +++ b/tasmota/berry/drivers/i2c_axp192_M5StackCore2.be @@ -3,7 +3,7 @@ -------------------------------------------------------------# class AXP192_M5Stack_Core2 : AXP192 def init() - super(self, AXP192).init() + super(self).init() if self.wire # Disable vbus hold limit @@ -116,6 +116,20 @@ class AXP192_M5Stack_Core2 : AXP192 self.write8(0x12, self.read8(0x12) | 0x40) # set EXTEN to enable 5v boost end end + + # Dimmer in percentage + def set_displaydimmer(x) + var v = tasmota.scale_uint(x, 0, 100, 2500, 3300) + self.set_lcd_voltage(v) + end + + # respond to display events + def display(cmd, idx, payload, raw) + if cmd == "dim" || cmd == "power" + self.set_displaydimmer(idx) + end + end + end axp = AXP192_M5Stack_Core2() diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 123d40276..da4439f61 100755 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -1861,6 +1861,10 @@ void DisplaySetPower(void) XdspCall(FUNC_DISPLAY_POWER); } else { renderer->DisplayOnff(disp_power); +#ifdef USE_BERRY + // still call Berry virtual display in case it is not managed entirely by renderer + Xdsp18(FUNC_DISPLAY_POWER); +#endif // USE_BERRY } } } @@ -1961,6 +1965,10 @@ void ApplyDisplayDimmer(void) { } if (renderer) { renderer->dim8(dimmer8, dimmer8_gamma); // provide 8 bits and gamma corrected dimmer in 8 bits +#ifdef USE_BERRY + // still call Berry virtual display in case it is not managed entirely by renderer + Xdsp18(FUNC_DISPLAY_DIM); +#endif // USE_BERRY } else { XdspCall(FUNC_DISPLAY_DIM); } diff --git a/tasmota/xdsp_18_berry_display.ino b/tasmota/xdsp_18_berry_display.ino index 463868312..11875692e 100644 --- a/tasmota/xdsp_18_berry_display.ino +++ b/tasmota/xdsp_18_berry_display.ino @@ -32,19 +32,19 @@ bool Xdsp18(uint8_t function) { switch (function) { case FUNC_DISPLAY_INIT_DRIVER: - result = callBerryEventDispatcher(PSTR("display"), PSTR("init_driver"), function, XdrvMailbox.data); + result = callBerryEventDispatcher(PSTR("display"), PSTR("init_driver"), 0, nullptr); break; case FUNC_DISPLAY_INIT: - result = callBerryEventDispatcher(PSTR("display"), PSTR("init_driver"), function, XdrvMailbox.data); + result = callBerryEventDispatcher(PSTR("display"), PSTR("init_driver"), 0, nullptr); break; case FUNC_DISPLAY_MODEL: - result = callBerryEventDispatcher(PSTR("display"), PSTR("model"), function, XdrvMailbox.data); + result = callBerryEventDispatcher(PSTR("display"), PSTR("model"), 0, nullptr); break; case FUNC_DISPLAY_DIM: - result = callBerryEventDispatcher(PSTR("display"), PSTR("dim"), function, XdrvMailbox.data); + result = callBerryEventDispatcher(PSTR("display"), PSTR("dim"), GetDisplayDimmer(), nullptr); break; case FUNC_DISPLAY_POWER: - result = callBerryEventDispatcher(PSTR("display"), PSTR("power"), function, XdrvMailbox.data); + result = callBerryEventDispatcher(PSTR("display"), PSTR("power"), disp_power ? GetDisplayDimmer() : 0, nullptr); break; } return result;