Skip to content

Commit 131318a

Browse files
andyp1perpeterbarker
authored andcommitted
RC_Channel: add function to stop or restart scripting
1 parent 7fbdfce commit 131318a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

libraries/RC_Channel/RC_Channel.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern const AP_HAL::HAL& hal;
6060
#include <AP_Torqeedo/AP_Torqeedo.h>
6161
#include <AP_Vehicle/AP_Vehicle_Type.h>
6262
#include <AP_Parachute/AP_Parachute_config.h>
63+
#include <AP_Scripting/AP_Scripting.h>
6364
#define SWITCH_DEBOUNCE_TIME_MS 200
6465

6566
const AP_Param::GroupInfo RC_Channel::var_info[] = {
@@ -259,7 +260,8 @@ const AP_Param::GroupInfo RC_Channel::var_info[] = {
259260
// @Values{Copter, Rover, Plane, Sub}: 212:Mount1 Roll, 213:Mount1 Pitch, 214:Mount1 Yaw, 215:Mount2 Roll, 216:Mount2 Pitch, 217:Mount2 Yaw
260261
// @Values{Copter, Rover, Plane, Blimp, Sub}: 218:Loweheiser throttle
261262
// @Values{Copter}: 219:Transmitter Tuning
262-
// @Values{Copter, Rover, Plane, Sub}: 300:Scripting1, 301:Scripting2, 302:Scripting3, 303:Scripting4, 304:Scripting5, 305:Scripting6, 306:Scripting7, 307:Scripting8, 308:Scripting9, 309:Scripting10, 310:Scripting11, 311:Scripting12, 312:Scripting13, 313:Scripting14, 314:Scripting15, 315:Scripting16
263+
// @Values: 300:Scripting1, 301:Scripting2, 302:Scripting3, 303:Scripting4, 304:Scripting5, 305:Scripting6, 306:Scripting7, 307:Scripting8, 308:Scripting9, 309:Scripting10, 310:Scripting11, 311:Scripting12, 312:Scripting13, 313:Scripting14, 314:Scripting15, 315:Scripting16
264+
// @Values: 316:Stop-Restart Scripting
263265
// @User: Standard
264266
AP_GROUPINFO("OPTION", 6, RC_Channel, option, 0),
265267

@@ -717,6 +719,7 @@ void RC_Channel::init_aux_function(const AUX_FUNC ch_option, const AuxSwitchPos
717719
case AUX_FUNC::SCRIPTING_14:
718720
case AUX_FUNC::SCRIPTING_15:
719721
case AUX_FUNC::SCRIPTING_16:
722+
case AUX_FUNC::STOP_RESTART_SCRIPTING:
720723
#endif
721724
#if AP_VIDEOTX_ENABLED
722725
case AUX_FUNC::VTX_POWER:
@@ -1896,7 +1899,26 @@ bool RC_Channel::do_aux_function(const AuxFuncTrigger &trigger)
18961899
}
18971900
#endif
18981901

1899-
// do nothing for these functions
1902+
#if AP_SCRIPTING_ENABLED
1903+
case AUX_FUNC::STOP_RESTART_SCRIPTING: {
1904+
AP_Scripting *scr = AP::scripting();
1905+
if (scr != nullptr) {
1906+
switch (ch_flag) {
1907+
case AuxSwitchPos::HIGH:
1908+
scr->stop();
1909+
break;
1910+
case AuxSwitchPos::MIDDLE:
1911+
break;
1912+
case AuxSwitchPos::LOW:
1913+
scr->restart_all();
1914+
break;
1915+
}
1916+
}
1917+
break;
1918+
}
1919+
#endif
1920+
1921+
// do nothing for these functions
19001922
#if HAL_MOUNT_ENABLED
19011923
case AUX_FUNC::MOUNT1_ROLL:
19021924
case AUX_FUNC::MOUNT1_PITCH:

libraries/RC_Channel/RC_Channel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,11 @@ class RC_Channel {
416416
SCRIPTING_14 = 313,
417417
SCRIPTING_15 = 314,
418418
SCRIPTING_16 = 315,
419+
STOP_RESTART_SCRIPTING = 316, // emergency scripting disablement
419420
#endif // AP_SCRIPTING_ENABLED
420421

421422
// this must be higher than any aux function above
422-
AUX_FUNCTION_MAX = 316,
423+
AUX_FUNCTION_MAX = 317,
423424
};
424425

425426
// auxiliary switch handling (n.b.: we store this as 2-bits!):

0 commit comments

Comments
 (0)