diff --git a/ArduPlane/ArduPlane.pde b/ArduPlane/ArduPlane.pde index 00a4bda8aa..9bb147ce3e 100644 --- a/ArduPlane/ArduPlane.pde +++ b/ArduPlane/ArduPlane.pde @@ -41,6 +41,7 @@ version 2.1 of the License, or (at your option) any later version. #include // RC Channel Library #include // Range finder library #include +#include // APM relay #include // MAVLink GCS definitions #include @@ -400,6 +401,7 @@ static unsigned long dTnav; // Delta Time in milliseconds for navigation c static float load; // % MCU cycles used RC_Channel_aux* g_rc_function[RC_Channel_aux::k_nr_aux_servo_functions]; // the aux. servo ch. assigned to each function +AP_Relay relay; //////////////////////////////////////////////////////////////////////////////// // Top-level logic diff --git a/ArduPlane/commands_logic.pde b/ArduPlane/commands_logic.pde index 3c4693d140..8f73520e31 100644 --- a/ArduPlane/commands_logic.pde +++ b/ArduPlane/commands_logic.pde @@ -483,11 +483,11 @@ static void do_set_servo() static void do_set_relay() { if (next_command.p1 == 1) { - relay_on(); + relay.on(); } else if (next_command.p1 == 0) { - relay_off(); + relay.off(); }else{ - relay_toggle(); + relay.toggle(); } } diff --git a/ArduPlane/events.pde b/ArduPlane/events.pde index d5eb2ae9fe..0dd7435406 100644 --- a/ArduPlane/events.pde +++ b/ArduPlane/events.pde @@ -104,23 +104,7 @@ static void update_events(void) // Used for MAV_CMD_DO_REPEAT_SERVO and MAV_CMD_ } if (event_id == RELAY_TOGGLE) { - relay_toggle(); + relay.toggle(); } } } - -static void relay_on() -{ - PORTL |= B00000100; -} - -static void relay_off() -{ - PORTL &= ~B00000100; -} - -static void relay_toggle() -{ - PORTL ^= B00000100; -} - diff --git a/libraries/AP_Relay/AP_Relay.cpp b/libraries/AP_Relay/AP_Relay.cpp new file mode 100644 index 0000000000..f57a74b503 --- /dev/null +++ b/libraries/AP_Relay/AP_Relay.cpp @@ -0,0 +1,46 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- + +/* + * AP_Relay.cpp + * + * Created on: Oct 2, 2011 + * Author: Amilcar Lucas + */ + +#include +#include "wiring.h" + +#include "AP_Relay.h" + +void AP_Relay::on() +{ + PORTL |= B00000100; +} + + +void AP_Relay::off() +{ + PORTL &= ~B00000100; +} + + +void AP_Relay::toggle() +{ + PORTL ^= B00000100; +} + + +void AP_Relay::set(bool status) +{ + if (status) + on(); + else + off(); +} + + +bool AP_Relay::get() +{ + // TODO get the relay status + return false; +} diff --git a/libraries/AP_Relay/AP_Relay.h b/libraries/AP_Relay/AP_Relay.h new file mode 100644 index 0000000000..a69c10edcf --- /dev/null +++ b/libraries/AP_Relay/AP_Relay.h @@ -0,0 +1,37 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- + +/* + * AP_Relay.h + * + * Created on: Oct 2, 2011 + * Author: Amilcar Lucas + */ + +/// @file AP_Relay.h +/// @brief APM relay control class + +#ifndef AP_RELAY_H_ +#define AP_RELAY_H_ + +/// @class AP_Relay +/// @brief Class to manage the APM relay +class AP_Relay{ +public: + // activate the relay + void on(); + + // de-activate the relay + void off(); + + // toggle the relay status + void toggle(); + + // set the relay status (on/off) + void set(bool status); + + // get the relay status (on/off) + bool get(); +}; + + +#endif /* AP_RELAY_H_ */