Skip to content

Commit 804c5fe

Browse files
committed
codal_app: Provide constants for setting microphone threshold.
Signed-off-by: Damien George <[email protected]>
1 parent a1be53a commit 804c5fe

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/codal_app/microbithal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ extern "C" {
9191
#define MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_LOW (1)
9292
#define MICROBIT_HAL_MICROPHONE_EVT_THRESHOLD_HIGH (2)
9393

94+
// Threshold kind, passed to microbit_hal_microphone_set_threshold().
95+
#define MICROBIT_HAL_MICROPHONE_SET_THRESHOLD_LOW (0)
96+
#define MICROBIT_HAL_MICROPHONE_SET_THRESHOLD_HIGH (1)
97+
9498
#define MICROBIT_HAL_LOG_TIMESTAMP_NONE (0)
9599
#define MICROBIT_HAL_LOG_TIMESTAMP_MILLISECONDS (1)
96100
#define MICROBIT_HAL_LOG_TIMESTAMP_SECONDS (10)

src/codal_app/microbithal_microphone.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void microbit_hal_microphone_init(void) {
5858
void microbit_hal_microphone_set_threshold(int kind, int value) {
5959
value = (value - HAL_LEVEL_MIN) * CODAL_LEVEL_RANGE / HAL_LEVEL_RANGE + CODAL_LEVEL_MIN;
6060
value = min(max(value, CODAL_LEVEL_MIN), CODAL_LEVEL_MAX);
61-
if (kind == 0) {
61+
if (kind == MICROBIT_HAL_MICROPHONE_SET_THRESHOLD_LOW) {
6262
uBit.audio.level->setLowThreshold(value);
6363
} else {
6464
uBit.audio.level->setHighThreshold(value);

src/codal_port/microbit_microphone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ STATIC mp_obj_t microbit_microphone_set_threshold(mp_obj_t self_in, mp_obj_t sou
8585
uint8_t sound = sound_event_from_obj(sound_in);
8686
int kind;
8787
if (sound == SOUND_EVENT_QUIET) {
88-
kind = 0;
88+
kind = MICROBIT_HAL_MICROPHONE_SET_THRESHOLD_LOW;
8989
} else if (sound == SOUND_EVENT_LOUD) {
90-
kind = 1;
90+
kind = MICROBIT_HAL_MICROPHONE_SET_THRESHOLD_HIGH;
9191
} else {
9292
mp_raise_ValueError(MP_ERROR_TEXT("invalid sound"));
9393
}

0 commit comments

Comments
 (0)