Hooked up power events

This commit is contained in:
Bryan Roe 2020-05-31 11:24:34 -07:00
parent 1736269b3f
commit c7e95dadc3
1 changed files with 29 additions and 0 deletions

View File

@ -251,6 +251,35 @@ function createMeshCore(agent) {
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() {
this.container = null;