click on USB plug area, becomes voltage change event

This commit is contained in:
Peter D. Gray 2024-01-31 09:02:53 -05:00
parent 607a78ffe4
commit d726a1e13c
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
5 changed files with 46 additions and 8 deletions

View File

@ -62,6 +62,19 @@ wallet (on testnet, always with the same seed). But there are other options:
See `variant/sim_settings.py` for the details of settings-related options.
## Clicking on Simulated Device
### Q
- send keystrokes when clicking on keys, but much easier to use real keyboard
- click screen to send current clipboard contents as a QR reading
- click on area near USB plug to cycle through battery levels and USB plugged/not
### Mk4
- sends keystrokes
## Requirements
- uses good olde `xterm` for console input and output

View File

@ -564,6 +564,11 @@ def q1_click_to_keynum(x, y):
if (90 <= x <= 430) and (90 <= y <= 345):
# click on screen
return 'SCREEN'
# detect click near USB to simulate unplug/plug events
if (230 <= x <= 290) and (810 <= y <= 852):
# click near USB connector
return 'PLUGGER'
# keypad area
left = 29
@ -650,6 +655,9 @@ def handle_q1_key_events(event, numpad_tx, data_tx):
data_tx.write(txt + b'\n')
return None
if kn == 'PLUGGER':
kn = 0xfe # see variant/touch.py
if kn is None: return
if is_press:

View File

@ -43,7 +43,11 @@ class Pin:
if self.name == 'LCD_TEAR':
from touch import Touch
Touch()
pass
else:
self.irq_handler = a[0]
def simulate_irq(self):
self.irq_handler(self)
def __call__(self, new_val=UNSPEC):
if new_val==UNSPEC:

View File

@ -4,14 +4,21 @@
#
import battery, sys
battery.setup_battery = lambda: None
battery.setup_adc = lambda: None
fake_voltage = 0 if ('--plugged' in sys.argv) else 4.0
def mock_get_batt_level():
if '--plugged' in sys.argv:
return None
return 3.3
return fake_voltage if fake_voltage != 0 else None
def sim_plug_toggler():
# user clicked on simulator's plug, so show different voltages
global fake_voltage
# defined by battery.get_batt_threshold()
levels = [0, 2.9, 3.5, 4.0, 4.5]
fake_voltage = levels[(levels.index(fake_voltage) + 1) % len(levels)]
battery.nbat_pin.simulate_irq()
battery.get_batt_level = mock_get_batt_level

View File

@ -36,10 +36,16 @@ class Touch:
# - pad with -1
pressed = await s.read(5)
if 0xfe in pressed:
# see PLUGGER in simulator.py
from sim_battery import sim_plug_toggler
sim_plug_toggler()
continue
try:
new_presses = set(kn for kn in pressed if kn!=255 and not numpad.is_pressed[kn])
except IndexError:
# some bug brings us here
# some bugs bring us here
print("wrong kn: %r" % kn)
continue