update credits
[librepilot.git] / flight / modules / Notify / inc / sequences.h
blob72e99203a2addbd6367509c7519f34c709b4e474
1 /**
2 ******************************************************************************
4 * @file sequences.h
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @brief Notify module, sequences configuration.
9 * @see The GNU Public License (GPL) Version 3
11 *****************************************************************************/
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.
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.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef SEQUENCES_H_
28 #define SEQUENCES_H_
29 #include <optypes.h>
30 #include <pios_notify.h>
31 #include <flightstatus.h>
32 #include <systemalarms.h>
33 #include <pios_helpers.h>
35 // This represent the list of basic light sequences, defined later
36 typedef enum {
37 NOTIFY_SEQUENCE_ARMED_FM_MANUAL = 0,
38 NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1,
39 NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2,
40 NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3,
41 NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4,
42 NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5,
43 NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6,
44 NOTIFY_SEQUENCE_ARMED_FM_GPS,
45 NOTIFY_SEQUENCE_ARMED_FM_RTH,
46 NOTIFY_SEQUENCE_ARMED_FM_LAND,
47 NOTIFY_SEQUENCE_ARMED_FM_AUTO,
48 NOTIFY_SEQUENCE_ALM_WARN_GPS,
49 NOTIFY_SEQUENCE_ALM_ERROR_GPS,
50 NOTIFY_SEQUENCE_ALM_WARN_BATTERY,
51 NOTIFY_SEQUENCE_ALM_ERROR_BATTERY,
52 NOTIFY_SEQUENCE_ALM_WARN_MAG,
53 NOTIFY_SEQUENCE_ALM_ERROR_MAG,
54 NOTIFY_SEQUENCE_ALM_CONFIG,
55 NOTIFY_SEQUENCE_ALM_RECEIVER,
56 NOTIFY_SEQUENCE_DISARMED,
57 NOTIFY_SEQUENCE_ALM_ATTITUDE,
58 NOTIFY_SEQUENCE_NULL = 255, // skips any signalling for this condition
59 } NotifySequences;
61 // This structure determine sequences attached to an alarm
62 typedef struct {
63 uint32_t timeBetweenNotifications; // time in milliseconds to wait between each notification iteration
64 uint8_t alarmIndex; // Index of the alarm, use one of the SYSTEMALARMS_ALARM_XXXXX defines
65 uint8_t warnNotification; // index of the sequence to be used when alarm is in warning status(pick one from NotifySequences enum)
66 uint8_t criticalNotification; // index of the sequence to be used when alarm is in critical status(pick one from NotifySequences enum)
67 uint8_t errorNotification; // index of the sequence to be used when alarm is in error status(pick one from NotifySequences enum)
68 } AlarmDefinition_t;
70 #define STANDARD_ERROR_SEQUENCE(alarm_color, alarm_repeats) \
71 { .repeats = alarm_repeats, .steps = { \
72 { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \
73 { .time_off = 100, .time_on = 300, .color = COLOR_DARKRED, .repeats = 1, }, \
74 { .time_off = 100, .time_on = 300, .color = alarm_color, .repeats = 2, }, \
75 { .time_off = 100, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \
76 }, }
78 #define STANDARD_WARN_SEQUENCE(alarm_color, alarm_repeats) \
79 { .repeats = alarm_repeats, .steps = { \
80 { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \
81 { .time_off = 100, .time_on = 300, .color = COLOR_ORANGE, .repeats = 1, }, \
82 { .time_off = 100, .time_on = 300, .color = alarm_color, .repeats = 1, }, \
83 { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \
84 }, }
86 // This is the list of defined light sequences
87 /* how each sequence is defined
88 * [NOTIFY_SEQUENCE_DISARMED] = { // Sequence ID
89 .repeats = -1, // Number of repetitions or -1 for infinite
90 .steps = { // List of steps (until NOTIFY_SEQUENCE_MAX_STEPS steps, default to 5)
92 .time_off = 500, // Off time for the step
93 .time_on = 500, // On time for the step
94 .color = COLOR_TEAL, // color
95 .repeats = 1, // repetitions for this step
100 * There are two kind of sequences:
101 * - "Background" sequences, executed if no higher priority sequence is played;
102 * - "Alarm" sequences, that are "modal", they temporarily suspends background sequences and plays.
103 * Cannot have "-1" repetitions
104 * At the end background sequence are resumed;
107 const LedSequence_t notifications[] = {
108 [NOTIFY_SEQUENCE_DISARMED] = { .repeats = -1, .steps = {
109 { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, },
110 { .time_off = 100, .time_on = 100, .color = COLOR_WHITE, .repeats = 1, },
111 { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, },
112 }, },
113 [NOTIFY_SEQUENCE_ARMED_FM_MANUAL] = { .repeats = -1, .steps = {
114 { .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
115 }, },
116 [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1] = { .repeats = -1, .steps = {
117 { .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
118 }, },
119 [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2] = { .repeats = -1, .steps = {
120 { .time_off = 100, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
121 { .time_off = 700, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
122 }, },
123 [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3] = { .repeats = -1, .steps = {
124 { .time_off = 100, .time_on = 100, .color = COLOR_BLUE, .repeats = 2, },
125 { .time_off = 500, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
126 }, },
127 [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4] = { .repeats = -1, .steps = {
128 { .time_off = 900, .time_on = 100, .color = COLOR_PURPLE, .repeats = 1, },
129 }, },
130 [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5] = { .repeats = -1, .steps = {
131 { .time_off = 100, .time_on = 100, .color = COLOR_PURPLE, .repeats = 1, },
132 { .time_off = 700, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
133 }, },
134 [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6] = { .repeats = -1, .steps = {
135 { .time_off = 100, .time_on = 100, .color = COLOR_PURPLE, .repeats = 1, },
136 { .time_off = 100, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
137 { .time_off = 500, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, },
138 }, },
139 [NOTIFY_SEQUENCE_ARMED_FM_GPS] = { .repeats = -1, .steps = {
140 { .time_off = 800, .time_on = 200, .color = COLOR_GREEN, .repeats = 1, },
141 }, },
142 [NOTIFY_SEQUENCE_ARMED_FM_RTH] = { .repeats = -1, .steps = {
143 { .time_off = 100, .time_on = 100, .color = COLOR_GREEN, .repeats = 1, },
144 { .time_off = 100, .time_on = 100, .color = COLOR_YELLOW, .repeats = 1, },
145 }, },
146 [NOTIFY_SEQUENCE_ARMED_FM_LAND] = { .repeats = -1, .steps = {
147 { .time_off = 100, .time_on = 100, .color = COLOR_GREEN, .repeats = 1, },
148 }, },
149 [NOTIFY_SEQUENCE_ARMED_FM_AUTO] = { .repeats = -1, .steps = {
150 { .time_off = 100, .time_on = 200, .color = COLOR_GREEN, .repeats = 2, },
151 { .time_off = 500, .time_on = 200, .color = COLOR_GREEN, .repeats = 1, },
152 }, },
153 [NOTIFY_SEQUENCE_ALM_WARN_GPS] = STANDARD_WARN_SEQUENCE(COLOR_GREEN, 1),
154 [NOTIFY_SEQUENCE_ALM_ERROR_GPS] = STANDARD_ERROR_SEQUENCE(COLOR_GREEN, 1),
155 [NOTIFY_SEQUENCE_ALM_WARN_BATTERY] = { .repeats = 1, .steps = {
156 { .time_off = 100, .time_on = 100, .color = COLOR_ORANGE, .repeats = 5, },
157 }, },
158 [NOTIFY_SEQUENCE_ALM_ERROR_BATTERY] = { .repeats = 1, .steps = {
159 { .time_off = 100, .time_on = 100, .color = COLOR_RED, .repeats = 5, },
160 }, },
161 [NOTIFY_SEQUENCE_ALM_ERROR_MAG] = STANDARD_ERROR_SEQUENCE(COLOR_PURPLE, 1),
162 [NOTIFY_SEQUENCE_ALM_WARN_MAG] = STANDARD_WARN_SEQUENCE(COLOR_PURPLE, 1),
163 [NOTIFY_SEQUENCE_ALM_CONFIG] = STANDARD_ERROR_SEQUENCE(COLOR_RED, 2),
164 [NOTIFY_SEQUENCE_ALM_RECEIVER] = STANDARD_ERROR_SEQUENCE(COLOR_YELLOW, 1),
165 [NOTIFY_SEQUENCE_ALM_ATTITUDE] = { .repeats = 10, .steps = {
166 { .time_off = 0, .time_on = 50, .color = COLOR_RED, .repeats = 1, },
167 { .time_off = 0, .time_on = 50, .color = COLOR_BLUE, .repeats = 1, },
168 }, },
171 // List of background sequences attached to each flight mode
172 const LedSequence_t *flightModeMap[] = {
173 [FLIGHTSTATUS_FLIGHTMODE_MANUAL] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_MANUAL],
174 [FLIGHTSTATUS_FLIGHTMODE_STABILIZED1] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1],
175 [FLIGHTSTATUS_FLIGHTMODE_STABILIZED2] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2],
176 [FLIGHTSTATUS_FLIGHTMODE_STABILIZED3] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3],
177 [FLIGHTSTATUS_FLIGHTMODE_STABILIZED4] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4],
178 [FLIGHTSTATUS_FLIGHTMODE_STABILIZED5] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5],
179 [FLIGHTSTATUS_FLIGHTMODE_STABILIZED6] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6],
180 [FLIGHTSTATUS_FLIGHTMODE_PATHPLANNER] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_AUTO],
181 [FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
182 [FLIGHTSTATUS_FLIGHTMODE_COURSELOCK] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
183 [FLIGHTSTATUS_FLIGHTMODE_VELOCITYROAM] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
184 [FLIGHTSTATUS_FLIGHTMODE_HOMELEASH] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
185 [FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
186 [FLIGHTSTATUS_FLIGHTMODE_RETURNTOBASE] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_RTH],
187 [FLIGHTSTATUS_FLIGHTMODE_LAND] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_LAND],
188 [FLIGHTSTATUS_FLIGHTMODE_POI] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
189 [FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_GPS],
190 [FLIGHTSTATUS_FLIGHTMODE_AUTOTAKEOFF] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_LAND],
191 #if !defined(PIOS_EXCLUDE_ADVANCED_FEATURES)
192 [FLIGHTSTATUS_FLIGHTMODE_AUTOTUNE] = &notifications[NOTIFY_SEQUENCE_ARMED_FM_MANUAL],
193 #endif /* !defined(PIOS_EXCLUDE_ADVANCED_FEATURES) */
196 // List of alarms to show with attached sequences for each status
197 const AlarmDefinition_t alarmsMap[] = {
199 .timeBetweenNotifications = 5000,
200 .alarmIndex = SYSTEMALARMS_ALARM_GPS,
201 .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_GPS,
202 .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_GPS,
203 .errorNotification = NOTIFY_SEQUENCE_ALM_ERROR_GPS,
206 .timeBetweenNotifications = 5000,
207 .alarmIndex = SYSTEMALARMS_ALARM_MAGNETOMETER,
208 .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_MAG,
209 .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG,
210 .errorNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG,
213 .timeBetweenNotifications = 15000,
214 .alarmIndex = SYSTEMALARMS_ALARM_BATTERY,
215 .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_BATTERY,
216 .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_BATTERY,
217 .errorNotification = NOTIFY_SEQUENCE_ALM_ERROR_BATTERY,
220 .timeBetweenNotifications = 5000,
221 .alarmIndex = SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION,
222 .warnNotification = NOTIFY_SEQUENCE_NULL,
223 .criticalNotification = NOTIFY_SEQUENCE_ALM_CONFIG,
224 .errorNotification = NOTIFY_SEQUENCE_ALM_CONFIG,
227 .timeBetweenNotifications = 5000,
228 .alarmIndex = SYSTEMALARMS_ALARM_RECEIVER,
229 .warnNotification = NOTIFY_SEQUENCE_ALM_RECEIVER,
230 .criticalNotification = NOTIFY_SEQUENCE_ALM_RECEIVER,
231 .errorNotification = NOTIFY_SEQUENCE_ALM_RECEIVER,
234 .timeBetweenNotifications = 1000,
235 .alarmIndex = SYSTEMALARMS_ALARM_ATTITUDE,
236 .warnNotification = NOTIFY_SEQUENCE_ALM_ATTITUDE,
237 .criticalNotification = NOTIFY_SEQUENCE_NULL,
238 .errorNotification = NOTIFY_SEQUENCE_ALM_ATTITUDE,
242 const uint8_t alarmsMapSize = NELEMENTS(alarmsMap);
244 #endif /* SEQUENCES_H_ */