/*==============================================================================
 * battery_saadc.h - Battery voltage SAADC measurement interface
 *
 * Uses the nRF52840 SAADC to measure battery voltage on AIN2.
 *
 * API:
 *   battery_level_meas()            : one-shot measurement (async, result via callback)
 *   battery_timer_init/start/stop() : 60-second periodic monitoring timer
 *
 * Periodic safety check (every 60 s):
 *   Battery SAADC -> IMU die temperature sequential measurement.
 *   Auto power-off after 5 consecutive readings below LOW_BATTERY_VOLTAGE (3500 mV)
 *   or above OVER_TEMPERATURE_THRESHOLD (40 C).
 *============================================================================*/

#ifndef _BATTERY_SAADC_H_
#define _BATTERY_SAADC_H_

/* Low-battery threshold (mV) — 5 consecutive readings below this -> power OFF */
#define LOW_BATTERY_VOLTAGE         3500

/* Over-temperature threshold (deg C) — 5 consecutive readings above this -> power OFF */
#define OVER_TEMPERATURE_THRESHOLD  40.0f

/* SAADC callback completion flag (used by all_sensors() to wait) */
extern volatile bool battery_saadc_done;

/* Called when safety check temperature measurement completes */
void safety_check_complete(float temp_c);

/* Start a single async battery measurement. Result handled in callback. */
void battery_level_meas(void);
/* Start the 60-second periodic battery monitoring timer. */
void battery_timer_start(void);
/* Stop the battery monitoring timer. */
void battery_timer_stop(void);
/* Initialise the battery monitoring timer (call once at app start). */
void battery_timer_init(void);

#endif //_BATTERY_SAADC_H_
