diff --git a/libraries/AP_EPM/AP_EPM.cpp b/libraries/AP_EPM/AP_EPM.cpp new file mode 100644 index 0000000000..67cba3a336 --- /dev/null +++ b/libraries/AP_EPM/AP_EPM.cpp @@ -0,0 +1,84 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- + +/* + * AP_EPM.cpp + * + * Created on: DEC 6, 2013 + * Author: Andreas Jochum + */ + +#include +#include "AP_EPM.h" + +extern const AP_HAL::HAL& hal; + +const AP_Param::GroupInfo AP_EPM::var_info[] PROGMEM = { + // @Param: ENABLE + // @DisplayName: EPM Enable/Disable + // @Description: EPM enable/disable. Note enabling will disable the external LEDs on the APM2 + // @User: Standard + // @Values: 0:Disabled, 1:Enabled + AP_GROUPINFO("ENABLE", 0, AP_EPM, _enabled, 0), + + AP_GROUPEND +}; + +AP_EPM::AP_EPM(void) +{ + AP_Param::setup_object_defaults(this, var_info); +} + +void AP_EPM::init() +{ + // return immediately if not enabled + if (!_enabled || !EPM_SUPPORTED) { + return; + } + + hal.gpio->pinMode(EPM_PIN_1, GPIO_OUTPUT); + hal.gpio->pinMode(EPM_PIN_2, GPIO_OUTPUT); + + neutral(); +} + +bool AP_EPM::enabled() +{ + if (!EPM_SUPPORTED) { + return false; + } + + return _enabled; +} + +void AP_EPM::on() +{ + // return immediately if not enabled + if (!_enabled || !EPM_SUPPORTED) { + return; + } + + hal.gpio->write(EPM_PIN_1, 1); + hal.gpio->write(EPM_PIN_2, 0); +} + +void AP_EPM::off() +{ + // return immediately if not enabled + if (!_enabled || !EPM_SUPPORTED) { + return; + } + + hal.gpio->write(EPM_PIN_1, 0); + hal.gpio->write(EPM_PIN_2, 1); +} + +void AP_EPM::neutral() +{ + // return immediately if not enabled + if (!_enabled || !EPM_SUPPORTED) { + return; + } + + hal.gpio->write(EPM_PIN_1, 0); + hal.gpio->write(EPM_PIN_2, 0); +} diff --git a/libraries/AP_EPM/AP_EPM.h b/libraries/AP_EPM/AP_EPM.h new file mode 100644 index 0000000000..ccb39a8d33 --- /dev/null +++ b/libraries/AP_EPM/AP_EPM.h @@ -0,0 +1,66 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- + +/* + * AP_EPM.h + * + * Created on: DEC 06, 2013 + * Author: Andreas Jochum + */ + +/// @file AP_EPM.h +/// @brief AP_EPM control class + +#ifndef __AP_EPM_h__ +#define __AP_EPM_h__ + +#include +#include +#include + +#if CONFIG_HAL_BOARD == HAL_BOARD_APM2 + #define EPM_PIN_1 61 // On pin - AN7 + #define EPM_PIN_2 62 // Off pin - AN8 + #define EPM_SUPPORTED true +#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1 + #define EPM_PIN_1 -1 // to be determine + #define EPM_PIN_2 -1 // to be determine + #define EPM_SUPPORTED false +#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4 + #define EPM_PIN_1 -1 // to be determine + #define EPM_PIN_2 -1 // to be determine + #define EPM_SUPPORTED false +#else + #define EPM_PIN_1 -1 // not supported + #define EPM_PIN_2 -1 // not supported + #define EPM_SUPPORTED false +#endif + +/// @class AP_EPM +/// @brief Class to manage the EPM_CargoGripper +class AP_EPM { +public: + AP_EPM(); + + // setup the epm pins + void init(); + + // enabled - true if the epm is enabled + bool enabled(); + + // activate the EPM + void on(); + + // de-activate the EPM + void off(); + + // do nothing + void neutral(); + + static const struct AP_Param::GroupInfo var_info[]; + +private: + AP_Int8 _enabled; + +}; + +#endif /* _AP_EPM_H_ */