Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Magic Mirror Leap Motion Controller Module for Gesture Detection

License

Notifications You must be signed in to change notification settings

manifestinteractive/MMM-Leap-Motion

Repository files navigation

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]);
}

About

Magic Mirror Leap Motion Controller Module for Gesture Detection

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published