Added device battery indication

This commit is contained in:
Ylian Saint-Hilaire 2020-05-30 17:21:45 -07:00
parent 1a2c85e9f0
commit bf5be3c145
7 changed files with 1406 additions and 1339 deletions

View File

@ -2176,6 +2176,16 @@ function createMeshCore(agent) {
response = "Available commands: \r\n" + fin + ".";
break;
}
case 'setbattery':
// require('MeshAgent').SendCommand({ action: 'battery', state: 'dc', level: 55 });
if ((args['_'].length > 0) && ((args['_'][0] == 'ac') || (args['_'][0] == 'dc'))) {
var b = { action: 'battery', state: args['_'][0] };
if (args['_'].length == 2) { b.level = parseInt(args['_'][1]); }
require('MeshAgent').SendCommand(b);
} else {
require('MeshAgent').SendCommand({ action: 'battery' });
}
break;
case 'fdsnapshot':
require('ChainViewer').getSnapshot().then(function (c) { sendConsoleText(c, this.sessionid); }).parentPromise.sessionid = sessionid;
break;

View File

@ -27,7 +27,6 @@ function amt_heci() {
this._setupPTHI = function _setupPTHI()
{
this._amt = heci.create();
this._amt.descriptorMetadata = "amt-pthi";
this._amt.BiosVersionLen = 65;
this._amt.UnicodeStringLen = 20;
@ -398,25 +397,20 @@ function amt_heci() {
fn.apply(this, opt);
}, callback, optional);
}
this.getProtocolVersion = function getProtocolVersion(callback)
{
this.getProtocolVersion = function getProtocolVersion(callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { opt.push(arguments[i]); }
if (!this._tmpSession) { this._tmpSession = heci.create(); this._tmpSession.parent = this;}
this._tmpSession.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt)
{
heci.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt) {
if (status == 0) {
var result = buffer.readUInt8(0).toString() + '.' + buffer.readUInt8(1).toString() + '.' + buffer.readUInt8(2).toString() + '.' + buffer.readUInt16BE(3).toString();
opt.unshift(result);
fn.apply(self, opt);
}
else
{
else {
opt.unshift(null);
fn.apply(self, opt);
}
}, this, callback, optional);
}
}

View File

@ -1351,6 +1351,15 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
obj.updateSessions();
break;
}
case 'battery': {
// Device battery and power state
if (obj.sessions == null) { obj.sessions = {}; }
if (obj.sessions.battery == null) { obj.sessions.battery = {}; }
if ((command.state == 'ac') || (command.state == 'dc')) { obj.sessions.battery.state = command.state; } else { delete obj.sessions.battery.state; }
if ((typeof command.level == 'number') && (command.level >= 0) && (command.level <= 100)) { obj.sessions.battery.level = command.level; } else { delete obj.sessions.battery.level; }
obj.updateSessions();
break;
}
case 'plugin': {
if ((parent.parent.pluginHandler == null) || (typeof command.plugin != 'string')) break;
try {

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -784,6 +784,23 @@ NoMeshesPanel img {
background-color:#44F;
}
.deviceBatteryLarge {
position:absolute;
left:10px;
top:140px;
width:28px;
height:48px;
border:none;
box-shadow:none;
}
.deviceBatteryLarge1 { background: url(../images/batteries48.png) 0px 0px; }
.deviceBatteryLarge2 { background: url(../images/batteries48.png) -28px 0px; }
.deviceBatteryLarge3 { background: url(../images/batteries48.png) -56px 0px; }
.deviceBatteryLarge4 { background: url(../images/batteries48.png) -84px 0px; }
.deviceBatteryLarge5 { background: url(../images/batteries48.png) -112px 0px; }
.deviceBatteryLarge6 { background: url(../images/batteries48.png) -140px 0px; }
.deviceNotifyLargeDot {
text-align:center;
position:absolute;

File diff suppressed because it is too large Load Diff

View File

@ -488,6 +488,7 @@
<td style=width:20px></td>
<td style=width:200px;vertical-align:top;position:relative valign=top>
<img id="p10deviceNotify" onclick=showDeviceSessions(null,null,event) class=deviceNotifyLargeDot src=images/icon-relay-notify-40.png width=40 height=40>
<div id="p10deviceBattery" class="deviceBatteryLarge deviceBatteryLarge1"></div>
<a href=# onclick=p10showiconselector()><img id=MainComputerImage></a>
<div id=MainComputerState></div>
</td>
@ -2646,8 +2647,8 @@
node.pwr = message.event.pwr;
node.lastconnect = Date.now();
// Clear sesssion information if needed
if ((node.conn & 1) == 0) { delete node.sessions; }
// Clear sesssion and battery information if needed
if ((node.conn & 1) == 0) { delete node.sessions; delete node.battery; }
// Web page update
masterUpdate(1 | 4 | 16);
@ -5007,7 +5008,31 @@
currentNode = node;
// Device Notification
QV('p10deviceNotify', currentNode.sessions != null);
QV('p10deviceNotify', (currentNode.sessions != null) && ((currentNode.sessions.kvm != null) || (currentNode.sessions.terminal != null) || (currentNode.sessions.files != null)));
// Device Battery
QV('p10deviceBattery', false);
if ((currentNode.sessions != null) && (currentNode.sessions.battery != null)) {
var bat = currentNode.sessions.battery;
if (bat.state == 'ac') {
QV('p10deviceBattery', true);
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge6';
Q('p10deviceBattery').title = "Device is plugged-in";
} else {
Q('p10deviceBattery').title = format("Device is battery powered, {0}%", bat.level);
if ((typeof bat.level == 'number') && (bat.level >= 0) && (bat.level <= 100)) {
QV('p10deviceBattery', true);
var lvl = (Math.floor((bat.level + 10) / 25) + 1);
if (lvl > 5) { lvl = 5; }
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge' + lvl;
} else {
QV('p10deviceBattery', true);
Q('p10deviceBattery').className = 'deviceBatteryLarge deviceBatteryLarge5';
}
}
} else {
QV('p10deviceBattery', false);
}
// Add node name
var nname = EscapeHtml(node.name), nnameEx;