dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_annunc.c
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
27 
28 /* Project Includes */
29 #include "pios.h"
30 #include "openpilot.h"
31 #include "hwsimulation.h"
32 
33 #if defined(PIOS_INCLUDE_ANNUNC)
34 
35 /* Private Function Prototypes */
36 
37 DONT_BUILD_IF(PIOS_ANNUNC_NUM < HWSIMULATION_LEDSTATE_NUMELEM, piosLedNumWrong);
38 DONT_BUILD_IF(PIOS_LED_ALARM != HWSIMULATION_LEDSTATE_ALARM, idxMismatch1);
39 DONT_BUILD_IF(PIOS_LED_HEARTBEAT != HWSIMULATION_LEDSTATE_HEARTBEAT, idxMismatch2);
40 
41 /* Local Variables */
42 static uint8_t ledState[PIOS_ANNUNC_NUM];
43 
44 static inline void set_led(uint32_t led, uint8_t stat) {
46 
47  uint8_t old_state = ledState[led];
48  uint8_t new_state = stat ? HWSIMULATION_LEDSTATE_ON : HWSIMULATION_LEDSTATE_OFF;
49 
50  if (old_state == new_state)
51  return;
52  ledState[led] = new_state;
53 
54  HwSimulationLedStateSet(ledState);
55 
56 #if 0
57  char leds[PIOS_ANNUNC_NUM + 1];
58  for (int i = 0; i < HWSIMULATION_LEDSTATE_NUMELEM; i++) {
59  leds[i] = (ledState[i] == HWSIMULATION_LEDSTATE_ON) ? '*' : '.';
60  }
61  leds[PIOS_ANNUNC_NUM] = '\0';
62  printf("LEDS\t%d\t%d\t%s\n", PIOS_Thread_Systime(),
63  PIOS_DELAY_GetRaw(), leds);
64 #endif
65 }
66 
70 void PIOS_ANNUNC_Init(void)
71 {
72 }
73 
77 bool PIOS_ANNUNC_GetStatus(uint32_t led)
78 {
80 
81  return ledState[led] == HWSIMULATION_LEDSTATE_ON;
82 }
83 
88 void PIOS_ANNUNC_On(uint32_t led)
89 {
90  set_led(led, 1);
91 }
92 
93 
98 void PIOS_ANNUNC_Off(uint32_t led)
99 {
100  set_led(led, 0);
101 }
102 
103 
108 void PIOS_ANNUNC_Toggle(uint32_t led)
109 {
111 
112  set_led(led, !PIOS_ANNUNC_GetStatus(led));
113 }
114 
115 #endif
uint32_t PIOS_Thread_Systime(void)
Definition: pios_thread.c:212
Main PiOS header to include all the compiled in PiOS options.
void PIOS_ANNUNC_Off(uint32_t annunc_id)
#define PIOS_ANNUNC_NUM
Definition: pios_board.h:42
#define PIOS_LED_ALARM
Definition: pios_board.h:86
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
void PIOS_ANNUNC_On(uint32_t annunc_id)
uint8_t i
Definition: msp_messages.h:97
void PIOS_ANNUNC_Toggle(uint32_t annunc_id)
#define DONT_BUILD_IF(COND, MSG)
Definition: morsel.c:206
Includes PiOS and core architecture components.
int printf(const char *format,...)
#define PIOS_Assert(test)
Definition: pios_debug.h:52
#define PIOS_LED_HEARTBEAT
Definition: pios_board.h:85
uint32_t PIOS_DELAY_GetRaw()
Get the raw delay timer, useful for timing.
Definition: pios_delay.c:153