sensortoy/www/js/standards/battery.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-05-20 16:10:40 +00:00
/**
*
* User: Martin Donnelly
* Date: 2016-05-20
* Time: 10:13
*
*/
/* global CAPABILITY */
/* global ble */
/* jshint browser: true , devel: true*/
var BATTERY = function() {
this.name = 'Battery';
this.capabilityID = '180F';
this.serviceDef = {
service: '180F',
level: '2A19'
};
this.onBatteryLevelChange = function(data) {
console.log(data);
var a = new Uint8Array(data);
this.state = a[0];
console.log('onBatteryLevelChange', this.state);
};
this.readBatteryState = function() {
console.log('readBatteryState');
ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.level, this.onReadBatteryLevel.bind(this), this.onError);
};
this.onReadBatteryLevel = function(data) {
console.log(data);
var a = new Uint8Array(data);
this.state = a[0];
console.log('onReadBatteryLevel', this.state);
};
this.startService = function() {
'use strict';
if (this.deviceID !== null) {
console.log('Starting Battery Service');
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.level, this.onBatteryLevelChange.bind(this), this.onError);
}
this.insertFrame();
};
};
inheritsFrom(BATTERY, CAPABILITY);