APM:Libraries
ToneAlarm_PX4.h
Go to the documentation of this file.
1 /*
2  ToneAlarm PX4 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 // wait 2 seconds before assuming a tone is done and continuing the continuous tone
23 #define AP_NOTIFY_PX4_MAX_TONE_LENGTH_MS 2000
24 
26 {
27 public:
29  bool init(void);
30 
32  void update();
33 
34  // handle a PLAY_TUNE message
35  void handle_play_tune(mavlink_message_t *msg);
36 
37 private:
39  void play_tone(const uint8_t tone_index);
40 
41  // play_string - play tone specified by the provided string of notes
42  void play_string(const char *str);
43 
44  // stop_cont_tone - stop playing the currently playing continuous tone
45  void stop_cont_tone();
46 
47  // check_cont_tone - check if we should begin playing a continuous tone
48  void check_cont_tone();
49 
50  int _tonealarm_fd; // file descriptor for the tone alarm
51 
53  struct tonealarm_type {
54  uint16_t armed : 1; // 0 = disarmed, 1 = armed
55  uint16_t failsafe_battery : 1; // 1 if battery failsafe
56  uint16_t parachute_release : 1; // 1 if parachute is being released
57  uint16_t pre_arm_check : 1; // 0 = failing checks, 1 = passed
58  uint16_t failsafe_radio : 1; // 1 if radio failsafe
59  uint16_t vehicle_lost : 1; // 1 if lost copter tone requested
60  uint16_t compass_cal_running : 1; // 1 if compass calibration is running
61  uint16_t waiting_for_throw : 1; // 1 if waiting for copter throw launch
62  uint16_t leak_detected : 1; // 1 if leak detected
63  uint16_t powering_off : 1; // 1 if smart battery is powering off
64  } flags;
66 
68  int8_t _tone_playing;
70 
71  struct Tone {
72  const char *str;
73  const uint8_t continuous : 1;
74  };
75 
76  const static Tone _tones[];
77 };
void update()
update - updates led according to timed_updated. Should be called at 50Hz
void play_string(const char *str)
const uint8_t continuous
Definition: ToneAlarm_PX4.h:73
tonealarm_type - bitmask of states we track
Definition: ToneAlarm_PX4.h:53
bool _have_played_ready_tone
Definition: ToneAlarm_PX4.h:65
void play_tone(const uint8_t tone_index)
play_tune - play one of the pre-defined tunes
int8_t _cont_tone_playing
Definition: ToneAlarm_PX4.h:67
bool init(void)
init - initialised the tone alarm
void check_cont_tone()
int8_t _tone_playing
Definition: ToneAlarm_PX4.h:68
uint32_t _tone_beginning_ms
Definition: ToneAlarm_PX4.h:69
static const Tone _tones[]
Definition: ToneAlarm_PX4.h:76
void handle_play_tune(mavlink_message_t *msg)
struct ToneAlarm_PX4::tonealarm_type flags
const char * str
Definition: ToneAlarm_PX4.h:72