diff --git a/flight/libraries/inc/optypes.h b/flight/libraries/inc/optypes.h new file mode 100644 index 000000000..d48e87887 --- /dev/null +++ b/flight/libraries/inc/optypes.h @@ -0,0 +1,61 @@ +/** + ****************************************************************************** + * + * @file optypes.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014. + * @brief OP Generic data type library + * -- + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef UTIL_H +#define UTIL_H +#include +typedef struct { + uint8_t R; + uint8_t G; + uint8_t B; +} Color_t; + +extern const Color_t Color_Off; +extern const Color_t Color_Red; +extern const Color_t Color_Lime; +extern const Color_t Color_Blue; +extern const Color_t Color_Yellow; +extern const Color_t Color_Cian; +extern const Color_t Color_Magenta; +extern const Color_t Color_Navy; +extern const Color_t Color_Green; +extern const Color_t Color_Purple; +extern const Color_t Color_Teal; +extern const Color_t Color_Orange; + +#define COLOR_OFF { .R = 0x00, .G = 0x00, .B = 0x00 } +#define COLOR_RED { .R = 0xFF, .G = 0x00, .B = 0x00 } +#define COLOR_LIME { .R = 0x00, .G = 0xFF, .B = 0x00 } +#define COLOR_BLUE { .R = 0x00, .G = 0x00, .B = 0xFF } +#define COLOR_YELLOW { .R = 0xFF, .G = 0xFF, .B = 0x00 } +#define COLOR_CIAN { .R = 0x00, .G = 0xFF, .B = 0xFF } +#define COLOR_MAGENTA { .R = 0xFF, .G = 0x00, .B = 0xFF } +#define COLOR_NAVY { .R = 0x00, .G = 0x00, .B = 0x80 } +#define COLOR_GREEN { .R = 0x00, .G = 0x80, .B = 0x00 } +#define COLOR_PURPLE { .R = 0x80, .G = 0x00, .B = 0x80 } +#define COLOR_TEAL { .R = 0x00, .G = 0x80, .B = 0x80 } +#define COLOR_ORANGE { .R = 0xFF, .G = 0xA5, .B = 0x00 } + +#endif /* UTIL_H */ diff --git a/flight/libraries/optypes.c b/flight/libraries/optypes.c new file mode 100644 index 000000000..a203ee555 --- /dev/null +++ b/flight/libraries/optypes.c @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * + * @file optypes.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014. + * @brief OP Generic data type library + * -- + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +const Color_t Color_Off = COLOR_OFF; +const Color_t Color_Red = COLOR_RED; +const Color_t Color_Lime = COLOR_LIME; +const Color_t Color_Blue = COLOR_BLUE; +const Color_t Color_Yellow = COLOR_YELLOW; +const Color_t Color_Cian = COLOR_CIAN; +const Color_t Color_Magenta = COLOR_MAGENTA; +const Color_t Color_Navy = COLOR_NAVY; +const Color_t Color_Green = COLOR_GREEN; +const Color_t Color_Purple = COLOR_PURPLE; +const Color_t Color_Teal = COLOR_TEAL; +const Color_t Color_Orange = COLOR_ORANGE; diff --git a/flight/pios/common/pios_notify.c b/flight/pios/common/pios_notify.c index bf83c22eb..5f47a18a6 100644 --- a/flight/pios/common/pios_notify.c +++ b/flight/pios/common/pios_notify.c @@ -28,7 +28,8 @@ static volatile pios_notify_notification currentNotification = NOTIFY_NONE; static volatile pios_notify_priority currentPriority; - +static volatile ExtLedNotification_t extLedNotification; +static volatile bool newNotification; void PIOS_NOTIFY_StartNotification(pios_notify_notification notification, pios_notify_priority priority) { @@ -47,3 +48,29 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear) } return ret; } + + +/* + * Play a sequence on the default external led. Sequences with priority higher than NOTIFY_PRIORITY_LOW + * are repeated only once if repeat = -1 + * @param sequence Sequence to be played + * @param priority Priority of the sequence being played + */ +void PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority) +{ + extLedNotification.priority = priority; + extLedNotification.sequence = *sequence; + newNotification = true; +} + + +ExtLedNotification_t *PIOS_NOTIFY_GetNewExtLedSequence(bool clear) +{ + if (!newNotification) { + return 0; + } + if (clear) { + newNotification = false; + } + return (ExtLedNotification_t *)&extLedNotification; +} diff --git a/flight/pios/inc/pios_notify.h b/flight/pios/inc/pios_notify.h index 1e800df5c..12daefdc2 100644 --- a/flight/pios/inc/pios_notify.h +++ b/flight/pios/inc/pios_notify.h @@ -26,7 +26,7 @@ #ifndef PIOS_NOTIFY_H_ #define PIOS_NOTIFY_H_ #include - +#include typedef enum { NOTIFY_NONE = 0, NOTIFY_OK, @@ -35,11 +35,35 @@ typedef enum { } pios_notify_notification; typedef enum { - NOTIFY_PRIORITY_CRITICAL = 2, - NOTIFY_PRIORITY_REGULAR = 1, + NOTIFY_PRIORITY_CRITICAL = 2, + NOTIFY_PRIORITY_REGULAR = 1, NOTIFY_PRIORITY_LOW = 0, + NOTIFY_PRIORITY_BACKGROUND = -1, } pios_notify_priority; + +// A single led step, Color, time On/Off, repeat count +#define NOTIFY_SEQUENCE_MAX_STEPS 5 + +typedef struct { + uint16_t time_off; + uint16_t time_on; + Color_t color; + uint8_t repeats; +} LedStep_t; + +typedef struct { + int8_t repeats; // -1 for infinite repetitions + LedStep_t steps[NOTIFY_SEQUENCE_MAX_STEPS]; +} LedSequence_t; + +typedef struct { + LedSequence_t sequence; + pios_notify_priority priority; +} ExtLedNotification_t; + +#define NOTIFY_IS_NULL_STEP(x) (!x || (!x->time_off && !x->time_on && !x->repeats)) + /** * start a new notification. If a notification is active it will be overwritten if its priority is lower than the new one. * The new will be discarded otherwise @@ -55,4 +79,24 @@ void PIOS_NOTIFY_StartNotification(pios_notify_notification notification, pios_n */ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear); +/* + * Play a sequence on the default external led. Sequences with priority higher than NOTIFY_PRIORITY_LOW + * are repeated only once if repeat = -1 + * @param sequence Sequence to be played + * @param priority Priority of the sequence being played + */ +void PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority); + +/* + * Play a sequence on an external rgb led. Sequences with priority higher than NOTIFY_PRIORITY_LOW + * are repeated only once if repeat = -1 + * @param sequence Sequence to be played + * @param ledNumber Led number + * @param priority Priority of the sequence being played + * + */ +// void PIOS_NOTIFICATION_Ext_Led_Play(const LedSequence_t sequence, uint8_t ledNumber, pios_notify_priority priority); + +ExtLedNotification_t *PIOS_NOTIFY_GetNewExtLedSequence(bool clear); + #endif /* PIOS_NOTIFY_H_ */ diff --git a/flight/pios/inc/pios_ws2811.h b/flight/pios/inc/pios_ws2811.h index cb05070ee..6b8778b19 100644 --- a/flight/pios/inc/pios_ws2811.h +++ b/flight/pios/inc/pios_ws2811.h @@ -35,7 +35,7 @@ #include #include #include - +#include #define sign(x) ((x > 0) - (x < 0)) #define PIOS_WS2811_NUMLEDS 2 @@ -106,12 +106,6 @@ typedef uint16_t ledbuf_t; -typedef struct Color Color; -struct Color { - uint8_t R; - uint8_t G; - uint8_t B; -}; struct pios_ws2811_pin_cfg { GPIO_TypeDef *gpio; GPIO_InitTypeDef gpioInit; @@ -139,9 +133,8 @@ struct pios_ws2811_cfg { void PIOS_WS2811_Init(const struct pios_ws2811_cfg *ws2811_cfg, const struct pios_ws2811_pin_cfg *ws2811_pin_cfg); -void PIOS_WS2811_setColorRGB(Color c, uint8_t led, bool update); +void PIOS_WS2811_setColorRGB(Color_t c, uint8_t led, bool update); void PIOS_WS2811_Update(); void PIOS_WS2811_DMA_irq_handler(); - #endif /* PIOS_WS2811_H_ */ diff --git a/flight/pios/stm32f4xx/pios_ws2811.c b/flight/pios/stm32f4xx/pios_ws2811.c index 96719a4a8..f4ffe1bed 100644 --- a/flight/pios/stm32f4xx/pios_ws2811.c +++ b/flight/pios/stm32f4xx/pios_ws2811.c @@ -177,7 +177,7 @@ void PIOS_WS2811_Init(const struct pios_ws2811_cfg *ws2811_cfg, const struct pio fb = (ledbuf_t *)pios_malloc(PIOS_WS2811_BUFFER_SIZE * sizeof(ledbuf_t)); memset(fb, 0, PIOS_WS2811_BUFFER_SIZE * sizeof(ledbuf_t)); - Color ledoff = { 0, 0, 0 }; + const Color_t ledoff = Color_Off; for (uint8_t i = 0; i < PIOS_WS2811_NUMLEDS; i++) { PIOS_WS2811_setColorRGB(ledoff, i, false); } @@ -302,7 +302,7 @@ void setColor(uint8_t color, ledbuf_t *buf) * @param led led number * @param update Perform an update after changing led color */ -void PIOS_WS2811_setColorRGB(Color c, uint8_t led, bool update) +void PIOS_WS2811_setColorRGB(Color_t c, uint8_t led, bool update) { if (led >= PIOS_WS2811_NUMLEDS) { return; diff --git a/make/apps-defs.mk b/make/apps-defs.mk index 72381423e..1c473383c 100644 --- a/make/apps-defs.mk +++ b/make/apps-defs.mk @@ -110,6 +110,7 @@ SRC += $(MATHLIB)/sin_lookup.c SRC += $(MATHLIB)/pid.c SRC += $(MATHLIB)/mathmisc.c SRC += $(FLIGHTLIB)/printf-stdarg.c +SRC += $(FLIGHTLIB)/optypes.c ## Modules SRC += $(foreach mod, $(MODULES), $(sort $(wildcard $(OPMODULEDIR)/$(mod)/*.c)))