|
30 | 30 | } |
31 | 31 | </style> |
32 | 32 |
|
| 33 | + <script src=" https://cdn.jsdelivr.net/npm/[email protected]/crypto-js.js" ></script> |
33 | 34 | <script type="module"> |
34 | 35 | import {Terminal} from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' |
35 | 36 | import {FitAddon} from 'https://cdn.jsdelivr.net/npm/@xterm/[email protected]/+esm' |
36 | 37 | import {ESPLoader, Transport} from "https://unpkg.com/esptool-js/bundle.js"; |
| 38 | + |
37 | 39 | var term = new Terminal(); |
38 | 40 | const fitAddon = new FitAddon(); |
39 | 41 | term.loadAddon(fitAddon); |
40 | 42 | term.open(document.getElementById('terminal')); |
41 | | - // fitAddon.fit(); |
| 43 | + fitAddon.fit(); |
42 | 44 |
|
43 | 45 | let transport; |
| 46 | + let esploader; |
44 | 47 | let device = null; |
| 48 | + let chip = null; |
| 49 | + |
| 50 | + const espLoaderTerminal = { |
| 51 | + clean() { |
| 52 | + term.clear(); |
| 53 | + }, |
| 54 | + writeLine(data) { |
| 55 | + term.writeln(data); |
| 56 | + }, |
| 57 | + write(data) { |
| 58 | + term.write(data); |
| 59 | + }, |
| 60 | + }; |
| 61 | + |
45 | 62 | let isConsoleClosed = false; |
46 | 63 |
|
47 | 64 | consoleStartButton.onclick = async () => { |
|
71 | 88 | await transport.setDTR(true); |
72 | 89 | } |
73 | 90 | }; |
| 91 | + |
| 92 | + function loadBinaryResource(url) { |
| 93 | + const req = new XMLHttpRequest(); |
| 94 | + req.open("GET", url, false); |
| 95 | + |
| 96 | + // XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com] |
| 97 | + req.overrideMimeType("text/plain; charset=x-user-defined"); |
| 98 | + req.send(null); |
| 99 | + return req.status === 200 ? req.responseText : ""; |
| 100 | + } |
| 101 | + |
| 102 | + programButton.onclick = async () => { |
| 103 | + if (device === null) { |
| 104 | + device = await navigator.serial.requestPort({}); |
| 105 | + transport = new Transport(device, true); |
| 106 | + } |
| 107 | + |
| 108 | + try { |
| 109 | + let flashOptions = { |
| 110 | + transport, |
| 111 | + baudrate: 921600, |
| 112 | + terminal: espLoaderTerminal, |
| 113 | + }; |
| 114 | + esploader = new ESPLoader(flashOptions); |
| 115 | + |
| 116 | + chip = await esploader.main(); |
| 117 | + |
| 118 | + flashOptions = { |
| 119 | + fileArray: [{data: loadBinaryResource("./_binaries/lrr-firmware.bin"), address: 0x0}], |
| 120 | + flashSize: "keep", |
| 121 | + eraseAll: false, |
| 122 | + compress: true, |
| 123 | + calculateMD5Hash: (image) => CryptoJS.MD5(CryptoJS.enc.Latin1.parse(image)), |
| 124 | + }; |
| 125 | + await esploader.writeFlash(flashOptions); |
| 126 | + } catch (e) { |
| 127 | + console.error(e); |
| 128 | + term.writeln(`Error: ${e.message}`); |
| 129 | + } |
| 130 | + }; |
74 | 131 | </script> |
75 | 132 | </head> |
76 | 133 |
|
77 | 134 | <body> |
| 135 | + <input type="button" id="programButton" value="Program" /> |
78 | 136 | <input type="button" id="consoleStartButton" value="Connect" /> |
79 | 137 | <input type="button" id="resetButton" value="Reset" /> |
80 | 138 | <div id="terminal"></div> |
|
0 commit comments