2011-10-01 19:55:41 -03:00
/*
* AP_Relay . cpp
*
* Created on : Oct 2 , 2011
* Author : Amilcar Lucas
*/
2015-08-11 03:28:45 -03:00
# include <AP_HAL/AP_HAL.h>
2011-10-01 19:55:41 -03:00
# include "AP_Relay.h"
2015-11-03 09:46:30 -04:00
# if CONFIG_HAL_BOARD == HAL_BOARD_SITL
2017-09-27 22:00:38 -03:00
# define RELAY1_PIN_DEFAULT 13
# elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
# if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
# define RELAY1_PIN_DEFAULT 57
# define RELAY2_PIN_DEFAULT 49
# define RELAY3_PIN_DEFAULT 116
# define RELAY4_PIN_DEFAULT 113
# endif
# endif
# ifndef RELAY1_PIN_DEFAULT
# define RELAY1_PIN_DEFAULT -1
2012-12-17 11:03:51 -04:00
# endif
2011-10-01 19:55:41 -03:00
2017-09-27 22:00:38 -03:00
# ifndef RELAY2_PIN_DEFAULT
# define RELAY2_PIN_DEFAULT -1
# endif
# ifndef RELAY3_PIN_DEFAULT
# define RELAY3_PIN_DEFAULT -1
# endif
# ifndef RELAY4_PIN_DEFAULT
# define RELAY4_PIN_DEFAULT -1
# endif
2018-10-03 10:03:49 -03:00
# ifndef RELAY5_PIN_DEFAULT
# define RELAY5_PIN_DEFAULT -1
# endif
# ifndef RELAY6_PIN_DEFAULT
# define RELAY6_PIN_DEFAULT -1
# endif
2017-09-27 22:00:38 -03:00
2015-10-25 14:03:46 -03:00
const AP_Param : : GroupInfo AP_Relay : : var_info [ ] = {
2013-06-24 09:39:18 -03:00
// @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
2019-02-27 01:16:27 -04:00
// @Values: -1:Disabled,49:BB Blue GP0 pin 4,50:AUXOUT1,51:AUXOUT2,52:AUXOUT3,53:AUXOUT4,54:AUXOUT5,55:AUXOUT6,57:BB Blue GP0 pin 3,113:BB Blue GP0 pin 6,116:BB Blue GP0 pin 5
2014-11-15 16:45:12 -04:00
AP_GROUPINFO ( " PIN " , 0 , AP_Relay , _pin [ 0 ] , RELAY1_PIN_DEFAULT ) ,
2014-01-19 21:59:21 -04:00
// @Param: PIN2
// @DisplayName: Second Relay Pin
// @Description: Digital pin number for 2nd relay control.
// @User: Standard
2019-02-27 01:16:27 -04:00
// @Values: -1:Disabled,49:BB Blue GP0 pin 4,50:AUXOUT1,51:AUXOUT2,52:AUXOUT3,53:AUXOUT4,54:AUXOUT5,55:AUXOUT6,57:BB Blue GP0 pin 3,113:BB Blue GP0 pin 6,116:BB Blue GP0 pin 5
2014-11-15 16:45:12 -04:00
AP_GROUPINFO ( " PIN2 " , 1 , AP_Relay , _pin [ 1 ] , RELAY2_PIN_DEFAULT ) ,
2014-01-19 21:59:21 -04:00
// @Param: PIN3
// @DisplayName: Third Relay Pin
// @Description: Digital pin number for 3rd relay control.
// @User: Standard
2019-02-27 01:16:27 -04:00
// @Values: -1:Disabled,49:BB Blue GP0 pin 4,50:AUXOUT1,51:AUXOUT2,52:AUXOUT3,53:AUXOUT4,54:AUXOUT5,55:AUXOUT6,57:BB Blue GP0 pin 3,113:BB Blue GP0 pin 6,116:BB Blue GP0 pin 5
2017-09-27 22:00:38 -03:00
AP_GROUPINFO ( " PIN3 " , 2 , AP_Relay , _pin [ 2 ] , RELAY3_PIN_DEFAULT ) ,
2014-01-19 21:59:21 -04:00
// @Param: PIN4
// @DisplayName: Fourth Relay Pin
// @Description: Digital pin number for 4th relay control.
2013-06-24 09:39:18 -03:00
// @User: Standard
2019-02-27 01:16:27 -04:00
// @Values: -1:Disabled,49:BB Blue GP0 pin 4,50:AUXOUT1,51:AUXOUT2,52:AUXOUT3,53:AUXOUT4,54:AUXOUT5,55:AUXOUT6,57:BB Blue GP0 pin 3,113:BB Blue GP0 pin 6,116:BB Blue GP0 pin 5
2017-09-27 22:00:38 -03:00
AP_GROUPINFO ( " PIN4 " , 3 , AP_Relay , _pin [ 3 ] , RELAY4_PIN_DEFAULT ) ,
2012-12-04 19:26:30 -04:00
2014-09-04 03:45:45 -03:00
// @Param: DEFAULT
// @DisplayName: Default relay state
2017-09-27 22:00:38 -03:00
// @Description: The state of the relay on boot.
2014-09-04 03:45:45 -03:00
// @User: Standard
// @Values: 0:Off,1:On,2:NoChange
AP_GROUPINFO ( " DEFAULT " , 4 , AP_Relay , _default , 0 ) ,
2018-10-03 10:03:49 -03:00
// @Param: PIN5
// @DisplayName: Fifth Relay Pin
// @Description: Digital pin number for 5th relay control.
// @User: Standard
2019-02-27 01:16:27 -04:00
// @Values: -1:Disabled,49:BB Blue GP0 pin 4,50:AUXOUT1,51:AUXOUT2,52:AUXOUT3,53:AUXOUT4,54:AUXOUT5,55:AUXOUT6,57:BB Blue GP0 pin 3,113:BB Blue GP0 pin 6,116:BB Blue GP0 pin 5
2018-10-03 10:03:49 -03:00
AP_GROUPINFO ( " PIN5 " , 5 , AP_Relay , _pin [ 4 ] , RELAY5_PIN_DEFAULT ) ,
// @Param: PIN6
// @DisplayName: Sixth Relay Pin
// @Description: Digital pin number for 6th relay control.
// @User: Standard
2019-02-27 01:16:27 -04:00
// @Values: -1:Disabled,49:BB Blue GP0 pin 4,50:AUXOUT1,51:AUXOUT2,52:AUXOUT3,53:AUXOUT4,54:AUXOUT5,55:AUXOUT6,57:BB Blue GP0 pin 3,113:BB Blue GP0 pin 6,116:BB Blue GP0 pin 5
2018-10-03 10:03:49 -03:00
AP_GROUPINFO ( " PIN6 " , 6 , AP_Relay , _pin [ 5 ] , RELAY6_PIN_DEFAULT ) ,
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 ) {
2014-09-04 03:45:45 -03:00
switch ( _default ) {
case 0 :
off ( i ) ;
break ;
case 1 :
on ( i ) ;
break ;
default :
break ;
}
2014-01-19 21:59:21 -04:00
}
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
}
}