Skip to content

Commit ae6d1dc

Browse files
committed
Add DFU mode
1 parent 93d9f25 commit ae6d1dc

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ Web Components library for micro:bit
4747
- [ ] Microbit Channel Selection
4848

4949
### Firmware
50+
- [x] Initiate DFU Mode
5051
- [ ] Update Firmware

examples/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ <h1>micro:bit Web Components</h1>
122122
<microbit-text button-label="Write"></microbit-text>
123123
<microbit-send delimiter=":" button-label="Send"></microbit-send>
124124
<microbit-receive></microbit-receive>
125+
<microbit-dfu></microbit-dfu>
125126
<microbit-calibrate></microbit-calibrate>
126127
<microbit-compass>
127128
<div id="compass"></div>

src/components.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export namespace Components {
7676
*/
7777
'disconnectedClass': string;
7878
}
79+
interface MicrobitDfu {
80+
/**
81+
* The button label to initiate DFU mode
82+
*/
83+
'dfuLabel': string;
84+
'services': Services;
85+
}
7986
interface MicrobitFirmware {
8087
'deviceInformation': DeviceInformation;
8188
/**
@@ -257,6 +264,12 @@ declare global {
257264
new (): HTMLMicrobitConnectionElement;
258265
};
259266

267+
interface HTMLMicrobitDfuElement extends Components.MicrobitDfu, HTMLStencilElement {}
268+
var HTMLMicrobitDfuElement: {
269+
prototype: HTMLMicrobitDfuElement;
270+
new (): HTMLMicrobitDfuElement;
271+
};
272+
260273
interface HTMLMicrobitFirmwareElement extends Components.MicrobitFirmware, HTMLStencilElement {}
261274
var HTMLMicrobitFirmwareElement: {
262275
prototype: HTMLMicrobitFirmwareElement;
@@ -335,6 +348,7 @@ declare global {
335348
'microbit-compass': HTMLMicrobitCompassElement;
336349
'microbit-connect': HTMLMicrobitConnectElement;
337350
'microbit-connection': HTMLMicrobitConnectionElement;
351+
'microbit-dfu': HTMLMicrobitDfuElement;
338352
'microbit-firmware': HTMLMicrobitFirmwareElement;
339353
'microbit-hardware': HTMLMicrobitHardwareElement;
340354
'microbit-manufacturer': HTMLMicrobitManufacturerElement;
@@ -413,6 +427,13 @@ declare namespace LocalJSX {
413427
*/
414428
'disconnectedClass'?: string;
415429
}
430+
interface MicrobitDfu extends JSXBase.HTMLAttributes<HTMLMicrobitDfuElement> {
431+
/**
432+
* The button label to initiate DFU mode
433+
*/
434+
'dfuLabel'?: string;
435+
'services'?: Services;
436+
}
416437
interface MicrobitFirmware extends JSXBase.HTMLAttributes<HTMLMicrobitFirmwareElement> {
417438
'deviceInformation'?: DeviceInformation;
418439
/**
@@ -561,6 +582,7 @@ declare namespace LocalJSX {
561582
'microbit-compass': MicrobitCompass;
562583
'microbit-connect': MicrobitConnect;
563584
'microbit-connection': MicrobitConnection;
585+
'microbit-dfu': MicrobitDfu;
564586
'microbit-firmware': MicrobitFirmware;
565587
'microbit-hardware': MicrobitHardware;
566588
'microbit-manufacturer': MicrobitManufacturer;

src/microbit-dfu/microbit-dfu.tsx

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { h, Component, Prop, Element, State, Watch } from "@stencil/core";
2+
import { Services } from "microbit-web-bluetooth";
3+
import { microbitStore } from '../microbit-store';
4+
5+
@Component({
6+
tag: 'microbit-dfu'
7+
})
8+
export class MicrobitDfu {
9+
constructor() {
10+
microbitStore.addListener(this);
11+
}
12+
13+
@Element()
14+
protected el;
15+
16+
@Prop({mutable: true})
17+
public services: Services = null;
18+
19+
/**
20+
* The button label to initiate DFU mode
21+
*/
22+
@Prop()
23+
public dfuLabel: string = "Initiate DFU"
24+
25+
@State()
26+
protected disabled = true;
27+
28+
@Watch('services')
29+
protected async servicesUpdated() {
30+
this.disabled = !this.services || !this.services.dfuControlService;
31+
}
32+
33+
private async calibrate() {
34+
if (this.services.dfuControlService) {
35+
await this.services.dfuControlService.requestDfu();
36+
}
37+
}
38+
39+
public render() {
40+
return (
41+
<button disabled={this.disabled} onClick={() => this.calibrate()}>{this.dfuLabel}</button>
42+
);
43+
}
44+
}

src/microbit-dfu/readme.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# microbit-dfu
2+
3+
4+
5+
<!-- Auto Generated Below -->
6+
7+
8+
## Properties
9+
10+
| Property | Attribute | Description | Type | Default |
11+
| ---------- | ----------- | ------------------------------------- | ---------- | ---------------- |
12+
| `dfuLabel` | `dfu-label` | The button label to initiate DFU mode | `string` | `"Initiate DFU"` |
13+
| `services` | -- | | `Services` | `null` |
14+
15+
16+
----------------------------------------------
17+
18+
*Built with [StencilJS](https://stenciljs.com/)*

0 commit comments

Comments
 (0)