diff --git a/index_old.html b/index_old.html index 46b2b5d..e737afd 100644 --- a/index_old.html +++ b/index_old.html @@ -88,10 +88,10 @@
current brightness: ?

-
-
-
-
+ + + +
@@ -486,7 +486,7 @@ window.sparkline_elements = []; window.onload = async () => { - + /* for(var i = 0; i<41; i++){ let child = document.createElement('div'); child.classList.add('bar'); @@ -524,6 +524,7 @@ document.getElementById('sparklines').append(_sl_wrapper) } + */ if (!Manager?.hidSupported()) { document.getElementById('noSupportHid').style.display = "block"; diff --git a/js_air/glasses.js b/js_air/glasses.js index 19f6763..3cb47a2 100644 --- a/js_air/glasses.js +++ b/js_air/glasses.js @@ -131,6 +131,10 @@ window.logPackets = () => { // } export default class Glasses extends EventTarget { + + /* RepeatingDeviceReportPoll */ + imu_poller_instance = null; + constructor(device) { console.log('constructing'); super(); @@ -138,6 +142,25 @@ export default class Glasses extends EventTarget { this._interestMsg = []; this._reports = new Map(); this._captures = []; + + // creates it, but doesn't start it... + this.imu_poller_instance = new RepeatingDeviceReportPoll({ + interval: 100, + callback: async ()=>{ + this.sendReportTimeout(Protocol.MESSAGES.R_IMU_DATA, [0x0]).then((report)=>{ + if(report){ + console.log('got report',report) + }else{ + console.log('no report') + } + }).catch((e)=>{ + console.error('error sending report',e) + }).finally(()=>{ + //console.log('finally') + }); + } + }); + // set input listener device.oninputreport = this._handleInputReport.bind(this); @@ -153,6 +176,14 @@ export default class Glasses extends EventTarget { // this.renderSparklines(); } + startIMUPolling(){ + this.imu_poller_instance.start(); + } + + stopIMUPolling(){ + this.imu_poller_instance.end(); + } + renderSparklines(){ if(!window.imu_output){ return; @@ -229,7 +260,7 @@ export default class Glasses extends EventTarget { } if(report.msgId === 0){ - // console.log(report.payload.length, report.status) + console.log(report.payload.length, report.status) imu_report_current++; @@ -430,4 +461,36 @@ export default class Glasses extends EventTarget { toString() { return ``; } + + +} + +class RepeatingDeviceReportPoll { + timer = null; + constructor(opts){ + opts = opts || {}; + opts = { + interval: 100, + callback: ()=>{}, // this is the function that will be called + ...opts + } + this.opts = opts; + + } + + start(){ + this.ended = false; + this.timer = setInterval(() => { + if(this.ended){ + clearInterval(this.timer) + }else{ + this.opts.callback() + } + },this.opts.interval) + } + + end(){ + // stop the timer on next tick + this.ended = true; + } } \ No newline at end of file diff --git a/js_air/manager.js b/js_air/manager.js index 773f9f8..2bb1320 100644 --- a/js_air/manager.js +++ b/js_air/manager.js @@ -513,7 +513,11 @@ export async function startIMU() { if(!glasses){ return Promise.reject('no device connected') } - return glasses.sendReportTimeout(Protocol.MESSAGES.W_TOGGLE_IMU, [1]) + + // kick off polling + glasses.startIMUPolling(); + + return glasses.sendReportTimeout(Protocol.MESSAGES.W_TOGGLE_IMU, [0x1]) .then(report => { console.warn('startIMU -> report',report); if (reportSuccess(report)){ @@ -529,7 +533,7 @@ export async function stopIMU() { return 'no device connected' } // arg 2: 0 is what turns "off" the stream - return glasses.sendReportTimeout(Protocol.MESSAGES.W_TOGGLE_IMU, [0]) + return glasses.sendReportTimeout(Protocol.MESSAGES.W_TOGGLE_IMU, [0x0]) .then(report => { console.warn('stopIMU -> report',report); if (reportSuccess(report)){ diff --git a/js_air/protocol.js b/js_air/protocol.js index d144302..300de17 100644 --- a/js_air/protocol.js +++ b/js_air/protocol.js @@ -22,6 +22,9 @@ export const MESSAGES = { W_ACTIVATION_TIME: 0x2A,//Write activation time W_SLEEP_TIME: 0x1E,//Write unsleep time + R_IMU_DATA: 0x80,//IMU data + UNKNOWN_40: 0x40,//Unknown + W_TOGGLE_IMU: 0x19, W_CANCEL_ACTIVATION: 0x19,