1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-15 07:29:15 +01:00

OP-1302 Add a stub pios_notify API for user interaction/notifications

right now all notifications produces the same output, the DRAW_ATTENTION sequence
This commit is contained in:
Alessio Morale 2014-04-13 17:42:57 +02:00
parent 132aa83dff
commit 299f388245
7 changed files with 295 additions and 120 deletions

View File

@ -1,32 +1,35 @@
/**
******************************************************************************
*
* @file notification.h
* @file notification.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
* @brief notification 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
/*
* 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
*
* 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.,
*
* 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 NOTIFICATION_H
#define NOTIFICATION_H
#define LED_BLINK_PERIOD_MS 200
// period of each blink phase
#define LED_BLINK_PERIOD_MS 200
// Define the pause in half blink periods to be added between phases
#define LED_PAUSE_BETWEEN_PHASES 3
// update the status snapshot used by notifcations
void NotificationUpdateStatus();

View File

@ -1,26 +1,26 @@
/**
******************************************************************************
*
* @file notification.c
* @file notification.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
* @brief brief goes here.
* @brief notification 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
/*
* 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
*
* 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.,
*
* 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 "inc/notification.h"
@ -28,6 +28,7 @@
#include <pios_struct_helper.h>
#include <systemalarms.h>
#include <flightstatus.h>
#include <pios_notify.h>
#ifdef PIOS_LED_ALARM
#define ALARM_LED_ON() PIOS_LED_On(PIOS_LED_ALARM)
@ -53,9 +54,9 @@
#define BLINK_COUNT(x) \
(x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED1 ? 2 : \
x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED2 ? 3 : \
x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED3 ? 4 : \
(x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED1 ? 1 : \
x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED2 ? 2 : \
x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED3 ? 3 : \
x == FLIGHTSTATUS_FLIGHTMODE_ALTITUDEHOLD ? 2 : \
x == FLIGHTSTATUS_FLIGHTMODE_ALTITUDEVARIO ? 2 : \
x == FLIGHTSTATUS_FLIGHTMODE_VELOCITYCONTROL ? 2 : \
@ -82,27 +83,31 @@
static volatile SystemAlarmsAlarmOptions currentAlarmLevel = SYSTEMALARMS_ALARM_OK;
static volatile FlightStatusData currentFlightStatus;
static volatile bool started = false;
static volatile pios_notify_notification nextNotification = NOTIFY_NONE;
void NotificationUpdateStatus(){
#ifdef PIOS_LED_ALARM
static bool handleAlarms(uint8_t cycleCount, uint8_t blinkCount);
#endif // PIOS_LED_ALARM
static bool handleNotifications(uint8_t cycleCount, pios_notify_notification runningNotification);
static void handleStatus(uint8_t cycleCount, uint8_t blinkCount);
void NotificationUpdateStatus()
{
started = true;
// get values to be used for led handling
FlightStatusGet((FlightStatusData *)&currentFlightStatus);
currentAlarmLevel = AlarmsGetHighestSeverity();
if (nextNotification == NOTIFY_NONE) {
nextNotification = PIOS_NOTIFY_GetActiveNotification(true);
}
}
void NotificationOnboardLedsRun(){
void NotificationOnboardLedsRun()
{
static portTickType lastRunTimestamp;
if (!started || (xTaskGetTickCount() - lastRunTimestamp) < (LED_BLINK_PERIOD_MS * portTICK_RATE_MS / 2)) {
return;
}
lastRunTimestamp = xTaskGetTickCount();
// the led will show various status information, subdivided in three phases
// - Notification
// - Alarm
// - Flight status
// they are shown using the above priority
// a phase last exactly 8 cycles (so bit 1<<4 is used to determine if a phase end
static uint8_t blinkCount; // number of blinks since phase start
static uint8_t cycleCount; // cound the number of cycles (half of a blink)
static pios_notify_notification runningNotification = NOTIFY_NONE;
static enum {
STATUS_NOTIFY,
@ -111,87 +116,145 @@ void NotificationOnboardLedsRun(){
STATUS_LENGHT
} status;
static uint8_t cycleCount;
cycleCount++;
// a blink last 2 cycles.
static uint8_t blinkCount;
blinkCount = (cycleCount & 0xF) >> 1;
if (cycleCount & 0x08) {
// add a short pause between each phase
if (cycleCount > 0xA) {
cycleCount = 0xFF;
status = (status + 1) % STATUS_LENGHT;
}
HEARTBEAT_LED_OFF();
ALARM_LED_OFF();
if (!started || (xTaskGetTickCount() - lastRunTimestamp) < (LED_BLINK_PERIOD_MS * portTICK_RATE_MS / 2)) {
return;
}
lastRunTimestamp = xTaskGetTickCount();
// the led will show various status information, subdivided in three phases
// - Notification
// - Alarm
// - Flight status
// they are shown using the above priority
// a phase last exactly 8 cycles (so bit 1<<4 is used to determine if a phase end
cycleCount++;
// Notifications are "modal" to other statuses so they takes precedence
if (status != STATUS_NOTIFY && nextNotification != NOTIFY_NONE) {
// Force a notification status
runningNotification = nextNotification;
nextNotification = NOTIFY_NONE;
status = STATUS_NOTIFY;
cycleCount = 0; // instantly start a notify cycle
}
// check if a phase has just finished
if (cycleCount & 0x08) {
// add a short pause between each phase
if (cycleCount > 0x8 + LED_PAUSE_BETWEEN_PHASES) {
// ready to start a new phase
cycleCount = 0x0;
// Notification has been already shown, so clear the running one
if (status == STATUS_NOTIFY) {
runningNotification = NOTIFY_NONE;
}
status = (status + 1) % STATUS_LENGHT;
} else {
HEARTBEAT_LED_OFF();
ALARM_LED_OFF();
return;
}
}
// a blink last 2 cycles.
blinkCount = (cycleCount & 0xF) >> 1;
if (status == STATUS_NOTIFY) {
// Not implemented yet
status++;
if (!handleNotifications(cycleCount, runningNotification)) {
status++;
}
}
// Handles Alarm display
if (status == STATUS_ALARM) {
#if defined(PIOS_LED_ALARM)
if (currentAlarmLevel > SYSTEMALARMS_ALARM_OK) {
if (currentAlarmLevel == SYSTEMALARMS_ALARM_CRITICAL) {
// Slow blink
ALARM_LED_OFF();
if (cycleCount & 0x4) {
ALARM_LED_OFF();
} else {
ALARM_LED_ON();
}
} else {
if ((blinkCount < (ALARM_BLINK_COUNT(currentAlarmLevel))) &&
(cycleCount & 0x1)) {
ALARM_LED_ON();
} else {
ALARM_LED_OFF();
}
}
} else {
#ifdef PIOS_LED_ALARM
if (!handleAlarms(cycleCount, blinkCount)) {
status++;
}
#else /* if defined(PIOS_LED_ALARM) */
// no alarms, handle next phase
#else
status++;
// #endif
#endif /* PIOS_LED_ALARM */
#endif // PIOS_LED_ALARM
}
// **** Handles flightmode display
if (status == STATUS_FLIGHTMODE) {
uint8_t flightmode = currentFlightStatus.FlightMode;
handleStatus(cycleCount, blinkCount);
}
}
// Flash the heartbeat LED
#if defined(PIOS_LED_HEARTBEAT)
if (currentFlightStatus.Armed == FLIGHTSTATUS_ARMED_DISARMED) {
#if defined(PIOS_LED_ALARM)
static bool handleAlarms(uint8_t cycleCount, uint8_t blinkCount)
{
if (currentAlarmLevel > SYSTEMALARMS_ALARM_OK) {
if (currentAlarmLevel == SYSTEMALARMS_ALARM_CRITICAL) {
// Slow blink
if (blinkCount < 3) {
HEARTBEAT_LED_ON();
ALARM_LED_OFF();
if (cycleCount & 0x4) {
ALARM_LED_OFF();
} else {
HEARTBEAT_LED_OFF();
ALARM_LED_ON();
}
} else {
if ((blinkCount < BLINK_COUNT(flightmode)) &&
if ((blinkCount < (ALARM_BLINK_COUNT(currentAlarmLevel))) &&
(cycleCount & 0x1)) {
// red led will be active active in last or last two (4 blinks case) blinks
if (BLINK_RED(flightmode) &&
((blinkCount == BLINK_COUNT(flightmode) - 1) ||
blinkCount > 1)) {
ALARM_LED_ON();
}
HEARTBEAT_LED_ON();
ALARM_LED_ON();
} else {
HEARTBEAT_LED_OFF();
ALARM_LED_OFF();
}
}
return true;
} else {
return false;
}
}
#endif /* PIOS_LED_ALARM */
static bool handleNotifications(uint8_t cycleCount, pios_notify_notification runningNotification)
{
if (runningNotification == NOTIFY_NONE) {
return false;
}
if (cycleCount & 0x1) {
ALARM_LED_OFF();
HEARTBEAT_LED_ON();
} else {
ALARM_LED_ON();
HEARTBEAT_LED_OFF();
}
return true;
}
static void handleStatus(uint8_t cycleCount, uint8_t blinkCount)
{
// Flash the heartbeat LED
#if defined(PIOS_LED_HEARTBEAT)
uint8_t flightmode = currentFlightStatus.FlightMode;
if (currentFlightStatus.Armed == FLIGHTSTATUS_ARMED_DISARMED) {
// Slow blink
if (blinkCount < 3) {
HEARTBEAT_LED_ON();
} else {
HEARTBEAT_LED_OFF();
}
} else {
if ((blinkCount < BLINK_COUNT(flightmode)) &&
(cycleCount & 0x1)) {
// red led will be active active in last or last two (4 blinks case) blinks
if (BLINK_RED(flightmode) &&
((blinkCount == BLINK_COUNT(flightmode) - 1) ||
blinkCount > 1)) {
ALARM_LED_ON();
}
HEARTBEAT_LED_ON();
} else {
HEARTBEAT_LED_OFF();
ALARM_LED_OFF();
}
}
#endif /* PIOS_LED_HEARTBEAT */
}

View File

@ -72,7 +72,7 @@
#endif
// Private constants
#define SYSTEM_UPDATE_PERIOD_MS 500
#define SYSTEM_UPDATE_PERIOD_MS 250
#if defined(PIOS_SYSTEM_STACK_SIZE)
#define STACK_SIZE_BYTES PIOS_SYSTEM_STACK_SIZE
@ -80,7 +80,7 @@
#define STACK_SIZE_BYTES 1024
#endif
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
// Private types
@ -620,34 +620,34 @@ void vApplicationIdleHook(void)
* Called by the RTOS when a stack overflow is detected.
*/
#define DEBUG_STACK_OVERFLOW 0
void vApplicationStackOverflowHook(__attribute__((unused)) xTaskHandle *pxTask,
__attribute__((unused)) signed portCHAR *pcTaskName)
{
stackOverflow = STACKOVERFLOW_CRITICAL;
void vApplicationStackOverflowHook(__attribute__((unused)) xTaskHandle *pxTask,
__attribute__((unused)) signed portCHAR *pcTaskName)
{
stackOverflow = STACKOVERFLOW_CRITICAL;
#if DEBUG_STACK_OVERFLOW
static volatile bool wait_here = true;
while (wait_here) {
;
}
wait_here = true;
#endif
static volatile bool wait_here = true;
while (wait_here) {
;
}
wait_here = true;
#endif
}
/**
* Called by the RTOS when a malloc call fails.
*/
#define DEBUG_MALLOC_FAILURES 0
void vApplicationMallocFailedHook(void)
{
mallocFailed = true;
void vApplicationMallocFailedHook(void)
{
mallocFailed = true;
#if DEBUG_MALLOC_FAILURES
static volatile bool wait_here = true;
while (wait_here) {
;
}
wait_here = true;
#endif
static volatile bool wait_here = true;
while (wait_here) {
;
}
wait_here = true;
#endif
}
/**
* @}

View File

@ -0,0 +1,49 @@
/**
******************************************************************************
*
* @file pios_notify.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
* @brief Handles user notifications.
* --
* @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 "pios_notify.h"
static volatile pios_notify_notification currentNotification = NOTIFY_NONE;
static volatile pios_notify_priority currentPriority;
void PIOS_NOTIFY_StartNotification(pios_notify_notification notification, pios_notify_priority priority)
{
if (currentNotification == NOTIFY_NONE || currentPriority < priority) {
currentPriority = priority;
currentNotification = notification;
}
}
pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear)
{
pios_notify_notification ret = currentNotification;
if (clear && ret != NOTIFY_NONE) {
currentNotification = NOTIFY_NONE;
}
return ret;
}

View File

@ -0,0 +1,58 @@
/**
******************************************************************************
*
* @file pios_notify.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
* @brief Handles user notifications.
* --
* @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 PIOS_NOTIFY_H_
#define PIOS_NOTIFY_H_
#include <stdbool.h>
typedef enum {
NOTIFY_NONE = 0,
NOTIFY_OK,
NOTIFY_NOK,
NOTIFY_DRAW_ATTENTION
} pios_notify_notification;
typedef enum {
NOTIFY_PRIORITY_CRITICAL = 2,
NOTIFY_PRIORITY_REGULAR = 1,
NOTIFY_PRIORITY_LOW = 0,
} pios_notify_priority;
/**
* 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
* @param notification kind of notification
* @param priority priority of the new notification
*/
void PIOS_NOTIFY_StartNotification(pios_notify_notification notification, pios_notify_priority priority);
/**
* retrieve any active notification
* @param clear
* @return
*/
pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear);
#endif /* PIOS_NOTIFY_H_ */

View File

@ -104,6 +104,8 @@ SRC += $(PIOSCORECOMMON)/pios_dosfs_logfs.c
SRC += $(PIOSCORECOMMON)/pios_debuglog.c
SRC += $(PIOSCORECOMMON)/pios_callbackscheduler.c
SRC += $(PIOSCORECOMMON)/pios_deltatime.c
SRC += $(PIOSCORECOMMON)/pios_notify.c
## PIOS Hardware
include $(PIOS)/posix/library.mk

View File

@ -99,7 +99,7 @@ SRC += $(PIOSCOMMON)/pios_usb_util.c
## PIOS system code
SRC += $(PIOSCOMMON)/pios_task_monitor.c
SRC += $(PIOSCOMMON)/pios_callbackscheduler.c
SRC += $(PIOSCOMMON)/pios_notify.c
## Misc library functions
SRC += $(FLIGHTLIB)/fifo_buffer.c
SRC += $(FLIGHTLIB)/sanitycheck.c