Skip to content

Commit

Permalink
Add code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ila-embsys committed Jan 14, 2024
1 parent 1ff9067 commit c6b0395
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/gjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env gjs

const GOpenHMD = imports.gi.GOpenHMD;


function devs_info(context) {
devs = context.enumerate()

for (var i = 0; i < devs.length; i++) {
print("Discovered device:" +
` vendor: '${devs[i].vendor}'` +
` product': '${devs[i].product}'`)
}
}


function dev_quat_info(context, dev) {
context.update();
var quat = dev.rotation_quat();
console.debug(`quat: x=${quat.x}, y=${quat.y}, z=${quat.z}, w=${quat.w}`);
GOpenHMD.sleep(0.01);
}


print(`Version: ${GOpenHMD.version().to_string()}`)

var context = new GOpenHMD.Context();

devs_info(context);

var dev = context.open_device(0, null)

for(var i = 0; i < 300; i++){
dev_quat_info(context, dev)
}
32 changes: 32 additions & 0 deletions examples/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import gi

gi.require_version('GOpenHMD', '1.0')
from gi.repository import GOpenHMD


def devs_info(context):
for dev in context.enumerate():
print(f"Discovered device: vendor '{dev.get_vendor()}'"
f", product '{dev.get_product()}'"
)


def dev_quat_info(context, dev):
context.update()
quat = dev.rotation_quat()
print(f"quat: x={quat.x} y={quat.y} z={quat.z} w={quat.w}")
GOpenHMD.sleep(0.01)


print(f"Version: {GOpenHMD.version().to_string()}")

context = GOpenHMD.Context()

devs_info(context)

dev = context.open_device(0)

for i in range(0, 300):
dev_quat_info(context, dev)

0 comments on commit c6b0395

Please # to comment.