Commit 259b2619 authored by Pavel Vainerman's avatar Pavel Vainerman

(DelayTimer): исправлена ошибка в логике работы!

parent 9e672ef7
...@@ -60,6 +60,8 @@ class DelayTimer ...@@ -60,6 +60,8 @@ class DelayTimer
inline bool check( bool st ) inline bool check( bool st )
{ {
prevState = st;
if( waiting_off ) if( waiting_off )
{ {
if( pt.checkTime() ) if( pt.checkTime() )
...@@ -71,10 +73,9 @@ class DelayTimer ...@@ -71,10 +73,9 @@ class DelayTimer
return state; return state;
} }
else if( st != prevState && !st ) else if( st )
pt.reset(); waiting_off = false;
prevState = st;
return state; return state;
} }
...@@ -89,17 +90,14 @@ class DelayTimer ...@@ -89,17 +90,14 @@ class DelayTimer
return state; return state;
} }
else if( st != prevState && st ) else if( !st )
pt.reset(); waiting_on = false;
prevState = st;
return state; return state;
} }
if( state != st ) if( state != st )
{ {
prevState = st;
if( st ) if( st )
{ {
pt.setTiming(onDelay); pt.setTiming(onDelay);
...@@ -111,8 +109,12 @@ class DelayTimer ...@@ -111,8 +109,12 @@ class DelayTimer
waiting_off = true; waiting_off = true;
} }
// на случае если таймеры = 0..
if( pt.checkTime() ) if( pt.checkTime() )
{
state = st;
return st; return st;
}
} }
return state; return state;
......
...@@ -128,5 +128,14 @@ TEST_CASE("[DelayTimer]: debounce", "[DelayTimer]" ) ...@@ -128,5 +128,14 @@ TEST_CASE("[DelayTimer]: debounce", "[DelayTimer]" )
msleep(40); msleep(40);
CHECK_FALSE( dt.check(false) ); CHECK_FALSE( dt.check(false) );
CHECK_FALSE( dt.get() ); CHECK_FALSE( dt.get() );
// проверяем срабатвание (одноразовый скачок)
CHECK_FALSE( dt.check(true) );
CHECK_FALSE( dt.check(false) );
msleep(160);
CHECK_FALSE( dt.check(true) );
CHECK_FALSE( dt.check(false) );
msleep(160);
CHECK_FALSE( dt.check(false) );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment