Skip to content

Commit

Permalink
Activate sim mic light when recording
Browse files Browse the repository at this point in the history
Passing this.microphone.microphoneOn/Off functions as BoardAudio constructors in  board/index.ts didn't work for some reasons. The microphone element was flagged as being undefined. So instead I passed the element directly into the BoardAudio constructor, which worked.
  • Loading branch information
microbit-grace committed Apr 11, 2024
1 parent 4ed8c93 commit aea7937
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/board/audio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class BoardAudio {
currentSoundExpressionCallback: undefined | (() => void);
private stopActiveRecording: (() => void) | undefined;

constructor() {}
constructor(
private microphoneEl: SVGElement
) {}

initializeCallbacks({
defaultAudioCallback,
Expand Down Expand Up @@ -190,6 +192,7 @@ export class BoardAudio {
this.stopRecording();
return;
}
this.microphoneEl.style.display = "unset"

const source = this.context!.createMediaStreamSource(micStream);
// TODO: wire up microphone sensitivity to this gain node
Expand Down Expand Up @@ -227,6 +230,7 @@ export class BoardAudio {
gain.disconnect();
source.disconnect();
micStream.getTracks().forEach(track => track.stop())
this.microphoneEl.style.display = "none"
this.stopActiveRecording = undefined;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/board/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class Board {
this.pins[MICROBIT_HAL_PIN_P19] = new StubPin("pin19");
this.pins[MICROBIT_HAL_PIN_P20] = new StubPin("pin20");

this.audio = new BoardAudio();
this.audio = new BoardAudio(this.svg.querySelector("#LitMicrophone")!);
this.temperature = new RangeSensor("temperature", -5, 50, 21, "°C");
this.accelerometer = new Accelerometer(onChange);
this.compass = new Compass();
Expand Down

0 comments on commit aea7937

Please sign in to comment.