restored stable code, current work in new branch

This commit is contained in:
dekuNukem
2025-08-24 22:42:02 +01:00
parent ee8b50f826
commit 9e96fd7cb1
5 changed files with 120 additions and 42 deletions

89
user_program/bb_tester.py Normal file
View File

@@ -0,0 +1,89 @@
import os
import sys
import time
import RPi.GPIO as GPIO
from demo_opts import get_device
from luma.core.render import canvas
from PIL import ImageFont
OLED_WIDTH = 128
OLED_HEIGHT = 32
my_arg = ['--display', 'ssd1306', '--interface', 'spi', '--spi-port', '0', '--spi-device', '1', '--gpio-reset', '6', '--gpio-data-command', '5', '--width', str(OLED_WIDTH), '--height', str(OLED_HEIGHT), '--spi-bus-speed', '2000000']
oled_device = get_device(my_arg)
time.sleep(0.5)
oled_device = get_device(my_arg)
font_regular = ImageFont.truetype("ProggyTiny.ttf", 16)
font_medium = ImageFont.truetype("ChiKareGo2.ttf", 16)
font_large = ImageFont.truetype("ProggyTiny.ttf", 32)
max_char_per_line = {font_regular:21, font_medium:17, font_large:11}
width_per_char = {font_regular:6, font_medium:7, font_large:12}
def oled_print_centered(text, font, y, this_canvas):
text = text.strip()[:max_char_per_line[font]]
start_x = int((OLED_WIDTH - (len(text) * width_per_char[font]))/2)
if start_x < 0:
start_x = 0
this_canvas.text((start_x, y), text, font=font, fill="white")
class my_button(object):
def __init__(self, bcm_pin):
super(my_button, self).__init__()
self.pin_number = bcm_pin
GPIO.setup(self.pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
self.prev_state = GPIO.input(self.pin_number)
def is_pressed(self):
result = False
current_state = GPIO.input(self.pin_number)
if self.prev_state == 1 and current_state == 0:
result = True
self.prev_state = current_state
return result
PLUS_BUTTON_PIN = 27
MINUS_BUTTON_PIN = 19
ENTER_BUTTON_PIN = 22
SHUTDOWN_BUTTON_PIN = 21
PCARD_CS_PIN = 8
SLEEP_LED_PIN = 26
GPIO.setup(SLEEP_LED_PIN, GPIO.OUT)
GPIO.output(SLEEP_LED_PIN, GPIO.LOW)
GPIO.setup(PCARD_CS_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
plus_button = my_button(PLUS_BUTTON_PIN)
minus_button = my_button(MINUS_BUTTON_PIN)
enter_button = my_button(ENTER_BUTTON_PIN)
shutdown_button = my_button(SHUTDOWN_BUTTON_PIN)
loop_count = 0
def print_pattern():
global loop_count
loop_count = (loop_count + 1) % 2
oled_device = get_device(my_arg)
if loop_count:
GPIO.output(SLEEP_LED_PIN, GPIO.HIGH)
with canvas(oled_device) as draw:
draw.text((0, 0), "ABCDEFGHIJKLMNO", font=font_medium, fill="white")
draw.text((0, 15), "PQRSTUVWXYZ0123", font=font_medium, fill="white")
else:
GPIO.output(SLEEP_LED_PIN, GPIO.LOW)
with canvas(oled_device) as draw:
draw.text((0, 0), "===================", font=font_medium, fill="white")
draw.text((0, 15), "===================", font=font_medium, fill="white")
print_pattern()
while 1:
time.sleep(0.05)
if GPIO.input(PCARD_CS_PIN) == 0:
GPIO.output(SLEEP_LED_PIN, GPIO.LOW)
exit()
if plus_button.is_pressed() or \
minus_button.is_pressed() or \
enter_button.is_pressed() or \
shutdown_button.is_pressed():
print_pattern()

View File

@@ -1,6 +1,22 @@
# -*- 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.

View File

@@ -1,12 +0,0 @@
USB4VC 2025 notes
Raspberry Pi 5
changelog
whats new
rpi5 support (no bt, 64bit kernel etc)
newest system version
web based dashboard
todo:

View File

@@ -7,8 +7,6 @@ import usb4vc_usb_scan
import usb4vc_ui
import subprocess
# usb4vc_ui.reset_pboard()
def get_current_rpi_model():
current_model = 'Unknown'
try:
@@ -40,13 +38,7 @@ def check_rpi_model():
stored_model = get_stored_rpi_model()
print('current_model', current_model)
print('stored_model', stored_model)
if "Raspberry Pi 5".lower() in current_model.lower():
usb4vc_ui.oled_print_model_changed()
os.system("cd /home/pi/xpadneo/; sudo ./uninstall.sh")
save_rpi_model(current_model)
return
elif current_model != stored_model:
if current_model != stored_model:
usb4vc_ui.oled_print_model_changed()
for x in range(20):
print("!!!!!!!!!! DO NOT UNPLUG UNTIL I REBOOT !!!!!!!!!!")
@@ -64,18 +56,12 @@ def check_rpi_model():
check_rpi_model()
cmdline_path = "/boot/firmware/cmdline.txt"
try:
boot_config = os.popen(f'cat {cmdline_path}').read()
boot_config = os.popen('cat /boot/cmdline.txt').read()
if "usbhid.mousepoll".lower() not in boot_config.lower():
print(f"@@@@@@@@@@@@ writing usbhid.mousepoll to {cmdline_path} @@@@@@@@@@@@")
print("@@@@@@@@@@@@ writing usbhid.mousepoll to /boot/cmdline.txt @@@@@@@@@@@@")
new_config = boot_config.replace('\r', '').replace('\n', '').strip() + ' usbhid.mousepoll=8\n'
with open(cmdline_path, 'w') as ffff:
ffff.write(new_config)
elif "usbhid.mousepoll=0" in boot_config:
print(f"@@@@@@@@@@@@ writing usbhid.mousepoll to {cmdline_path} @@@@@@@@@@@@")
new_config = boot_config.replace('\r', '').replace('\n', '').strip().replace("usbhid.mousepoll=0", "usbhid.mousepoll=8")
with open(cmdline_path, 'w') as ffff:
with open('/boot/cmdline.txt', 'w') as ffff:
ffff.write(new_config)
except Exception as e:
print('usbhid.mousepoll exception:', e)
@@ -84,17 +70,16 @@ usb4vc_ui.ui_init()
usb4vc_ui.ui_thread.start()
usb4vc_usb_scan.usb_device_scan_thread.start()
# usb4vc_usb_scan.raw_input_event_parser_thread.start()
usb4vc_usb_scan.raw_input_event_parser_thread.start()
while 1:
time.sleep(2)
if os.path.exists("/sys/module/bluetooth/parameters/disable_ertm"):
try:
ertm_status = subprocess.getoutput("cat /sys/module/bluetooth/parameters/disable_ertm").replace('\n', '').replace('\r', '').strip()
if ertm_status != 'Y':
# print('ertm_status:', ertm_status)
# print("Disabling ERTM....")
subprocess.call('echo Y > /sys/module/bluetooth/parameters/disable_ertm')
# print("DONE")
except Exception:
continue
try:
ertm_status = subprocess.getoutput("cat /sys/module/bluetooth/parameters/disable_ertm").replace('\n', '').replace('\r', '').strip()
if ertm_status != 'Y':
print('ertm_status:', ertm_status)
print("Disabling ERTM....")
subprocess.call('echo 1 > /sys/module/bluetooth/parameters/disable_ertm')
print("DONE")
except Exception:
continue

View File

@@ -384,7 +384,7 @@ def pair_device(mac_addr):
def get_paired_devices():
dev_set = set()
try:
device_str = subprocess.getoutput(f"timeout 5 bluetoothctl --agent NoInputNoOutput devices Paired")
device_str = subprocess.getoutput(f"timeout 5 bluetoothctl --agent NoInputNoOutput paired-devices")
for line in device_str.replace('\r', '').split('\n'):
if 'device' not in line.lower():
continue