Skip to content

Commit

Permalink
codal_port/microbit_microphone: Add microphone.sound_level_db() method.
Browse files Browse the repository at this point in the history
This returns a floating-point number in dB.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Sep 9, 2024
1 parent 6fdfc3f commit 703abc8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/codal_port/microbit_microphone.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ static mp_obj_t microbit_microphone_sound_level(mp_obj_t self_in) {
}
static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_obj, microbit_microphone_sound_level);

static mp_obj_t microbit_microphone_sound_level_db(mp_obj_t self_in) {
(void)self_in;
microphone_init();
return mp_obj_new_float_from_f(microbit_hal_microphone_get_level_db());
}
static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_db_obj, microbit_microphone_sound_level_db);

static mp_obj_t microbit_microphone_current_event(mp_obj_t self_in) {
(void)self_in;
microphone_init();
Expand Down Expand Up @@ -154,6 +161,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_get_events_obj, microbit_mi
static const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_set_threshold), MP_ROM_PTR(&microbit_microphone_set_threshold_obj) },
{ MP_ROM_QSTR(MP_QSTR_sound_level), MP_ROM_PTR(&microbit_microphone_sound_level_obj) },
{ MP_ROM_QSTR(MP_QSTR_sound_level_db), MP_ROM_PTR(&microbit_microphone_sound_level_db_obj) },
{ MP_ROM_QSTR(MP_QSTR_current_event), MP_ROM_PTR(&microbit_microphone_current_event_obj) },
{ MP_ROM_QSTR(MP_QSTR_is_event), MP_ROM_PTR(&microbit_microphone_is_event_obj) },
{ MP_ROM_QSTR(MP_QSTR_was_event), MP_ROM_PTR(&microbit_microphone_was_event_obj) },
Expand Down

0 comments on commit 703abc8

Please sign in to comment.