LP-512 pios_usart: Shared ports support: Initializing same uart multiple times will...
[librepilot.git] / flight / pios / inc / pios_notify.h
blob3ee6a3dec6c70aa6b9c3189fa8def6d95a0947b2
1 /**
2 ******************************************************************************
4 * @file pios_notify.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
6 * @brief Handles user notifications.
7 * --
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef PIOS_NOTIFY_H_
27 #define PIOS_NOTIFY_H_
28 #include <stdbool.h>
29 #include <optypes.h>
30 typedef enum {
31 NOTIFY_NONE = 0,
32 NOTIFY_OK,
33 NOTIFY_NOK,
34 NOTIFY_DRAW_ATTENTION
35 } pios_notify_notification;
37 typedef enum {
38 NOTIFY_PRIORITY_CRITICAL = 2,
39 NOTIFY_PRIORITY_REGULAR = 1,
40 NOTIFY_PRIORITY_LOW = 0,
41 NOTIFY_PRIORITY_BACKGROUND = -1,
42 } pios_notify_priority;
45 // A single led step, Color, time On/Off, repeat count
46 #define NOTIFY_SEQUENCE_MAX_STEPS 5
48 typedef struct {
49 uint16_t time_off;
50 uint16_t time_on;
51 Color_t color;
52 uint8_t repeats;
53 } LedStep_t;
55 typedef struct {
56 int8_t repeats; // -1 for infinite repetitions
57 LedStep_t steps[NOTIFY_SEQUENCE_MAX_STEPS];
58 } LedSequence_t;
60 typedef struct {
61 LedSequence_t sequence;
62 pios_notify_priority priority;
63 } ExtLedNotification_t;
65 #define NOTIFY_IS_NULL_STEP(x) (!x || (!x->time_off && !x->time_on && !x->repeats))
67 /**
68 * start a new notification. If a notification is active it will be overwritten if its priority is lower than the new one.
69 * The new will be discarded otherwise
70 * @param notification kind of notification
71 * @param priority priority of the new notification
73 void PIOS_NOTIFY_StartNotification(pios_notify_notification notification, pios_notify_priority priority);
75 /**
76 * retrieve any active notification
77 * @param clear
78 * @return
80 pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear);
83 * Play a sequence on the default external led. Sequences with priority higher than NOTIFY_PRIORITY_LOW
84 * are repeated only once if repeat = -1
85 * @param sequence Sequence to be played
86 * @param priority Priority of the sequence being played
87 * @return true if sequence is enqueued, false otherwise
89 bool PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority);
92 * Play a sequence on an external rgb led. Sequences with priority higher than NOTIFY_PRIORITY_LOW
93 * are repeated only once if repeat = -1
94 * @param sequence Sequence to be played
95 * @param ledNumber Led number
96 * @param priority Priority of the sequence being played
99 // void PIOS_NOTIFICATION_Ext_Led_Play(const LedSequence_t sequence, uint8_t ledNumber, pios_notify_priority priority);
101 ExtLedNotification_t *PIOS_NOTIFY_GetNewExtLedSequence(bool clear);
103 #endif /* PIOS_NOTIFY_H_ */