/**
*
* User: Martin Donnelly
* Date: 2016-05-20
* Time: 10:13
*
*/
/* global CAPABILITY, inheritsFrom, capabilityManager */
/* global ble */
/* jshint browser: true , devel: true*/
var BUTTON = function(p) {
'use strict';
this.name = 'Button';
this.deviceID = p.deviceID || null;
this.target = p.target || null;
this.capabilityID = 'FFE0';
this.serviceDef = {
service: 'FFE0',
data: 'FFE1' // Bit 2: side key, Bit 1- right key, Bit 0 –left key
};
this.buttonMatrix = {
LEFT_BUTTON: 1, // 0001
RIGHT_BUTTON: 2, // 0010
REED_SWITCH: 4 // 0100
};
this.setFrame();
this.onButtonData = function(data) {
console.log('+ onButtonData');
console.log(data);
var state = new Uint8Array(data);
var message = '';
if (state === 0) {
message = 'No buttons are pressed.';
}
if (state & this.buttonMatrix.LEFT_BUTTON) {
message += 'Left button is pressed. ';
}
if (state & this.buttonMatrix.RIGHT_BUTTON) {
message += 'Right button is pressed.';
}
if (state & this.buttonMatrix.REED_SWITCH) {
message += 'Reed switch is activated.
';
}
this.state = message;
if (this.$result !== null)
{
this.$result.text(this.state);
}
console.log('ButtonState: ', this.state);
console.log('- onButtonData');
};
this.startService = function() {
'use strict';
if (this.deviceID !== null) {
console.log('Starting Button Service on ', this.deviceID);
console.log(this.serviceDef);
ble.startNotification(this.deviceID, this.serviceDef.service, this.serviceDef.data, this.onButtonData.bind(this), this.onError);
}
this.insertFrame();
};
this.insertFrame = function() {
var self = this;
console.log('Overloading...');
// Call the parent displayForm first...
this.superClass_.insertFrame.call(self);
var detail = this.frameID + '-d';
var row = $('