Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
light.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Gautier Hattenberger
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 
23 #include "modules/light/light.h"
24 #include "led.h"
25 #include "generated/airframe.h"
26 
29 
30 #ifndef LIGHT_LED_STROBE
31 #define LIGHT_LED_STROBE 2
32 #endif
33 
34 #ifndef STROBE_LIGHT_MODE_DEFAULT
35 #define STROBE_LIGHT_MODE_DEFAULT 6
36 #endif
37 
38 #ifndef NAV_LIGHT_MODE_DEFAULT
39 #define NAV_LIGHT_MODE_DEFAULT 4
40 #endif
41 
42 
43 void init_light(void)
44 {
45  // this part is already done by led_init in fact
49 #ifdef LIGHT_LED_NAV
50  LED_INIT(LIGHT_LED_NAV);
51  LED_OFF(LIGHT_LED_NAV);
53 #endif
54 }
55 
56 void periodic_light(void)
57 {
58  static uint8_t counter = 0;
59 #ifdef LIGHT_LED_NAV
60  static uint8_t counter_nav = 0;
61 #endif
62 
63  switch (strobe_light_mode) {
64  default: // Always off
66  break;
67  case 1: // Always on
69  break;
70  case 2: // Blink
71  case 3:
72  case 4:
73  if (counter == (strobe_light_mode * 5 - 4)) {
75  } else if (counter >= 20) {
77  counter = 0;
78  }
79  break;
80  case 5: // Complex Blinking
81  if (counter == 3) {
83  } else if (counter == 4) {
85  } else if (counter == 6) {
87  } else if (counter == 7) {
89  } else if (counter == 8) {
91  } else if (counter >= 25) {
93  counter = 0;
94  }
95  break;
96  case 6:
97  if (counter <= 18) {
98  if ((counter % 2) == 0) {
100  } else {
102  }
103  } else if (counter == 35) {
104  counter = 0;
105  }
106  break;
107  }
108 
109 #ifdef LIGHT_LED_NAV
110  switch (nav_light_mode) {
111  default: // Always off
112  LED_OFF(LIGHT_LED_NAV);
113  break;
114  case 1: // Always on
115  LED_ON(LIGHT_LED_NAV);
116  break;
117  case 2: // Blink
118  case 3:
119  case 4:
120  if (counter_nav == (nav_light_mode * 5 - 4)) {
121  LED_OFF(LIGHT_LED_NAV);
122  } else if (counter_nav >= 20) {
123  LED_ON(LIGHT_LED_NAV);
124  counter_nav = 0;
125  }
126  break;
127  }
128  counter_nav++;
129 #endif
130 
131  counter++;
132 }
133 
uint8_t nav_light_mode
Definition: light.c:28
void periodic_light(void)
Definition: light.c:56
#define NAV_LIGHT_MODE_DEFAULT
Definition: light.c:39
#define LIGHT_LED_STROBE
Definition: light.c:31
#define LED_OFF(i)
Definition: led_hw.h:50
#define LED_INIT(i)
Definition: led_hw.h:48
#define STROBE_LIGHT_MODE_DEFAULT
Definition: light.c:35
int32_t counter
void init_light(void)
Definition: light.c:43
unsigned char uint8_t
Definition: types.h:14
arch independent LED (Light Emitting Diodes) API
#define LED_ON(i)
Definition: led_hw.h:49
uint8_t strobe_light_mode
Definition: light.c:27