Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions oculus_reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def __init__(self,
port = 5555,
APK_name='com.rail.oculus.teleop',
print_FPS=False,
run=True
run=True,
callback=None,
):
self.running = False
self.last_transforms = {}
Expand All @@ -32,6 +33,7 @@ def __init__(self,
self.port = port
self.APK_name = APK_name
self.print_FPS = print_FPS
self.callback = callback
if self.print_FPS:
self.fps_counter = FPSCounter()

Expand All @@ -46,7 +48,7 @@ def __del__(self):
def run(self):
self.running = True
self.device.shell('am start -n "com.rail.oculus.teleop/com.rail.oculus.teleop.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER')
self.thread = threading.Thread(target=self.device.shell, args=("logcat -T 0", self.read_logcat_by_line))
self.thread = threading.Thread(target=self.device.shell, args=("logcat", self.read_logcat_by_line))
self.thread.start()

def stop(self):
Expand Down Expand Up @@ -191,6 +193,8 @@ def read_logcat_by_line(self, connection):
transforms, buttons = OculusReader.process_data(data)
with self._lock:
self.last_transforms, self.last_buttons = transforms, buttons
if self.callback:
self.callback(transforms, buttons)
if self.print_FPS:
self.fps_counter.getAndPrintFPS()
except UnicodeDecodeError:
Expand All @@ -200,11 +204,19 @@ def read_logcat_by_line(self, connection):


def main():
oculus_reader = OculusReader()
import atexit

while True:
time.sleep(0.3)
print(oculus_reader.get_transformations_and_buttons())
def on_frame(transforms, buttons):
print(f"right:\n{transforms.get('r')}\nleft:\n{transforms.get('l')}\nbuttons: {buttons}")

reader = OculusReader(print_FPS=True, callback=on_frame)

atexit.register(reader.stop)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
reader.stop()


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
version='1.0.0',
packages=['oculus_reader'],
license='Apache-2.0 License',
long_description=open('README.md').read(),
long_description=open('README.md', encoding='utf-8').read(),
install_requires=[
'numpy', 'pure-python-adb'
],
Expand Down