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

          Line data    Source code
       1             : /*
       2             :   Buzzer driver
       3             : */
       4             : /*
       5             :    This program is free software: you can redistribute it and/or modify
       6             :    it under the terms of the GNU General Public License as published by
       7             :    the Free Software Foundation, either version 3 of the License, or
       8             :    (at your option) any later version.
       9             : 
      10             :    This program is distributed in the hope that it will be useful,
      11             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :    GNU General Public License for more details.
      14             : 
      15             :    You should have received a copy of the GNU General Public License
      16             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             :  */
      18             : #pragma once
      19             : 
      20             : #include "NotifyDevice.h"
      21             : 
      22             : class Buzzer: public NotifyDevice
      23             : {
      24             : public:
      25             :     /// Constructor
      26        2094 :     Buzzer() {}
      27             : 
      28             :     /// init - initialise the buzzer
      29             :     bool init(void) override;
      30             : 
      31             :     /// update - updates buzzer according to timed_updated.  Should be called at 50Hz
      32             :     void update() override;
      33             : 
      34             : private:
      35             : 
      36             :     /// on - turns the buzzer on or off
      37             :     void on(bool on_off);
      38             : 
      39             :     // Patterns - how many beeps will be played; read from
      40             :     // left-to-right, each bit represents 100ms
      41             :     static const uint32_t    SINGLE_BUZZ = 0b10000000000000000000000000000000UL;
      42             :     static const uint32_t    DOUBLE_BUZZ = 0b10100000000000000000000000000000UL;
      43             :     static const uint32_t    ARMING_BUZZ = 0b11111111111111111111111111111100UL; // 3s
      44             :     static const uint32_t      BARO_BUZZ = 0b10101010100000000000000000000000UL;
      45             :     static const uint32_t        EKF_BAD = 0b11101101010000000000000000000000UL;
      46             :     static const uint32_t      INIT_GYRO = 0b10010010010010010010000000000000UL;
      47             :     static const uint32_t   PRE_ARM_GOOD = 0b10101011111111110000000000000000UL;
      48             : 
      49             :     /// play_pattern - plays the defined buzzer pattern
      50             :     void play_pattern(const uint32_t pattern);
      51             : 
      52             :     /// buzzer_flag_type - bitmask of current state and ap_notify states we track
      53             :     struct buzzer_flag_type {
      54             :         uint8_t on                  : 1;    // 1 if the buzzer is currently on
      55             :         uint8_t arming              : 1;    // 1 if we are beginning the arming process
      56             :         uint8_t armed               : 1;    // 0 = disarmed, 1 = armed
      57             :         uint8_t failsafe_battery    : 1;    // 1 if battery failsafe has triggered
      58             :         uint8_t ekf_bad             : 1;    // 1 if ekf position has gone bad
      59             :         uint8_t gyro_calibrated     : 1;    // 1 if calibrating gyro
      60             :         uint8_t pre_arm_check       : 1;    // 1 if pre-arm check has passed
      61             :     } _flags;
      62             : 
      63             :     uint32_t _pattern;           // current pattern
      64             :     int8_t _pin;
      65             :     uint32_t _pattern_start_time;
      66             : 
      67             :     // enforce minumum 100ms interval between patterns:
      68             :     const uint16_t _pattern_start_interval_time_ms = 32*100 + 100;
      69             : 
      70             :     void update_playing_pattern();
      71             :     void update_pattern_to_play();
      72             : 
      73             : };

Generated by: LCOV version 1.14