Skip to content

Commit

Permalink
Fixed seniority with events
Browse files Browse the repository at this point in the history
  • Loading branch information
ddetommaso committed Dec 15, 2021
1 parent 4c2c64b commit 82aabe4
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 152 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PROJECT_NAME=hidman
RELEASE_TAG=v0.9
DOCKER_SRC=iitschri/ubuntu20.04-docker:2021.12.1
32 changes: 0 additions & 32 deletions .github/workflows/build.yml

This file was deleted.

5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ ARG DOCKER_SRC
FROM ${DOCKER_SRC}
LABEL maintainer="Davide De Tommaso <davide.detommaso@iit.it>"

USER root

RUN apt-get update
RUN apt-get install -y python3-pip

USER docky
RUN python3 -m pip install --upgrade pip

WORKDIR /usr/local/src/

COPY . hidman

RUN cd hidman && pip3 install .
23 changes: 0 additions & 23 deletions apps/device.yml

This file was deleted.

18 changes: 0 additions & 18 deletions apps/latency_test.yml

This file was deleted.

34 changes: 13 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
version: '3.7'
version: '3.8'

x-hidmanbase: &hidman-base

build:
context: .
dockerfile: Dockerfile
args:
DOCKER_SRC: python:3.8
services:

volumes:
- type: bind
source: ./
target: /usr/local/src/hidman
main:
image: ${LOCAL_DOCKER_IMAGE}

image: iitschri/hidman:latest
environment:
- PROJECT_NAME=${PROJECT_NAME}

privileged: true
stdin_open: true
tty: true
network_mode: host
volumes:
- type: bind
source: ./
target: /home/docky/hidman

services:
devices:
- "/dev/input/event18:/dev/input/hidman0"

hidman-dev:
<<: *hidman-base
command: bash
command: terminator
1 change: 1 addition & 0 deletions apps/lsl/.env → examples/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
RELEASE_TAG=v0.8
HIDMAN_DEVICE=/dev/input/event7
15 changes: 15 additions & 0 deletions examples/test_device.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.7'

services:

test-device:
image: iitschri/hidman-docker:${RELEASE_TAG}
command: python3 /home/docky/workdir/examples/device.py

devices:
- ${HIDMAN_DEVICE}:/dev/input/hidman0

volumes:
- type: bind
source: ../workdir
target: /home/docky/workdir
12 changes: 12 additions & 0 deletions examples/test_latency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.7'

services:

test-latency:
image: iitschri/hidman-docker:${RELEASE_TAG}
command: python3 /home/docky/workdir/examples/latency_test.py

volumes:
- type: bind
source: ../workdir
target: /home/docky/workdir
2 changes: 1 addition & 1 deletion hidman/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__authors__ = 'Davide De Tommaso'
__emails__ = 'davide.detommaso@iit.it'
__license__ = 'MIT'
__version__ = '0.8'
__version__ = '0.9'
__description__ = 'A Python based HID (Human Interface Device) events manager'
__requirements__ = ['pytest>=6.2.4', 'evdev>=1.4.0', 'pyzmq>=22.1.0']
15 changes: 9 additions & 6 deletions hidman/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ def readOne(self):
return 0 #virtual event for testing purposes

def waitEvent(self, event_type=None, event_code=None, event_status=None, timeout_ms=None):
t0 = time.perf_counter()
t0 = time.time()
lastReadSeniority = -1
res = None
while res is None:
elapsed_time = (time.perf_counter() - t0)*1000.0
while res is None or lastReadSeniority < 0:
elapsed_time = (time.time() - t0)*1000.0
if not timeout_ms is None:
if timeout_ms <= elapsed_time:
break
event = self.readOne()
if not event is None:
lastReadSeniority = event.timestamp() - t0
res = HIDEvent.parse(event, event_type, event_code, event_status)
time.sleep(HIDDevice.POLLING_TIME_MS/1000.0)
return (res, elapsed_time)
Expand Down Expand Up @@ -116,14 +119,14 @@ def __init__(self, address="ipc://pyboard"):
self._socket.setsockopt(zmq.SUBSCRIBE, b'')

def waitEvent(self, event_type=None, event_code=None, event_status=None, timeout_ms=None):
t0 = time.perf_counter()
t0 = time.time()
if not timeout_ms is None:
poller = zmq.Poller()
poller.register(self._socket, zmq.POLLIN)
res = None
while res is None:
if not timeout_ms is None:
elapsed_time = (time.perf_counter() - t0)*1000.0
elapsed_time = (time.time() - t0)*1000.0
if timeout_ms <= elapsed_time:
break
elif poller.poll(timeout_ms-elapsed_time):
Expand All @@ -135,7 +138,7 @@ def waitEvent(self, event_type=None, event_code=None, event_status=None, timeout
event = self._socket.recv_pyobj()
res = HIDEvent.parse(event, event_type, event_code, event_status)

return (res, time.perf_counter()-t0)
return (res, time.time()-t0)

def waitKey(self, keyList=None, evstate=None, timeout_ms=None):
return self.waitEvent(event_type=ecodes.EV_KEY, event_code=keyList, event_status=evstate, timeout_ms=timeout_ms)
Expand Down
2 changes: 2 additions & 0 deletions workdir/apps/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RELEASE_TAG=v0.8
HIDMAN_DEVICE=/dev/input/event7
19 changes: 2 additions & 17 deletions apps/client_server.yml → workdir/apps/client_server.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
version: '3.7'

x-hidmanbase: &hidman-base

volumes:
- type: bind
source: ../
target: /usr/local/src/hidman

image: iitschri/hidman:latest

privileged: true
stdin_open: true
tty: true
network_mode: host

services:

hidman-server:
<<: *hidman-base
image: iitschri/hidman:${RELEASE_TAG}
command: python3 /usr/local/src/hidman/apps/python-examples/server.py
devices:
- ${HIDMAN_DEVICE}:/dev/input/hidman0

hidman-client:
<<: *hidman-base
image: iitschri/hidman:${RELEASE_TAG}
command: python3 /usr/local/src/hidman/apps/python-examples/client.py
depends_on:
- hidman-server
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
version: '3.7'

x-hidmanbase: &hidman-base

volumes:
- type: bind
source: ../
target: /usr/local/src/hidman

image: iitschri/hidman:latest

privileged: true
stdin_open: true
tty: true
network_mode: host

services:

hidman-server:
<<: *hidman-base
image: iitschri/hidman:${RELEASE_TAG}
command: python3 /usr/local/src/hidman/apps/python-examples/server.py
devices:
- ${HIDMAN_DEVICE}:/dev/input/hidman0

hidman-client:
<<: *hidman-base
image: iitschri/hidman:${RELEASE_TAG}
command: python3 /usr/local/src/hidman/apps/python-examples/client_threads.py
depends_on:
- hidman-server
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
version: '3.7'

x-hidmanbase: &hidman-base

volumes:
- type: bind
source: ../
target: /usr/local/src/hidman

image: iitschri/hidman:latest

privileged: true
stdin_open: true
tty: true
network_mode: host

services:

hidman-server:
<<: *hidman-base
image: iitschri/hidman:${RELEASE_TAG}
command: python3 /usr/local/src/hidman/apps/python-examples/server.py
devices:
- ${HIDMAN_DEVICE}:/dev/input/hidman0

hidman-client:
<<: *hidman-base
image: iitschri/hidman:${RELEASE_TAG}
command: python3 /usr/local/src/hidman/apps/python-examples/client_timeout.py
depends_on:
- hidman-server
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 82aabe4

Please sign in to comment.