Skip to content

Commit e876dca

Browse files
committed
codal_port/microbit_microphone: Add microphone.sound_level_db() method.
This returns a floating-point number in dB. Signed-off-by: Damien George <[email protected]>
1 parent 8dad9e6 commit e876dca

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/codal_port/microbit_microphone.c

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ static mp_obj_t microbit_microphone_sound_level(mp_obj_t self_in) {
109109
}
110110
static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_obj, microbit_microphone_sound_level);
111111

112+
static mp_obj_t microbit_microphone_sound_level_db(mp_obj_t self_in) {
113+
(void)self_in;
114+
microphone_init();
115+
return mp_obj_new_float_from_f(microbit_hal_microphone_get_level_db());
116+
}
117+
static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_sound_level_db_obj, microbit_microphone_sound_level_db);
118+
112119
static mp_obj_t microbit_microphone_current_event(mp_obj_t self_in) {
113120
(void)self_in;
114121
microphone_init();
@@ -154,6 +161,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(microbit_microphone_get_events_obj, microbit_mi
154161
static const mp_rom_map_elem_t microbit_microphone_locals_dict_table[] = {
155162
{ MP_ROM_QSTR(MP_QSTR_set_threshold), MP_ROM_PTR(&microbit_microphone_set_threshold_obj) },
156163
{ MP_ROM_QSTR(MP_QSTR_sound_level), MP_ROM_PTR(&microbit_microphone_sound_level_obj) },
164+
{ MP_ROM_QSTR(MP_QSTR_sound_level_db), MP_ROM_PTR(&microbit_microphone_sound_level_db_obj) },
157165
{ MP_ROM_QSTR(MP_QSTR_current_event), MP_ROM_PTR(&microbit_microphone_current_event_obj) },
158166
{ MP_ROM_QSTR(MP_QSTR_is_event), MP_ROM_PTR(&microbit_microphone_is_event_obj) },
159167
{ MP_ROM_QSTR(MP_QSTR_was_event), MP_ROM_PTR(&microbit_microphone_was_event_obj) },

0 commit comments

Comments
 (0)