Removed old gpio scripts
This commit is contained in:
parent
1e39d3a8d2
commit
8006f3688c
3 changed files with 0 additions and 213 deletions
|
@ -1,51 +0,0 @@
|
|||
$(document).ready(function() {
|
||||
var $container = $('#gpio-container');
|
||||
|
||||
var initElements = function() {
|
||||
execute({ type: 'request', action: 'gpio.read_all' }, function(data) {
|
||||
var response = data.response.output;
|
||||
|
||||
for (var pin of response) {
|
||||
var $pin = $('<div></div>').addClass('row gpio-pin').data('pin', pin.pin);
|
||||
var $name = $('<div></div>').addClass('pin-name ten columns').text(pin.name);
|
||||
var $value = $('<div></div>').addClass('pin-value two columns');
|
||||
var $select = $('<select></select>').data('pin', pin.pin).addClass('pin-ctrl');
|
||||
var $option0 = $('<option></option>').attr('name', '0').text('0');
|
||||
var $option1 = $('<option></option>').attr('name', '1').text('1');
|
||||
|
||||
$option0.appendTo($select);
|
||||
$option1.appendTo($select);
|
||||
$select.appendTo($value);
|
||||
$name.appendTo($pin);
|
||||
$value.appendTo($pin);
|
||||
$pin.appendTo($container);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var initBindings = function() {
|
||||
$container.on('change', '.pin-ctrl', function() {
|
||||
var pin = $(this).data('pin');
|
||||
var val = parseInt($(this).val());
|
||||
|
||||
execute(
|
||||
{
|
||||
type: 'request',
|
||||
action: 'gpio.write',
|
||||
args: {
|
||||
pin: pin,
|
||||
val: val,
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
initElements();
|
||||
initBindings();
|
||||
};
|
||||
|
||||
init();
|
||||
});
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
$(document).ready(function() {
|
||||
var $container = $('#sensors-container');
|
||||
|
||||
var onEvent = function(event) {
|
||||
switch (event.args.type) {
|
||||
case 'platypush.message.event.sensor.SensorDataChangeEvent':
|
||||
var data = event.args.data;
|
||||
|
||||
for (var sensor of Object.keys(data)) {
|
||||
var $sensor = $container.find('[data-sensor-type=' + sensor + ']');
|
||||
var $value;
|
||||
|
||||
if ($sensor.length === 0) {
|
||||
$sensor = $('<div></div>')
|
||||
.addClass('row sensor-data')
|
||||
.attr('data-sensor-type', sensor);
|
||||
|
||||
var $name = $('<div></div>')
|
||||
.addClass('sensor-name six columns')
|
||||
.text(sensor);
|
||||
|
||||
$value = $('<div></div>')
|
||||
.addClass('sensor-value six columns');
|
||||
|
||||
$name.appendTo($sensor);
|
||||
$value.appendTo($sensor);
|
||||
$sensor.appendTo($container);
|
||||
} else {
|
||||
$value = $sensor.find('.sensor-value');
|
||||
}
|
||||
|
||||
$value.text(data[sensor]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
var initEvents = function() {
|
||||
window.registerEventListener(onEvent);
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
initEvents();
|
||||
};
|
||||
|
||||
init();
|
||||
});
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
$(document).ready(function() {
|
||||
var $container = $('#zb-container'),
|
||||
$controlsContainer = $('.zb-controls-container'),
|
||||
curDirection = undefined;
|
||||
|
||||
var initBindings = function() {
|
||||
$controlsContainer.on('mousedown touchstart', '.zb-ctrl-btn[data-direction]', function() {
|
||||
var direction = $(this).data('direction');
|
||||
curDirection = direction;
|
||||
console.log(direction + ' press start');
|
||||
|
||||
$(this).addClass('selected');
|
||||
execute({
|
||||
type: 'request',
|
||||
action: 'gpio.zeroborg.drive',
|
||||
args: {
|
||||
direction: direction
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$controlsContainer.on('mouseup touchend', '.zb-ctrl-btn[data-direction]', function() {
|
||||
console.log($(this).data('direction') + ' press end');
|
||||
curDirection = undefined;
|
||||
|
||||
$(this).removeClass('selected');
|
||||
execute({
|
||||
type: 'request',
|
||||
action: 'gpio.zeroborg.stop',
|
||||
});
|
||||
});
|
||||
|
||||
$controlsContainer.on('click touch', '.zb-ctrl-btn[data-action]', function() {
|
||||
console.log('Running ' + $(this).data('action') + ' action');
|
||||
|
||||
if ($(this).data('action') === 'stop') {
|
||||
$controlsContainer.find('.zb-ctrl-btn[data-action=auto]').removeClass('selected');
|
||||
curDirection = undefined;
|
||||
|
||||
execute({
|
||||
type: 'request',
|
||||
action: 'gpio.zeroborg.stop',
|
||||
});
|
||||
} else if ($(this).data('action') === 'auto') {
|
||||
$(this).toggleClass('selected');
|
||||
curDirection = 'auto_toggle';
|
||||
|
||||
execute({
|
||||
type: 'request',
|
||||
action: 'gpio.zeroborg.drive',
|
||||
args: {
|
||||
direction: 'auto_toggle'
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var keyEventToDirection = function(event) {
|
||||
var direction;
|
||||
|
||||
switch (event.keyCode) {
|
||||
case 32: // SPACE bar
|
||||
direction = 'auto'; break;
|
||||
case 37: // LEFT
|
||||
direction = 'left'; break;
|
||||
case 38: // UP
|
||||
direction = 'up'; break;
|
||||
case 39: // RIGHT
|
||||
direction = 'right'; break;
|
||||
case 40: // DOWN
|
||||
direction = 'down'; break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
return direction;
|
||||
};
|
||||
|
||||
$container.on('keydown', function(event) {
|
||||
if (curDirection) {
|
||||
return;
|
||||
}
|
||||
|
||||
var direction = keyEventToDirection(event);
|
||||
if (direction) {
|
||||
if (direction === 'auto') {
|
||||
$controlsContainer.find('.zb-ctrl-btn[data-action=auto]').click();
|
||||
} else {
|
||||
$controlsContainer.find('.zb-ctrl-btn[data-direction=' + direction + ']').mousedown();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$container.on('keyup', function(event) {
|
||||
var direction = keyEventToDirection(event);
|
||||
if (direction) {
|
||||
if (direction === 'auto') {
|
||||
$controlsContainer.find('.zb-ctrl-btn[data-action=auto]').click();
|
||||
$controlsContainer.find('.zb-ctrl-btn[data-action=stop]').click();
|
||||
} else {
|
||||
$controlsContainer.find('.zb-ctrl-btn[data-direction=' + direction + ']').mouseup();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
initBindings();
|
||||
};
|
||||
|
||||
init();
|
||||
});
|
||||
|
Loading…
Reference in a new issue