From d9e89eb60289490c39c3ba03ae15f1c9bb6e446e Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 6 Jun 2023 18:05:07 +1000 Subject: [PATCH] ArduSub: add option to disable relay and servorelay libraries --- ArduSub/ArduSub.cpp | 2 ++ ArduSub/Parameters.cpp | 2 ++ ArduSub/joystick.cpp | 8 ++++++++ ArduSub/system.cpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/ArduSub/ArduSub.cpp b/ArduSub/ArduSub.cpp index 4ccc431fa3..7c231a071a 100644 --- a/ArduSub/ArduSub.cpp +++ b/ArduSub/ArduSub.cpp @@ -252,7 +252,9 @@ void Sub::three_hz_loop() fence_check(); #endif // AP_FENCE_ENABLED +#if AP_SERVORELAYEVENTS_ENABLED ServoRelayEvents.update_events(); +#endif } // one_hz_loop - runs at 1Hz diff --git a/ArduSub/Parameters.cpp b/ArduSub/Parameters.cpp index 75afeb22ca..a856205233 100644 --- a/ArduSub/Parameters.cpp +++ b/ArduSub/Parameters.cpp @@ -409,9 +409,11 @@ const AP_Param::Info Sub::var_info[] = { GOBJECT(camera, "CAM", AP_Camera), #endif +#if AP_RELAY_ENABLED // @Group: RELAY_ // @Path: ../libraries/AP_Relay/AP_Relay.cpp GOBJECT(relay, "RELAY_", AP_Relay), +#endif // @Group: COMPASS_ // @Path: ../libraries/AP_Compass/AP_Compass.cpp diff --git a/ArduSub/joystick.cpp b/ArduSub/joystick.cpp index bbbd19c346..baf5874053 100644 --- a/ArduSub/joystick.cpp +++ b/ArduSub/joystick.cpp @@ -359,6 +359,7 @@ void Sub::handle_jsbutton_press(uint8_t _button, bool shift, bool held) controls_reset_since_input_hold = !input_hold_engaged; } break; +#if AP_RELAY_ENABLED case JSButton::button_function_t::k_relay_1_on: relay.on(0); break; @@ -423,10 +424,12 @@ void Sub::handle_jsbutton_press(uint8_t _button, bool shift, bool held) relay.on(3); } break; +#endif //////////////////////////////////////////////// // Servo functions // TODO: initialize +#if AP_SERVORELAYEVENTS_ENABLED case JSButton::button_function_t::k_servo_1_inc: { SRV_Channel* chan = SRV_Channels::srv_channel(SERVO_CHAN_1 - 1); // 0-indexed @@ -557,6 +560,7 @@ void Sub::handle_jsbutton_press(uint8_t _button, bool shift, bool held) ServoRelayEvents.do_set_servo(SERVO_CHAN_3, chan->get_trim()); // 1-indexed } break; +#endif // AP_SERVORELAYEVENTS_ENABLED case JSButton::button_function_t::k_roll_pitch_toggle: if (!held) { @@ -595,6 +599,7 @@ void Sub::handle_jsbutton_release(uint8_t _button, bool shift) { // Act based on the function assigned to this button switch (get_button(_button)->function(shift)) { +#if AP_RELAY_ENABLED case JSButton::button_function_t::k_relay_1_momentary: relay.off(0); break; @@ -607,6 +612,8 @@ void Sub::handle_jsbutton_release(uint8_t _button, bool shift) { case JSButton::button_function_t::k_relay_4_momentary: relay.off(3); break; +#endif +#if AP_SERVORELAYEVENTS_ENABLED case JSButton::button_function_t::k_servo_1_min_momentary: case JSButton::button_function_t::k_servo_1_max_momentary: { @@ -628,6 +635,7 @@ void Sub::handle_jsbutton_release(uint8_t _button, bool shift) { ServoRelayEvents.do_set_servo(SERVO_CHAN_3, chan->get_trim()); // 1-indexed } break; +#endif } } diff --git a/ArduSub/system.cpp b/ArduSub/system.cpp index d397f73148..f69cbf6976 100644 --- a/ArduSub/system.cpp +++ b/ArduSub/system.cpp @@ -70,7 +70,9 @@ void Sub::init_ardupilot() init_rc_out(); // sets up motors and output to escs init_joystick(); // joystick initialization +#if AP_RELAY_ENABLED relay.init(); +#endif /* * setup the 'main loop is dead' check. Note that this relies on