AP_Relay: rewritten for AP_HAL

This commit is contained in:
Pat Hickey 2012-11-30 17:47:32 -08:00 committed by Andrew Tridgell
parent 71a360b3e3
commit f4f3062df1
2 changed files with 23 additions and 29 deletions

View File

@ -7,43 +7,37 @@
* Author: Amilcar Lucas * Author: Amilcar Lucas
*/ */
#include <avr/io.h> #include <AP_HAL.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "wiring.h"
#endif
#include "AP_Relay.h" #include "AP_Relay.h"
void AP_Relay::on() extern const AP_HAL::HAL& hal;
{
PORTL |= B00000100; #define RELAY_PIN 47
void AP_Relay::on() {
hal.gpio->write(RELAY_PIN, 1);
} }
void AP_Relay::off() void AP_Relay::off() {
{ hal.gpio->write(RELAY_PIN, 0);
PORTL &= ~B00000100;
} }
void AP_Relay::toggle() void AP_Relay::toggle() {
{ bool ison = hal.gpio->read(RELAY_PIN);
PORTL ^= B00000100; if (ison)
}
void AP_Relay::set(bool status)
{
if (status)
on();
else
off(); off();
else
on();
} }
bool AP_Relay::get() void AP_Relay::set(bool status){
{ hal.gpio->write(RELAY_PIN, status);
return PORTL & B00000100; }
bool AP_Relay::get() {
return hal.gpio->read(RELAY_PIN);
} }

View File

@ -10,8 +10,8 @@
/// @file AP_Relay.h /// @file AP_Relay.h
/// @brief APM relay control class /// @brief APM relay control class
#ifndef AP_RELAY_H_ #ifndef __AP_RELAY_H__
#define AP_RELAY_H_ #define __AP_RELAY_H__
/// @class AP_Relay /// @class AP_Relay
/// @brief Class to manage the APM relay /// @brief Class to manage the APM relay