diff --git a/src/modules/events/events_params.c b/src/modules/events/events_params.c new file mode 100644 index 0000000000..b3d6a5d391 --- /dev/null +++ b/src/modules/events/events_params.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * + * Copyright (c) 2018 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file events_params.c + * + * Parameters defined by the events module. + */ + +#include +#include + +/** + * Status Display + * + * Enable/disable event task for displaying the vehicle status using arm-mounted + * LEDs. When enabled and if the vehicle supports it, LEDs will flash + * indicating various vehicle status changes. Currently PX4 has not implemented + * any specific status events. + * - + * + * @group Events + * @boolean + * @reboot_required true + * @value 0 OFF + * @value 1 ON + */ +PARAM_DEFINE_INT32(EV_TSK_STAT_DIS, 0); + +/** + * RC Loss Alarm + * + * Enable/disable event task for RC Loss. When enabled, an alarm tune will be + * played via buzzer or ESCs, if supported. + * + * @group Events + * @boolean + * @reboot_required true + * @value 0 OFF + * @value 1 ON + */ +PARAM_DEFINE_INT32(EV_TSK_RC_LOSS, 0); diff --git a/src/modules/events/send_event.cpp b/src/modules/events/send_event.cpp index 14004e93c7..67c97dccce 100644 --- a/src/modules/events/send_event.cpp +++ b/src/modules/events/send_event.cpp @@ -66,9 +66,26 @@ int SendEvent::task_spawn(int argc, char *argv[]) return 0; } -SendEvent::SendEvent() - : _status_display(_subscriber_handler), _rc_loss_alarm(_subscriber_handler) +SendEvent::SendEvent() : ModuleParams(nullptr) { + if (_param_status_display.get()) { + _status_display = new status::StatusDisplay(_subscriber_handler); + } + + if (_param_rc_loss.get()) { + _rc_loss_alarm = new rc_loss::RC_Loss_Alarm(_subscriber_handler); + } +} + +SendEvent::~SendEvent() +{ + if (_status_display != nullptr) { + delete _status_display; + } + + if (_rc_loss_alarm != nullptr) { + delete _rc_loss_alarm; + } } int SendEvent::start() @@ -119,8 +136,13 @@ void SendEvent::cycle() process_commands(); - _status_display.process(); - _rc_loss_alarm.process(); + if (_status_display != nullptr) { + _status_display->process(); + } + + if (_rc_loss_alarm != nullptr) { + _rc_loss_alarm->process(); + } work_queue(LPWORK, &_work, (worker_t)&SendEvent::cycle_trampoline, this, USEC2TICK(SEND_EVENT_INTERVAL_US)); diff --git a/src/modules/events/send_event.h b/src/modules/events/send_event.h index 6fd4ad5548..0cb57e96f0 100644 --- a/src/modules/events/send_event.h +++ b/src/modules/events/send_event.h @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -47,10 +48,11 @@ namespace events extern "C" __EXPORT int send_event_main(int argc, char *argv[]); -class SendEvent : public ModuleBase +class SendEvent : public ModuleBase, public ModuleParams { public: SendEvent(); + ~SendEvent(); /** * Initialize class in the same context as the work queue. And start the background listener. @@ -87,9 +89,14 @@ private: static struct work_s _work; SubscriberHandler _subscriber_handler; - status::StatusDisplay _status_display; - rc_loss::RC_Loss_Alarm _rc_loss_alarm; + status::StatusDisplay *_status_display = nullptr; + rc_loss::RC_Loss_Alarm *_rc_loss_alarm = nullptr; orb_advert_t _command_ack_pub = nullptr; + + DEFINE_PARAMETERS( + (ParamBool) _param_status_display, + (ParamBool) _param_rc_loss + ) }; } /* namespace events */