2013-09-19 03:27:31 -03:00
|
|
|
/*
|
|
|
|
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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-01-29 00:38:21 -04:00
|
|
|
#pragma once
|
2013-09-19 03:27:31 -03:00
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2015-12-01 16:22:26 -04:00
|
|
|
#include <AP_Param/AP_Param.h>
|
2016-01-29 00:38:21 -04:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
|
|
|
|
#include "NotifyDevice.h"
|
2013-09-19 03:27:31 -03:00
|
|
|
|
2015-12-01 16:22:26 -04:00
|
|
|
// Device parameters values
|
|
|
|
#define RGB_LED_OFF 0
|
|
|
|
#define RGB_LED_LOW 1
|
|
|
|
#define RGB_LED_MEDIUM 2
|
|
|
|
#define RGB_LED_HIGH 3
|
2016-03-31 15:18:52 -03:00
|
|
|
#define BUZZER_ON 1
|
|
|
|
#define BUZZER_OFF 0
|
2015-12-01 16:22:26 -04:00
|
|
|
|
2016-09-30 04:21:28 -03:00
|
|
|
#define NOTIFY_TEXT_BUFFER_SIZE 51
|
|
|
|
|
|
|
|
//Type of on-board display
|
|
|
|
#define DISPLAY_OFF 0
|
|
|
|
#define DISPLAY_SSD1306 1
|
|
|
|
#define DISPLAY_SH1106 2
|
|
|
|
|
2013-09-19 03:27:31 -03:00
|
|
|
class AP_Notify
|
|
|
|
{
|
2016-09-30 04:21:28 -03:00
|
|
|
friend class RGBLed; // RGBLed needs access to notify parameters
|
2017-01-19 03:15:24 -04:00
|
|
|
friend class Display; // Display needs access to notify parameters
|
2013-09-19 03:27:31 -03:00
|
|
|
public:
|
2017-08-23 11:54:39 -03:00
|
|
|
static AP_Notify create() { return AP_Notify{}; }
|
2017-06-01 19:08:07 -03:00
|
|
|
|
2017-07-08 20:40:45 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_Notify *instance(void) {
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
2017-08-23 11:54:39 -03:00
|
|
|
constexpr AP_Notify(AP_Notify &&other) = default;
|
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_Notify(const AP_Notify &other) = delete;
|
|
|
|
AP_Notify &operator=(const AP_Notify&) = delete;
|
|
|
|
|
2017-06-01 19:08:07 -03:00
|
|
|
// Oreo LED Themes
|
|
|
|
enum Oreo_LED_Theme {
|
|
|
|
OreoLED_Disabled = 0, // Disabled the OLED driver entirely
|
|
|
|
OreoLED_Aircraft = 1, // Standard aviation themed lighting
|
|
|
|
OreoLED_Automobile = 2, // Automobile themed lighting (white front, red back)
|
|
|
|
};
|
2015-12-01 16:22:26 -04:00
|
|
|
|
2014-12-14 23:20:59 -04:00
|
|
|
/// notify_flags_type - bitmask of notification flags
|
2016-09-30 04:21:28 -03:00
|
|
|
struct notify_flags_and_values_type {
|
2015-02-02 16:54:19 -04:00
|
|
|
uint32_t initialising : 1; // 1 if initialising and copter should not be moved
|
|
|
|
uint32_t gps_status : 3; // 0 = no gps, 1 = no lock, 2 = 2d lock, 3 = 3d lock, 4 = dgps lock, 5 = rtk lock
|
2015-12-22 17:14:15 -04:00
|
|
|
uint32_t gps_num_sats : 6; // number of sats
|
2016-09-30 04:21:28 -03:00
|
|
|
uint32_t flight_mode : 8; // flight mode
|
2015-02-02 16:54:19 -04:00
|
|
|
uint32_t armed : 1; // 0 = disarmed, 1 = armed
|
|
|
|
uint32_t pre_arm_check : 1; // 0 = failing checks, 1 = passed
|
|
|
|
uint32_t pre_arm_gps_check : 1; // 0 = failing pre-arm GPS checks, 1 = passed
|
|
|
|
uint32_t save_trim : 1; // 1 if gathering trim data
|
|
|
|
uint32_t esc_calibration : 1; // 1 if calibrating escs
|
|
|
|
uint32_t failsafe_radio : 1; // 1 if radio failsafe
|
|
|
|
uint32_t failsafe_battery : 1; // 1 if battery failsafe
|
|
|
|
uint32_t parachute_release : 1; // 1 if parachute is being released
|
|
|
|
uint32_t ekf_bad : 1; // 1 if ekf is reporting problems
|
2015-03-06 01:19:48 -04:00
|
|
|
uint32_t autopilot_mode : 1; // 1 if vehicle is in an autopilot flight mode (only used by OreoLEDs)
|
2015-03-05 04:17:19 -04:00
|
|
|
uint32_t firmware_update : 1; // 1 just before vehicle firmware is updated
|
2015-03-09 22:50:03 -03:00
|
|
|
uint32_t compass_cal_running: 1; // 1 if a compass calibration is running
|
2017-02-07 14:54:57 -04:00
|
|
|
uint32_t leak_detected : 1; // 1 if leak detected
|
2017-01-20 06:14:34 -04:00
|
|
|
float battery_voltage ; // battery voltage
|
2017-06-01 19:08:07 -03:00
|
|
|
uint32_t gps_fusion : 1; // 0 = GPS fix rejected by EKF, not usable for flight. 1 = GPS in use by EKF, usable for flight
|
2017-07-25 08:41:56 -03:00
|
|
|
uint32_t gps_glitching : 1; // 1 if gps is glitching
|
2013-11-30 09:53:40 -04:00
|
|
|
|
|
|
|
// additional flags
|
2015-02-02 16:54:19 -04:00
|
|
|
uint32_t external_leds : 1; // 1 if external LEDs are enabled (normally only used for copter)
|
2015-04-26 09:23:18 -03:00
|
|
|
uint32_t vehicle_lost : 1; // 1 when lost copter tone is requested (normally only used for copter)
|
2015-12-19 07:19:51 -04:00
|
|
|
uint32_t waiting_for_throw : 1; // 1 when copter is in THROW mode and waiting to detect the user hand launch
|
2016-01-22 16:39:24 -04:00
|
|
|
uint32_t powering_off : 1; // 1 when the vehicle is powering off
|
2013-09-19 03:27:31 -03:00
|
|
|
};
|
|
|
|
|
2014-12-14 23:20:04 -04:00
|
|
|
/// notify_events_type - bitmask of active events.
|
|
|
|
// Notify library is responsible for setting back to zero after notification has been completed
|
2014-10-23 09:04:34 -03:00
|
|
|
struct notify_events_type {
|
2016-05-09 04:24:38 -03:00
|
|
|
uint32_t arming_failed : 1; // 1 if copter failed to arm after user input
|
|
|
|
uint32_t user_mode_change : 1; // 1 if user has initiated a flight mode change
|
|
|
|
uint32_t user_mode_change_failed: 1; // 1 when user initiated flight mode change fails
|
|
|
|
uint32_t failsafe_mode_change : 1; // 1 when failsafe has triggered a flight mode change
|
|
|
|
uint32_t autotune_complete : 1; // 1 when autotune has successfully completed
|
|
|
|
uint32_t autotune_failed : 1; // 1 when autotune has failed
|
|
|
|
uint32_t autotune_next_axis : 1; // 1 when autotune has completed one axis and is moving onto the next
|
|
|
|
uint32_t mission_complete : 1; // 1 when the mission has completed successfully
|
|
|
|
uint32_t waypoint_complete : 1; // 1 as vehicle completes a waypoint
|
|
|
|
uint32_t initiated_compass_cal : 1; // 1 when user input to begin compass cal was accepted
|
|
|
|
uint32_t compass_cal_saved : 1; // 1 when compass calibration was just saved
|
|
|
|
uint32_t compass_cal_failed : 1; // 1 when compass calibration has just failed
|
|
|
|
uint32_t compass_cal_canceled : 1; // 1 when compass calibration was just canceled
|
|
|
|
uint32_t tune_started : 1; // tuning a parameter has started
|
|
|
|
uint32_t tune_next : 3; // tuning switched to next parameter
|
|
|
|
uint32_t tune_save : 1; // tuning saved parameters
|
2016-05-27 01:16:25 -03:00
|
|
|
uint32_t tune_error : 1; // tuning controller error
|
2014-10-23 09:04:34 -03:00
|
|
|
};
|
|
|
|
|
2016-09-30 04:21:28 -03:00
|
|
|
// The notify flags and values are static to allow direct class access
|
|
|
|
// without declaring the object.
|
|
|
|
static struct notify_flags_and_values_type flags;
|
2014-10-23 09:04:34 -03:00
|
|
|
static struct notify_events_type events;
|
2013-09-19 03:27:31 -03:00
|
|
|
|
|
|
|
// initialisation
|
2013-11-30 09:53:40 -04:00
|
|
|
void init(bool enable_external_leds);
|
2013-09-19 03:27:31 -03:00
|
|
|
|
2017-09-06 07:12:36 -03:00
|
|
|
// add all backends
|
|
|
|
void add_backends(void);
|
|
|
|
|
2013-09-19 03:27:31 -03:00
|
|
|
/// update - allow updates of leds that cannot be updated during a timed interrupt
|
|
|
|
void update(void);
|
|
|
|
|
2015-02-26 03:07:33 -04:00
|
|
|
// handle a LED_CONTROL message
|
|
|
|
static void handle_led_control(mavlink_message_t* msg);
|
|
|
|
|
2016-07-22 00:37:25 -03:00
|
|
|
// handle a PLAY_TUNE message
|
|
|
|
static void handle_play_tune(mavlink_message_t* msg);
|
2015-12-01 16:22:26 -04:00
|
|
|
|
2016-03-31 15:18:52 -03:00
|
|
|
bool buzzer_enabled() const { return _buzzer_enable; }
|
2016-09-30 04:21:28 -03:00
|
|
|
|
2017-01-20 06:13:37 -04:00
|
|
|
// set flight mode string
|
|
|
|
void set_flight_mode_str(const char *str);
|
|
|
|
const char* get_flight_mode_str() const { return _flight_mode_str; }
|
|
|
|
|
2017-01-20 01:50:07 -04:00
|
|
|
// send text to display
|
|
|
|
void send_text(const char *str);
|
|
|
|
const char* get_text() const { return _send_text; }
|
2016-09-30 04:21:28 -03:00
|
|
|
|
2017-01-20 01:51:04 -04:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2013-09-19 03:27:31 -03:00
|
|
|
private:
|
2017-08-23 11:54:39 -03:00
|
|
|
AP_Notify();
|
2015-12-01 16:22:26 -04:00
|
|
|
|
2017-07-08 20:40:45 -03:00
|
|
|
static AP_Notify *_instance;
|
|
|
|
|
2017-01-20 01:51:04 -04:00
|
|
|
// parameters
|
2015-12-01 16:22:26 -04:00
|
|
|
AP_Int8 _rgb_led_brightness;
|
2016-07-16 03:02:27 -03:00
|
|
|
AP_Int8 _rgb_led_override;
|
2016-03-31 15:18:52 -03:00
|
|
|
AP_Int8 _buzzer_enable;
|
2016-09-30 04:21:28 -03:00
|
|
|
AP_Int8 _display_type;
|
2017-06-01 19:08:07 -03:00
|
|
|
AP_Int8 _oreo_theme;
|
2016-09-30 04:21:28 -03:00
|
|
|
|
2017-01-20 01:50:07 -04:00
|
|
|
char _send_text[NOTIFY_TEXT_BUFFER_SIZE];
|
2017-02-17 03:19:16 -04:00
|
|
|
uint32_t _send_text_updated_millis; // last time text changed
|
2017-01-20 06:13:37 -04:00
|
|
|
char _flight_mode_str[5];
|
2017-01-20 01:51:04 -04:00
|
|
|
|
|
|
|
static NotifyDevice* _devices[];
|
2017-09-06 07:12:36 -03:00
|
|
|
static uint8_t _num_devices;
|
2013-09-19 03:27:31 -03:00
|
|
|
};
|