Commit f8f75923 authored by martin hou's avatar martin hou

feat: 增加P1电量API实现

parent 1feaf54e
...@@ -26,7 +26,7 @@ const TONE_UPDATE = 0x17; ...@@ -26,7 +26,7 @@ const TONE_UPDATE = 0x17;
const REQUEST_UAC_UPDATE = 0x18; const REQUEST_UAC_UPDATE = 0x18;
const UAC_UPDATE = 0x19; const UAC_UPDATE = 0x19;
const FACTORY_RESET = 0xf00b; const FACTORY_RESET = 0xf00b;
const GET_BATTERY_STATUS = 0x1004;
const REALTIME_READ_SETTING = 0x20; const REALTIME_READ_SETTING = 0x20;
const REALTIME_CONTROL = 0x21; const REALTIME_CONTROL = 0x21;
const REALTIME_TRANSFER = 0x22; const REALTIME_TRANSFER = 0x22;
...@@ -1108,7 +1108,11 @@ Jensen.prototype.getFileBlock = async function (filename, length, ondata) { ...@@ -1108,7 +1108,11 @@ Jensen.prototype.getFileBlock = async function (filename, length, ondata) {
return this.send(new Command(GET_FILE_BLOCK).body(data)); return this.send(new Command(GET_FILE_BLOCK).body(data));
}; };
Jensen.prototype.getBatteryStatus = function(seconds)
{
if (this.model != 'hidock-p1') return null;
return this.send(new Command(GET_BATTERY_STATUS), seconds);
}
Jensen.prototype.writeSerialNumber = async function (sn) { Jensen.prototype.writeSerialNumber = async function (sn) {
let data = []; let data = [];
for (let i = 0; i < sn.length; i++) { for (let i = 0; i < sn.length; i++) {
...@@ -1205,6 +1209,16 @@ Jensen.registerHandler(REALTIME_READ_SETTING, (msg) => { ...@@ -1205,6 +1209,16 @@ Jensen.registerHandler(REALTIME_READ_SETTING, (msg) => {
// console.log(msg); // console.log(msg);
return msg; return msg;
}); });
Jensen.registerHandler(GET_BATTERY_STATUS, (msg) => {
let status = msg.body[0] & 0xff;
let percent = msg.body[1] & 0xff;
let voltage = ((msg.body[2] & 0xff) << 24) | ((msg.body[3] & 0xff) << 16) | ((msg.body[4] & 0xff) << 8) | (msg.body[5] & 0xff);
return {
status : status == 0 ? 'idle' : (status == 1 ? 'charging' : 'full'),
battery : percent,
voltage : voltage
};
})
Jensen.registerHandler(REALTIME_TRANSFER, (msg) => { Jensen.registerHandler(REALTIME_TRANSFER, (msg) => {
let a = msg.body[0] & 0xff; let a = msg.body[0] & 0xff;
let b = msg.body[1] & 0xff; let b = msg.body[1] & 0xff;
......
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