Support for DisplayDimmer for Core2 with Berry drivers

This commit is contained in:
Stephan Hadinger 2021-11-04 19:29:06 +01:00
parent a9bc3fdde8
commit 3cfae4ccce
3 changed files with 28 additions and 6 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------# -------------------------------------------------------------#
class AXP192_M5Stack_Core2 : AXP192 class AXP192_M5Stack_Core2 : AXP192
def init() def init()
super(self, AXP192).init() super(self).init()
if self.wire if self.wire
# Disable vbus hold limit # 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 self.write8(0x12, self.read8(0x12) | 0x40) # set EXTEN to enable 5v boost
end end
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 end
axp = AXP192_M5Stack_Core2() axp = AXP192_M5Stack_Core2()

View File

@ -1861,6 +1861,10 @@ void DisplaySetPower(void)
XdspCall(FUNC_DISPLAY_POWER); XdspCall(FUNC_DISPLAY_POWER);
} else { } else {
renderer->DisplayOnff(disp_power); 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) { if (renderer) {
renderer->dim8(dimmer8, dimmer8_gamma); // provide 8 bits and gamma corrected dimmer in 8 bits 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 { } else {
XdspCall(FUNC_DISPLAY_DIM); XdspCall(FUNC_DISPLAY_DIM);
} }

View File

@ -32,19 +32,19 @@ bool Xdsp18(uint8_t function) {
switch (function) { switch (function) {
case FUNC_DISPLAY_INIT_DRIVER: 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; break;
case FUNC_DISPLAY_INIT: case FUNC_DISPLAY_INIT:
result = callBerryEventDispatcher(PSTR("display"), PSTR("init_driver"), function, XdrvMailbox.data); result = callBerryEventDispatcher(PSTR("display"), PSTR("init_driver"), 0, nullptr);
break; break;
case FUNC_DISPLAY_MODEL: case FUNC_DISPLAY_MODEL:
result = callBerryEventDispatcher(PSTR("display"), PSTR("model"), function, XdrvMailbox.data); result = callBerryEventDispatcher(PSTR("display"), PSTR("model"), 0, nullptr);
break; break;
case FUNC_DISPLAY_DIM: case FUNC_DISPLAY_DIM:
result = callBerryEventDispatcher(PSTR("display"), PSTR("dim"), function, XdrvMailbox.data); result = callBerryEventDispatcher(PSTR("display"), PSTR("dim"), GetDisplayDimmer(), nullptr);
break; break;
case FUNC_DISPLAY_POWER: 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; break;
} }
return result; return result;