Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
light.c
Go to the documentation of this file.
1 /*
2  * $Id: demo_module.c 3079 2009-03-11 16:55:42Z gautier $
3  *
4  * Copyright (C) 2009 Gautier Hattenberger
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
25 #include "light.h"
26 #include "led.h"
27 
30 
31 #ifndef STROBE_LIGHT_MODE_DEFAULT
32 #define STROBE_LIGHT_MODE_DEFAULT 6
33 #endif
34 
35 #ifndef NAV_LIGHT_MODE_DEFAULT
36 #define NAV_LIGHT_MODE_DEFAULT 4
37 #endif
38 
39 
40 void init_light(void) {
41  // this part is already done by led_init in fact
45 #ifdef LIGHT_LED_NAV
46  LED_INIT(LIGHT_LED_NAV);
47  LED_OFF(LIGHT_LED_NAV);
49 #endif
50 }
51 
52 void periodic_light(void)
53 {
54  static uint8_t counter = 0;
55 #ifdef LIGHT_LED_NAV
56  static uint8_t counter_nav = 0;
57 #endif
58 
59  switch (strobe_light_mode)
60  {
61  default: // Always off
63  break;
64  case 1: // Always on
66  break;
67  case 2: // Blink
68  case 3:
69  case 4:
70  if (counter == (strobe_light_mode*5 - 4))
71  {
73  }
74  else if (counter >= 20)
75  {
77  counter = 0;
78  }
79  break;
80  case 5: // Complex Blinking
81  if (counter == 3)
82  {
84  }
85  else if (counter == 4)
86  {
88  }
89  else if (counter == 6)
90  {
92  }
93  else if (counter == 7)
94  {
96  }
97  else if (counter == 8)
98  {
100  }
101  else if (counter >= 25)
102  {
104  counter = 0;
105  }
106  break;
107  case 6:
108  if (counter <= 18)
109  {
110  if ((counter % 2) == 0)
111  {
113  }
114  else
115  {
117  }
118  }
119  else if (counter == 35)
120  {
121  counter = 0;
122  }
123  break;
124  }
125 
126 #ifdef LIGHT_LED_NAV
127  switch (nav_light_mode)
128  {
129  default: // Always off
130  LED_OFF(LIGHT_LED_NAV);
131  break;
132  case 1: // Always on
133  LED_ON(LIGHT_LED_NAV);
134  break;
135  case 2: // Blink
136  case 3:
137  case 4:
138  if (counter_nav == (nav_light_mode*5 - 4))
139  {
140  LED_OFF(LIGHT_LED_NAV);
141  }
142  else if (counter_nav >= 20)
143  {
144  LED_ON(LIGHT_LED_NAV);
145  counter_nav = 0;
146  }
147  break;
148  }
149  counter_nav++;
150 #endif
151 
152  counter++;
153 }
154 
uint8_t nav_light_mode
Definition: light.c:29
void periodic_light(void)
Definition: light.c:52
#define NAV_LIGHT_MODE_DEFAULT
Definition: light.c:36
#define LIGHT_LED_STROBE
Definition: light.h:36
#define LED_ON(i)
Definition: led_hw.h:28
#define STROBE_LIGHT_MODE_DEFAULT
Definition: light.c:32
void init_light(void)
Definition: light.c:40
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
uint8_t strobe_light_mode
Definition: light.c:28