File tree Expand file tree Collapse file tree 6 files changed +19
-18
lines changed Expand file tree Collapse file tree 6 files changed +19
-18
lines changed Original file line number Diff line number Diff line change @@ -48,8 +48,8 @@ export class Accelerometer {
4848
4949 setValue ( id : StateKeys , value : any ) {
5050 this . state [ id ] . setValue ( value ) ;
51- if ( id === "gesture" ) {
52- this . gestureCallback ! (
51+ if ( id === "gesture" && this . gestureCallback ) {
52+ this . gestureCallback (
5353 convertAccelerometerStringToNumber ( this . state . gesture . value )
5454 ) ;
5555 }
@@ -71,7 +71,7 @@ export class Accelerometer {
7171 } ) ;
7272 }
7373
74- initialize ( gestureCallback : GestureCallback ) {
74+ initializeCallbacks ( gestureCallback : GestureCallback ) {
7575 this . gestureCallback = gestureCallback ;
7676 }
7777
Original file line number Diff line number Diff line change @@ -23,7 +23,10 @@ export class Audio {
2323
2424 constructor ( ) { }
2525
26- initialize ( { defaultAudioCallback, speechAudioCallback } : AudioOptions ) {
26+ initializeCallbacks ( {
27+ defaultAudioCallback,
28+ speechAudioCallback,
29+ } : AudioOptions ) {
2730 this . context = new AudioContext ( {
2831 // The highest rate is the sound expression synth.
2932 sampleRate : 44100 ,
Original file line number Diff line number Diff line change @@ -115,8 +115,6 @@ export class Button {
115115 return result ;
116116 }
117117
118- initialize ( ) { }
119-
120118 dispose ( ) {
121119 this . _presses = 0 ;
122120 }
Original file line number Diff line number Diff line change @@ -169,14 +169,14 @@ export class Board {
169169 noInitialRun : true ,
170170 } ) ;
171171 const module = new ModuleWrapper ( wrapped ) ;
172- this . audio . initialize ( {
172+ this . audio . initializeCallbacks ( {
173173 defaultAudioCallback : wrapped . _microbit_hal_audio_ready_callback ,
174174 speechAudioCallback : wrapped . _microbit_hal_audio_speech_ready_callback ,
175175 } ) ;
176- this . buttons . forEach ( ( b ) => b . initialize ( ) ) ;
177- this . pins . forEach ( ( p ) => p . initialize ( ) ) ;
178- this . accelerometer . initialize ( wrapped . _microbit_hal_gesture_callback ) ;
179- this . microphone . initialize (
176+ this . accelerometer . initializeCallbacks (
177+ wrapped . _microbit_hal_gesture_callback
178+ ) ;
179+ this . microphone . initializeCallbacks (
180180 wrapped . _microbit_hal_audio_speech_ready_callback
181181 ) ;
182182 return module ;
Original file line number Diff line number Diff line change @@ -50,14 +50,16 @@ export class Microphone {
5050
5151 const low = this . soundLevel . lowThreshold ! ;
5252 const high = this . soundLevel . highThreshold ! ;
53- if ( prev > low && curr <= low ) {
54- this . soundLevelCallback ! ( MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_LOW ) ;
55- } else if ( prev < high && curr >= high ! ) {
56- this . soundLevelCallback ! ( MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_HIGH ) ;
53+ if ( this . soundLevelCallback ) {
54+ if ( prev > low && curr <= low ) {
55+ this . soundLevelCallback ( MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_LOW ) ;
56+ } else if ( prev < high && curr >= high ! ) {
57+ this . soundLevelCallback ( MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_HIGH ) ;
58+ }
5759 }
5860 }
5961
60- initialize ( soundLevelCallback : ( v : number ) => void ) {
62+ initializeCallbacks ( soundLevelCallback : ( v : number ) => void ) {
6163 this . soundLevelCallback = soundLevelCallback ;
6264 }
6365
Original file line number Diff line number Diff line change @@ -113,7 +113,5 @@ export class Pin {
113113 }
114114 }
115115
116- initialize ( ) { }
117-
118116 dispose ( ) { }
119117}
You can’t perform that action at this time.
0 commit comments