From 117d6b852d011e4dc29c580de02a5d01100cdcb2 Mon Sep 17 00:00:00 2001 From: Samathy Barratt Date: Wed, 22 Mar 2017 22:01:00 +0000 Subject: [PATCH] Added method to clear all outstanding events. Clearing the outstanding events is useful if you need to get rid of a button release event in preparation for receiving the next button press event. Since the release event happens after the previous call to wait_for_event() or get_events() it isnt cleared and will appear in the next call to wait_for_event() or get_events(). --- sense_hat/stick.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sense_hat/stick.py b/sense_hat/stick.py index 896a9f8..eeba2b2 100644 --- a/sense_hat/stick.py +++ b/sense_hat/stick.py @@ -197,6 +197,15 @@ def wait_for_event(self, emptybuffer=False): if event: return event + def clear_events(self): + """ + Clear all outstanding events + """ + + while( self._read() != None): + pass + + def get_events(self): """ Returns a list of all joystick events that have occurred since the last