LCOV - code coverage report
Current view: top level - AP_Notify - AP_Notify.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 12 66.7 %
Date: 2026-09-09 11:02:08 Functions: 7 11 63.6 %

          Line data    Source code
       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_GPS/AP_GPS_FixType.h>
      18             : 
      19             : #include <AP_Common/AP_Common.h>
      20             : #include <AP_Param/AP_Param.h>
      21             : #include "AP_Notify_config.h"
      22             : #include <AP_IOMCU/AP_IOMCU.h>
      23             : 
      24             : #include "NotifyDevice.h"
      25             : 
      26             : // Device parameters values
      27             : #define RGB_LED_OFF     0
      28             : #define RGB_LED_LOW     1
      29             : #define RGB_LED_MEDIUM  2
      30             : #define RGB_LED_HIGH    3
      31             : 
      32             : #define NOTIFY_TEXT_BUFFER_SIZE 51
      33             : 
      34             : //Type of on-board display
      35             : #define DISPLAY_OFF     0
      36             : #define DISPLAY_SSD1306 1
      37             : #define DISPLAY_SH1106  2
      38             : #define DISPLAY_SITL 10
      39             : 
      40             : class AP_Notify
      41             : {
      42             :     friend class RGBLed;            // RGBLed needs access to notify parameters
      43             :     friend class Display;           // Display needs access to notify parameters
      44             : public:
      45             :     AP_Notify();
      46             : 
      47             :     /* Do not allow copies */
      48             :     CLASS_NO_COPY(AP_Notify);
      49             : 
      50             :     // get singleton instance
      51      290086 :     static AP_Notify *get_singleton(void) {
      52      290086 :         return _singleton;
      53             :     }
      54             : 
      55             :     enum Notify_LED_Type {
      56             :         Notify_LED_None                     = 0,        // not enabled
      57             :         Notify_LED_Board                    = (1 << 0), // Built in board LED's
      58             : #if AP_NOTIFY_TOSHIBALED_ENABLED
      59             :         Notify_LED_ToshibaLED_I2C_Internal  = (1 << 1), // Internal ToshibaLED_I2C
      60             :         Notify_LED_ToshibaLED_I2C_External  = (1 << 2), // External ToshibaLED_I2C
      61             : #endif
      62             : #if AP_NOTIFY_PCA9685_ENABLED
      63             :         Notify_LED_PCA9685LED_I2C_External  = (1 << 3), // External PCA9685_I2C
      64             : #endif
      65             : #if AP_NOTIFY_OREOLED_ENABLED
      66             :         Notify_LED_OreoLED                  = (1 << 4), // Oreo
      67             : #endif
      68             : #if AP_NOTIFY_DRONECAN_LED_ENABLED
      69             :         Notify_LED_DroneCAN                   = (1 << 5), // UAVCAN RGB LED
      70             : #endif
      71             : #if AP_NOTIFY_NCP5623_ENABLED
      72             :         Notify_LED_NCP5623_I2C_External     = (1 << 6), // External NCP5623
      73             :         Notify_LED_NCP5623_I2C_Internal     = (1 << 7), // Internal NCP5623
      74             : #endif
      75             : #if AP_NOTIFY_NEOPIXEL_ENABLED
      76             :         Notify_LED_NeoPixel                 = (1 << 8), // NeoPixel 5050 AdaFruit 1655 SK6812  Worldsemi WS2812B
      77             : #endif
      78             : #if AP_NOTIFY_PROFILED_ENABLED
      79             :         Notify_LED_ProfiLED                 = (1 << 9), // ProfiLED
      80             : #endif
      81             : #if AP_NOTIFY_SCRIPTING_LED_ENABLED
      82             :         Notify_LED_Scripting                = (1 << 10),// Colour accessor for scripting
      83             : #endif
      84             : #if AP_NOTIFY_DSHOT_LED_ENABLED
      85             :         Notify_LED_DShot                    = (1 << 11),// Use dshot commands to set ESC LEDs
      86             : #endif
      87             : #if AP_NOTIFY_PROFILED_SPI_ENABLED
      88             :         Notify_LED_ProfiLED_SPI             = (1 << 12), // ProfiLED (SPI)
      89             : #endif
      90             : #if AP_NOTIFY_LP5562_ENABLED
      91             :         Notify_LED_LP5562_I2C_External      = (1 << 13), // LP5562
      92             :         Notify_LED_LP5562_I2C_Internal      = (1 << 14), // LP5562
      93             : #endif
      94             : #if AP_NOTIFY_IS31FL3195_ENABLED
      95             :         Notify_LED_IS31FL3195_I2C_External  = (1 << 15), // IS31FL3195
      96             :         Notify_LED_IS31FL3195_I2C_Internal  = (1 << 16), // IS31FL3195
      97             : #endif
      98             : #if AP_NOTIFY_DISCRETE_RGB_ENABLED
      99             :         Notify_LED_DiscreteRGB              = (1 << 17), // DiscreteRGB
     100             : #endif
     101             : #if AP_NOTIFY_NEOPIXEL_ENABLED
     102             :         Notify_LED_NeoPixelRGB              = (1 << 18), // NeoPixel AdaFruit 4544 Worldsemi WS2811
     103             : #endif
     104             : #if HAL_WITH_IO_MCU && AP_IOMCU_PROFILED_SUPPORT_ENABLED
     105             :         Notify_LED_ProfiLED_IOMCU           = (1 << 19), // ProfiLED IOMCU
     106             : #endif
     107             :         Notify_LED_MAX
     108             :     };
     109             : 
     110             :     enum class BuzzerType : uint8_t {
     111             :         NONE                    = 0,
     112             :         BUILTIN                 = (1 << 0), // Built in default Alarm Out
     113             :         DSHOT                   = (1 << 1), // DShot Alarm
     114             :         UAVCAN                  = (1 << 2), // UAVCAN Alarm
     115             :     };
     116             : 
     117             :     /// notify_flags_type - bitmask of notification flags
     118             :     struct notify_flags_and_values_type {
     119             :         bool initialising;        // true if initialising and the vehicle should not be moved
     120             :         AP_GPS_FixType gps_status; // GPS fix type
     121             :         uint8_t gps_num_sats;     // number of sats
     122             :         uint8_t flight_mode;      // flight mode
     123             :         bool armed;               // 0 = disarmed, 1 = armed
     124             :         bool flying;              // 0 = not flying, 1 = flying/driving/diving/tracking
     125             :         bool pre_arm_check;       // true if passing pre arm checks
     126             :         bool pre_arm_gps_check;   // true if passing pre arm gps checks
     127             :         bool save_trim;           // true if gathering trim data
     128             :         bool esc_calibration;     // true if calibrating escs
     129             :         bool failsafe_radio;      // true if radio failsafe
     130             :         bool failsafe_battery;    // true if battery failsafe
     131             :         bool failsafe_gcs;        // true if GCS failsafe
     132             :         bool failsafe_ekf;        // true if ekf failsafe
     133             :         bool parachute_release;   // true if parachute is being released
     134             :         bool ekf_bad;             // true if ekf is reporting problems
     135             :         bool autopilot_mode;      // true if vehicle is in an autopilot flight mode (only used by OreoLEDs)
     136             :         bool firmware_update;     // true just before vehicle firmware is updated
     137             :         bool compass_cal_running; // true if a compass calibration is running
     138             :         bool leak_detected;       // true if leak detected
     139             :         bool gps_fusion;          // true if the GPS is in use by EKF, usable for flight
     140             :         bool gps_glitching;       // true f the GPS is believed to be glitching is affecting navigation accuracy
     141             :         bool have_pos_abs;        // true if absolute position is available
     142             :         bool vehicle_lost;        // true when lost copter tone is requested (normally only used for copter)
     143             :         bool waiting_for_throw;   // true when copter is in THROW mode and waiting to detect the user hand launch
     144             :         bool powering_off;        // true when the vehicle is powering off
     145             :         bool video_recording;     // true when the vehicle is recording video
     146             :         bool temp_cal_running;    // true if a temperature calibration is running
     147             :         bool gyro_calibrated;     // true if calibrated gyro/acc
     148             :     };
     149             : 
     150             :     /// notify_events_type - bitmask of active events.
     151             :     //      Notify library is responsible for setting back to zero after notification has been completed
     152             :     struct notify_events_type {
     153             :         uint32_t arming_failed          : 1;    // 1 if copter failed to arm after user input
     154             :         uint32_t user_mode_change       : 1;    // 1 if user has initiated a flight mode change
     155             :         uint32_t user_mode_change_failed: 1;    // 1 when user initiated flight mode change fails
     156             :         uint32_t failsafe_mode_change   : 1;    // 1 when failsafe has triggered a flight mode change
     157             :         uint32_t autotune_complete      : 1;    // 1 when autotune has successfully completed
     158             :         uint32_t autotune_failed        : 1;    // 1 when autotune has failed
     159             :         uint32_t autotune_next_axis     : 1;    // 1 when autotune has completed one axis and is moving onto the next
     160             :         uint32_t mission_complete       : 1;    // 1 when the mission has completed successfully
     161             :         uint32_t waypoint_complete      : 1;    // 1 as vehicle completes a waypoint
     162             :         uint32_t initiated_compass_cal  : 1;    // 1 when user input to begin compass cal was accepted
     163             :         uint32_t compass_cal_saved      : 1;    // 1 when compass calibration was just saved
     164             :         uint32_t compass_cal_failed     : 1;    // 1 when compass calibration has just failed
     165             :         uint32_t compass_cal_canceled   : 1;    // 1 when compass calibration was just canceled
     166             :         uint32_t tune_started           : 1;    // tuning a parameter has started
     167             :         uint32_t tune_next              : 3;    // tuning switched to next parameter
     168             :         uint32_t tune_save              : 1;    // tuning saved parameters
     169             :         uint32_t tune_error             : 1;    // tuning controller error
     170             :         uint32_t initiated_temp_cal     : 1;    // 1 when temperature calibration starts
     171             :         uint32_t temp_cal_saved         : 1;    // 1 when temperature calibration was just saved
     172             :         uint32_t temp_cal_failed        : 1;    // 1 when temperature calibration has just failed
     173             :     };
     174             : 
     175             :     // The notify flags and values are static to allow direct class access
     176             :     // without declaring the object.
     177             :     static struct notify_flags_and_values_type flags;
     178             :     static struct notify_events_type events;
     179             : 
     180             :     // initialisation
     181             :     void init(void);
     182             : 
     183             :     /// update - allow updates of leds that cannot be updated during a timed interrupt
     184             :     void update(void);
     185             : 
     186             : #if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
     187             :     // handle a LED_CONTROL message
     188             :     static void handle_led_control(const mavlink_message_t &msg);
     189             : #endif
     190             : 
     191             :     // handle RGB from Scripting or AP_Periph
     192             :     static void handle_rgb(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz = 0);
     193             : 
     194             :     // handle RGB from Scripting
     195             :     static void handle_rgb_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id);
     196             : 
     197             : #if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED
     198             :     // handle a PLAY_TUNE message
     199             :     static void handle_play_tune(const mavlink_message_t &msg);
     200             : #endif
     201             : 
     202             :     // play a tune string
     203             :     static void play_tune(const char *tune);
     204             : 
     205        4188 :     bool buzzer_enabled() const { return _buzzer_type != 0; }
     206             : 
     207        2094 :     uint8_t get_buzzer_types() const { return _buzzer_type; }
     208             : 
     209             :     // set flight mode string
     210             :     void set_flight_mode_str(const char *str);
     211         565 :     const char* get_flight_mode_str() const { return _flight_mode_str; }
     212             : 
     213             :     // send text to display
     214             :     void send_text(const char *str);
     215         521 :     const char* get_text() const { return _send_text; }
     216         652 :     uint32_t get_text_updated_millis() const {return _send_text_updated_millis; }
     217             :  
     218             : #if AP_SCRIPTING_ENABLED
     219             :     // send text to the display using scripting
     220             :     void send_text_scripting(const char *str, uint8_t r);
     221             :     void release_text_scripting(uint8_t r);
     222             : #endif
     223             : 
     224             :     static const struct AP_Param::GroupInfo var_info[];
     225        2094 :     int8_t get_buzz_pin() const  { return _buzzer_pin; }
     226           0 :     uint8_t get_buzz_level() const  { return _buzzer_level; }
     227           0 :     uint8_t get_buzz_volume() const  { return _buzzer_volume; }
     228           0 :     uint8_t get_led_len() const { return _led_len; }
     229           0 :     uint32_t get_led_type() const { return _led_type; }
     230             :     int8_t get_rgb_led_brightness_percent() const;
     231             : 
     232             : #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
     233             :     HAL_Semaphore sf_window_mutex;
     234             : #endif
     235             : 
     236             : private:
     237             : 
     238             :     static AP_Notify *_singleton;
     239             : 
     240             :     void add_backend_helper(NotifyDevice *backend);
     241             : 
     242             :     // add all backends
     243             :     void add_backends(void);
     244             : 
     245             :     // parameters
     246             :     AP_Int8 _rgb_led_brightness;
     247             :     AP_Int8 _rgb_led_override;
     248             :     AP_Int8 _buzzer_type;
     249             :     AP_Int8 _display_type;
     250             :     AP_Int8 _oreo_theme;
     251             :     AP_Int8 _buzzer_pin;
     252             :     AP_Int32 _led_type;
     253             :     AP_Int8 _buzzer_level;
     254             :     AP_Int8 _buzzer_volume;
     255             :     AP_Int8 _led_len;
     256             : 
     257             :     char _send_text[NOTIFY_TEXT_BUFFER_SIZE];
     258             :     uint32_t _send_text_updated_millis; // last time text changed
     259             :     char _flight_mode_str[5];
     260             : 
     261             :     static NotifyDevice* _devices[];
     262             :     static uint8_t _num_devices;
     263             : };
     264             : 
     265             : namespace AP {
     266             :     AP_Notify &notify();
     267             : };

Generated by: LCOV version 1.14