I’ve had some success at converting kodi_panel.py
to use a framebuffer display. The changes amount to the following, all performed on an RPi3:
-
Comment out the luma.*
imports.
-
After copying Pytorinox’s framebuffer.py
file locally, add
from framebuffer import Framebuffer
-
Change USE_BACKLIGHT
to False
.
-
Change the Image.new()
call to use "RGBA"
rather than "RGB"
.
-
Instead of invoking the constructors for spi()
and ili9341()
, instantiate a Framebuffer object:
fb = Framebuffer(1)
This example is using /dev/fb1
.
-
Replace all device.display(image)
calls with fb.show(image)
That was it!
In order to make use of the existing GPIO approach for the touchscreen interrupt, I did recompile the dtoverlay (added to github in the other/ directory) to comment out the whole ti,ads7846
section. That left GPIO 16 (RPi.GPIO or BCM numbering) free for use by kodi_panel.py
.
Without that change, I couldn’t get RPi.GPIO to “attach” an interrupt. With the overlay as originally written, the ads7846 driver does got loaded, but I haven’t figured out how one can get equivalent asynchronous interrupt functionality in Python via that driver. The Python evdev
package does see the touchscreen as /dev/input/event3
, but I didn’t investigate further (as it looked to require use of Python’s asyncio).
So, sticking with GPIO for the touchscreen interrupt, the only thing I haven’t figured out is how to control the backlight from Python for the tinyDRM mi0283qt driver. The usual advice I’ve found on the web about writing a 1
or 0
to a file down in /sys/class/backlight
didn’t seem to accomplish anything.
Cheers,
Matt
Representative diff for framebuffer operation
diff --git a/kodi_panel.py b/kodi_panel.py
index af0cf8e..576e4bb 100644
--- a/kodi_panel.py
+++ b/kodi_panel.py
@@ -21,9 +21,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-from luma.core.interface.serial import spi
-from luma.core.render import canvas
-from luma.lcd.device import ili9341
+#from luma.core.interface.serial import spi
+#from luma.core.render import canvas
+#from luma.lcd.device import ili9341
@@ -32,6 +32,8 @@ from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
+from framebuffer import Framebuffer # pytorinox
+
from datetime import datetime, timedelta
from enum import Enum
import time
@@ -80,7 +83,7 @@ color_progfg = color7S # progress bar foreground
color_artist = 'yellow' # artist name
# Pillow objects
-image = Image.new('RGB', (frame_size), 'black')
+image = Image.new('RGBA', (frame_size), 'black')
draw = ImageDraw.Draw(image)
# Audio/Video codec lookup
@@ -250,7 +253,7 @@ lock = threading.Lock()
# luma.lcd at all to change backlight state. Uses with OLED displays
# should set it to False.
#
-USE_BACKLIGHT = True
+USE_BACKLIGHT = False
USE_PWM = False
PWM_FREQ = 362 # frequency, presumably in Hz
PWM_LEVEL = 75.0 # float value between 0 and 100
@@ -288,20 +291,24 @@ PWM_LEVEL = 75.0 # float value between 0 and 100
# once non-zero reset hold and release times were specified
# for the device.
#
-serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=25,
- reset_hold_time=0.2, reset_release_time=0.2)
+#serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=25,
+# reset_hold_time=0.2, reset_release_time=0.2)
+#
+# if USE_PWM:
+# device = ili9341(serial, active_low=False, width=320, height=240,
+# bus_speed_hz=32000000,
+# gpio_LIGHT=18,
+# pwm_frequency=PWM_FREQ
+# )
+# else:
+# device = ili9341(serial, active_low=False, width=320, height=240,
+# bus_speed_hz=32000000,
+# gpio_LIGHT=18
+# )
+
+
+fb = Framebuffer(1)
-if USE_PWM:
- device = ili9341(serial, active_low=False, width=320, height=240,
- bus_speed_hz=32000000,
- gpio_LIGHT=18,
- pwm_frequency=PWM_FREQ
- )
-else:
- device = ili9341(serial, active_low=False, width=320, height=240,
- bus_speed_hz=32000000,
- gpio_LIGHT=18
- )
@@ -784,7 +791,7 @@ def update_display():
audio_screens(image, draw, track_info, prog)
# Output to OLED/LCD display
- device.display(image)
+ fb.show(image)
lock.release()
@@ -825,7 +834,9 @@ def main():
screen_on()
draw.rectangle([(0,0), (frame_size[0],frame_size[1])], 'black', 'black')
draw.text(( 5, 5), "Waiting to connect with Kodi...", fill='white', font=font_main)
- device.display(image)
+ fb.show(image)