mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-27 10:13:57 -04:00
AP_Relay: allow for no relay pin
This commit is contained in:
parent
3a762f891e
commit
5923808526
@ -17,35 +17,50 @@ extern const AP_HAL::HAL& hal;
|
|||||||
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
||||||
#define RELAY_PIN 26
|
#define RELAY_PIN 26
|
||||||
#else
|
#else
|
||||||
#error "no RELAY_PIN defined for this board"
|
// no relay for this board
|
||||||
|
#define RELAY_PIN -1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void AP_Relay::init() {
|
void AP_Relay::init() {
|
||||||
|
#if RELAY_PIN != -1
|
||||||
hal.gpio->pinMode(RELAY_PIN, GPIO_OUTPUT);
|
hal.gpio->pinMode(RELAY_PIN, GPIO_OUTPUT);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AP_Relay::on() {
|
void AP_Relay::on() {
|
||||||
|
#if RELAY_PIN != -1
|
||||||
hal.gpio->write(RELAY_PIN, 1);
|
hal.gpio->write(RELAY_PIN, 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AP_Relay::off() {
|
void AP_Relay::off() {
|
||||||
|
#if RELAY_PIN != -1
|
||||||
hal.gpio->write(RELAY_PIN, 0);
|
hal.gpio->write(RELAY_PIN, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AP_Relay::toggle() {
|
void AP_Relay::toggle() {
|
||||||
|
#if RELAY_PIN != -1
|
||||||
bool ison = hal.gpio->read(RELAY_PIN);
|
bool ison = hal.gpio->read(RELAY_PIN);
|
||||||
if (ison)
|
if (ison)
|
||||||
off();
|
off();
|
||||||
else
|
else
|
||||||
on();
|
on();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AP_Relay::set(bool status){
|
void AP_Relay::set(bool status){
|
||||||
|
#if RELAY_PIN != -1
|
||||||
hal.gpio->write(RELAY_PIN, status);
|
hal.gpio->write(RELAY_PIN, status);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AP_Relay::get() {
|
bool AP_Relay::get() {
|
||||||
|
#if RELAY_PIN != -1
|
||||||
return hal.gpio->read(RELAY_PIN);
|
return hal.gpio->read(RELAY_PIN);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user