diff options
author | Simon Wilks <sjwilks@gmail.com> | 2013-01-06 04:21:04 +0100 |
---|---|---|
committer | Simon Wilks <sjwilks@gmail.com> | 2013-01-06 04:21:04 +0100 |
commit | 7842caf3b2d5686c4e909d7d7f28758119e8918f (patch) | |
tree | bb0b773138ea9997543ef7c98a6433c4e19ba408 /apps/drivers/px4io/px4io.cpp | |
parent | 0a89ab7075e4d637c91e21246c4790599f046aec (diff) | |
download | px4-firmware-7842caf3b2d5686c4e909d7d7f28758119e8918f.tar.gz px4-firmware-7842caf3b2d5686c4e909d7d7f28758119e8918f.tar.bz2 px4-firmware-7842caf3b2d5686c4e909d7d7f28758119e8918f.zip |
Moved the channel mappings and attributes to the config section
Diffstat (limited to 'apps/drivers/px4io/px4io.cpp')
-rw-r--r-- | apps/drivers/px4io/px4io.cpp | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/apps/drivers/px4io/px4io.cpp b/apps/drivers/px4io/px4io.cpp index 07c65d8cd..cc6a425a3 100644 --- a/apps/drivers/px4io/px4io.cpp +++ b/apps/drivers/px4io/px4io.cpp @@ -222,7 +222,7 @@ PX4IO::PX4IO() : _relays(0), _switch_armed(false), _send_needed(false), - _config_needed(false) + _config_needed(true) { /* we need this potentially before it could be set in task_main */ g_dev = this; @@ -447,12 +447,6 @@ PX4IO::task_main() } } - /* send an update to IO if required */ - if (_send_needed) { - _send_needed = false; - io_send(); - } - /* send a config packet to IO if required */ if (_config_needed) { _config_needed = false; @@ -467,6 +461,12 @@ PX4IO::task_main() _mix_buf = nullptr; _mix_buf_len = 0; } + + /* send an update to IO if required */ + if (_send_needed) { + _send_needed = false; + io_send(); + } } unlock(); @@ -608,49 +608,60 @@ PX4IO::io_send() cmd.manual_override_ok = _vstatus.flag_external_manual_override_ok; /* set desired PWM output rate */ cmd.servo_rate = _update_rate; + + ret = hx_stream_send(_io_stream, &cmd, sizeof(cmd)); - /* maintaing the standard order of Roll, Pitch, Yaw, Throttle */ - cmd.rc_map[0] = param_find("RC_MAP_ROLL"); - cmd.rc_map[1] = param_find("RC_MAP_PITCH"); - cmd.rc_map[2] = param_find("RC_MAP_YAW"); - cmd.rc_map[3] = param_find("RC_MAP_THROTTLE"); + if (ret) + debug("send error %d", ret); +} + +void +PX4IO::config_send() +{ + px4io_config cfg; + int ret; + + cfg.f2i_config_magic = F2I_CONFIG_MAGIC; + + int val; + + /* maintaing the standard order of Roll, Pitch, Yaw, Throttle */ + param_get(param_find("RC_MAP_ROLL"), &val); + cfg.rc_map[0] = (uint8_t)val; + param_get(param_find("RC_MAP_PITCH"), &val); + cfg.rc_map[1] = (uint8_t)val; + param_get(param_find("RC_MAP_YAW"), &val); + cfg.rc_map[2] = (uint8_t)val; + param_get(param_find("RC_MAP_THROTTLE"), &val); + cfg.rc_map[3] = (uint8_t)val; /* set the individual channel properties */ char nbuf[16]; for (unsigned i = 0; i < 4; i++) { - sprintf(nbuf, "RC%d_MIN", i); - cmd.rc_min[i] = (uint16_t)param_find(nbuf); + sprintf(nbuf, "RC%d_MIN", i); + param_get(param_find(nbuf), &val); + cfg.rc_min[i] = (uint16_t)val; } for (unsigned i = 0; i < 4; i++) { sprintf(nbuf, "RC%d_TRIM", i); - cmd.rc_trim[i] = (uint16_t)param_find(nbuf); + param_get(param_find(nbuf), &val); + cfg.rc_trim[i] = (uint16_t)val; } for (unsigned i = 0; i < 4; i++) { sprintf(nbuf, "RC%d_MAX", i); - cmd.rc_max[i] = (uint16_t)param_find(nbuf); + param_get(param_find(nbuf), &val); + cfg.rc_max[i] = (uint16_t)val; } for (unsigned i = 0; i < 4; i++) { sprintf(nbuf, "RC%d_REV", i); - cmd.rc_rev[i] = (uint16_t)param_find(nbuf); + param_get(param_find(nbuf), &val); + cfg.rc_rev[i] = (uint16_t)val; } for (unsigned i = 0; i < 4; i++) { sprintf(nbuf, "RC%d_DZ", i); - cmd.rc_dz[i] = (uint16_t)param_find(nbuf); + param_get(param_find(nbuf), &val); + cfg.rc_dz[i] = (uint16_t)val; } - - ret = hx_stream_send(_io_stream, &cmd, sizeof(cmd)); - - if (ret) - debug("send error %d", ret); -} - -void -PX4IO::config_send() -{ - px4io_config cfg; - int ret; - - cfg.f2i_config_magic = F2I_CONFIG_MAGIC; ret = hx_stream_send(_io_stream, &cfg, sizeof(cfg)); |