From 39a8ac7ed6c0763ecfc779480a9d34acbeef9328 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 30 Jan 2024 16:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=B5=E6=B1=A0=E7=94=B5?= =?UTF-8?q?=E9=87=8F=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ app/src/one_conduction/one_conduction_board.c | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 362f89d..52cd786 100644 --- a/README.md +++ b/README.md @@ -272,4 +272,6 @@ TODO: 12. 优化定时器周期 13. 支持低电量事件 + 14. 添加设备激活逻辑,根据设备是否通过过时间来判断当前是否彻底断电。 + ``` \ No newline at end of file diff --git a/app/src/one_conduction/one_conduction_board.c b/app/src/one_conduction/one_conduction_board.c index 5193c2f..e73fc9d 100644 --- a/app/src/one_conduction/one_conduction_board.c +++ b/app/src/one_conduction/one_conduction_board.c @@ -249,8 +249,26 @@ void SingleLeadECG_battery_init() {} void SingleLeadECG_battery_deinit() {} int16_t SingleLeadECG_battery_get_adc_val() { return SingleLeadECG_adc_get_val(BATTERY_ADC_CHANNEL); } -int16_t SingleLeadECG_battery_val() { return 50; } -void SingleLeadECG_battery_charge_detect_io_init() { // +int16_t SingleLeadECG_battery_val() { // + + static const float maxv = 4.0; + static const float minv = 3.5; + + float voltage = SingleLeadECG_battery_get_adc_val() / 4096.0 * 3.3 / 2.0* 3; + if (voltage > maxv) voltage = maxv; + if (voltage < minv) voltage = minv; + + float percent = (voltage - minv) / (maxv - minv) * 100 + (float)0.1 /*加0.1是为了避免999.999时显示电量为90*/; + int16_t percent_int = (int16_t)percent; + if (percent_int < 10 && percent_int != 0) { + percent_int = 3; + } else { + percent_int = percent_int / 10 * 10; + } + // ZLOGI("battery %d ", SingleLeadECG_battery_get_adc_val()); + return percent_int; +} +void SingleLeadECG_battery_charge_detect_io_init() { // nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE); } bool SingleLeadECG_battery_charge_get_state() { return nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN) == 0; }