Hooked up power events

This commit is contained in:
Bryan Roe 2020-05-31 11:24:34 -07:00
parent 32bc5f79fb
commit 5ad469e8b4

View File

@ -251,6 +251,35 @@ function createMeshCore(agent) {
return (svc); return (svc);
} }
if (require('identifiers').isBatteryPowered && require('identifiers').isBatteryPowered())
{
require('MeshAgent')._battLevelChanged = function _battLevelChanged(val)
{
_battLevelChanged.self.SendCommand({ action: 'battery', state: _battLevelChanged.self._currentPowerState, level: val });
};
require('MeshAgent')._battLevelChanged.self = require('MeshAgent');
require('MeshAgent')._powerChanged = function _powerChanged(val)
{
_powerChanged.self._currentPowerState = (val == 'AC' ? 'ac' : 'dc');
_powerChanged.self.SendCommand({ action: 'battery', state: (val == 'AC' ? 'ac' : 'dc') });
};
require('MeshAgent')._powerChanged.self = require('MeshAgent');
require('MeshAgent').on('Connected', function (status)
{
if (status == 0)
{
require('power-monitor').removeListener('acdc', this._powerChanged);
require('power-monitor').removeListener('batteryLevel', this._battLevelChanged);
}
else
{
require('power-monitor').on('acdc', this._powerChanged);
require('power-monitor').on('batteryLevel', this._battLevelChanged);
}
});
}
/* /*
function borderController() { function borderController() {
this.container = null; this.container = null;