@@ -13,6 +13,7 @@ class EspSerial(Serial):
13
13
14
14
Attributes:
15
15
esp: esptool.ESPLoader, will auto upload stub.
16
+ stub: esptool.ESPStubLoader, stubbed loader.
16
17
"""
17
18
18
19
DEFAULT_BAUDRATE = 115200
@@ -58,7 +59,7 @@ def __init__(
58
59
raise ValueError ('Couldn\' t auto detect chip. Please manually specify with "--port"' )
59
60
60
61
# stub loader has more functionalities, need to run after calling `run_stub()`
61
- self .stub : esptool .ESPLoader = None # type: ignore
62
+ self .stub : esptool .ESPLoader = self . esp . run_stub ()
62
63
63
64
if baud > initial_baud :
64
65
self .esp .change_baud (baud ) # change back to the users settings
@@ -78,29 +79,21 @@ def _post_init(self):
78
79
79
80
def use_esptool (func ):
80
81
"""
81
- 1. close the port and open the port to kill the `self._forward_io` thread
82
- 2. call `run_stub()`
83
- 3. call to the decorated function, could use `self.stub` as the stubbed loader
84
- 4. call `hard_reset()`
85
- 5. create the `self.forward_io` thread again.
82
+ 1. call to the decorated function, could use `self.stub` as the stubbed loader
83
+ 2. call `hard_reset()`
84
+ 3. create the `self.forward_io` thread again.
86
85
"""
87
86
88
87
@functools .wraps (func )
89
88
def wrapper (self , * args , ** kwargs ):
90
- self .proc .close ()
91
- self .proc .open ()
92
-
93
89
settings = self .proc .get_settings ()
94
90
95
91
try :
96
92
with DuplicateStdout (self .pexpect_proc ):
97
- self .esp .connect ('hard_reset' )
98
- self .stub = self .esp .run_stub ()
99
93
ret = func (self , * args , ** kwargs )
100
94
self .stub .hard_reset ()
101
95
finally :
102
96
self .proc .apply_settings (settings )
103
- self .create_forward_io_thread (self .pexpect_proc )
104
97
105
98
return ret
106
99
0 commit comments