aboutsummaryrefslogtreecommitdiff
path: root/apps/drivers
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2013-01-06 00:32:04 -0800
committerpx4dev <px4@purgatory.org>2013-01-06 00:32:04 -0800
commitb3e16b48617ada1b72ba07fab2f9b3ef48cd5058 (patch)
tree373ad673a6adab696dfef4d1a5c09eaa6f52dc59 /apps/drivers
parent76277ec622742388aade35ef9d439d42ea6caad7 (diff)
parent5b92c517779500d79e6e5f5cff48336550ce5edb (diff)
downloadpx4-firmware-b3e16b48617ada1b72ba07fab2f9b3ef48cd5058.tar.gz
px4-firmware-b3e16b48617ada1b72ba07fab2f9b3ef48cd5058.tar.bz2
px4-firmware-b3e16b48617ada1b72ba07fab2f9b3ef48cd5058.zip
Merge pull request #123 from PX4/#106-px4io-relays
Initial implementation of application access to the PX4IO relays.
Diffstat (limited to 'apps/drivers')
-rw-r--r--apps/drivers/px4io/px4io.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/apps/drivers/px4io/px4io.cpp b/apps/drivers/px4io/px4io.cpp
index 9f3dba047..f32f9a105 100644
--- a/apps/drivers/px4io/px4io.cpp
+++ b/apps/drivers/px4io/px4io.cpp
@@ -61,6 +61,7 @@
#include <drivers/device/device.h>
#include <drivers/drv_rc_input.h>
#include <drivers/drv_pwm_output.h>
+#include <drivers/drv_gpio.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_mixer.h>
@@ -116,6 +117,8 @@ private:
bool _primary_pwm_device; ///< true if we are the default PWM output
+ uint32_t _relays; ///< state of the PX4IO relays, one bit per relay
+
volatile bool _switch_armed; ///< PX4IO switch armed state
// XXX how should this work?
@@ -188,6 +191,7 @@ PX4IO::PX4IO() :
_t_outputs(-1),
_mixers(nullptr),
_primary_pwm_device(false),
+ _relays(0),
_switch_armed(false),
_send_needed(false),
_config_needed(false)
@@ -510,7 +514,9 @@ PX4IO::io_send()
/* publish as we send */
orb_publish(ORB_ID_VEHICLE_CONTROLS, _t_outputs, &_outputs);
- // XXX relays
+ /* update relays */
+ for (unsigned i = 0; i < PX4IO_RELAY_CHANNELS; i++)
+ cmd.relay_state[i] = (_relays & (1<< i)) ? true : false;
/* armed and not locked down */
cmd.arm_ok = (_armed.armed && !_armed.lockdown);
@@ -572,6 +578,30 @@ PX4IO::ioctl(file *filep, int cmd, unsigned long arg)
*(servo_position_t *)arg = _outputs.output[cmd - PWM_SERVO_GET(0)];
break;
+ case GPIO_RESET:
+ _relays = 0;
+ _send_needed = true;
+ break;
+
+ case GPIO_SET:
+ case GPIO_CLEAR:
+ /* make sure only valid bits are being set */
+ if ((arg & ((1UL << PX4IO_RELAY_CHANNELS) - 1)) != arg) {
+ ret = EINVAL;
+ break;
+ }
+ if (cmd == GPIO_SET) {
+ _relays |= arg;
+ } else {
+ _relays &= ~arg;
+ }
+ _send_needed = true;
+ break;
+
+ case GPIO_GET:
+ *(uint32_t *)arg = _relays;
+ break;
+
case MIXERIOCGETOUTPUTCOUNT:
*(unsigned *)arg = _max_actuators;
break;