mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
Added simulated tone_alarm and enabled led for POSIX
Added simulated tone_alarm class and enabled led class for posix build. The simulator implements the led_init, led_on, led_off, led_toggle calls. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ MODULES += drivers/device
|
||||
MODULES += drivers/blinkm
|
||||
MODULES += drivers/hil
|
||||
MODULES += drivers/rgbled
|
||||
MODULES += drivers/led
|
||||
MODULES += modules/sensors
|
||||
#MODULES += drivers/ms5611
|
||||
|
||||
@@ -62,12 +63,13 @@ MODULES += platforms/posix/drivers/accelsim
|
||||
MODULES += platforms/posix/drivers/gyrosim
|
||||
MODULES += platforms/posix/drivers/adcsim
|
||||
MODULES += platforms/posix/drivers/barosim
|
||||
MODULES += platforms/posix/drivers/tonealrmsim
|
||||
|
||||
#
|
||||
# Unit tests
|
||||
#
|
||||
#MODULES += platforms/posix/tests/hello
|
||||
#MODULES += platforms/posix/tests/vcdev_test
|
||||
#MODULES += platforms/posix/tests/hrt_test
|
||||
#MODULES += platforms/posix/tests/wqueue
|
||||
MODULES += platforms/posix/tests/hrt_test
|
||||
MODULES += platforms/posix/tests/wqueue
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
simulator start
|
||||
uorb start
|
||||
simulator start
|
||||
barosim start
|
||||
adcsim start
|
||||
accelsim start
|
||||
|
||||
+21
-2
@@ -38,8 +38,10 @@
|
||||
*/
|
||||
|
||||
#include <px4_config.h>
|
||||
#include <px4_posix.h>
|
||||
#include <drivers/device/device.h>
|
||||
#include <drivers/drv_led.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* Ideally we'd be able to get these from up_internal.h,
|
||||
@@ -55,18 +57,26 @@ extern void led_off(int led);
|
||||
extern void led_toggle(int led);
|
||||
__END_DECLS
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
class LED : device::CDev
|
||||
#else
|
||||
class LED : device::VDev
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
LED();
|
||||
virtual ~LED();
|
||||
|
||||
virtual int init();
|
||||
virtual int ioctl(struct file *filp, int cmd, unsigned long arg);
|
||||
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
LED::LED() :
|
||||
#ifdef __PX4_NUTTX
|
||||
CDev("led", LED0_DEVICE_PATH)
|
||||
#else
|
||||
VDev("led", LED0_DEVICE_PATH)
|
||||
#endif
|
||||
{
|
||||
// force immediate init/device registration
|
||||
init();
|
||||
@@ -79,14 +89,19 @@ LED::~LED()
|
||||
int
|
||||
LED::init()
|
||||
{
|
||||
printf("Initializing LED\n");
|
||||
#ifdef __PX4_NUTTX
|
||||
CDev::init();
|
||||
#else
|
||||
VDev::init();
|
||||
#endif
|
||||
led_init();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
LED::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
LED::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||
{
|
||||
int result = OK;
|
||||
|
||||
@@ -105,7 +120,11 @@ LED::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
|
||||
|
||||
default:
|
||||
#ifdef __PX4_NUTTX
|
||||
result = CDev::ioctl(filp, cmd, arg);
|
||||
#else
|
||||
result = VDev::ioctl(filp, cmd, arg);
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <drivers/drv_led.h>
|
||||
#ifndef __PX4_QURT
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
@@ -79,6 +80,8 @@ int Simulator::start(int argc, char *argv[])
|
||||
int ret = 0;
|
||||
_instance = new Simulator();
|
||||
if (_instance) {
|
||||
printf("Simulator started\n");
|
||||
drv_led_start();
|
||||
#ifndef __PX4_QURT
|
||||
_instance->updateSamples();
|
||||
#endif
|
||||
@@ -186,3 +189,45 @@ int simulator_main(int argc, char *argv[])
|
||||
|
||||
}
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern void led_init(void);
|
||||
extern void led_on(int led);
|
||||
extern void led_off(int led);
|
||||
extern void led_toggle(int led);
|
||||
__END_DECLS
|
||||
|
||||
bool static _led_state = false;
|
||||
|
||||
__EXPORT void led_init()
|
||||
{
|
||||
printf("LED_ON\n");
|
||||
}
|
||||
|
||||
__EXPORT void led_on(int led)
|
||||
{
|
||||
if (led == 1)
|
||||
{
|
||||
printf("LED_ON\n");
|
||||
_led_state = true;
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void led_off(int led)
|
||||
{
|
||||
if (led == 1)
|
||||
{
|
||||
printf("LED_OFF\n");
|
||||
_led_state = false;
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void led_toggle(int led)
|
||||
{
|
||||
if (led == 1)
|
||||
{
|
||||
_led_state = !_led_state;
|
||||
printf("LED_TOGGLE: %s\n", _led_state ? "ON" : "OFF");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2012, 2013 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
#
|
||||
# Tone alarm driver
|
||||
#
|
||||
|
||||
MODULE_COMMAND = tone_alarm
|
||||
|
||||
SRCS = tone_alarm.cpp
|
||||
|
||||
MAXOPTIMIZATION = -Os
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user