1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-1379 add base types for colour, Initial ext rgb led api definition

This commit is contained in:
Alessio Morale 2014-08-12 09:44:44 +02:00
parent 99f09d588f
commit 1f74977472
7 changed files with 181 additions and 15 deletions

View File

@ -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 <stdint.h>
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 */

View File

@ -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 <optypes.h>
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;

View File

@ -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;
}

View File

@ -26,7 +26,7 @@
#ifndef PIOS_NOTIFY_H_
#define PIOS_NOTIFY_H_
#include <stdbool.h>
#include <optypes.h>
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_ */

View File

@ -35,7 +35,7 @@
#include <stm32f4xx.h>
#include <stm32f4xx_tim.h>
#include <stm32f4xx_dma.h>
#include <optypes.h>
#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_ */

View File

@ -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;

View File

@ -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)))