@@ -28,6 +28,7 @@ public static partial class M5Core2
2828 private static Thread _callbackThread ;
2929 private static CancellationTokenSource _cancelThread ;
3030 private static CancellationTokenSource _startThread ;
31+ private static Point _lastPoint ;
3132
3233 /// <summary>
3334 /// Touch event handler for the touch event.
@@ -111,6 +112,8 @@ public static void InitializeScreen()
111112 Console . Font = Resource . GetFont ( Resource . FontResources . consolas_regular_16 ) ;
112113 _touchController = new ( I2cDevice . Create ( new I2cConnectionSettings ( 1 , Ft6xx6x . DefaultI2cAddress ) ) ) ;
113114 _touchController . SetInterruptMode ( false ) ;
115+ _lastPoint = new ( ) ;
116+ _cancelThread = new ( ) ;
114117 _startThread = new ( ) ;
115118 _callbackThread = new ( ThreadTouchCallback ) ;
116119 _callbackThread . Start ( ) ;
@@ -130,9 +133,13 @@ private static void TouchCallback(object sender, PinValueChangedEventArgs pinVal
130133 {
131134 _startThread = new ( ) ;
132135 _cancelThread . Cancel ( ) ;
133- var point = _touchController . GetPoint ( true ) ;
134- var touchCategory = CheckIfInButtons ( point . X , point . Y , TouchEventCategory . Unknown ) | TouchEventCategory . LiftUp ;
135- TouchEvent ? . Invoke ( _touchController , new TouchEventArgs ( ) { TimeStamp = DateTime . UtcNow , EventCategory = EventCategory . Touch , TouchEventCategory = touchCategory , X = point . X , Y = point . Y , Id = point . TouchId } ) ;
136+ var point = _touchController . GetPoint ( true ) ;
137+ if ( ( _lastPoint . X != point . X ) && ( _lastPoint . Y != point . Y ) )
138+ {
139+ _lastPoint = point ;
140+ var touchCategory = CheckIfInButtons ( point . X , point . Y , TouchEventCategory . Unknown ) | TouchEventCategory . LiftUp ;
141+ TouchEvent ? . Invoke ( _touchController , new TouchEventArgs ( ) { TimeStamp = DateTime . UtcNow , EventCategory = EventCategory . Touch , TouchEventCategory = touchCategory , X = point . X , Y = point . Y , Id = point . TouchId } ) ;
142+ }
136143 }
137144 }
138145
@@ -152,6 +159,7 @@ private static void ThreadTouchCallback()
152159 if ( touchNumber == 1 )
153160 {
154161 var point = _touchController . GetPoint ( true ) ;
162+ _lastPoint = point ;
155163 touchCategory = CheckIfInButtons ( point . X , point . Y , TouchEventCategory . Unknown ) ;
156164 touchCategory = point . Event == Event . Contact ? touchCategory | TouchEventCategory . Moving : touchCategory ;
157165 TouchEvent ? . Invoke ( _touchController , new TouchEventArgs ( ) { TimeStamp = DateTime . UtcNow , EventCategory = EventCategory . Touch , TouchEventCategory = touchCategory , X = point . X , Y = point . Y , Id = point . TouchId } ) ;
0 commit comments