stubbing polling
mode switch hide garbage msg id vs payload data isn't right
This commit is contained in:
parent
db8fb8eb61
commit
4861bd6338
|
|
@ -88,10 +88,10 @@
|
||||||
<div>current brightness: <span class="current-brightness">?</span></div>
|
<div>current brightness: <span class="current-brightness">?</span></div>
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<div id="imu-labels"></div>
|
<!-- <div id="imu-labels"></div> -->
|
||||||
<div id="imu"></div>
|
<!-- <div id="imu"></div> -->
|
||||||
<div id="imu-bars"></div>
|
<!-- <div id="imu-bars"></div> -->
|
||||||
<div id="sparklines"></div>
|
<!-- <div id="sparklines"></div> -->
|
||||||
|
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
@ -486,7 +486,7 @@
|
||||||
window.sparkline_elements = [];
|
window.sparkline_elements = [];
|
||||||
|
|
||||||
window.onload = async () => {
|
window.onload = async () => {
|
||||||
|
/*
|
||||||
for(var i = 0; i<41; i++){
|
for(var i = 0; i<41; i++){
|
||||||
let child = document.createElement('div');
|
let child = document.createElement('div');
|
||||||
child.classList.add('bar');
|
child.classList.add('bar');
|
||||||
|
|
@ -524,6 +524,7 @@
|
||||||
|
|
||||||
document.getElementById('sparklines').append(_sl_wrapper)
|
document.getElementById('sparklines').append(_sl_wrapper)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (!Manager?.hidSupported()) {
|
if (!Manager?.hidSupported()) {
|
||||||
document.getElementById('noSupportHid').style.display = "block";
|
document.getElementById('noSupportHid').style.display = "block";
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,10 @@ window.logPackets = () => {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export default class Glasses extends EventTarget {
|
export default class Glasses extends EventTarget {
|
||||||
|
|
||||||
|
/* RepeatingDeviceReportPoll */
|
||||||
|
imu_poller_instance = null;
|
||||||
|
|
||||||
constructor(device) {
|
constructor(device) {
|
||||||
console.log('constructing');
|
console.log('constructing');
|
||||||
super();
|
super();
|
||||||
|
|
@ -138,6 +142,25 @@ export default class Glasses extends EventTarget {
|
||||||
this._interestMsg = [];
|
this._interestMsg = [];
|
||||||
this._reports = new Map();
|
this._reports = new Map();
|
||||||
this._captures = [];
|
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
|
// set input listener
|
||||||
device.oninputreport = this._handleInputReport.bind(this);
|
device.oninputreport = this._handleInputReport.bind(this);
|
||||||
|
|
||||||
|
|
@ -153,6 +176,14 @@ export default class Glasses extends EventTarget {
|
||||||
// this.renderSparklines();
|
// this.renderSparklines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startIMUPolling(){
|
||||||
|
this.imu_poller_instance.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
stopIMUPolling(){
|
||||||
|
this.imu_poller_instance.end();
|
||||||
|
}
|
||||||
|
|
||||||
renderSparklines(){
|
renderSparklines(){
|
||||||
if(!window.imu_output){
|
if(!window.imu_output){
|
||||||
return;
|
return;
|
||||||
|
|
@ -229,7 +260,7 @@ export default class Glasses extends EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(report.msgId === 0){
|
if(report.msgId === 0){
|
||||||
// console.log(report.payload.length, report.status)
|
console.log(report.payload.length, report.status)
|
||||||
imu_report_current++;
|
imu_report_current++;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -430,4 +461,36 @@ export default class Glasses extends EventTarget {
|
||||||
toString() {
|
toString() {
|
||||||
return `<Glasses deviceName=${this._device.productName} vid=${this._device.vendorId} pid=${this._device.vendorId}>`;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -513,7 +513,11 @@ export async function startIMU() {
|
||||||
if(!glasses){
|
if(!glasses){
|
||||||
return Promise.reject('no device connected')
|
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 => {
|
.then(report => {
|
||||||
console.warn('startIMU -> report',report);
|
console.warn('startIMU -> report',report);
|
||||||
if (reportSuccess(report)){
|
if (reportSuccess(report)){
|
||||||
|
|
@ -529,7 +533,7 @@ export async function stopIMU() {
|
||||||
return 'no device connected'
|
return 'no device connected'
|
||||||
}
|
}
|
||||||
// arg 2: 0 is what turns "off" the stream
|
// 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 => {
|
.then(report => {
|
||||||
console.warn('stopIMU -> report',report);
|
console.warn('stopIMU -> report',report);
|
||||||
if (reportSuccess(report)){
|
if (reportSuccess(report)){
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ export const MESSAGES = {
|
||||||
W_ACTIVATION_TIME: 0x2A,//Write activation time
|
W_ACTIVATION_TIME: 0x2A,//Write activation time
|
||||||
W_SLEEP_TIME: 0x1E,//Write unsleep time
|
W_SLEEP_TIME: 0x1E,//Write unsleep time
|
||||||
|
|
||||||
|
R_IMU_DATA: 0x80,//IMU data
|
||||||
|
UNKNOWN_40: 0x40,//Unknown
|
||||||
|
|
||||||
W_TOGGLE_IMU: 0x19,
|
W_TOGGLE_IMU: 0x19,
|
||||||
W_CANCEL_ACTIVATION: 0x19,
|
W_CANCEL_ACTIVATION: 0x19,
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue