diff options
author | Andrew Tridgell <tridge@samba.org> | 2013-02-17 16:43:45 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2013-02-18 08:32:49 +1100 |
commit | b53d34a3f0d6db396da398c42d4884998d4eb488 (patch) | |
tree | f01a29acea18e5bca5e8913d0c44991ab2c9b15b | |
parent | d6c108d870034a8dfc328487dc3477738937894d (diff) | |
download | px4-firmware-b53d34a3f0d6db396da398c42d4884998d4eb488.tar.gz px4-firmware-b53d34a3f0d6db396da398c42d4884998d4eb488.tar.bz2 px4-firmware-b53d34a3f0d6db396da398c42d4884998d4eb488.zip |
px4fmu: add support for write() interface for PWM output
this matches the PX4IO interface
-rw-r--r-- | apps/drivers/px4fmu/fmu.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/apps/drivers/px4fmu/fmu.cpp b/apps/drivers/px4fmu/fmu.cpp index ed3635fc9..c29fe0ba3 100644 --- a/apps/drivers/px4fmu/fmu.cpp +++ b/apps/drivers/px4fmu/fmu.cpp @@ -85,6 +85,7 @@ public: ~PX4FMU(); virtual int ioctl(file *filp, int cmd, unsigned long arg); + virtual ssize_t write(file *filp, const char *buffer, size_t len); virtual int init(); @@ -651,6 +652,30 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg) return ret; } +/* + this implements PWM output via a write() method, for compatibility + with px4io + */ +ssize_t +PX4FMU::write(file *filp, const char *buffer, size_t len) +{ + unsigned count = len / 2; + uint16_t values[4]; + + if (count > 4) { + // we only have 4 PWM outputs on the FMU + count = 4; + } + + // allow for misaligned values + memcpy(values, buffer, count*2); + + for (uint8_t i=0; i<count; i++) { + up_pwm_servo_set(i, values[i]); + } + return count * 2; +} + void PX4FMU::gpio_reset(void) { |