diff --git a/index.html b/index.html index d343f95..05f3ada 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,7 @@ diff --git a/index_old.html b/index_old.html index f5e146f..46b2b5d 100644 --- a/index_old.html +++ b/index_old.html @@ -74,6 +74,7 @@
+
@@ -430,7 +431,19 @@ } window.startIMU = function(){ - Manager.startIMU(); + Manager.startIMU().then(result=>{ + console.warn('Manager.startIMU().then...',{result}) + }).catch(err=>{ + console.error(err) + }); + } + + window.stopIMU = function(){ + Manager.stopIMU().then(result=>{ + console.warn('Manager.stopIMU().then...',{result}) + }).catch(err=>{ + console.error(err) + }); } window.disconnectDevices = () => { diff --git a/js_air/glasses.js b/js_air/glasses.js index bb5eb3b..19f6763 100644 --- a/js_air/glasses.js +++ b/js_air/glasses.js @@ -392,18 +392,16 @@ export default class Glasses extends EventTarget { sendReport(msgId, payload) { const data = new Uint8Array(payload); const cmd = Protocol.cmd_build(msgId, data); - // console.log({ - // msgId, - // payload, - // data, - // cmd - // }) + + console.warn('js_air:sendReport',{msgId,payload}) console.table([{ + id: 'sendReport', dir: 'OUT', msgId: [msgId, '0x'+(msgId.toString(16))].join(' '), key: Protocol.keyForHex(msgId), payload: data.join(' '), + _input_payload: payload, cmd: cmd.map(b => b.toString(16).padStart(2, "0")).join(' ') }]) this._device.sendReport(0x00, cmd); diff --git a/js_air/manager.js b/js_air/manager.js index d14199e..773f9f8 100644 --- a/js_air/manager.js +++ b/js_air/manager.js @@ -511,9 +511,9 @@ export async function getSN() { /** init air IMU tracking mode */ export async function startIMU() { if(!glasses){ - return 'no device connected' + return Promise.reject('no device connected') } - return glasses.sendReportTimeout(Protocol.MESSAGES.R_INIT_IMU_TRACKING_SESSION) + return glasses.sendReportTimeout(Protocol.MESSAGES.W_TOGGLE_IMU, [1]) .then(report => { console.warn('startIMU -> report',report); if (reportSuccess(report)){ @@ -524,6 +524,22 @@ export async function startIMU() { }) } +export async function stopIMU() { + if(!glasses){ + return 'no device connected' + } + // arg 2: 0 is what turns "off" the stream + return glasses.sendReportTimeout(Protocol.MESSAGES.W_TOGGLE_IMU, [0]) + .then(report => { + console.warn('stopIMU -> report',report); + if (reportSuccess(report)){ + return String.fromCharCode.apply(null, report.payload); + }else{ + console.error('error w/ report',report) + } + }) +} + /** read air glassess Brightness */ export async function getBrightness() { let glasses = await common.connectDevice(); diff --git a/js_air/protocol.js b/js_air/protocol.js index 87b086e..d144302 100644 --- a/js_air/protocol.js +++ b/js_air/protocol.js @@ -10,10 +10,10 @@ const RESERVED_OFS = 17; export const NREAL_VENDOR_ID = 0x3318; export const BOOT_PRODUCT_ID = 0x0423; - +export const IMU_TIMEOUT = 250; export const MESSAGES = { - W_CANCEL_ACTIVATION: 0x19, + R_MCU_APP_FW_VERSION: 0x26,//MCU APP FW version. R_GLASSID: 0x15,//MCU APP FW version. // R_DSP_APP_FW_VERSION: 0x21,//DSP APP FW version. @@ -22,6 +22,9 @@ export const MESSAGES = { W_ACTIVATION_TIME: 0x2A,//Write activation time W_SLEEP_TIME: 0x1E,//Write unsleep time + W_TOGGLE_IMU: 0x19, + W_CANCEL_ACTIVATION: 0x19, + // R_IS_NEED_UPGRADE_DSP_FW: 0x49,//Check whether the DSP needs to be upgraded. // W_FORCE_UPGRADE_DSP_FW: 0x69,//Force upgrade DSP. R_DSP_VERSION: 0x18,//DSP APP FW version. diff --git a/js_light/glasses.js b/js_light/glasses.js index c640d00..f713e2d 100644 --- a/js_light/glasses.js +++ b/js_light/glasses.js @@ -32,6 +32,7 @@ export default class Glasses extends EventTarget { // light connect sendReport(msgId, payload, option) { + console.warn('js_light:sendReport',{msgId,payload,option}) const data = new Uint8Array(payload); const cmd = Protocol.cmd_build(msgId, data, option); this._device.sendReport(0x00, cmd);