Skip to content

Commit

Permalink
Add DFU mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko committed Jul 15, 2019
1 parent 93d9f25 commit ae6d1dc
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ Web Components library for micro:bit
- [ ] Microbit Channel Selection

### Firmware
- [x] Initiate DFU Mode
- [ ] Update Firmware
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ <h1>micro:bit Web Components</h1>
<microbit-text button-label="Write"></microbit-text>
<microbit-send delimiter=":" button-label="Send"></microbit-send>
<microbit-receive></microbit-receive>
<microbit-dfu></microbit-dfu>
<microbit-calibrate></microbit-calibrate>
<microbit-compass>
<div id="compass"></div>
Expand Down
22 changes: 22 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export namespace Components {
*/
'disconnectedClass': string;
}
interface MicrobitDfu {
/**
* The button label to initiate DFU mode
*/
'dfuLabel': string;
'services': Services;
}
interface MicrobitFirmware {
'deviceInformation': DeviceInformation;
/**
Expand Down Expand Up @@ -257,6 +264,12 @@ declare global {
new (): HTMLMicrobitConnectionElement;
};

interface HTMLMicrobitDfuElement extends Components.MicrobitDfu, HTMLStencilElement {}
var HTMLMicrobitDfuElement: {
prototype: HTMLMicrobitDfuElement;
new (): HTMLMicrobitDfuElement;
};

interface HTMLMicrobitFirmwareElement extends Components.MicrobitFirmware, HTMLStencilElement {}
var HTMLMicrobitFirmwareElement: {
prototype: HTMLMicrobitFirmwareElement;
Expand Down Expand Up @@ -335,6 +348,7 @@ declare global {
'microbit-compass': HTMLMicrobitCompassElement;
'microbit-connect': HTMLMicrobitConnectElement;
'microbit-connection': HTMLMicrobitConnectionElement;
'microbit-dfu': HTMLMicrobitDfuElement;
'microbit-firmware': HTMLMicrobitFirmwareElement;
'microbit-hardware': HTMLMicrobitHardwareElement;
'microbit-manufacturer': HTMLMicrobitManufacturerElement;
Expand Down Expand Up @@ -413,6 +427,13 @@ declare namespace LocalJSX {
*/
'disconnectedClass'?: string;
}
interface MicrobitDfu extends JSXBase.HTMLAttributes<HTMLMicrobitDfuElement> {
/**
* The button label to initiate DFU mode
*/
'dfuLabel'?: string;
'services'?: Services;
}
interface MicrobitFirmware extends JSXBase.HTMLAttributes<HTMLMicrobitFirmwareElement> {
'deviceInformation'?: DeviceInformation;
/**
Expand Down Expand Up @@ -561,6 +582,7 @@ declare namespace LocalJSX {
'microbit-compass': MicrobitCompass;
'microbit-connect': MicrobitConnect;
'microbit-connection': MicrobitConnection;
'microbit-dfu': MicrobitDfu;
'microbit-firmware': MicrobitFirmware;
'microbit-hardware': MicrobitHardware;
'microbit-manufacturer': MicrobitManufacturer;
Expand Down
44 changes: 44 additions & 0 deletions src/microbit-dfu/microbit-dfu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { h, Component, Prop, Element, State, Watch } from "@stencil/core";
import { Services } from "microbit-web-bluetooth";
import { microbitStore } from '../microbit-store';

@Component({
tag: 'microbit-dfu'
})
export class MicrobitDfu {
constructor() {
microbitStore.addListener(this);
}

@Element()
protected el;

@Prop({mutable: true})
public services: Services = null;

/**
* The button label to initiate DFU mode
*/
@Prop()
public dfuLabel: string = "Initiate DFU"

@State()
protected disabled = true;

@Watch('services')
protected async servicesUpdated() {
this.disabled = !this.services || !this.services.dfuControlService;
}

private async calibrate() {
if (this.services.dfuControlService) {
await this.services.dfuControlService.requestDfu();
}
}

public render() {
return (
<button disabled={this.disabled} onClick={() => this.calibrate()}>{this.dfuLabel}</button>
);
}
}
18 changes: 18 additions & 0 deletions src/microbit-dfu/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# microbit-dfu



<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
| ---------- | ----------- | ------------------------------------- | ---------- | ---------------- |
| `dfuLabel` | `dfu-label` | The button label to initiate DFU mode | `string` | `"Initiate DFU"` |
| `services` | -- | | `Services` | `null` |


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*

0 comments on commit ae6d1dc

Please sign in to comment.