From 447ed18ab4540f357a4c850fad301261733706ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beat=20K=C3=BCng?= <beat-kueng@gmx.net>
Date: Mon, 3 Dec 2018 09:55:31 +0100
Subject: [PATCH] commander: use C API for MC_AIRMODE & RC_MAP_ARM_SW to remove
 multirotor modules dependency

---
 src/modules/commander/Commander.cpp | 18 ++++++++++++++----
 src/modules/commander/Commander.hpp |  5 +----
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp
index 3524ac49bd..590a6f52b3 100644
--- a/src/modules/commander/Commander.cpp
+++ b/src/modules/commander/Commander.cpp
@@ -1200,6 +1200,9 @@ Commander::run()
 	param_t _param_fmode_5 = param_find("COM_FLTMODE5");
 	param_t _param_fmode_6 = param_find("COM_FLTMODE6");
 
+	param_t _param_airmode = param_find("MC_AIRMODE");
+	param_t _param_rc_map_arm_switch = param_find("RC_MAP_ARM_SW");
+
 	/* failsafe response to loss of navigation accuracy */
 	param_t _param_posctl_nav_loss_act = param_find("COM_POSCTL_NAVL");
 
@@ -1391,6 +1394,8 @@ Commander::run()
 	int32_t geofence_action = 0;
 
 	int32_t flight_uuid = 0;
+	int32_t airmode = 0;
+	int32_t rc_map_arm_switch = 0;
 
 	/* RC override auto modes */
 	int32_t rc_override = 0;
@@ -1527,10 +1532,15 @@ Commander::run()
 			param_get(_param_takeoff_finished_action, &takeoff_complete_act);
 
 			/* check for unsafe Airmode settings: yaw airmode requires the use of an arming switch */
-			if (_airmode.get() == 2 && _rc_map_arm_switch.get() == 0) {
-				_airmode.set(1); // change to roll/pitch airmode
-				_airmode.commit();
-				mavlink_log_critical(&mavlink_log_pub, "Yaw Airmode requires the use of an Arm Switch")
+			if (_param_airmode != PARAM_INVALID && _param_rc_map_arm_switch != PARAM_INVALID) {
+				param_get(_param_airmode, &airmode);
+				param_get(_param_rc_map_arm_switch, &rc_map_arm_switch);
+
+				if (airmode == 2 && rc_map_arm_switch == 0) {
+					airmode = 1; // change to roll/pitch airmode
+					param_set(_param_airmode, &airmode);
+					mavlink_log_critical(&mavlink_log_pub, "Yaw Airmode requires the use of an Arm Switch")
+				}
 			}
 
 			param_init_forced = false;
diff --git a/src/modules/commander/Commander.hpp b/src/modules/commander/Commander.hpp
index ad56a8dca7..1cb4d171af 100644
--- a/src/modules/commander/Commander.hpp
+++ b/src/modules/commander/Commander.hpp
@@ -110,10 +110,7 @@ private:
 		(ParamInt<px4::params::COM_POS_FS_GAIN>) _failsafe_pos_gain,
 
 		(ParamInt<px4::params::COM_LOW_BAT_ACT>) _low_bat_action,
-		(ParamFloat<px4::params::COM_DISARM_LAND>) _disarm_when_landed_timeout,
-
-		(ParamInt<px4::params::MC_AIRMODE>) _airmode,
-		(ParamInt<px4::params::RC_MAP_ARM_SW>) _rc_map_arm_switch
+		(ParamFloat<px4::params::COM_DISARM_LAND>) _disarm_when_landed_timeout
 	)
 
 	const int64_t POSVEL_PROBATION_MIN = 1_s;	/**< minimum probation duration (usec) */
-- 
GitLab