diff --git a/src/drivers/battery/battery_adc.c b/src/drivers/battery/battery_adc.c index 9ebf0f5..ec7cb7f 100644 --- a/src/drivers/battery/battery_adc.c +++ b/src/drivers/battery/battery_adc.c @@ -21,6 +21,7 @@ #include "battery_adc.h" #include "debug_print.h" +#include "imu_i2c.h" #include "main.h" /*============================================================================== @@ -42,6 +43,10 @@ volatile uint16_t info_batt = 0; static struct k_timer battery_timer; static struct k_work battery_work; static uint8_t low_battery_cnt = 0; +static uint8_t high_temperature_cnt = 0; + +#define BATTERY_MONITOR_LIMIT_COUNT 5U +#define HIGH_TEMPERATURE_CDEG 4000 /* 40.00 C */ #define BATTERY_MONITOR_INTERVAL_MS 60000 /* 60초 주기 */ @@ -159,17 +164,48 @@ static void battery_work_handler(struct k_work *work) low_battery_cnt++; DBG_PRINTF("[BATT] LOW! cnt=%d mv=%d\r\n", low_battery_cnt, batt); - if (low_battery_cnt >= 10) + if (low_battery_cnt >= BATTERY_MONITOR_LIMIT_COUNT) { low_battery_cnt = 0; - DBG_PRINTF("[BATT] 10x low -> Power OFF\r\n"); + DBG_PRINTF("[BATT] %ux low -> Power OFF\r\n", BATTERY_MONITOR_LIMIT_COUNT); sleep_mode_enter(); + return; } } else { low_battery_cnt = 0; } + + int16_t temp_cdeg = 0; + int temp_ret = imu_read_temperature_cdeg(&temp_cdeg); + + if (temp_ret != 0) + { + DBG_PRINTF("[TEMP] IMU read failed ret=%d\r\n", temp_ret); + return; + } + + if (temp_cdeg > HIGH_TEMPERATURE_CDEG) + { + high_temperature_cnt++; + DBG_PRINTF("[TEMP] HIGH! cnt=%d temp=%d.%02d C\r\n", + high_temperature_cnt, + temp_cdeg / 100, + (temp_cdeg < 0 ? -temp_cdeg : temp_cdeg) % 100); + + if (high_temperature_cnt >= BATTERY_MONITOR_LIMIT_COUNT) + { + high_temperature_cnt = 0; + DBG_PRINTF("[TEMP] %ux high -> Power OFF\r\n", BATTERY_MONITOR_LIMIT_COUNT); + sleep_mode_enter(); + return; + } + } + else + { + high_temperature_cnt = 0; + } } /* 타이머 ISR → k_work 예약 */