Skip to content

Commit dd6e205

Browse files
committed
Add text, temp and build
1 parent 2a45b9a commit dd6e205

15 files changed

+277
-51
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
# micro:bit Web Components
2+
3+
[![Circle CI](https://circleci.com/gh/thegecko/microbit-web-components.svg?style=shield&circle-token=eac64b63d7ab07b21242da11f5e3e8ce83e76140)](https://circleci.com/gh/thegecko/microbit-web-components/)
4+
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://spdx.org/licenses/MIT.html)
5+
26
Web Components library for micro:bit
37

48
# Implementation Status
59

610
- [x] Select Device
711
- [x] Connection Status
8-
- [ ] Device Info
12+
- [x] Firmware Information
13+
- [ ] Hardware Information
14+
- [ ] Manufacturer Information
15+
- [ ] Model Number
16+
- [ ] Serial Number
17+
- [x] Write Text
18+
- [ ] Write LEDs
19+
- [ ] Button States
20+
- [x] Temperature
921
- [ ] Accelerometer Data
1022
- [ ] Magnetometer Data
11-
- [ ] Temperature
12-
- [ ] Button States
13-
- [ ] Write Text
14-
- [ ] Write LEDs
1523
- [ ] Read / Write IO (A/D/PWM)
1624
- [ ] Read / Write UART
1725
- [ ] Update Firmware

circle.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: circleci/node:8
7+
steps:
8+
- checkout
9+
- run: npm install
10+
- run: npm run build
11+
- persist_to_workspace:
12+
root: ../
13+
paths:
14+
- project
15+
16+
deploy:
17+
docker:
18+
- image: circleci/node:8
19+
steps:
20+
- attach_workspace:
21+
at: ../
22+
- run: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
23+
- run: git config --global user.name thegecko
24+
- run: git config --global user.email [email protected]
25+
- run: git add --force dist www
26+
- run: git stash save
27+
- run: git checkout gh-pages
28+
- run: git merge master --no-commit
29+
- run: git checkout stash -- .
30+
- run: git commit --allow-empty --message "Automatic Deployment [skip ci]"
31+
- run: git push
32+
33+
workflows:
34+
version: 2
35+
commit:
36+
jobs:
37+
- build
38+
- deploy:
39+
requires:
40+
- build
41+
filters:
42+
branches:
43+
only: master

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="refresh" content="0; url='www/index.html'" />
4+
</head>
5+
</body>

src/components.d.ts

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export namespace Components {
4545
'setServices'?: (services: Services) => void;
4646
}
4747

48-
interface MicrobitInfoFirmware {
49-
'device': BluetoothDevice;
48+
interface MicrobitFirmware {
5049
/**
5150
* The text shown when disconnected
5251
*/
@@ -57,8 +56,7 @@ export namespace Components {
5756
'noInfo': string;
5857
'services': Services;
5958
}
60-
interface MicrobitInfoFirmwareAttributes extends StencilHTMLAttributes {
61-
'device'?: BluetoothDevice;
59+
interface MicrobitFirmwareAttributes extends StencilHTMLAttributes {
6260
/**
6361
* The text shown when disconnected
6462
*/
@@ -92,21 +90,79 @@ export namespace Components {
9290
*/
9391
'disconnectedText'?: string;
9492
}
93+
94+
interface MicrobitTemperature {
95+
/**
96+
* The text shown when disconnected
97+
*/
98+
'disconnectedText': string;
99+
/**
100+
* The text shown when no temperature
101+
*/
102+
'noTemperature': string;
103+
'services': Services;
104+
/**
105+
* The interval to check the temperature (ms)
106+
*/
107+
'temperaturePeriod': number;
108+
}
109+
interface MicrobitTemperatureAttributes extends StencilHTMLAttributes {
110+
/**
111+
* The text shown when disconnected
112+
*/
113+
'disconnectedText'?: string;
114+
/**
115+
* The text shown when no temperature
116+
*/
117+
'noTemperature'?: string;
118+
'services'?: Services;
119+
/**
120+
* The interval to check the temperature (ms)
121+
*/
122+
'temperaturePeriod'?: number;
123+
}
124+
125+
interface MicrobitText {
126+
/**
127+
* The text shown on the button
128+
*/
129+
'buttonText': string;
130+
/**
131+
* The speed to scroll the text
132+
*/
133+
'scrollDelay': number;
134+
'services': Services;
135+
}
136+
interface MicrobitTextAttributes extends StencilHTMLAttributes {
137+
/**
138+
* The text shown on the button
139+
*/
140+
'buttonText'?: string;
141+
/**
142+
* The speed to scroll the text
143+
*/
144+
'scrollDelay'?: number;
145+
'services'?: Services;
146+
}
95147
}
96148

97149
declare global {
98150
interface StencilElementInterfaces {
99151
'MicrobitApp': Components.MicrobitApp;
100152
'MicrobitConnect': Components.MicrobitConnect;
101-
'MicrobitInfoFirmware': Components.MicrobitInfoFirmware;
153+
'MicrobitFirmware': Components.MicrobitFirmware;
102154
'MicrobitStatus': Components.MicrobitStatus;
155+
'MicrobitTemperature': Components.MicrobitTemperature;
156+
'MicrobitText': Components.MicrobitText;
103157
}
104158

105159
interface StencilIntrinsicElements {
106160
'microbit-app': Components.MicrobitAppAttributes;
107161
'microbit-connect': Components.MicrobitConnectAttributes;
108-
'microbit-info-firmware': Components.MicrobitInfoFirmwareAttributes;
162+
'microbit-firmware': Components.MicrobitFirmwareAttributes;
109163
'microbit-status': Components.MicrobitStatusAttributes;
164+
'microbit-temperature': Components.MicrobitTemperatureAttributes;
165+
'microbit-text': Components.MicrobitTextAttributes;
110166
}
111167

112168

@@ -122,10 +178,10 @@ declare global {
122178
new (): HTMLMicrobitConnectElement;
123179
};
124180

125-
interface HTMLMicrobitInfoFirmwareElement extends Components.MicrobitInfoFirmware, HTMLStencilElement {}
126-
var HTMLMicrobitInfoFirmwareElement: {
127-
prototype: HTMLMicrobitInfoFirmwareElement;
128-
new (): HTMLMicrobitInfoFirmwareElement;
181+
interface HTMLMicrobitFirmwareElement extends Components.MicrobitFirmware, HTMLStencilElement {}
182+
var HTMLMicrobitFirmwareElement: {
183+
prototype: HTMLMicrobitFirmwareElement;
184+
new (): HTMLMicrobitFirmwareElement;
129185
};
130186

131187
interface HTMLMicrobitStatusElement extends Components.MicrobitStatus, HTMLStencilElement {}
@@ -134,18 +190,34 @@ declare global {
134190
new (): HTMLMicrobitStatusElement;
135191
};
136192

193+
interface HTMLMicrobitTemperatureElement extends Components.MicrobitTemperature, HTMLStencilElement {}
194+
var HTMLMicrobitTemperatureElement: {
195+
prototype: HTMLMicrobitTemperatureElement;
196+
new (): HTMLMicrobitTemperatureElement;
197+
};
198+
199+
interface HTMLMicrobitTextElement extends Components.MicrobitText, HTMLStencilElement {}
200+
var HTMLMicrobitTextElement: {
201+
prototype: HTMLMicrobitTextElement;
202+
new (): HTMLMicrobitTextElement;
203+
};
204+
137205
interface HTMLElementTagNameMap {
138206
'microbit-app': HTMLMicrobitAppElement
139207
'microbit-connect': HTMLMicrobitConnectElement
140-
'microbit-info-firmware': HTMLMicrobitInfoFirmwareElement
208+
'microbit-firmware': HTMLMicrobitFirmwareElement
141209
'microbit-status': HTMLMicrobitStatusElement
210+
'microbit-temperature': HTMLMicrobitTemperatureElement
211+
'microbit-text': HTMLMicrobitTextElement
142212
}
143213

144214
interface ElementTagNameMap {
145215
'microbit-app': HTMLMicrobitAppElement;
146216
'microbit-connect': HTMLMicrobitConnectElement;
147-
'microbit-info-firmware': HTMLMicrobitInfoFirmwareElement;
217+
'microbit-firmware': HTMLMicrobitFirmwareElement;
148218
'microbit-status': HTMLMicrobitStatusElement;
219+
'microbit-temperature': HTMLMicrobitTemperatureElement;
220+
'microbit-text': HTMLMicrobitTextElement;
149221
}
150222

151223

src/components/microbit-app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DeviceTunnel from '../data/device-tunnel';
88
export class MicrobitApp {
99

1010
@State() device: BluetoothDevice = undefined;
11-
@State() services: Services = {};
11+
@State() services: Services = undefined;
1212

1313
setDevice = (device: BluetoothDevice) => {
1414
this.device = device;

src/components/microbit-connect/microbit-connect.tsx renamed to src/components/microbit-connect.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { Component, Prop, Element } from "@stencil/core";
22
import { requestMicrobit, getServices, Services } from "microbit-web-bluetooth";
3-
import DeviceTunnel from '../../data/device-tunnel';
3+
import DeviceTunnel from '../data/device-tunnel';
44

55
@Component({
6-
tag: 'microbit-connect',
7-
styleUrl: 'microbit-connect.css',
8-
shadow: true
6+
tag: 'microbit-connect'
97
})
108
export class MicrobitConnect {
119
@Element() el;
@@ -39,6 +37,7 @@ export class MicrobitConnect {
3937
await this.device.gatt.disconnect();
4038
}
4139
this.setDevice(undefined);
40+
this.setServices(undefined);
4241
return;
4342
}
4443

src/components/microbit-connect/microbit-connect.css

Lines changed: 0 additions & 1 deletion
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { Component, Prop, Element, State, Watch } from "@stencil/core";
22
import { Services } from "microbit-web-bluetooth";
3-
import DeviceTunnel from '../../data/device-tunnel';
3+
import DeviceTunnel from '../data/device-tunnel';
44

55
@Component({
6-
tag: 'microbit-info-firmware',
7-
styleUrl: 'microbit-info-firmware.css',
8-
shadow: true
6+
tag: 'microbit-firmware'
97
})
10-
export class MicrobitInfo {
11-
@Element() el;
12-
@Prop() device: BluetoothDevice = undefined;
13-
@Prop() services: Services = {};
14-
@State() info: string = "";
15-
8+
export class MicrobitFirmware {
169
/**
1710
* The text shown when disconnected
1811
*/
@@ -23,8 +16,17 @@ export class MicrobitInfo {
2316
*/
2417
@Prop() noInfo: string = "No firmware info found";
2518

19+
@Element() el;
20+
@Prop() services: Services = undefined;
21+
@State() info: string = this.disconnectedText;
22+
2623
@Watch('services')
2724
async watchHandler() {
25+
if (!this.services) {
26+
this.info = this.disconnectedText;
27+
return;
28+
}
29+
2830
const service = this.services.deviceInformationService;
2931

3032
if (!service) {
@@ -38,16 +40,9 @@ export class MicrobitInfo {
3840

3941
render() {
4042
return (
41-
<div>{this.getText()}</div>
43+
<div>{this.info}</div>
4244
);
4345
}
44-
45-
private getText() {
46-
if (!this.device) {
47-
return this.disconnectedText;
48-
}
49-
return this.info;
50-
}
5146
}
5247

53-
DeviceTunnel.injectProps(MicrobitInfo, ['device', 'services']);
48+
DeviceTunnel.injectProps(MicrobitFirmware, ['services']);

src/components/microbit-info-firmware/microbit-info-firmware.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/microbit-status/microbit-status.tsx renamed to src/components/microbit-status.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Component, Prop, Element } from "@stencil/core";
2-
import DeviceTunnel from '../../data/device-tunnel';
2+
import DeviceTunnel from '../data/device-tunnel';
33

44
@Component({
5-
tag: 'microbit-status',
6-
styleUrl: 'microbit-status.css',
7-
shadow: true
5+
tag: 'microbit-status'
86
})
97
export class MicrobitStatus {
108
@Element() el;

0 commit comments

Comments
 (0)