APM:Libraries
AP_Notify.h
Go to the documentation of this file.
1 /*
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License as published by
4  the Free Software Foundation, either version 3 of the License, or
5  (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 #pragma once
16 
17 #include <AP_Common/AP_Common.h>
18 #include <AP_Param/AP_Param.h>
20 
21 #include "NotifyDevice.h"
22 
23 // Device parameters values
24 #define RGB_LED_OFF 0
25 #define RGB_LED_LOW 1
26 #define RGB_LED_MEDIUM 2
27 #define RGB_LED_HIGH 3
28 #define BUZZER_ON 1
29 #define BUZZER_OFF 0
30 
31 #define NOTIFY_TEXT_BUFFER_SIZE 51
32 
33 //Type of on-board display
34 #define DISPLAY_OFF 0
35 #define DISPLAY_SSD1306 1
36 #define DISPLAY_SH1106 2
37 
38 class AP_Notify
39 {
40  friend class RGBLed; // RGBLed needs access to notify parameters
41  friend class Display; // Display needs access to notify parameters
42 public:
43  AP_Notify();
44 
45  /* Do not allow copies */
46  AP_Notify(const AP_Notify &other) = delete;
47  AP_Notify &operator=(const AP_Notify&) = delete;
48 
49  // get singleton instance
50  static AP_Notify *instance(void) {
51  return _instance;
52  }
53 
54  // Oreo LED Themes
56  OreoLED_Disabled = 0, // Disabled the OLED driver entirely
57  OreoLED_Aircraft = 1, // Standard aviation themed lighting
58  OreoLED_Automobile = 2, // Automobile themed lighting (white front, red back)
59  };
60 
63  uint32_t initialising : 1; // 1 if initialising and copter should not be moved
64  uint32_t gps_status : 3; // 0 = no gps, 1 = no lock, 2 = 2d lock, 3 = 3d lock, 4 = dgps lock, 5 = rtk lock
65  uint32_t gps_num_sats : 6; // number of sats
66  uint32_t flight_mode : 8; // flight mode
67  uint32_t armed : 1; // 0 = disarmed, 1 = armed
68  uint32_t pre_arm_check : 1; // 0 = failing checks, 1 = passed
69  uint32_t pre_arm_gps_check : 1; // 0 = failing pre-arm GPS checks, 1 = passed
70  uint32_t save_trim : 1; // 1 if gathering trim data
71  uint32_t esc_calibration : 1; // 1 if calibrating escs
72  uint32_t failsafe_radio : 1; // 1 if radio failsafe
73  uint32_t failsafe_battery : 1; // 1 if battery failsafe
74  uint32_t parachute_release : 1; // 1 if parachute is being released
75  uint32_t ekf_bad : 1; // 1 if ekf is reporting problems
76  uint32_t autopilot_mode : 1; // 1 if vehicle is in an autopilot flight mode (only used by OreoLEDs)
77  uint32_t firmware_update : 1; // 1 just before vehicle firmware is updated
78  uint32_t compass_cal_running: 1; // 1 if a compass calibration is running
79  uint32_t leak_detected : 1; // 1 if leak detected
80  float battery_voltage ; // battery voltage
81  uint32_t gps_fusion : 1; // 0 = GPS fix rejected by EKF, not usable for flight. 1 = GPS in use by EKF, usable for flight
82  uint32_t gps_glitching : 1; // 1 if GPS glitching is affecting navigation accuracy
83  uint32_t have_pos_abs : 1; // 0 = no absolute position available, 1 = absolute position available
84 
85  // additional flags
86  uint32_t external_leds : 1; // 1 if external LEDs are enabled (normally only used for copter)
87  uint32_t vehicle_lost : 1; // 1 when lost copter tone is requested (normally only used for copter)
88  uint32_t waiting_for_throw : 1; // 1 when copter is in THROW mode and waiting to detect the user hand launch
89  uint32_t powering_off : 1; // 1 when the vehicle is powering off
90  uint32_t video_recording : 1; // 1 when the vehicle is recording video
91  };
92 
94  // Notify library is responsible for setting back to zero after notification has been completed
96  uint32_t arming_failed : 1; // 1 if copter failed to arm after user input
97  uint32_t user_mode_change : 1; // 1 if user has initiated a flight mode change
98  uint32_t user_mode_change_failed: 1; // 1 when user initiated flight mode change fails
99  uint32_t failsafe_mode_change : 1; // 1 when failsafe has triggered a flight mode change
100  uint32_t autotune_complete : 1; // 1 when autotune has successfully completed
101  uint32_t autotune_failed : 1; // 1 when autotune has failed
102  uint32_t autotune_next_axis : 1; // 1 when autotune has completed one axis and is moving onto the next
103  uint32_t mission_complete : 1; // 1 when the mission has completed successfully
104  uint32_t waypoint_complete : 1; // 1 as vehicle completes a waypoint
105  uint32_t initiated_compass_cal : 1; // 1 when user input to begin compass cal was accepted
106  uint32_t compass_cal_saved : 1; // 1 when compass calibration was just saved
107  uint32_t compass_cal_failed : 1; // 1 when compass calibration has just failed
108  uint32_t compass_cal_canceled : 1; // 1 when compass calibration was just canceled
109  uint32_t tune_started : 1; // tuning a parameter has started
110  uint32_t tune_next : 3; // tuning switched to next parameter
111  uint32_t tune_save : 1; // tuning saved parameters
112  uint32_t tune_error : 1; // tuning controller error
113  };
114 
115  // The notify flags and values are static to allow direct class access
116  // without declaring the object.
118  static struct notify_events_type events;
119 
120  // initialisation
121  void init(bool enable_external_leds);
122 
123  // add all backends
124  void add_backends(void);
125 
127  void update(void);
128 
129  // handle a LED_CONTROL message
130  static void handle_led_control(mavlink_message_t* msg);
131 
132  // handle a PLAY_TUNE message
133  static void handle_play_tune(mavlink_message_t* msg);
134 
135  bool buzzer_enabled() const { return _buzzer_enable; }
136 
137  // set flight mode string
138  void set_flight_mode_str(const char *str);
139  const char* get_flight_mode_str() const { return _flight_mode_str; }
140 
141  // send text to display
142  void send_text(const char *str);
143  const char* get_text() const { return _send_text; }
144 
145  static const struct AP_Param::GroupInfo var_info[];
146  uint8_t get_buzz_pin() const { return _buzzer_pin; }
147 
148 private:
149 
151 
152  // parameters
155  AP_Int8 _buzzer_enable;
156  AP_Int8 _display_type;
157  AP_Int8 _oreo_theme;
158  AP_Int8 _buzzer_pin;
159 
161  uint32_t _send_text_updated_millis; // last time text changed
163 
165  static uint8_t _num_devices;
166 };
AP_Int8 _buzzer_enable
Definition: AP_Notify.h:155
Definition: RGBLed.h:25
static void handle_led_control(mavlink_message_t *msg)
Definition: AP_Notify.cpp:300
AP_Int8 _rgb_led_override
Definition: AP_Notify.h:154
static uint8_t _num_devices
Definition: AP_Notify.h:165
AP_Int8 _oreo_theme
Definition: AP_Notify.h:157
static const struct AP_Param::GroupInfo var_info[]
Definition: AP_Notify.h:145
char _flight_mode_str[5]
Definition: AP_Notify.h:162
notify_flags_type - bitmask of notification flags
Definition: AP_Notify.h:62
AP_Int8 _display_type
Definition: AP_Notify.h:156
const char * get_flight_mode_str() const
Definition: AP_Notify.h:139
static AP_Notify * instance(void)
Definition: AP_Notify.h:50
notify_events_type - bitmask of active events.
Definition: AP_Notify.h:95
A system for managing and storing variables that are of general interest to the system.
bool buzzer_enabled() const
Definition: AP_Notify.h:135
void init(bool enable_external_leds)
Definition: AP_Notify.cpp:262
#define NOTIFY_TEXT_BUFFER_SIZE
Definition: AP_Notify.h:31
void add_backends(void)
Definition: AP_Notify.cpp:119
const char * get_text() const
Definition: AP_Notify.h:143
uint32_t _send_text_updated_millis
Definition: AP_Notify.h:161
uint8_t get_buzz_pin() const
Definition: AP_Notify.h:146
static void handle_play_tune(mavlink_message_t *msg)
Definition: AP_Notify.cpp:310
void set_flight_mode_str(const char *str)
Definition: AP_Notify.cpp:320
Common definitions and utility routines for the ArduPilot libraries.
static AP_Notify * _instance
Definition: AP_Notify.h:150
AP_Int8 _buzzer_pin
Definition: AP_Notify.h:158
static struct notify_flags_and_values_type flags
Definition: AP_Notify.h:117
AP_Int8 _rgb_led_brightness
Definition: AP_Notify.h:153
Oreo_LED_Theme
Definition: AP_Notify.h:55
void update(void)
update - allow updates of leds that cannot be updated during a timed interrupt
Definition: AP_Notify.cpp:287
void send_text(const char *str)
Definition: AP_Notify.cpp:326
char _send_text[NOTIFY_TEXT_BUFFER_SIZE]
Definition: AP_Notify.h:160
static struct notify_events_type events
Definition: AP_Notify.h:118
AP_Notify & operator=(const AP_Notify &)=delete
static NotifyDevice * _devices[]
Definition: AP_Notify.h:164