Преглед изворни кода

option for a battery handler

Philippe G пре 3 година
родитељ
комит
86953fff14
2 измењених фајлова са 4 додато и 0 уклоњено
  1. 3 0
      components/services/battery.c
  2. 1 0
      components/services/monitor.h

+ 3 - 0
components/services/battery.c

@@ -41,6 +41,8 @@ static struct {
 	.attenuation = ADC_ATTEN_DB_0,
 };	
 
+void (*battery_handler_svc)(float value);
+
 /****************************************************************************************
  * 
  */
@@ -65,6 +67,7 @@ static void battery_callback(TimerHandle_t xTimer) {
 	if (++battery.count == 30) {
 		battery.avg = battery.sum / battery.count;
 		battery.sum = battery.count = 0;
+		if (battery_handler_svc) (battery_handler_svc)(battery.avg);
 		ESP_LOGI(TAG, "Voltage %.2fV", battery.avg);
 	}	
 }

+ 1 - 0
components/services/monitor.h

@@ -20,6 +20,7 @@ extern bool jack_inserted_svc(void);
 extern void (*spkfault_handler_svc)(bool inserted);
 extern bool spkfault_svc(void);
 
+extern void (*battery_handler_svc)(float value);
 extern float battery_value_svc(void);
 extern uint16_t battery_level_svc(void);