Jog: bind right back buttons (R1/R2) to A axis hold-to-jog

The default USB pendant config exposed A only via the right stick
X axis (ABS_RX). Most Onefinity-shipped pendants only have one
usable stick, so A was effectively unreachable.

Map BTN_TR (0x137, upper-right back) to A+ and BTN_TR2 (0x139,
lower-right back) to A- while held. Speed scaling matches the
sticks (1/128, 1/32, 1/4, 1x via X/A/B/Y).

R1 was the vertical-axis-lock toggle; horizontal lock on L1 is
preserved, vertical lock is dropped to free R1.
This commit is contained in:
2026-05-03 16:12:42 +02:00
parent 9d7bc57056
commit 99b5af56cc

View File

@@ -51,12 +51,18 @@ class Jog(inevent.JogHandler):
"dir": [1, -1, -1, 1],
"arrows": [ABS_HAT0X, ABS_HAT0Y],
"speed": [0x133, 0x130, 0x131, 0x134],
"lock": [0x136, 0x137],
"lock": [0x136], # L1 = horiz-lock; R1/R2 now A axis
# Right back triggers drive the A axis while held:
# BTN_TR (0x137, upper-right) -> A+
# BTN_TR2 (0x139, lower-right) -> A-
"a_pos": 0x137,
"a_neg": 0x139,
}
}
super().__init__(config)
self.a_button = 0 # -1, 0, +1 from R1/R2 hold state
self.v = [0.0] * 4
self.lastV = self.v
self.callback()
@@ -64,6 +70,27 @@ class Jog(inevent.JogHandler):
self.processor = inevent.InEvent(ctrl.ioloop, self, types = ['js'])
def event(self, event, state, dev_name):
cfg = self.get_config(dev_name)
a_changed = False
if event.type == EV_KEY:
old = self.a_button
if event.code == cfg.get('a_pos'):
self.a_button = 1 if event.value else (
0 if self.a_button == 1 else self.a_button)
elif event.code == cfg.get('a_neg'):
self.a_button = -1 if event.value else (
0 if self.a_button == -1 else self.a_button)
if self.a_button != old: a_changed = True
super().event(event, state, dev_name)
# JogHandler.event() only fires changed() when stick axes move.
# Force a recompute when R1/R2 hold state flips.
if a_changed: self.changed()
def up(self): self.ctrl.lcd.page_up()
def down(self): self.ctrl.lcd.page_down()
def left(self): self.ctrl.lcd.page_left()
@@ -91,3 +118,7 @@ class Jog(inevent.JogHandler):
if self.speed == 3: scale = 1.0 / 4.0
self.v = [x * scale for x in self.axes]
# R1/R2 buttons override the A axis (axes[3]) while held.
if self.a_button:
self.v[3] = self.a_button * scale