]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/esptool/tasks.py
Add more checks
[dotfiles.git] / invoke / esptool / tasks.py
1 from invoke import task
2
3 from datetime import datetime as dt
4 import os
5
6 HOME = os.path.expanduser('~')
7 TODAY = dt.now().strftime('%Y.%m.%d')
8
9 # Examples for CardputerAdv
10 DEVICE = 'Espressif'
11 PORT='/dev/ttyACM0' # Linux
12 CHIP='ESP32-S3'
13 # PORT='COM0' # Windows
14
15 @task
16 def help(c):
17 '''
18 On using this tasks file
19
20 - Set the Cardputer Adv power to 'off' state
21 - Plugging in to USB will cause it to boot
22 - Hold 'Go' while booting
23 - Hold 'Go' and press 'Reset' to try again.
24 - On success, the usual screen content still shows up
25 > Tip: Be sure to use a cable that can carry data, not just power.
26
27 Consider burnin
28 https://github.com/echo-lalia/MicroHydra
29
30 '''
31 print(help.__doc__)
32
33 @task
34 def groups(c):
35 '''Check that the current user is a member of dialout'''
36 result = c.run(f'groups {os.getlogin()}')
37 assert 'dialout' in result.stdout
38 print('ok')
39
40 @task
41 def usbdiff(c):
42 '''Use lsusb to try to find the new device.'''
43 input('Un-plug in the device...')
44 c.run('lsusb > /tmp/before.txt')
45 input('Plug in the device...')
46 c.run('lsusb > /tmp/after.txt')
47 result = c.run('diff /tmp/before.txt /tmp/after.txt')
48 print(result.stdout)
49 # breakpoint()
50
51 # Maybe https://thelastoutpostworkshop.github.io/ESPConnect/ in Chromium?
52
53
54 @task
55 def check_conn(c):
56 result = c.run(f'lsusb | grep {DEVICE}')
57 assert DEVICE in result.stdout
58 print('[ok]')
59
60 @task
61 def listusb(c):
62 # result = c.run('ls /dev/ttyACM*')
63 result = c.run(f'ls {PORT}')
64 assert result.ok
65 print('[ok]')
66 # c.run('ls /dev/ttyUSB*')
67
68 @task
69 def chip_id(c):
70 result = c.run(f'esptool --port {PORT} chip-id')
71 assert CHIP in result.stdout
72 print('[ok]')
73
74 @task
75 def check_all(c):
76 listusb(c)
77 check_conn(c)
78 chip_id(c)
79
80 @task
81 def erase_flash(c):
82 '''Erasing flash is recommended before flashing fresh.'''
83 c.run(f'esptool --port {PORT} erase-flash')
84
85 @task
86 def write_flash(c, filepath):
87 '''Write flash'''
88 c.run(f'esptool --chip {CHIP} --port {PORT} --baud 460800 write_flash -z 0x1000 {filepath}')