Code Monkey home page Code Monkey logo

mmm-leap-motion's Introduction

MMM-Leap-Motion

This is a module for the MagicMirror².

Add Leap Motion support to Magic Mirror.

screenshot

IMPORTANT: This ONLY works with the Native Leap Motion App

You will not be able to use this with the Raspberry Pi, or any other hardware that does not have the Native Leap Motion App running in the background. Your Magic Mirror computer will need to be powerful enough to meet the Minimum Requirements to run the Leap Motion Controller.

Features

  • Visual Indicator when your hand is detected, letting you know you can make a gesture
  • Visual Representation of Gestures on Screen
  • Supports Swipe Gestures: Up, Down, Left, Right, Forward & Back
  • Ability to limit which gestures you want to watch for

Installation

Make sure you have the Leap Motion Controller software running in the background, and then perform the following:

cd /home/pi/MagicMirror
git clone https://github.com/manifestinteractive/MMM-Leap-Motion ./modules/MMM-Leap-Motion
cd ./modules/MMM-Leap-Motion
npm install

Using the module

To use this module, add the following configuration block to the modules array in the config/config.js file:

var config = {
  modules: [
    {
      module: 'MMM-Leap-Motion'
      position: 'top_bar',
      config: {
        watchGestureUp: true,
        watchGestureDown: true,
        watchGestureLeft: true,
        watchGestureRight: true,
        watchGestureForward: true,
        watchGestureBack: true,
        orientation: 'up'
      }
    }
  ]
}

Notifications

You can watch for Leap Motion Gestures in your modules via:

notificationReceived: function(notification) {
  if (notification === 'LEAP_MOTION_HAND_DETECTED') {
    // Do something cool
  }
}

Here are all the notifications this module will send:

Notification Description
LEAP_MOTION_HAND_DETECTED When a hand is detected, letting you know you can make a gesture
LEAP_MOTION_HAND_MISSING Hand is no longer detected, no gestures will work
LEAP_MOTION_SWIPE_UP Swipe Up Detected
LEAP_MOTION_SWIPE_DOWN Swipe Down Detected
LEAP_MOTION_SWIPE_LEFT Swipe Left Detected
LEAP_MOTION_SWIPE_RIGHT Swipe Right Detected
LEAP_MOTION_SWIPE_FORWARD Swipe Forward Detected
LEAP_MOTION_SWIPE_BACK Swipe Back Detected

Configuration options

Option Type Default Description
watchGestureUp boolean true Watch Swipe Up Gestures
watchGestureDown boolean true Watch Swipe Down Gestures
watchGestureLeft boolean true Watch Swipe Left Gestures
watchGestureRight boolean true Watch Swipe Right Gestures
watchGestureForward boolean true Watch Swipe Forward Gestures
watchGestureBack boolean true Watch Swipe Back Gestures
orientation string up Orientation of Leap Motion Controller: up = glass facing ceiling, forward = glass facing wall

NOTE: The orientation automatically changes the up, down, forward & back to more intuitive. In order to make this work correctly, make sure the Leap Motion logo on the back of the controller is facing the top of the device, otherwise you're going to have a hard time.

Integration with MMM-Page-Selector

I integrated this module with the MMM-Page-Selector file by adding the following code to the end of the notificationReceived function in the MMM-Page-Selector.js file.

if (notification === 'LEAP_MOTION_SWIPE_LEFT') {
  let indexOfPage = Object.keys(self.pages).indexOf(self.page);

  indexOfPage = indexOfPage + 1;

  if (indexOfPage >= Object.keys(self.pages).length) {
    indexOfPage = 0;
  }

  self.sendSocketNotification('RELAY_PAGE_SELECT', Object.keys(self.pages)[indexOfPage]);
} else if (notification === 'LEAP_MOTION_SWIPE_RIGHT') {
  let indexOfPage = Object.keys(self.pages).indexOf(self.page);

  indexOfPage = indexOfPage - 1;

  if (indexOfPage < 0) {
    indexOfPage = (Object.keys(self.pages).length - 1);
  }

  self.sendSocketNotification('RELAY_PAGE_SELECT', Object.keys(self.pages)[indexOfPage]);
}

mmm-leap-motion's People

Contributors

manifestinteractive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.