2011-10-01 19:55:41 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AP_Relay.cpp
|
|
|
|
*
|
|
|
|
* Created on: Oct 2, 2011
|
|
|
|
* Author: Amilcar Lucas
|
|
|
|
*/
|
|
|
|
|
2012-11-30 21:47:32 -04:00
|
|
|
#include <AP_HAL.h>
|
2011-10-01 19:55:41 -03:00
|
|
|
#include "AP_Relay.h"
|
|
|
|
|
2012-12-17 11:03:51 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
2012-11-30 21:47:32 -04:00
|
|
|
#define RELAY_PIN 47
|
2013-01-01 19:19:43 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
2013-01-05 17:51:59 -04:00
|
|
|
#define RELAY_PIN 13
|
2013-07-11 00:02:18 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
2014-01-19 21:59:21 -04:00
|
|
|
#ifdef CONFIG_ARCH_BOARD_PX4FMU_V1
|
2013-07-11 00:49:37 -03:00
|
|
|
#define RELAY_PIN 111
|
2012-12-17 11:03:51 -04:00
|
|
|
#else
|
2014-01-19 21:59:21 -04:00
|
|
|
#define RELAY_PIN 54
|
|
|
|
#endif
|
2014-03-31 14:54:43 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
|
|
|
#define RELAY_PIN -1
|
2014-01-19 21:59:21 -04:00
|
|
|
#else
|
2013-01-01 21:51:56 -04:00
|
|
|
// no relay for this board
|
|
|
|
#define RELAY_PIN -1
|
2012-12-17 11:03:51 -04:00
|
|
|
#endif
|
2011-10-01 19:55:41 -03:00
|
|
|
|
2013-06-24 09:39:18 -03:00
|
|
|
const AP_Param::GroupInfo AP_Relay::var_info[] PROGMEM = {
|
|
|
|
// @Param: PIN
|
2014-01-19 21:59:21 -04:00
|
|
|
// @DisplayName: First Relay Pin
|
|
|
|
// @Description: Digital pin number for first relay control. This is the pin used for camera control.
|
|
|
|
// @User: Standard
|
2014-05-15 04:56:19 -03:00
|
|
|
// @Values: -1:Disabled,13:APM2 A9 pin,47:APM1 relay,50:Pixhawk FMU AUX1,51:Pixhawk FMU AUX2,52:Pixhawk FMU AUX3,53:Pixhawk FMU AUX4,54:Pixhawk FMU AUX5,55:Pixhawk FMU AUX6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2
|
2014-01-19 21:59:21 -04:00
|
|
|
AP_GROUPINFO("PIN", 0, AP_Relay, _pin[0], RELAY_PIN),
|
|
|
|
|
|
|
|
// @Param: PIN2
|
|
|
|
// @DisplayName: Second Relay Pin
|
|
|
|
// @Description: Digital pin number for 2nd relay control.
|
|
|
|
// @User: Standard
|
2014-05-15 04:56:19 -03:00
|
|
|
// @Values: -1:Disabled,13:APM2 A9 pin,47:APM1 relay,50:Pixhawk FMU AUX1,51:Pixhawk FMU AUX2,52:Pixhawk FMU AUX3,53:Pixhawk FMU AUX4,54:Pixhawk FMU AUX5,55:Pixhawk FMU AUX6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2
|
2014-01-19 21:59:21 -04:00
|
|
|
AP_GROUPINFO("PIN2", 1, AP_Relay, _pin[1], -1),
|
|
|
|
|
|
|
|
// @Param: PIN3
|
|
|
|
// @DisplayName: Third Relay Pin
|
|
|
|
// @Description: Digital pin number for 3rd relay control.
|
|
|
|
// @User: Standard
|
2014-05-15 04:56:19 -03:00
|
|
|
// @Values: -1:Disabled,13:APM2 A9 pin,47:APM1 relay,50:Pixhawk FMU AUX1,51:Pixhawk FMU AUX2,52:Pixhawk FMU AUX3,53:Pixhawk FMU AUX4,54:Pixhawk FMU AUX5,55:Pixhawk FMU AUX6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2
|
2014-01-19 21:59:21 -04:00
|
|
|
AP_GROUPINFO("PIN3", 2, AP_Relay, _pin[2], -1),
|
|
|
|
|
|
|
|
// @Param: PIN4
|
|
|
|
// @DisplayName: Fourth Relay Pin
|
|
|
|
// @Description: Digital pin number for 4th relay control.
|
2013-06-24 09:39:18 -03:00
|
|
|
// @User: Standard
|
2014-05-15 04:56:19 -03:00
|
|
|
// @Values: -1:Disabled,13:APM2 A9 pin,47:APM1 relay,50:Pixhawk FMU AUX1,51:Pixhawk FMU AUX2,52:Pixhawk FMU AUX3,53:Pixhawk FMU AUX4,54:Pixhawk FMU AUX5,55:Pixhawk FMU AUX6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2
|
2014-01-19 21:59:21 -04:00
|
|
|
AP_GROUPINFO("PIN4", 3, AP_Relay, _pin[3], -1),
|
2012-12-04 19:26:30 -04:00
|
|
|
|
2013-06-24 09:39:18 -03:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
2011-10-01 19:55:41 -03:00
|
|
|
|
|
|
|
|
2013-06-24 09:39:18 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
AP_Relay::AP_Relay(void)
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2011-10-01 19:55:41 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 09:39:18 -03:00
|
|
|
void AP_Relay::init()
|
|
|
|
{
|
2014-01-19 21:59:21 -04:00
|
|
|
for (uint8_t i=0; i<AP_RELAY_NUM_RELAYS; i++) {
|
|
|
|
if (_pin[i].get() != -1) {
|
|
|
|
off(i);
|
|
|
|
}
|
2013-06-24 09:39:18 -03:00
|
|
|
}
|
2012-11-30 21:47:32 -04:00
|
|
|
}
|
|
|
|
|
2014-01-19 21:59:21 -04:00
|
|
|
void AP_Relay::on(uint8_t relay)
|
2013-06-24 09:39:18 -03:00
|
|
|
{
|
2014-01-19 21:59:21 -04:00
|
|
|
if (relay < AP_RELAY_NUM_RELAYS && _pin[relay] != -1) {
|
2014-06-01 20:27:15 -03:00
|
|
|
hal.gpio->pinMode(_pin[relay], HAL_GPIO_OUTPUT);
|
2014-01-19 21:59:21 -04:00
|
|
|
hal.gpio->write(_pin[relay], 1);
|
2013-06-24 09:39:18 -03:00
|
|
|
}
|
2011-10-01 19:55:41 -03:00
|
|
|
}
|
|
|
|
|
2013-06-24 09:39:18 -03:00
|
|
|
|
2014-01-19 21:59:21 -04:00
|
|
|
void AP_Relay::off(uint8_t relay)
|
2013-06-24 09:39:18 -03:00
|
|
|
{
|
2014-01-19 21:59:21 -04:00
|
|
|
if (relay < AP_RELAY_NUM_RELAYS && _pin[relay] != -1) {
|
2014-06-01 20:27:15 -03:00
|
|
|
hal.gpio->pinMode(_pin[relay], HAL_GPIO_OUTPUT);
|
2014-01-19 21:59:21 -04:00
|
|
|
hal.gpio->write(_pin[relay], 0);
|
2013-06-24 09:39:18 -03:00
|
|
|
}
|
2011-10-01 19:55:41 -03:00
|
|
|
}
|
2013-06-24 09:39:18 -03:00
|
|
|
|
|
|
|
|
2014-01-19 21:59:21 -04:00
|
|
|
void AP_Relay::toggle(uint8_t relay)
|
2013-06-24 09:39:18 -03:00
|
|
|
{
|
2014-01-19 21:59:21 -04:00
|
|
|
if (relay < AP_RELAY_NUM_RELAYS && _pin[relay] != -1) {
|
|
|
|
bool ison = hal.gpio->read(_pin[relay]);
|
2013-06-24 09:39:18 -03:00
|
|
|
if (ison)
|
2014-01-19 21:59:21 -04:00
|
|
|
off(relay);
|
2013-06-24 09:39:18 -03:00
|
|
|
else
|
2014-01-19 21:59:21 -04:00
|
|
|
on(relay);
|
2013-06-24 09:39:18 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|