APM_OBC: ensure pins are setup as outputs

constructor is run before parameters are loaded
This commit is contained in:
Andrew Tridgell 2012-08-25 15:02:21 +10:00
parent ecc6a52904
commit 747a926809
2 changed files with 14 additions and 6 deletions

View File

@ -74,6 +74,10 @@ APM_OBC::check(APM_OBC::control_mode mode,
// mode. This tells it to pass through controls from the
// receiver
if (_manual_pin != -1) {
if (_manual_pin != _last_manual_pin) {
pinMode(_manual_pin, OUTPUT);
_last_manual_pin = _manual_pin;
}
digitalWrite(_manual_pin, mode==OBC_MANUAL);
}
@ -146,6 +150,10 @@ APM_OBC::check(APM_OBC::control_mode mode,
// if we are not terminating then toggle the heartbeat pin at 10Hz
if (!_terminate && _heartbeat_pin != -1) {
if (_heartbeat_pin != _last_heartbeat_pin) {
pinMode(_heartbeat_pin, OUTPUT);
_last_heartbeat_pin = _heartbeat_pin;
}
_heartbeat_pin_value = !_heartbeat_pin_value;
digitalWrite(_heartbeat_pin, _heartbeat_pin_value);
}

View File

@ -34,12 +34,8 @@ public:
// Constructor
APM_OBC(void)
{
if (_heartbeat_pin != -1) {
pinMode(_heartbeat_pin, OUTPUT);
}
if (_manual_pin != -1) {
pinMode(_manual_pin, OUTPUT);
}
_last_heartbeat_pin = -1;
_last_manual_pin = -1;
_state = STATE_PREFLIGHT;
_terminate.set(0);
@ -64,6 +60,10 @@ private:
AP_Int8 _manual_pin;
AP_Int8 _terminate;
// last pins to cope with changing at runtime
int8_t _last_heartbeat_pin;
int8_t _last_manual_pin;
// waypoint numbers to jump to on failsafe conditions
AP_Int8 _wp_comms_hold;
AP_Int8 _wp_gps_loss;