Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions ArduSub/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,3 +980,50 @@ void Sub::update_lights_from_rcin()
}
}
}

#if LEAKDETECTOR_MAX_INSTANCES > 0

void Sub::update_leak_pins() {
for (uint8_t instance = 0; instance < LEAKDETECTOR_MAX_INSTANCES; instance++) {
if (leak_detector.get_pin(instance) > 0) {
uint8_t servo_channel;
if (hal.gpio->pin_to_servo_channel(leak_detector.get_pin(instance), servo_channel)) {
if (!SRV_Channels::is_GPIO(servo_channel)) {
char param_name[20];
if (SRV_Channels::channel_function(servo_channel) == SRV_Channel::Aux_servo_function_t::k_none) {
gcs().send_text(MAV_SEVERITY_INFO, "Leak detector %u pin (servo %u) auto-set to GPIO", instance + 1, servo_channel + 1);
snprintf(param_name, sizeof(param_name), "SERVO%u_FUNCTION", servo_channel + 1);
AP_Param::set_and_save_by_name(param_name, static_cast<int>(SRV_Channel::Aux_servo_function_t::k_GPIO));
}
else {
gcs().send_text(MAV_SEVERITY_WARNING, "Leak detector %u error. Please set SERVO%u_FUNCTION to GPIO", instance + 1, servo_channel + 1);
}
}
}
}
}
}
#endif

#if AP_RELAY_ENABLED
void Sub::update_relay_pins() {
for (uint8_t instance = 0; instance < AP_RELAY_NUM_RELAYS; instance++) {
if (relay.get_gpio_pin(instance) > 0) {
uint8_t servo_channel;
if (hal.gpio->pin_to_servo_channel(relay.get_gpio_pin(instance), servo_channel)) {
if (relay.enabled(instance) && !SRV_Channels::is_GPIO(servo_channel)) {
if (SRV_Channels::channel_function(servo_channel) == SRV_Channel::Aux_servo_function_t::k_none) {
gcs().send_text(MAV_SEVERITY_INFO, "Relay %u pin (servo %u) auto-set to GPIO", instance + 1, servo_channel + 1);
char param_name[20];
snprintf(param_name, sizeof(param_name), "SERVO%u_FUNCTION", servo_channel + 1);
AP_Param::set_and_save_by_name(param_name, static_cast<int>(SRV_Channel::Aux_servo_function_t::k_GPIO));
}
else {
gcs().send_text(MAV_SEVERITY_WARNING, "Relay %u error. Please set SERVO%u_FUNCTION to GPIO", instance + 1, servo_channel + 1);
}
}
}
}
}
}
#endif
6 changes: 6 additions & 0 deletions ArduSub/Sub.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,12 @@ class Sub : public AP_Vehicle {
void convert_old_parameters(void);
void update_actuators_from_jsbuttons();
void update_lights_from_rcin();
#if LEAKDETECTOR_MAX_INSTANCES > 0
void update_leak_pins();
#endif
#if AP_RELAY_ENABLED
void update_relay_pins();
#endif
bool handle_do_motor_test(mavlink_command_int_t command);
bool init_motor_test();
bool verify_motor_test();
Expand Down
8 changes: 7 additions & 1 deletion ArduSub/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,14 @@ void Sub::init_ardupilot()

g2.actuators.initialize_actuators();

// flag that initialisation has completed
update_lights_from_rcin();
#if LEAKDETECTOR_MAX_INSTANCES > 0
update_leak_pins();
#endif
#if AP_RELAY_ENABLED
update_relay_pins();
#endif
// flag that initialisation has completed
ap.initialised = true;
}

Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_LeakDetector/AP_LeakDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class AP_LeakDetector {
// Update all drivers
bool update(void);

int8_t get_pin(uint8_t instance) const { return _pin[instance]; }

static const struct AP_Param::GroupInfo var_info[];

private:
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Relay/AP_Relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class AP_Relay {
// see if the relay is enabled
bool enabled(AP_Relay_Params::FUNCTION function) const;

int8_t get_gpio_pin(uint8_t instance) const { return _params[instance].pin.get(); }

private:
static AP_Relay *singleton;

Expand Down
Loading