stubbing polling

mode switch

hide garbage

msg id vs payload data isn't right
This commit is contained in:
jake downs 2024-02-08 21:54:48 -05:00 committed by jakedowns
parent db8fb8eb61
commit 4861bd6338
4 changed files with 79 additions and 8 deletions

View File

@ -88,10 +88,10 @@
<div>current brightness: <span class="current-brightness">?</span></div>
<hr/>
<div id="imu-labels"></div>
<div id="imu"></div>
<div id="imu-bars"></div>
<div id="sparklines"></div>
<!-- <div id="imu-labels"></div> -->
<!-- <div id="imu"></div> -->
<!-- <div id="imu-bars"></div> -->
<!-- <div id="sparklines"></div> -->
<hr/>
@ -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";

View File

@ -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 `<Glasses deviceName=${this._device.productName} vid=${this._device.vendorId} pid=${this._device.vendorId}>`;
}
}
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;
}
}

View File

@ -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)){

View File

@ -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,