From 28933d0ae8454f40e4fab7c170715856d9cbac7e Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 29 Mar 2025 20:00:48 +0100 Subject: [PATCH] anti zero devision --- lib/bs412.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bs412.c b/lib/bs412.c index 265113c..ae2904b 100644 --- a/lib/bs412.c +++ b/lib/bs412.c @@ -8,7 +8,11 @@ void init_modulation_power_measure(MPXPowerMeasurement* mpx, int sample_rate) { float measure_mpx(MPXPowerMeasurement* mpx, int deviation) { mpx->sample += 10*log10f(deviation/19000.0f); - float modulation_power = mpx->sample/mpx->i; + + float div = mpx->i; + if(div == 0) div = 1; + float modulation_power = mpx->sample/div; + mpx->i++; if (mpx->i >= mpx->sample_rate) { mpx->sample = modulation_power;