Skip to content

Commit

Permalink
Merge pull request #53 from pupil-labs/event_sensor
Browse files Browse the repository at this point in the history
Support "event" sensor and sending "events" to the host
  • Loading branch information
papr authored Jan 29, 2020
2 parents fb2ad72 + efb5399 commit 37364aa
Show file tree
Hide file tree
Showing 11 changed files with 1,069 additions and 706 deletions.
754 changes: 404 additions & 350 deletions examples/glfw.py

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions examples/ndsi-client-example.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import logging, time, signal, sys

logging.basicConfig(
format='%(asctime)s [%(levelname)8s | %(name)-14s] %(message)s',
datefmt='%H:%M:%S',
level=logging.DEBUG
format="%(asctime)s [%(levelname)8s | %(name)-14s] %(message)s",
datefmt="%H:%M:%S",
level=logging.DEBUG,
)
logger = logging.getLogger(__name__)
logging.getLogger('pyre').setLevel(logging.WARNING)
logging.getLogger("pyre").setLevel(logging.WARNING)

import ndsi

sensors = {}


def on_sensor_event(sensor, event):
logger.debug('%s [%s] %s %s'%(sensor, event['seq'], event['subject'], event['control_id']))
logger.debug(
"%s [%s] %s %s" % (sensor, event["seq"], event["subject"], event["control_id"])
)


def on_network_event(network, event):
if event['subject'] == 'attach':
sensor = network.sensor(event['sensor_uuid'], callbacks=(on_sensor_event,))
logger.debug('Linking sensor %s...'%sensor)
sensors[event['sensor_uuid']] = sensor
if event['subject'] == 'detach':
logger.debug('Unlinking sensor %s...'%event['sensor_uuid'])
sensors[event['sensor_uuid']].unlink()
del sensors[event['sensor_uuid']]
if event["subject"] == "attach":
sensor = network.sensor(event["sensor_uuid"], callbacks=(on_sensor_event,))
logger.debug("Linking sensor %s..." % sensor)
sensors[event["sensor_uuid"]] = sensor
if event["subject"] == "detach":
logger.debug("Unlinking sensor %s..." % event["sensor_uuid"])
sensors[event["sensor_uuid"]].unlink()
del sensors[event["sensor_uuid"]]


n = ndsi.Network(callbacks=(on_network_event,))
n.start()
Expand All @@ -34,7 +40,7 @@ def on_network_event(network, event):
for s in sensors.values():
if s.has_notifications:
s.handle_notification()
time.sleep(.1)
time.sleep(0.1)
except (KeyboardInterrupt, SystemExit):
n.stop()
sys.exit()
sys.exit()
Loading

0 comments on commit 37364aa

Please sign in to comment.