Commit 26ac80e7 authored by martin hou's avatar martin hou

Merge branch 'v20250816' into device-mgr

parents 8845d9d0 5021a609
......@@ -143,6 +143,7 @@ declare class Jensen {
// 事件:当连接异常时触发
onerror: (e: Error) => void;
onwakeup: () => void;
addWakeupListener: (listener: () => void) => void;
// 主动断开连接(单连接时适用)
disconnect: () => void;
// 事件:当连接断开时触发
......
......@@ -14,9 +14,9 @@ export function Home() {
jensen.connect();
jensen.onconnect = () => {
console.log('connect successfully');
jensen.onwakeup = function() {
jensen.addWakeupListener(function() {
console.log('从休眠中恢复过来了?');
}
});
jensen.getDeviceInfo().then((info) => {
console.log('getDeviceInfo', info);
alert(info.sn + ' connected');
......
......@@ -173,6 +173,21 @@ function Jensen(log, conn) {
} catch (err) {
Logger.error('jensen', 'setup', err);
}
};
this.initialize = async function() {
if (conn)
{
if (!conn.opened) conn.open();
await setup();
}
return true;
}
this.addWakeupListener = function(listener) {
this.onwakeup = listener;
const self = this;
Logger.info('jensen', 'hibernate', 'setup');
if (self.sleepChecker) window.clearInterval(self.sleepChecker);
self.sleepChecker = setInterval(function() {
let now = new Date().getTime();
......@@ -184,22 +199,18 @@ function Jensen(log, conn) {
{
setTimeout(function() {
let currentTime = new Date().getTime();
if (currentTime - self.wakeupTime < 200) self.onwakeup();
if (currentTime - self.wakeupTime < 200)
{
Logger.info('jensen', 'hibernate', 'wakeup');
self.onwakeup();
}
else Logger.info('jensen', 'hibernate', 'fake wake');
}, 100);
self.wakeupTime = now;
}
}
self.lastTimerInvoked = now;
}, 5000);
};
this.initialize = async function() {
if (conn)
{
if (!conn.opened) conn.open();
await setup();
}
return true;
}
this.sequence = function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment