MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / EspTool

Class EspTool

tools/xsbug/esptool.js:74–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72 undefined, undefined, undefined, "80m"];
73
74class EspTool {
75 #device;
76 #serial;
77 #readable;
78 #loader;
79 #mcu;
80 #statusSize;
81 #baud;
82 #reset;
83 #baudDownload;
84 #serialOptions;
85 #flashOptions;
86 #writeSpaceAvailable;
87 #writable;
88
89 constructor(options) {
90 if (!options.device)
91 throw new Error("device required");
92
93 this.#device = options.device;
94
95 if ("esp8266" === options.mcu) {
96 this.#loader = ESP8266ROM;
97 this.#statusSize = 2;
98 }
99 else if ("esp32" === options.mcu) {
100 this.#loader = ESP32ROM;
101 this.#statusSize = 4;
102 }
103 else
104 throw new Error("mcu required");
105 this.#mcu = options.mcu;
106
107 this.#flashOptions = options.flash || {};
108
109 this.#baud = baudROM;
110 this.#serialOptions = options.serial || {};
111 this.#reset = (undefined === options.reset) ? true : options.reset;
112 this.#baudDownload = this.#serialOptions.baud;
113 }
114 close() {
115 this.#device = undefined;
116 if (this.#serial) {
117 this.#serial.close();
118 this.#serial = undefined;
119 }
120 }
121 async reset() {
122 if (!this.#serial)
123 await this.buildSerial(this.#baud);
124
125 this.#serial.set({DTR: false, RTS: true});
126
127 this.#serial.purge(true, false);
128 await delay(50);
129
130 this.#serial.set({DTR: false, RTS: false});
131 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected