AP_Notify: add PX4's tone_alarm
Sounds added for arming, disarming and low battery events
This commit is contained in:
parent
226cb265af
commit
d16587340d
@ -26,6 +26,9 @@ void AP_Notify::init(void)
|
|||||||
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
||||||
toshibaled.init();
|
toshibaled.init();
|
||||||
#endif
|
#endif
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
||||||
|
tonealarm.init();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// main update function, called at 50Hz
|
// main update function, called at 50Hz
|
||||||
@ -36,4 +39,8 @@ void AP_Notify::update(void)
|
|||||||
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
||||||
toshibaled.update();
|
toshibaled.update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
||||||
|
tonealarm.update();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <ToshibaLED.h>
|
#include <ToshibaLED.h>
|
||||||
#include <ToshibaLED_I2C.h>
|
#include <ToshibaLED_I2C.h>
|
||||||
#include <ToshibaLED_PX4.h>
|
#include <ToshibaLED_PX4.h>
|
||||||
|
#include <ToneAlarm_PX4.h>
|
||||||
|
|
||||||
class AP_Notify
|
class AP_Notify
|
||||||
{
|
{
|
||||||
@ -56,6 +57,7 @@ private:
|
|||||||
ToshibaLED_I2C toshibaled;
|
ToshibaLED_I2C toshibaled;
|
||||||
#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
||||||
ToshibaLED_PX4 toshibaled;
|
ToshibaLED_PX4 toshibaled;
|
||||||
|
ToneAlarm_PX4 tonealarm;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
85
libraries/AP_Notify/ToneAlarm_PX4.cpp
Normal file
85
libraries/AP_Notify/ToneAlarm_PX4.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
ToneAlarm PX4 driver
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <AP_HAL.h>
|
||||||
|
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
||||||
|
#include "ToneAlarm_PX4.h"
|
||||||
|
#include "AP_Notify.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <drivers/drv_tone_alarm.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
|
bool ToneAlarm_PX4::init()
|
||||||
|
{
|
||||||
|
// open the tone alarm device
|
||||||
|
_tonealarm_fd = open(TONEALARM_DEVICE_PATH, 0);
|
||||||
|
if (_tonealarm_fd == -1) {
|
||||||
|
hal.console->printf("Unable to open " TONEALARM_DEVICE_PATH);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// play_tune - play one of the pre-defined tunes
|
||||||
|
bool ToneAlarm_PX4::play_tune(const uint8_t tune_number)
|
||||||
|
{
|
||||||
|
int ret = ioctl(_tonealarm_fd, TONE_SET_ALARM, tune_number);
|
||||||
|
return (ret == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update - updates led according to timed_updated. Should be called at 50Hz
|
||||||
|
void ToneAlarm_PX4::update()
|
||||||
|
{
|
||||||
|
// exit immediately if we haven't initialised successfully
|
||||||
|
if (_tonealarm_fd <= 0 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if arming status has changed
|
||||||
|
if (flags.armed != AP_Notify::flags.armed) {
|
||||||
|
flags.armed = AP_Notify::flags.armed;
|
||||||
|
if (flags.armed) {
|
||||||
|
// arming tune
|
||||||
|
play_tune(TONE_ARMING_WARNING_TUNE);
|
||||||
|
}else{
|
||||||
|
// disarming tune
|
||||||
|
play_tune(TONE_NOTIFY_NEUTRAL_TUNE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if battery status has changed
|
||||||
|
if (flags.failsafe_battery != AP_Notify::flags.failsafe_battery) {
|
||||||
|
flags.failsafe_battery = AP_Notify::flags.failsafe_battery;
|
||||||
|
if (flags.failsafe_battery) {
|
||||||
|
// low battery warning tune
|
||||||
|
play_tune(TONE_BATTERY_WARNING_FAST_TUNE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
45
libraries/AP_Notify/ToneAlarm_PX4.h
Normal file
45
libraries/AP_Notify/ToneAlarm_PX4.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
ToneAlarm PX4 driver
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef __TONE_ALARM_PX4_H__
|
||||||
|
#define __TONE_ALARM_PX4_H__
|
||||||
|
|
||||||
|
#include "ToneAlarm_PX4.h"
|
||||||
|
|
||||||
|
class ToneAlarm_PX4
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// init - initialised the tone alarm
|
||||||
|
bool init(void);
|
||||||
|
|
||||||
|
/// play_tune - play one of the pre-defined tunes
|
||||||
|
bool play_tune(const uint8_t tune_number);
|
||||||
|
|
||||||
|
/// update - updates led according to timed_updated. Should be called at 50Hz
|
||||||
|
void update();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _tonealarm_fd; // file descriptor for the tone alarm
|
||||||
|
|
||||||
|
/// tonealarm_type - bitmask of states we track
|
||||||
|
struct tonealarm_type {
|
||||||
|
uint8_t armed : 1; // 0 = disarmed, 1 = armed
|
||||||
|
uint8_t failsafe_battery : 1; // 1 if battery failsafe
|
||||||
|
} flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __TONE_ALARM_PX4_H__
|
Loading…
Reference in New Issue
Block a user