Skip to content

Commit

Permalink
v0.3.10: DFU (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin authored Jun 21, 2024
2 parents 931d798 + 7efba82 commit 79f6e57
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 100 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"module": "./dist/index.mjs",
"name": "chameleon-ultra.js",
"type": "commonjs",
"version": "0.3.9",
"version": "0.3.10",
"bugs": {
"url": "https://github.com/taichunmin/chameleon-ultra.js/issues"
},
Expand Down
6 changes: 4 additions & 2 deletions pages/demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ A ChameleonUltra tool to management the device info and settings.

## [dfu.html](https://taichunmin.idv.tw/chameleon-ultra.js/dfu.html)

A tool to upload firmware to ChameleonUltra.
A tool to update ChameleonUltra firmware.

![](https://i.imgur.com/yYsKXgx.png)

### Features

- Select tag to upload firmware
- Select tag to update firmware

### Related links

Expand Down
30 changes: 15 additions & 15 deletions pug/src/dfu.pug
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extends /include/bootstrapV4

block beforehtml
- const title = 'Upload Firmware'
- const title = 'Device Firmware Update'

block style
meta(property="og:description", content="A tool to upload firmware to ChameleonUltra.")
meta(property="og:description", content="A tool to update ChameleonUltra firmware.")
meta(property="og:locale", content="zh_TW")
meta(property="og:title", content=title)
meta(property="og:type", content="website")
Expand Down Expand Up @@ -34,22 +34,22 @@ block content
option(value="usb") USB Serial (PC only)
.input-group-append: button.btn.btn-outline-secondary(@click="btnAdapterTips") #[i.fa.fa-fw.fa-question]
.card.shadow-sm.mb-2
h6.card-header #[i.fa.fa-fw.fa-github] From GitHub
h6.card-header #[i.fa.mr-1.fa-github] From GitHub
.card-body.px-3.pt-3.pb-2.letter-spacing-n1px
.form-group.letter-spacing-n1px.mb-3
label Tag Name:
label Tag (gitVersion):
select.form-control.form-control-sm(v-model="ss.tagName")
option(v-for="[k, v] of tagNames", :value="k") {{ v }}
button.btn.btn-block.btn-outline-primary.letter-spacing-n1px.mb-2(@click="btnUploadRelease") #[i.fa.mr-1.fa-puzzle-piece] Upload Firmware
button.btn.btn-block.btn-outline-primary.letter-spacing-n1px.mb-2(@click="btnUpdateRelease") #[i.fa.mr-1.fa-puzzle-piece] Update release
.card.shadow-sm.mb-2
h6.card-header #[i.fa.fa-fw.fa-file-archive-o] From Zip File
h6.card-header #[i.fa.mr-1.fa-file-archive-o] From Zip File
.card-body.px-3.pt-3.pb-2.letter-spacing-n1px
.form-group.letter-spacing-n1px.mb-3
label Choose firmware:
.custom-file.form-control-sm.letter-spacing-n1px
input.custom-file-input#imageSelected(type="file", v-model="imageSelected", ref="imageSelected", accept=".zip")
label.custom-file-label(for="imageSelected") {{ getFilename(imageSelected) || 'Choose firmware...' }}
button.btn.btn-block.btn-outline-primary.letter-spacing-n1px.mb-2(@click="btnUploadSelected") #[i.fa.mr-1.fa-puzzle-piece] Upload Firmware
input.custom-file-input#imageSelected(type="file", v-model="imageSelected", ref="imageSelected", accept=".zip,application/zip,application/x-zip-compressed")
label.custom-file-label(for="imageSelected", :class="['','text-muted'][+_.isEmpty(imageSelected)]") {{ getFilename(imageSelected) || 'Choose firmware...' }}
button.btn.btn-block.btn-outline-primary.letter-spacing-n1px.mb-2(@click="btnUpdateSelected") #[i.fa.mr-1.fa-puzzle-piece] Update selected

block script
script.
Expand Down Expand Up @@ -122,11 +122,11 @@ block script
this.ss.tagName = _.first(this.tagNames)[0]
Swal.close()
},
async btnUploadRelease () {
async btnUpdateRelease () {
const { ultra } = this
const numFormater = new Intl.NumberFormat('en', { minimumFractionDigits: 1, maximumFractionDigits: 1 })
const showProgress = ({ func, offset, size, type }) => {
if (func !== 'dfuUploadObject' || type !== 2) return
if (func !== 'dfuUpdateObject' || type !== 2) return
const width = _.round(size > 0 ? offset / size * 100 : 0, 1)
const html = `<div class="d-flex flex-column"><div class="progress mb-2"><div class="progress-bar progress-bar-striped" role="progressbar" style="width: ${width}%"></div></div><div class="d-flex justify-content-between"><span>Uploading:</span><span>${numFormater.format(width)} %</span></div></div>`
this.showLoading({ html })
Expand Down Expand Up @@ -164,7 +164,7 @@ block script
let isUploadSuccess = false
for (const image of images) {
try {
await ultra.dfuUploadImage(image)
await ultra.dfuUpdateImage(image)
isUploadSuccess = true
break
} catch (err) {
Expand All @@ -179,11 +179,11 @@ block script
}
ultra.emitter.removeListener('progress', showProgress)
},
async btnUploadSelected () {
async btnUpdateSelected () {
const { ultra } = this
const numFormater = new Intl.NumberFormat('en', { minimumFractionDigits: 1, maximumFractionDigits: 1 })
const showProgress = ({ func, offset, size, type }) => {
if (func !== 'dfuUploadObject' || type !== 2) return
if (func !== 'dfuUpdateObject' || type !== 2) return
const width = _.round(size > 0 ? offset / size * 100 : 0, 1)
const html = `<div class="d-flex flex-column"><div class="progress mb-2"><div class="progress-bar progress-bar-striped" role="progressbar" style="width: ${width}%"></div></div><div class="d-flex justify-content-between"><span>Uploading:</span><span>${numFormater.format(width)} %</span></div></div>`
this.showLoading({ html })
Expand Down Expand Up @@ -215,7 +215,7 @@ block script
}
this.showLoading({ text: 'Uploading Firmware...' })
ultra.emitter.on('progress', showProgress)
await ultra.dfuUploadImage(image)
await ultra.dfuUpdateImage(image)
await Swal.fire({ icon: 'success', title: 'Upload Success' })
} catch (err) {
ultra.emitter.emit('error', err)
Expand Down
Loading

0 comments on commit 79f6e57

Please sign in to comment.