mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
got OLED working
This commit is contained in:
BIN
user_program/cc.ttf
Normal file
BIN
user_program/cc.ttf
Normal file
Binary file not shown.
67
user_program/demo_opts.py
Normal file
67
user_program/demo_opts.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2014-18 Richard Hull and contributors
|
||||
# See LICENSE.rst for details.
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from luma.core import cmdline, error
|
||||
|
||||
|
||||
# logging
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)-15s - %(message)s'
|
||||
)
|
||||
# ignore PIL debug messages
|
||||
logging.getLogger('PIL').setLevel(logging.ERROR)
|
||||
|
||||
|
||||
def display_settings(device, args):
|
||||
"""
|
||||
Display a short summary of the settings.
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
iface = ''
|
||||
display_types = cmdline.get_display_types()
|
||||
if args.display not in display_types['emulator']:
|
||||
iface = 'Interface: {}\n'.format(args.interface)
|
||||
|
||||
lib_name = cmdline.get_library_for_display_type(args.display)
|
||||
if lib_name is not None:
|
||||
lib_version = cmdline.get_library_version(lib_name)
|
||||
else:
|
||||
lib_name = lib_version = 'unknown'
|
||||
|
||||
import luma.core
|
||||
version = 'luma.{} {} (luma.core {})'.format(
|
||||
lib_name, lib_version, luma.core.__version__)
|
||||
|
||||
return 'Version: {}\nDisplay: {}\n{}Dimensions: {} x {}\n{}'.format(
|
||||
version, args.display, iface, device.width, device.height, '-' * 60)
|
||||
|
||||
|
||||
def get_device(actual_args=None):
|
||||
"""
|
||||
Create device from command-line arguments and return it.
|
||||
"""
|
||||
if actual_args is None:
|
||||
actual_args = sys.argv[1:]
|
||||
parser = cmdline.create_parser(description='luma.examples arguments')
|
||||
args = parser.parse_args(actual_args)
|
||||
|
||||
if args.config:
|
||||
# load config from file
|
||||
config = cmdline.load_config(args.config)
|
||||
args = parser.parse_args(config + actual_args)
|
||||
|
||||
# create device
|
||||
try:
|
||||
device = cmdline.create_device(args)
|
||||
print(display_settings(device, args))
|
||||
return device
|
||||
|
||||
except error.Error as e:
|
||||
parser.error(e)
|
||||
return None
|
||||
@@ -1 +1 @@
|
||||
scp ./u2p2* pi@192.168.1.56:~/u2p2
|
||||
scp ./* pi@192.168.1.56:~/usb4vc
|
||||
2
user_program/usb4vc_config_parser.py
Normal file
2
user_program/usb4vc_config_parser.py
Normal file
@@ -0,0 +1,2 @@
|
||||
import sys
|
||||
import time
|
||||
29
user_program/usb4vc_oled.py
Normal file
29
user_program/usb4vc_oled.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# https://luma-oled.readthedocs.io/en/latest/software.html
|
||||
|
||||
import sys
|
||||
import time
|
||||
from demo_opts import get_device
|
||||
from luma.core.render import canvas
|
||||
from PIL import ImageFont
|
||||
|
||||
my_arg = ['--display', 'sh1106', '--interface', 'spi', '--spi-port', '0', '--spi-device', '1', '--gpio-reset', '6', '--gpio-data-command', '5', '--width', '128', '--height', '32']
|
||||
device = get_device(my_arg)
|
||||
|
||||
"""
|
||||
OLED for USB4VC
|
||||
128*32
|
||||
command&conquer ttf font, 12 point
|
||||
3 lines, y=0, 10, 20
|
||||
up to 20 characters per line
|
||||
"""
|
||||
|
||||
font_path = "cc.ttf"
|
||||
font2 = ImageFont.truetype(font_path, 12)
|
||||
|
||||
while 1:
|
||||
with canvas(device) as draw:
|
||||
draw.rectangle(device.bounding_box, outline="white", fill="black")
|
||||
draw.text((0, 0), "888888888877777777776666666666", font=font2, fill="white")
|
||||
draw.text((0, 10), "ABCDEFGHIJ", font=font2, fill="white")
|
||||
draw.text((0, 20), "abcdefghij", font=font2, fill="white")
|
||||
time.sleep(1)
|
||||
16
user_program/usb4vc_ui.py
Normal file
16
user_program/usb4vc_ui.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import time
|
||||
import sys
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
BUTTON_GPIO = 16
|
||||
|
||||
def button_pressed_callback(channel):
|
||||
print(time.time(), "Button pressed!")
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
# https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/
|
||||
GPIO.add_event_detect(BUTTON_GPIO, GPIO.FALLING, callback=button_pressed_callback, bouncetime=100)
|
||||
|
||||
while 1:
|
||||
time.sleep(1)
|
||||
Reference in New Issue
Block a user