Skip to content

Commit

Permalink
Add support for Dial status LEDs
Browse files Browse the repository at this point in the history
Fixes: b6b82e4 ("Add support for relative dials (#665)")
  • Loading branch information
whot committed Nov 4, 2024
1 parent deacd3f commit 5b900d9
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libwacom/libwacom-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ static const struct {
{ "Ring", WACOM_STATUS_LED_RING },
{ "Ring2", WACOM_STATUS_LED_RING2 },
{ "Touchstrip", WACOM_STATUS_LED_TOUCHSTRIP },
{ "Touchstrip2", WACOM_STATUS_LED_TOUCHSTRIP2 }
{ "Touchstrip2", WACOM_STATUS_LED_TOUCHSTRIP2 },
{ "Dial", WACOM_STATUS_LED_DIAL },
{ "Dial2", WACOM_STATUS_LED_DIAL2 },
};

static const struct {
Expand Down
4 changes: 3 additions & 1 deletion libwacom/libwacom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,9 @@ static const struct {
{ WACOM_BUTTON_RING_MODESWITCH, WACOM_STATUS_LED_RING },
{ WACOM_BUTTON_RING2_MODESWITCH, WACOM_STATUS_LED_RING2 },
{ WACOM_BUTTON_TOUCHSTRIP_MODESWITCH, WACOM_STATUS_LED_TOUCHSTRIP },
{ WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH, WACOM_STATUS_LED_TOUCHSTRIP2 }
{ WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH, WACOM_STATUS_LED_TOUCHSTRIP2 },
{ WACOM_BUTTON_DIAL_MODESWITCH, WACOM_STATUS_LED_DIAL },
{ WACOM_BUTTON_DIAL2_MODESWITCH, WACOM_STATUS_LED_DIAL2 },
};

LIBWACOM_EXPORT int
Expand Down
4 changes: 3 additions & 1 deletion libwacom/libwacom.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ typedef enum {
WACOM_STATUS_LED_RING = 0,
WACOM_STATUS_LED_RING2 = 1,
WACOM_STATUS_LED_TOUCHSTRIP = 2,
WACOM_STATUS_LED_TOUCHSTRIP2 = 3
WACOM_STATUS_LED_TOUCHSTRIP2 = 3,
WACOM_STATUS_LED_DIAL = 4,
WACOM_STATUS_LED_DIAL2 = 5,
} WacomStatusLEDs;

/**
Expand Down
24 changes: 23 additions & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def instance(cls):
_Api(
name="libwacom_get_status_leds",
args=(c_void_p, c_void_p),
return_type=c_void_p,
return_type=ctypes.POINTER(ctypes.c_int),
),
_Api(
name="libwacom_get_button_led_group",
Expand Down Expand Up @@ -394,6 +394,8 @@ def instance(cls):
_Enum(name="WACOM_STATUS_LED_RING2", value=2),
_Enum(name="WACOM_STATUS_LED_TOUCHSTRIP", value=3),
_Enum(name="WACOM_STATUS_LED_TOUCHSTRIP2", value=4),
_Enum(name="WACOM_STATUS_LED_DIAL", value=1),
_Enum(name="WACOM_STATUS_LED_DIAL2", value=2),
]


Expand Down Expand Up @@ -616,6 +618,16 @@ def get_paired_styli(self) -> List["WacomStylus"]:
return styli


class WacomStatusLed(enum.IntEnum):
UNAVAILABLE = -1
RING = 0
RING2 = 1
TOUCHSTRIP = 2
TOUCHSTRIP2 = 3
DIAL = 4
DIAL2 = 5


class WacomDevice:
"""
Convenience wrapper to make using libwacom a bit more pythonic.
Expand Down Expand Up @@ -795,6 +807,16 @@ def button_flags(self, button: str) -> List[ButtonFlags]:
def button_evdev_code(self, button: str) -> int:
return self.get_button_evdev_code(button.encode("utf-8"))

def button_led_group(self, button: str) -> List[ButtonFlags]:
return self.get_button_led_group(button.encode("utf-8"))

@property
def status_leds(self) -> List["WacomStatusLed"]:
nleds = c_int()
leds = self.get_status_leds(ctypes.byref(nleds))

return [WacomStatusLed(l) for l in leds[: nleds.value]]


class WacomDatabase:
"""
Expand Down
79 changes: 78 additions & 1 deletion test/test_libwacom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import logging
import pytest

from . import WacomBuilder, WacomBustype, WacomDatabase, WacomDevice, WacomEraserType
from . import (
WacomBuilder,
WacomBustype,
WacomDatabase,
WacomDevice,
WacomEraserType,
WacomStatusLed,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -604,6 +611,76 @@ def test_button_modeswitch(custom_datadir, feature, count):
assert expected_flag not in flags


@pytest.mark.parametrize(
"feature",
("Ring", "Touchstrip", "Dial"),
)
@pytest.mark.parametrize("count", (1, 2))
def test_status_leds(custom_datadir, feature, count):
USBID = (0x1234, 0x5678)

# sigh, Touchstrip but StripsNumModes...
num_mode_key = f"{feature}s" if feature != "Touchstrip" else "Strip"

extra = {
"Buttons": {
"Left": "A;B;C;",
"Right": "D;E;F;",
feature: "A",
},
"Features": {
"StatusLEDs": f"{feature};{feature}2" if count > 1 else f"{feature}",
num_mode_key: 4,
},
}
if count > 1:
extra["Buttons"][f"{feature}2"] = "D"

TabletFile(
name="some tablet",
matches=[f"usb|{USBID[0]:04x}|{USBID[1]:04x}"],
extra=extra,
).write_to(custom_datadir / "led.tablet")

db = WacomDatabase(path=custom_datadir)
builder = WacomBuilder.create(usbid=USBID)
device = db.new_from_builder(builder)
assert device is not None

expected = [
{
"Ring": WacomStatusLed.RING,
"Touchstrip": WacomStatusLed.TOUCHSTRIP,
"Dial": WacomStatusLed.DIAL,
}[feature]
]

if count > 1:
expected.append(
{
"Ring": WacomStatusLed.RING2,
"Touchstrip": WacomStatusLed.TOUCHSTRIP2,
"Dial": WacomStatusLed.DIAL2,
}[feature]
)

leds = device.status_leds
assert sorted(leds) == sorted(expected)

led_group = device.button_led_group("A")
assert led_group == 0

led_group = device.button_led_group("D")
if count > 1:
assert led_group == 1
else:
assert led_group == -1

for b in "BCEF":
led_group = device.button_led_group(b)
assert led_group == -1


def test_nonwacom_stylus_ids(tmp_path):
styli = StylusFile.default()
s1 = StylusEntry(
Expand Down
2 changes: 2 additions & 0 deletions tools/debug-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ handle_device(WacomDeviceDatabase *db, const char *path)
case WACOM_STATUS_LED_RING2: ledstr = "RING2"; break;
case WACOM_STATUS_LED_TOUCHSTRIP: ledstr = "TOUCHSTRIP"; break;
case WACOM_STATUS_LED_TOUCHSTRIP2: ledstr = "TOUCHSTRIP2"; break;
case WACOM_STATUS_LED_DIAL: ledstr = "DIAL"; break;
case WACOM_STATUS_LED_DIAL2: ledstr = "DIAL2"; break;
}
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s%s", i > 0 ? ", " : "", ledstr);
}
Expand Down

0 comments on commit 5b900d9

Please sign in to comment.