stubbing polling
This commit is contained in:
parent
db8fb8eb61
commit
b0c27a160b
|
|
@ -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: ()=>{
|
||||
this.sendReport(Protocol.MESSAGES.R_IMU_DATA).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,35 @@ 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
start(){
|
||||
this.ended = false;
|
||||
this.timer = setInterval(() => {
|
||||
if(this.ended){
|
||||
clearInterval(this.timer)
|
||||
}else{
|
||||
opts.callback()
|
||||
}
|
||||
},opts.interval)
|
||||
}
|
||||
|
||||
end(){
|
||||
// stop the timer on next tick
|
||||
this.ended = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -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)){
|
||||
|
|
|
|||
Loading…
Reference in New Issue