APM:Libraries
ToneAlarm_ChibiOS.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_CHIBIOS
22 #include "ToneAlarm_ChibiOS.h"
24 #include "AP_Notify.h"
25 
26 extern const AP_HAL::HAL& hal;
27 
29 {
30  // open the tone alarm device
32  if (!_initialized) {
33  hal.console->printf("AP_Notify: Failed to initialise ToneAlarm");
34  return false;
35  }
36 
37  // set initial boot states. This prevents us issuing a arming
38  // warning in plane and rover on every boot
41  return true;
42 }
43 
44 // play_tune - play one of the pre-defined tunes
45 bool ToneAlarm_ChibiOS::play_tune(uint8_t tune_number)
46 {
47  hal.util->toneAlarm_set_tune(tune_number);
48  return true;
49 }
50 
51 
52 // update - updates led according to timed_updated. Should be called at 50Hz
54 {
55  // exit immediately if we haven't initialised successfully
56  if (!_initialized) {
57  return;
58  }
59 
60  // exit if buzzer is not enabled
61  if (pNotify->buzzer_enabled() == false) {
62  return;
63  }
64 
65  // check for arming failure
66  if (AP_Notify::events.arming_failed) {
68  }
69 
70  // check if arming status has changed
73  if (flags.armed) {
74  // arming tune
76  }else{
77  // disarming tune
79  }
80  }
81 
82  // notify the user when their mode change was successful
83  if (AP_Notify::events.user_mode_change) {
84  if (AP_Notify::flags.armed) {
86  } else {
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_CHIBIOS
#define TONE_PARACHUTE_RELEASE_TUNE
Definition: ToneAlarm.h:110
bool init(void)
init - initialised the tone alarm
#define TONE_NOTIFY_MODE_CHANGE_SOFT
Definition: ToneAlarm.h:112
void update()
update - updates led according to timed_updated. Should be called at 50Hz
AP_HAL::UARTDriver * console
Definition: HAL.h:110
#define TONE_ARMING_FAILURE_TUNE
Definition: ToneAlarm.h:109
#define TONE_NOTIFY_NEUTRAL_TUNE
Definition: ToneAlarm.h:103
AP_HAL::Util * util
Definition: HAL.h:115
struct ToneAlarm_ChibiOS::tonealarm_type flags
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 buzzer_enabled() const
Definition: AP_Notify.h:135
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: AC_PID_test.cpp:14
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
bool play_tune(uint8_t tune_number)
play_tune - play one of the pre-defined tunes
#define TONE_ARMING_WARNING_TUNE
Definition: ToneAlarm.h:105
#define TONE_NOTIFY_MODE_CHANGE_LOUD
Definition: ToneAlarm.h:111
static struct notify_events_type events
Definition: AP_Notify.h:118
virtual bool toneAlarm_init()
Definition: Util.h:78