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
*/
#include <avr/io.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "wiring.h"
#endif
#include <AP_HAL.h>
#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);
}

View File

@ -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