Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startLeapController: function() {
var controller = new leap.Controller(),
lightSetInterval = null,
updatingLights = false,
state = {
"on": false, // lights on: true/false
"bri": null, // brightness: 0-255
"hue": null, // hue: 0-65535
"sat": 255 // always set to 255 for full color
};
hue.updateLights(state);
console.log('Put your hand over the leapmotion to turn the lights on...');
// continuous loop from the Leap Motion
controller.on('frame', function(frame) {
// Camera benhavior variables
var sensitivityX = 0.09;
var sensitivityY = 0.0725;
var centerX = 0;
var x_box_width = 12.5;
var centerY = 205;
var y_box_width = 15;
var x_safe = [centerX - x_box_width, centerX + x_box_width]
var y_safe = [centerY - y_box_width, centerY + y_box_width];
//Main event loop
var controller = new Leap.Controller({ loopWhileDisconnected: true });
controller.setBackground(true);
controller.loop(function(frame) {
if (frame.hands.length === 0) {
bangEventEmitted = false;
return;
}
var hand = frame.hands[0];
//Update camera position
var posX = hand.indexFinger.stabilizedTipPosition[0];
var posY = hand.indexFinger.stabilizedTipPosition[1];
if (posX > x_safe[0] && posX < x_safe[1]) {
posX = 0;
}
var MIN_Y = 0;
var MIN_Z = 0;
var MAX_Z = 800;
// How many past frames to cache for smoothing; slows down response time with a higher number
var SMOOTHING_FRAMES = 10;
/*
* Need to set up 4 servos: shoulder, elbow, claw, and base
* Use inverse kinematics equation on servoShoulder & servoElbow
* Use fingerDistance to rotate servoClaw to desired position
* Servos must be placed on the Arduino's PWM pins
*/
// Leap motion controller
var controller = new Leap.Controller();
// Main Leap frame loop
controller.on('frame', function(frame) {
// Hand position controls the robot arm position
if(frame.hands.length > 0) {
handPosition = frame.hands[0].palmPosition;
// Offset z to always keep the value positive
frame.hands[0].palmPosition[1] -= 150;
frame.hands[0].palmPosition[2] = 200 + (-1*frame.hands[0].palmPosition[2]);
var smoothedInput = smoothInput(handPosition);
smoothingQueue(handPosition);
// Restrict certain inputs to prevent physical damage
// These values should be changed depending on your arm design
function Leap(data) {
this.threshold = data.threshold || 10;
var controllerOptions = {
host: data.host || '127.0.0.1',
port: data.port || 6437,
enableGestures: data.enableGestures || false,
enableHeartbeat: data.enableHeartbeat || true,
heartbeatInterval: data.heartbeatInterval || 100,
requestProtocolVersion: data.requestProtocolVersion || 3
};
this.controller = new Leapjs.Controller(controllerOptions);
this.controller.on('frame', this.handleFrame.bind(this));
if (controllerOptions.enableGestures) {
this.controller.on('gesture', this.handleGesture.bind(this));
}
this.controller.on('ready', function() {
console.log("Leap ready");
});
this.controller.on('connect', function() {
console.log("Leap connected");
});
this.controller.on('disconnect', function() {
console.log("Leap disconnected");
});
var controlSphero = function(sphero) {
var controller = new Leap.Controller({frameEventName:'deviceFrame', enableGestures:true});
//Debugging console messages to make sure the Leap Motion is connected and working.
controller.on('connect', function() {
console.log('connected to leap motion');
});
controller.on('ready', function() {
console.log('ready');
});
controller.on('focus', function() {
console.log('focus?');
});
controller.on('deviceConnected', function() {
console.log('device connected');
});
controller.on('deviceDisconnected', function() {
console.log('device disconnected');
const five = require('johnny-five');
const Leap = require('leapjs');
const LeapFrame = require('./lib/leapFrame');
const Joint = require('./lib/joint');
const controller = new Leap.Controller({ enableGestures: true });
const board = new five.Board();
let frame;
let i = 0;
try {
board.on('ready', () => {
const headBulb = new Joint({
minPos: -60,
maxPos: 30,
pin: 9,
range: [60, 175],
});
const headNod = new Joint({
(function() {
Leap = require('leapjs');;
var Gesture, KeyboardAction, MainController, MouseAction, config, keyboard, loopController, mainController, processFrame, robot;
require('./lib/leap.hand-entry.js');
robot = require("robotjs");
config = require('./config.json');
loopController = new Leap.Controller({
inBrowser: false,
enableGestures: true,
frameEventName: 'deviceFrame',
background: true,
loopWhileDisconnected: false
});
loopController.use('handEntry');
MainController = (function() {
function MainController() {
this.gestureSequence = [];
this.extendedFingers = [];
this.timeout = false;
this.lastGestureTime = 0;
this.wait = 0;