Skip to content

Commit

Permalink
camera_trigger : cleanup pwm interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkabir committed Apr 7, 2017
1 parent 0f7de7c commit d388078
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 48 deletions.
60 changes: 15 additions & 45 deletions src/drivers/camera_trigger/interfaces/src/pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,10 @@ void CameraInterfacePWM::trigger(bool enable)
return;
}

if (enable) {
// Set all valid pins to shoot level
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
up_pwm_trigger_set(_pins[i + 1], math::constrain(PWM_CAMERA_INSTANT_SHOOT, 1000, 2000));
}
}

} else {
// Set all valid pins back to neutral level
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
up_pwm_trigger_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000));
}
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
// Set all valid pins to shoot or neutral levels
up_pwm_trigger_set(_pins[i + 1], math::constrain(enable ? PWM_CAMERA_INSTANT_SHOOT : PWM_CAMERA_NEUTRAL, 1000, 2000));
}
}
}
Expand All @@ -101,46 +91,26 @@ void CameraInterfacePWM::keep_alive(bool signal_on)
return;
}

if (signal_on) {
// Set channel 2 pin to keep_alive signal
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
up_pwm_trigger_set(_pins[i], math::constrain(PWM_2_CAMERA_KEEP_ALIVE, 1000, 2000));
}
}

} else {
// Set channel 2 pin to neutral signal
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
up_pwm_trigger_set(_pins[i], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000));
}
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
// Set channel 2 pin to keep_alive or netural signal
up_pwm_trigger_set(_pins[i], math::constrain(signal_on ? PWM_2_CAMERA_KEEP_ALIVE : PWM_CAMERA_NEUTRAL, 1000, 2000));
}
}
}

void CameraInterfacePWM::turn_on_off(bool enable)
{
if (enable) {
// For now, set channel one on neutral upon startup.
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
up_pwm_trigger_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000));
up_pwm_trigger_set(_pins[i], math::constrain(PWM_2_CAMERA_ON_OFF, 1000, 2000));
}
}

} else {
// For now, set channel one on neutral upon startup.
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
up_pwm_trigger_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000));
up_pwm_trigger_set(_pins[i], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000));
}
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
// For now, set channel one to neutral upon startup.
up_pwm_trigger_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000));
up_pwm_trigger_set(_pins[i], math::constrain(enable ? PWM_2_CAMERA_ON_OFF : PWM_CAMERA_NEUTRAL, 1000, 2000));
}

_camera_is_on = !_camera_is_on;
}

_camera_is_on = enable;
}

void CameraInterfacePWM::info()
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/stm32/drv_pwm_trigger.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2012, 2017 PX4 Development Team. All rights reserved.
* Copyright (C) 2017 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -80,15 +80,15 @@ int up_pwm_trigger_init(uint32_t channel_mask)
}
}

/* enable the timers */
/* Enable the timers */
up_pwm_trigger_arm(true);

return OK;
}

void up_pwm_trigger_deinit()
{
/* disable the timers */
/* Disable the timers */
up_pwm_trigger_arm(false);

/* Deinit channels */
Expand Down

0 comments on commit d388078

Please sign in to comment.