|
61 | 61 |
|
62 | 62 | let isConsoleClosed = false;
|
63 | 63 |
|
64 |
| - consoleStartButton.onclick = async () => { |
| 64 | + async function reset() { |
| 65 | + if (transport) { |
| 66 | + await transport.setDTR(false); |
| 67 | + await new Promise((resolve) => setTimeout(resolve, 100)); |
| 68 | + await transport.setDTR(true); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + async function startConsole() { |
| 73 | + if (transport) { |
| 74 | + await transport.disconnect(); |
| 75 | + await transport.waitForUnlock(1500); |
| 76 | + } |
65 | 77 | if (device === null) {
|
66 | 78 | device = await navigator.serial.requestPort({});
|
67 | 79 | transport = new Transport(device, true);
|
|
70 | 82 | await transport.connect(115200);
|
71 | 83 | isConsoleClosed = false;
|
72 | 84 |
|
| 85 | + reset(); |
| 86 | + |
73 | 87 | while (true && !isConsoleClosed) {
|
74 | 88 | const val = await transport.rawRead();
|
75 | 89 | if (typeof val !== "undefined") {
|
|
78 | 92 | break;
|
79 | 93 | }
|
80 | 94 | }
|
| 95 | + isConsoleClosed = true; |
81 | 96 | console.log("quitting console");
|
82 | 97 | };
|
83 | 98 |
|
84 |
| - resetButton.onclick = async () => { |
85 |
| - if (transport) { |
86 |
| - await transport.setDTR(false); |
87 |
| - await new Promise((resolve) => setTimeout(resolve, 100)); |
88 |
| - await transport.setDTR(true); |
89 |
| - } |
90 |
| - }; |
91 |
| - |
92 | 99 | function loadBinaryResource(url) {
|
93 | 100 | const req = new XMLHttpRequest();
|
94 | 101 | req.open("GET", url, false);
|
95 | 102 |
|
96 |
| - // XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com] |
97 | 103 | req.overrideMimeType("text/plain; charset=x-user-defined");
|
98 | 104 | req.send(null);
|
99 | 105 | return req.status === 200 ? req.responseText : "";
|
100 | 106 | }
|
101 | 107 |
|
102 |
| - programButton.onclick = async () => { |
| 108 | + async function program() { |
| 109 | + if (transport) { |
| 110 | + await transport.disconnect(); |
| 111 | + await transport.waitForUnlock(1500); |
| 112 | + } |
103 | 113 | if (device === null) {
|
104 | 114 | device = await navigator.serial.requestPort({});
|
105 | 115 | transport = new Transport(device, true);
|
|
127 | 137 | console.error(e);
|
128 | 138 | term.writeln(`Error: ${e.message}`);
|
129 | 139 | }
|
| 140 | + startConsole(); |
130 | 141 | };
|
| 142 | + |
| 143 | + consoleStartButton.onclick = startConsole; |
| 144 | + |
| 145 | + resetButton.onclick = reset; |
| 146 | + |
| 147 | + programButton.onclick = program; |
131 | 148 | </script>
|
132 | 149 | </head>
|
133 | 150 |
|
134 | 151 | <body>
|
135 | 152 | <input type="button" id="programButton" value="Program" />
|
136 |
| - <input type="button" id="consoleStartButton" value="Connect" /> |
| 153 | + <input type="button" id="consoleStartButton" value="Open Console" /> |
137 | 154 | <input type="button" id="resetButton" value="Reset" />
|
138 | 155 | <div id="terminal"></div>
|
139 | 156 | </body>
|
|
0 commit comments