Migrate MCP and utilities to CircuitPython, including color GIF and volume fixes
This commit is contained in:
@@ -439,3 +439,62 @@ class ILI9341:
|
||||
self.spi.write(self.row_buffer)
|
||||
|
||||
self.cs(1)
|
||||
|
||||
def set_brightness(self, level):
|
||||
"""Set backlight brightness percentage (0-100)."""
|
||||
if self.bl is None:
|
||||
return
|
||||
from machine import Pin, PWM
|
||||
level = max(0, min(100, level))
|
||||
if level == 0:
|
||||
if hasattr(self, '_bl_pwm') and self._bl_pwm is not None:
|
||||
try:
|
||||
self._bl_pwm.deinit()
|
||||
except:
|
||||
pass
|
||||
self._bl_pwm = None
|
||||
if isinstance(self.bl, Pin):
|
||||
self.bl.init(Pin.OUT, value=0)
|
||||
elif level == 100:
|
||||
if hasattr(self, '_bl_pwm') and self._bl_pwm is not None:
|
||||
try:
|
||||
self._bl_pwm.deinit()
|
||||
except:
|
||||
pass
|
||||
self._bl_pwm = None
|
||||
if isinstance(self.bl, Pin):
|
||||
self.bl.init(Pin.OUT, value=1)
|
||||
else:
|
||||
if not hasattr(self, '_bl_pwm') or self._bl_pwm is None:
|
||||
self._bl_pwm = PWM(self.bl)
|
||||
self._bl_pwm.freq(1000)
|
||||
self._bl_pwm.duty_u16(int(level * 655.35))
|
||||
|
||||
def set_power(self, on):
|
||||
"""Set display power status (True = ON, False = OFF)."""
|
||||
if on:
|
||||
self.write_cmd(0x11) # SLPOUT
|
||||
time.sleep_ms(120)
|
||||
self.write_cmd(0x29) # DISPON
|
||||
if self.bl is not None:
|
||||
if hasattr(self, '_bl_pwm') and self._bl_pwm is not None:
|
||||
pass
|
||||
else:
|
||||
from machine import Pin
|
||||
if isinstance(self.bl, Pin):
|
||||
self.bl.init(Pin.OUT, value=1)
|
||||
else:
|
||||
self.write_cmd(0x28) # DISPOFF
|
||||
self.write_cmd(0x10) # SLPIN
|
||||
time.sleep_ms(10)
|
||||
if self.bl is not None:
|
||||
if hasattr(self, '_bl_pwm') and self._bl_pwm is not None:
|
||||
try:
|
||||
self._bl_pwm.deinit()
|
||||
except:
|
||||
pass
|
||||
self._bl_pwm = None
|
||||
from machine import Pin
|
||||
if isinstance(self.bl, Pin):
|
||||
self.bl.init(Pin.OUT, value=0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user