diff --git a/libraries/AP_Relay/AP_Relay.cpp b/libraries/AP_Relay/AP_Relay.cpp index b236bd886f..d9f3effc32 100644 --- a/libraries/AP_Relay/AP_Relay.cpp +++ b/libraries/AP_Relay/AP_Relay.cpp @@ -7,43 +7,37 @@ * Author: Amilcar Lucas */ -#include -#if defined(ARDUINO) && ARDUINO >= 100 - #include "Arduino.h" -#else - #include "wiring.h" -#endif - +#include #include "AP_Relay.h" -void AP_Relay::on() -{ - PORTL |= B00000100; +extern const AP_HAL::HAL& hal; + +#define RELAY_PIN 47 + +void AP_Relay::on() { + hal.gpio->write(RELAY_PIN, 1); } -void AP_Relay::off() -{ - PORTL &= ~B00000100; +void AP_Relay::off() { + hal.gpio->write(RELAY_PIN, 0); } -void AP_Relay::toggle() -{ - PORTL ^= B00000100; -} - - -void AP_Relay::set(bool status) -{ - if (status) - on(); - else +void AP_Relay::toggle() { + bool ison = hal.gpio->read(RELAY_PIN); + if (ison) off(); + else + on(); } -bool AP_Relay::get() -{ - return PORTL & B00000100; +void AP_Relay::set(bool status){ + hal.gpio->write(RELAY_PIN, status); +} + + +bool AP_Relay::get() { + return hal.gpio->read(RELAY_PIN); } diff --git a/libraries/AP_Relay/AP_Relay.h b/libraries/AP_Relay/AP_Relay.h index 5b73410ed8..a04e4de220 100644 --- a/libraries/AP_Relay/AP_Relay.h +++ b/libraries/AP_Relay/AP_Relay.h @@ -10,8 +10,8 @@ /// @file AP_Relay.h /// @brief APM relay control class -#ifndef AP_RELAY_H_ -#define AP_RELAY_H_ +#ifndef __AP_RELAY_H__ +#define __AP_RELAY_H__ /// @class AP_Relay /// @brief Class to manage the APM relay