switch from pygame event loop to glib
This commit is contained in:
parent
562497c2df
commit
cd243353a9
21
csc.py
21
csc.py
@ -1,5 +1,6 @@
|
|||||||
import BLE_GATT
|
import BLE_GATT
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
import pdb
|
import pdb
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
@ -121,15 +122,8 @@ csc_measurement = '00002a5b-0000-1000-8000-00805F9B34FB'
|
|||||||
bike.on_value_change(csc_measurement, app.listener.process)
|
bike.on_value_change(csc_measurement, app.listener.process)
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
try:
|
|
||||||
# Time to go live
|
|
||||||
context = bike.mainloop.get_context()
|
|
||||||
|
|
||||||
print("Listening for events...")
|
def handle_pygame_event(event):
|
||||||
while running:
|
|
||||||
time.sleep(0.1)
|
|
||||||
context.iteration(False)
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
if event.type == pygame.KEYUP and event.key == pygame.K_q:
|
if event.type == pygame.KEYUP and event.key == pygame.K_q:
|
||||||
@ -144,7 +138,18 @@ try:
|
|||||||
app.height = event.h
|
app.height = event.h
|
||||||
app.font = None
|
app.font = None
|
||||||
|
|
||||||
|
def on_timer():
|
||||||
|
handle_pygame_event(pygame.event.poll())
|
||||||
app.on_update()
|
app.on_update()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
GLib.timeout_add(100, on_timer)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Time to go live
|
||||||
|
print("Listening for events...")
|
||||||
|
bike.mainloop.run()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
Loading…
Reference in New Issue
Block a user