@@ -2,6 +2,7 @@ import svgText from "../microbit-drawing.svg";
22import { Accelerometer } from "./accelerometer" ;
33import { Audio } from "./audio" ;
44import { Button } from "./buttons" ;
5+ import { Compass } from "./compass" ;
56import {
67 MICROBIT_HAL_PIN_FACE ,
78 MICROBIT_HAL_PIN_P0 ,
@@ -10,11 +11,11 @@ import {
1011} from "./constants" ;
1112import { Display } from "./display" ;
1213import { FileSystem } from "./fs" ;
13- import { WebAssemblyOperations } from "./wasm" ;
1414import { Microphone } from "./microphone" ;
1515import { Pin } from "./pins" ;
1616import { Radio } from "./radio" ;
17- import { EnumSensor , RangeSensor , Sensor , State } from "./state" ;
17+ import { RangeSensor , State } from "./state" ;
18+ import { WebAssemblyOperations } from "./wasm" ;
1819
1920const stoppedOpactity = "0.5" ;
2021
@@ -43,6 +44,7 @@ export class Board {
4344 temperature : RangeSensor ;
4445 microphone : Microphone ;
4546 accelerometer : Accelerometer ;
47+ compass : Compass ;
4648 radio : Radio ;
4749
4850 public serialInputBuffer : number [ ] = [ ] ;
@@ -89,6 +91,7 @@ export class Board {
8991 this . audio = new Audio ( ) ;
9092 this . temperature = new RangeSensor ( "temperature" , - 5 , 50 , 21 , "°C" ) ;
9193 this . accelerometer = new Accelerometer ( onChange ) ;
94+ this . compass = new Compass ( ) ;
9295 this . microphone = new Microphone (
9396 this . svg . querySelector ( "#LitMicrophone" ) ! ,
9497 onChange
@@ -124,6 +127,11 @@ export class Board {
124127 accelerometerZ : this . accelerometer . state . accelerometerZ ,
125128 gesture : this . accelerometer . state . gesture ,
126129
130+ compassX : this . compass . state . compassX ,
131+ compassY : this . compass . state . compassY ,
132+ compassZ : this . compass . state . compassZ ,
133+ compassHeading : this . compass . state . compassHeading ,
134+
127135 lightLevel : this . display . lightLevel ,
128136 dataLogging : {
129137 // Placeholder.
@@ -144,6 +152,13 @@ export class Board {
144152 this . accelerometer . setValue ( id , value ) ;
145153 break ;
146154 }
155+ case "compassX" :
156+ case "compassY" :
157+ case "compassZ" :
158+ case "compassHeading" : {
159+ this . compass . setValue ( id , value ) ;
160+ break ;
161+ }
147162 case "buttonA" : {
148163 this . buttons [ 0 ] . setValue ( value ) ;
149164 break ;
@@ -198,6 +213,7 @@ export class Board {
198213 this . pins . forEach ( ( p ) => p . initialize ( ) ) ;
199214 this . display . initialize ( ) ;
200215 this . accelerometer . initialize ( this . operations . gestureCallback ! ) ;
216+ this . compass . initialize ( ) ;
201217 this . microphone . initialize ( this . operations . soundLevelCallback ! ) ;
202218 this . radio . initialize ( ) ;
203219 this . serialInputBuffer . length = 0 ;
@@ -292,6 +308,7 @@ export class Board {
292308 this . pins . forEach ( ( p ) => p . dispose ( ) ) ;
293309 this . display . dispose ( ) ;
294310 this . accelerometer . dispose ( ) ;
311+ this . compass . dispose ( ) ;
295312 this . microphone . dispose ( ) ;
296313 this . radio . dispose ( ) ;
297314 this . serialInputBuffer . length = 0 ;
0 commit comments