Commit 2dea3215 authored by Skye Yu's avatar Skye Yu

perf: Send all schedule information at once.

parent 8fb3c00c
...@@ -92,7 +92,7 @@ declare class Jensen { ...@@ -92,7 +92,7 @@ declare class Jensen {
test: (seconds?: number) => Promise<ReturnStruct['common']>; test: (seconds?: number) => Promise<ReturnStruct['common']>;
setBluetoothPromptPlay: (state: boolean, seconds?: number) => Promise<ReturnStruct['common']>; setBluetoothPromptPlay: (state: boolean, seconds?: number) => Promise<ReturnStruct['common']>;
writeSerialNumber: (sn: string) => Promise<ReturnStruct['common']>; writeSerialNumber: (sn: string) => Promise<ReturnStruct['common']>;
sendScheduleInfo: (info: ScheduleInfo) => Promise<ReturnStruct['common']>; sendScheduleInfo: (info: ScheduleInfo[]) => Promise<ReturnStruct['common']>;
} }
export = Jensen; export = Jensen;
...@@ -910,21 +910,26 @@ const commonMessageParser = (msg) => { ...@@ -910,21 +910,26 @@ const commonMessageParser = (msg) => {
return { result: msg.body[0] === 0x00 ? 'success' : 'failed' }; return { result: msg.body[0] === 0x00 ? 'success' : 'failed' };
}; };
Jensen.prototype.sendScheduleInfo = function (info) { Jensen.prototype.sendScheduleInfo = function (infos) {
let codes = new Array(33).fill(0); if (Array.isArray(infos) && infos.length) {
if (shortcutKeys[info.platform] && shortcutKeys[info.platform][info.os]) { const bodys = [];
codes = shortcutKeys[info.platform][info.os]; for (info of infos) {
} let codes = new Array(33).fill(0);
let startDate = new Array(7).fill(0); if (shortcutKeys[info.platform] && shortcutKeys[info.platform][info.os]) {
let endDate = new Array(7).fill(0); codes = shortcutKeys[info.platform][info.os];
if (info.startDate && info.endDate) { }
startDate = formatTime(info.startDate); let startDate = new Array(7).fill(0);
endDate = formatTime(info.endDate); let endDate = new Array(7).fill(0);
if (info.startDate && info.endDate) {
startDate = formatTime(info.startDate);
endDate = formatTime(info.endDate);
}
const reserved = 0x00; // 预留
bodys.concat([...startDate, ...endDate, reserved, ...codes]);
}
console.log('send schedule info', info, bodys);
return this.send(new Command(SCHEDULE_INFO).body(bodys));
} }
const reserved = 0x00; // 预留
const body = [...startDate, ...endDate, reserved, ...codes];
console.log('send schedule info', info, body);
return this.send(new Command(SCHEDULE_INFO).body(body));
}; };
Jensen.registerHandler(SET_DEVICE_TIME, commonMessageParser); Jensen.registerHandler(SET_DEVICE_TIME, commonMessageParser);
......
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