mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 10:28:52 +08:00
RPMCapture: refactor to clarify when an interrupt happened
This commit is contained in:
@@ -107,11 +107,11 @@ void RPMCapture::Run()
|
||||
|
||||
hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
if (!_value_processed.load()) {
|
||||
if (_interrupt_happened.load()) {
|
||||
// There was an interrupt
|
||||
_period = _hrt_timestamp - _hrt_timestamp_prev;
|
||||
_hrt_timestamp_prev = _hrt_timestamp;
|
||||
_value_processed.store(true);
|
||||
_interrupt_happened.store(false);
|
||||
|
||||
pwm_input_s pwm_input{};
|
||||
pwm_input.timestamp = now;
|
||||
@@ -157,12 +157,12 @@ int RPMCapture::gpio_interrupt_callback(int irq, void *context, void *arg)
|
||||
{
|
||||
RPMCapture *instance = static_cast<RPMCapture *>(arg);
|
||||
|
||||
if (!instance->_value_processed.load()) {
|
||||
if (instance->_interrupt_happened.load()) {
|
||||
++instance->_error_count;
|
||||
}
|
||||
|
||||
instance->_hrt_timestamp = hrt_absolute_time();
|
||||
instance->_value_processed.store(false);
|
||||
instance->_interrupt_happened.store(true);
|
||||
instance->ScheduleNow();
|
||||
|
||||
return PX4_OK;
|
||||
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
hrt_abstime _hrt_timestamp_prev{0};
|
||||
uint32_t _period{UINT32_MAX};
|
||||
uint32_t _error_count{0};
|
||||
px4::atomic<bool> _value_processed{true};
|
||||
px4::atomic<bool> _interrupt_happened{false};
|
||||
|
||||
hrt_abstime _timestamp_last_update{0}; ///< to caluclate dt
|
||||
AlphaFilter<float> _rpm_filter;
|
||||
|
||||
Reference in New Issue
Block a user