APM:Libraries
ToneAlarm_Linux.cpp
Go to the documentation of this file.
1 /*
2  ToneAlarm Linux 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 
19 #include <AP_HAL/AP_HAL.h>
20 
21 #if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
22 #include "ToneAlarm_Linux.h"
23 
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <stdio.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 
31 #include <AP_HAL_Linux/Util.h>
32 
33 #include "AP_Notify.h"
34 
35 extern const AP_HAL::HAL& hal;
36 
38 {
39  // open the tone alarm device
41  if (!_initialized) {
42  hal.console->printf("AP_Notify: Failed to initialise ToneAlarm");
43  return false;
44  }
45 
46  // set initial boot states. This prevents us issuing a arming
47  // warning in plane and rover on every boot
50  return true;
51 }
52 
53 // play_tune - play one of the pre-defined tunes
54 bool ToneAlarm_Linux::play_tune(uint8_t tune_number)
55 {
56  hal.util->toneAlarm_set_tune(tune_number);
57  return true;
58 }
59 
60 
61 // update - updates led according to timed_updated. Should be called at 50Hz
63 {
64  // exit immediately if we haven't initialised successfully
65  if (!_initialized) {
66  return;
67  }
68 
69  // exit if buzzer is not enabled
70  if (pNotify->buzzer_enabled() == false) {
71  return;
72  }
73 
74  // check for arming failure
75  if (AP_Notify::events.arming_failed) {
77  }
78 
79  // check if arming status has changed
82  if (flags.armed) {
83  // arming tune
85  }else{
86  // disarming tune
88  }
89  }
90 
91  // check if battery status has changed
94  if (flags.failsafe_battery) {
95  // low battery warning tune
97  }
98  }
99 
100  // check parachute release
103  if (flags.parachute_release) {
104  // parachute release warning tune
106  }
107  }
108 }
109 
110 #endif // CONFIG_HAL_BOARD == HAL_BOARD_PX4
void update()
update - updates led according to timed_updated. Should be called at 50Hz
#define TONE_PARACHUTE_RELEASE_TUNE
Definition: ToneAlarm.h:110
struct ToneAlarm_Linux::tonealarm_type flags
AP_HAL::UARTDriver * console
Definition: HAL.h:110
#define TONE_ARMING_FAILURE_TUNE
Definition: ToneAlarm.h:109
bool init(void)
init - initialised the tone alarm
#define TONE_NOTIFY_NEUTRAL_TUNE
Definition: ToneAlarm.h:103
AP_HAL::Util * util
Definition: HAL.h:115
virtual void toneAlarm_set_tune(uint8_t tune)
Definition: Util.h:79
virtual void printf(const char *,...) FMT_PRINTF(2
Definition: BetterStream.cpp:5
bool play_tune(uint8_t tune_number)
play_tune - play one of the pre-defined tunes
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: AC_PID_test.cpp:14
bool buzzer_enabled() const
Definition: AP_Notify.h:135
const AP_Notify * pNotify
Definition: NotifyDevice.h:24
static struct notify_flags_and_values_type flags
Definition: AP_Notify.h:117
#define TONE_BATTERY_WARNING_FAST_TUNE
Definition: ToneAlarm.h:107
#define TONE_ARMING_WARNING_TUNE
Definition: ToneAlarm.h:105
static struct notify_events_type events
Definition: AP_Notify.h:118
virtual bool toneAlarm_init()
Definition: Util.h:78