]> us-delaporte.pagekite.me Git - dotfiles.git/blobdiff - invoke/esptool/tasks.py
Add matrix TUI
[dotfiles.git] / invoke / esptool / tasks.py
index 454cc47e1f7beef6e7fdef8872a692f8b7c9973e..96f3b8384351cb73b9164464824b504be1aa6ec6 100644 (file)
@@ -6,8 +6,40 @@ import os
 HOME = os.path.expanduser('~')
 TODAY = dt.now().strftime('%Y.%m.%d')
 
 HOME = os.path.expanduser('~')
 TODAY = dt.now().strftime('%Y.%m.%d')
 
+# Examples for CardputerAdv
+DEVICE = 'Espressif'
+PORT='/dev/ttyACM0' # Linux
+CHIP='ESP32-S3'
+# PORT='COM0' # Windows
+
+@task
+def help(c):
+    '''
+    On using this tasks file
+
+    - Set the Cardputer Adv power to 'off' state
+    - Plugging in to USB will cause it to boot
+    - Hold 'Go' while booting
+    - Hold 'Go' and press 'Reset' to try again.
+    - On success, the usual screen content still shows up
+    > Tip: Be sure to use a cable that can carry data, not just power.
+
+    Consider burnin
+    https://github.com/echo-lalia/MicroHydra
+
+    '''
+    print(help.__doc__)
+
+@task
+def groups(c):
+    '''Check that the current user is a member of dialout'''
+    result = c.run(f'groups {os.getlogin()}')
+    assert 'dialout' in result.stdout
+    print('ok')
+
 @task
 def usbdiff(c):
 @task
 def usbdiff(c):
+    '''Use lsusb to try to find the new device.'''
     input('Un-plug in the device...')
     c.run('lsusb > /tmp/before.txt')
     input('Plug in the device...')
     input('Un-plug in the device...')
     c.run('lsusb > /tmp/before.txt')
     input('Plug in the device...')
@@ -16,19 +48,41 @@ def usbdiff(c):
     print(result.stdout)
     # breakpoint()
 
     print(result.stdout)
     # breakpoint()
 
+# Maybe https://thelastoutpostworkshop.github.io/ESPConnect/ in Chromium?
 
 
-# Set power to 'off' state
-# Hold 'Go' while booting
 
 
-# Maybe https://thelastoutpostworkshop.github.io/ESPConnect/ in Chromium?
+@task
+def check_conn(c):
+    result = c.run(f'lsusb | grep {DEVICE}')
+    assert DEVICE in result.stdout
+    print('[ok]')
 
 @task
 def listusb(c):
 
 @task
 def listusb(c):
-    c.run('ls /dev/ttyUSB*')
-    c.run('ls /dev/ttyACM*')
+    # result = c.run('ls /dev/ttyACM*')
+    result = c.run(f'ls {PORT}')
+    assert result.ok
+    print('[ok]')
+    # c.run('ls /dev/ttyUSB*')
+
+@task
+def chip_id(c):
+    result = c.run(f'esptool --port {PORT} chip-id')
+    assert CHIP in result.stdout
+    print('[ok]')
 
 
-@task()
-def status(c):
+@task
+def check_all(c):
+    listusb(c)
+    check_conn(c)
+    chip_id(c)
 
 
-    c.run('esptool --port /dev/ttyUSB0 chip-id')
+@task
+def erase_flash(c):
+    '''Erasing flash is recommended before flashing fresh.'''
+    c.run(f'esptool --port {PORT} erase-flash')
 
 
+@task
+def write_flash(c, filepath):
+    '''Write flash'''
+    c.run(f'esptool --chip {CHIP} --port {PORT} --baud 460800 write_flash -z 0x1000 {filepath}')