Browse Source

autosign: add `test_led`, `list_led` operations

The MMGen Project 6 days ago
parent
commit
f9e2afc6e0
3 changed files with 54 additions and 6 deletions
  1. 3 1
      mmgen/autosign.py
  2. 41 5
      mmgen/main_autosign.py
  3. 10 0
      test/cmdtest_d/autosign.py

+ 3 - 1
mmgen/autosign.py

@@ -470,7 +470,9 @@ class Autosign:
 		'enable_swap',
 		'enable_swap',
 		'disable_swap',
 		'disable_swap',
 		'clean',
 		'clean',
-		'wipe_key')
+		'wipe_key',
+		'list_led',
+		'test_led')
 
 
 	mn_fmts = {
 	mn_fmts = {
 		'mmgen': 'words',
 		'mmgen': 'words',

+ 41 - 5
mmgen/main_autosign.py

@@ -22,7 +22,7 @@ autosign: Auto-sign MMGen transactions, message files and XMR wallet output file
 
 
 import sys
 import sys
 
 
-from .util import msg, die, fmt_list, exit_if_mswin, async_run
+from .util import msg, ymsg, gmsg, die, fmt_list, exit_if_mswin, async_run
 
 
 exit_if_mswin('autosigning')
 exit_if_mswin('autosigning')
 
 
@@ -94,6 +94,8 @@ wipe_key  - wipe the wallet encryption key on the removable device, making
             signing transactions or stealing the user’s seed impossible.
             signing transactions or stealing the user’s seed impossible.
             The operation is intended as a ‘kill switch’ and thus performed
             The operation is intended as a ‘kill switch’ and thus performed
             without prompting
             without prompting
+list_led  - list boards with tested LED signaling support
+test_led  - test the current board for LED signaling support
 
 
 
 
                                USAGE NOTES
                                USAGE NOTES
@@ -107,10 +109,6 @@ If invoked with ‘wait’, the program waits in a loop, mounting the removable
 device, performing signing operations and unmounting the device every time it
 device, performing signing operations and unmounting the device every time it
 is inserted.
 is inserted.
 
 
-On supported platforms (currently Orange Pi, Rock Pi and Raspberry Pi boards),
-the status LED indicates whether the program is busy or in standby mode, i.e.
-ready for device insertion or removal.
-
 The removable device must have a partition with a filesystem labeled MMGEN_TX
 The removable device must have a partition with a filesystem labeled MMGEN_TX
 and a user-writable root directory.  For interoperability between OS-es, it’s
 and a user-writable root directory.  For interoperability between OS-es, it’s
 recommended to use the exFAT file system.
 recommended to use the exFAT file system.
@@ -126,6 +124,27 @@ the directory ‘{asi.wallet_dir}’ (as currently configured).  The wallet is
 encrypted with a 32-byte password saved in the file ‘autosign.key’ in the
 encrypted with a 32-byte password saved in the file ‘autosign.key’ in the
 root of the removable device’s filesystem.
 root of the removable device’s filesystem.
 
 
+
+                             LED SIGNALING SUPPORT
+
+On supported platforms (selected Orange Pi, Rock Pi, Banana Pi, Nano Pi and
+Raspberry Pi boards), a flashing LED indicates whether signing is in progress
+or the program is in standby mode, i.e. ready for device insertion or removal.
+
+The operation ‘test_led’ tests the current installation for LED support, while
+‘list_led’ displays a list of supported board/OS combinations.  Note that this
+list is not exhaustive: signaling may work with other boards, especially those
+produced by the listed manufacturers.  If ‘test_led’ reports that your board is
+not supported, please submit an issue to the mmgen-wallet repository on Github
+or via e-mail, including the board model, OS version and output of the
+following shell command:
+
+    ls -RH /sys/class/leds/{{*status*,*led*}}
+
+In the absence of LED support, the user must observe the signing progress
+on-screen and wait for the “safe to extract” message to appear.
+
+
 The password and temporary wallet may be created in one operation by invoking
 The password and temporary wallet may be created in one operation by invoking
 ‘mmgen-autosign setup’ with the removable device inserted.  In this case, the
 ‘mmgen-autosign setup’ with the removable device inserted.  In this case, the
 temporary wallet is created from the user’s default wallet, if it exists and
 temporary wallet is created from the user’s default wallet, if it exists and
@@ -206,6 +225,23 @@ cmd = cfg._args[0] if len(cfg._args) == 1 else 'sign' if not cfg._args else cfg.
 if cmd not in Autosign.cmds + Autosign.util_cmds:
 if cmd not in Autosign.cmds + Autosign.util_cmds:
 	die(1, f'‘{cmd}’: unrecognized command')
 	die(1, f'‘{cmd}’: unrecognized command')
 
 
+if cmd in ('test_led', 'list_led'):
+	from .led import LEDControl
+	match cmd:
+		case 'list_led':
+			msg(
+				'Boards with tested LED signaling support:\n' +
+				'\n'.join(f'  {v.name}' for k, v in LEDControl.boards.items() if k != 'dummy'))
+		case 'test_led':
+			from .exception import NoLEDSupport
+			try:
+				LEDControl(enabled=True)
+			except NoLEDSupport:
+				ymsg('No LED signaling support for this platform')
+			else:
+				gmsg('LED signaling is supported by this platform!')
+	sys.exit(0)
+
 if cmd != 'setup':
 if cmd != 'setup':
 	for opt in ('seed_len', 'mnemonic_fmt', 'keys_from_file'):
 	for opt in ('seed_len', 'mnemonic_fmt', 'keys_from_file'):
 		if getattr(cfg, opt):
 		if getattr(cfg, opt):

+ 10 - 0
test/cmdtest_d/autosign.py

@@ -646,6 +646,8 @@ class CmdTestAutosign(CmdTestAutosignBase):
 	)
 	)
 
 
 	cmd_group = (
 	cmd_group = (
+		('test_led',                  'testing for LED support'),
+		('list_led',                  'listing LED-supported boards'),
 		('start_daemons',             'starting daemons'),
 		('start_daemons',             'starting daemons'),
 		('copy_tx_files',             'copying transaction files'),
 		('copy_tx_files',             'copying transaction files'),
 		('gen_key',                   'generating key'),
 		('gen_key',                   'generating key'),
@@ -1015,6 +1017,14 @@ class CmdTestAutosign(CmdTestAutosignBase):
 		self.remove_device()
 		self.remove_device()
 		return t
 		return t
 
 
+	def test_led(self, *, op='test_led', expect_str='LED signaling'):
+		t = self.spawn('mmgen-autosign', ['--quiet', '--no-insert-check', op])
+		t.expect(expect_str)
+		return t
+
+	def list_led(self):
+		return self.test_led(op='list_led', expect_str='Boards with')
+
 class CmdTestAutosignBTC(CmdTestAutosign):
 class CmdTestAutosignBTC(CmdTestAutosign):
 	'autosigning BTC transactions'
 	'autosigning BTC transactions'
 	coins        = ['btc']
 	coins        = ['btc']