From c34a40b0b597cc98f33f509406abe277710d5756 Mon Sep 17 00:00:00 2001 From: Lucien Date: Tue, 6 Jan 2026 21:38:36 +0100 Subject: [PATCH] Make Button agnostic of the SoC Currently, the filename id hardcoded using Raspberry SoC id. The current id matches Raspberry 2/3B but does not work with 1B+ (impossible to use Button). To make it agnostic of the underlying SoC I suggest to get the filename from evdev. Should this method be in a util class? --- ev3dev2/_platform/pistorms.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ev3dev2/_platform/pistorms.py b/ev3dev2/_platform/pistorms.py index 1dfa0b2..8653549 100644 --- a/ev3dev2/_platform/pistorms.py +++ b/ev3dev2/_platform/pistorms.py @@ -2,6 +2,13 @@ An assortment of classes modeling specific features of the PiStorms. """ from collections import OrderedDict +from evdev import InputDevice, list_devices + +def find_filename(device_name): + for path in list_devices(): + dev = InputDevice(path) + if device_name in dev.name: + return dev.fn OUTPUT_A = 'pistorms:BAM1' OUTPUT_B = 'pistorms:BAM2' @@ -13,8 +20,8 @@ INPUT_3 = 'pistorms:BBS1' INPUT_4 = 'pistorms:BBS2' -BUTTONS_FILENAME = '/dev/input/by-path/platform-3f804000.i2c-event' EVDEV_DEVICE_NAME = 'PiStorms' +BUTTONS_FILENAME = find_filename(EVDEV_DEVICE_NAME) LEDS = OrderedDict() LEDS['red_left'] = 'pistorms:BB:red:brick-status' @@ -38,3 +45,5 @@ LED_COLORS['MAGENTA'] = (1, 0, 1) LED_DEFAULT_COLOR = 'GREEN' + +