From 6fdfc3fae1cf355e3b4eb371e23668115343f2e1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Sep 2024 12:07:22 +1000 Subject: [PATCH] codal_app/microbithal_microphone: Add hal_microphone_get_level_db(). Signed-off-by: Damien George --- src/codal_app/microbithal.h | 1 + src/codal_app/microbithal_microphone.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/codal_app/microbithal.h b/src/codal_app/microbithal.h index 2ebeaf0..6da1f38 100644 --- a/src/codal_app/microbithal.h +++ b/src/codal_app/microbithal.h @@ -165,6 +165,7 @@ int microbit_hal_compass_get_heading(void); void microbit_hal_microphone_init(void); void microbit_hal_microphone_set_threshold(int kind, int value); int microbit_hal_microphone_get_level(void); +float microbit_hal_microphone_get_level_db(void); const uint8_t *microbit_hal_get_font_data(char c); diff --git a/src/codal_app/microbithal_microphone.cpp b/src/codal_app/microbithal_microphone.cpp index 0cceb16..e530432 100644 --- a/src/codal_app/microbithal_microphone.cpp +++ b/src/codal_app/microbithal_microphone.cpp @@ -59,4 +59,11 @@ int microbit_hal_microphone_get_level(void) { return value; } +float microbit_hal_microphone_get_level_db(void) { + uBit.audio.levelSPL->setUnit(LEVEL_DETECTOR_SPL_DB); + float value = uBit.audio.levelSPL->getValue(); + uBit.audio.levelSPL->setUnit(LEVEL_DETECTOR_SPL_8BIT); + return value; +} + }