Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bat_checker.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Thomas Kolb
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include "bat_checker.h"
23 #include "generated/airframe.h"
24 #include "generated/modules.h"
25 #include "subsystems/electrical.h"
26 #include "led.h"
27 
28 #ifndef CRITIC_BAT_LEVEL
29 #error You must define CRITIC_BAT_LEVEL to use this module!
30 #endif
31 
32 #ifndef LOW_BAT_LEVEL
33 #error You must define LOW_BAT_LEVEL to use this module!
34 #endif
35 
36 #ifndef BAT_CHECKER_LED
37 #error You must define BAT_CHECKER_LED in your airframe file.
38 #endif
39 
40 #ifndef BAT_CHECKER_DELAY
41 #define BAT_CHECKER_DELAY 5
42 #endif
43 PRINT_CONFIG_VAR(BAT_CHECKER_DELAY)
44 
45 // at this level, the buzzer will be activated periodically
46 #define WARN_BAT_LEVEL1 (LOW_BAT_LEVEL*10)
47 
48 // at this level, the buzzer will be activated permanently
49 #define WARN_BAT_LEVEL2 (CRITIC_BAT_LEVEL*10)
50 
51 void init_bat_checker(void) {
52  LED_INIT(BAT_CHECKER_LED);
53  LED_OFF(BAT_CHECKER_LED);
54 }
55 
57  static uint8_t bat_low_counter = 0;
59  if(bat_low_counter)
60  bat_low_counter--;
61  } else {
62  bat_low_counter = BAT_CHECKER_DELAY * BAT_CHECKER_PERIODIC_FREQ;
63  }
64 
65  if(!bat_low_counter) {
67  LED_ON(BAT_CHECKER_LED);
68  } else if(electrical.vsupply < WARN_BAT_LEVEL1) {
69  LED_TOGGLE(BAT_CHECKER_LED);
70  }
71  } else {
72  LED_OFF(BAT_CHECKER_LED);
73  }
74 }
75 
void bat_checker_periodic(void)
Definition: bat_checker.c:56
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:8
#define LED_ON(i)
Definition: led_hw.h:28
#define BAT_CHECKER_DELAY
Definition: bat_checker.c:41
void init_bat_checker(void)
Definition: bat_checker.c:51
#define WARN_BAT_LEVEL1
Definition: bat_checker.c:46
#define LED_TOGGLE(i)
Definition: led_hw.h:30
unsigned char uint8_t
Definition: types.h:14
#define LED_INIT(i)
Definition: led_hw.h:26
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
#define WARN_BAT_LEVEL2
Definition: bat_checker.c:49
struct Electrical electrical