()
| 148 | |
| 149 | // Flash Firmware |
| 150 | const program = async () => { |
| 151 | setConfirmProgram(false) |
| 152 | setFlashing(true) |
| 153 | |
| 154 | let success = false |
| 155 | |
| 156 | const toArrayBuffer = (inputFile) => { |
| 157 | const reader = new FileReader() |
| 158 | |
| 159 | return new Promise((resolve, reject) => { |
| 160 | reader.onerror = () => { |
| 161 | reader.abort(); |
| 162 | reject(new DOMException('Problem parsing input file.')); |
| 163 | } |
| 164 | |
| 165 | reader.onload = () => { |
| 166 | resolve(reader.result); |
| 167 | } |
| 168 | reader.readAsArrayBuffer(inputFile) |
| 169 | }) |
| 170 | } |
| 171 | |
| 172 | for (const file of uploads) { |
| 173 | if (!file.fileName || !file.obj) continue |
| 174 | success = true |
| 175 | |
| 176 | toast(`Uploading ${file.fileName.substring(0, 28)}...`, { position: 'top-center', progress: 0, toastId: 'upload' }) |
| 177 | |
| 178 | try { |
| 179 | const contents = await toArrayBuffer(file.obj) |
| 180 | |
| 181 | await espStub.flashData( |
| 182 | contents, |
| 183 | (bytesWritten, totalBytes) => { |
| 184 | const progress = (bytesWritten / totalBytes) |
| 185 | const percentage = Math.floor(progress * 100) |
| 186 | |
| 187 | toast.update('upload', { progress: progress }) |
| 188 | |
| 189 | addOutput(`Flashing... ${percentage}%`) |
| 190 | }, |
| 191 | parseInt(file.offset, 16) |
| 192 | ) |
| 193 | |
| 194 | await sleep(100) |
| 195 | } catch (e) { |
| 196 | addOutput(`ERROR!`) |
| 197 | addOutput(`${e}`) |
| 198 | console.error(e) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (success) { |
| 203 | addOutput(`Done!`) |
| 204 | addOutput(`To run the new firmware please reset your device.`) |
| 205 | |
| 206 | toast.success('Done! Reset ESP to run new firmware.', { position: 'top-center', toastId: 'uploaded', autoClose: 3000 }) |
| 207 | } else { |
nothing calls this directly
no test coverage detected