Giter VIP home page Giter VIP logo

mmm-mpr121's Introduction

Magic Mirror Module: MPR121

This a module for Magic Mirror² to act based on touch (capacitive) buttons via the MPR121 touch-button controller. It is capable of connecting up to 12 buttons, which can be individually configured. This module is heavily based on the awesome [MMM-Buttons module] (https://github.com/Jopyth/MMM-Buttons)

This module sends out notifications to other modules.

For example this can be used to send notifications to the following modules:

Installation

Clone this repository in your modules folder, and install dependencies:

cd ~/MagicMirror/modules # adapt directory if you are using a different one
git clone https://github.com/PatriceG/MMM-MPR121.git
cd MMM-MPR121
npm install

Configuration

Add the module to your modules array in your config.js.

Below is a simple example (needs Remote Control installed), with two touch-buttons (electrodes) conneted, on inputs 0 and 1 of the MPR121. One switches on the display on a short touch, and switches it off on a long touch. The other does not do anything on a short touch, but shuts down the system after keeping it touched for 3 seconds with an explanatory user alert.

{
    module: 'MMM-MPR121',
    config: {
        buttons: [
            {
                pin: 0,
                name: "monitor_control",
                longPress: {
                    notification: "REMOTE_ACTION",
                    payload: {action: "MONITOROFF"}
                },
                shortPress: {
                    notification: "REMOTE_ACTION",
                    payload: {action: "MONITORON"}
                }
            },
            {
                pin: 1,
                name: "power",
                longPress: {
                    title: "Power off",
                    message: "Keep pressed for 3 seconds to shut down",
                    imageFA: "power-off",
                    notification: "REMOTE_ACTION",
                    payload: {action: "SHUTDOWN"}
                },
                shortPress: undefined
            }
        ]
    }
},

Module Configuration

Here is full documentation of options for the modules configuration:

Option Description
buttons An array of button configurations. See Button Configuration below. Default is [] (no buttons registered).
minShortPressTime Minimum duration to trigger a short press in ms. Default is 0.
maxShortPressTime Maximum duration to trigger a short press in ms. Default is 500.
minLongPressTime Minimum time needed to trigger a long press in ms. Default is 3000. Any press duration between maxShortPressTime and minLongPressTime does not do anything.

Button Configuration

Each button configuration is an object with the following properties:

Property Description
pin Input pin number of the button input on the MPR121 (0 to 11)
name Name of the button for easier identification and log output.
longPress Choose what notification to send on a long press. See Notification Configuration below. Use undefined if nothing should trigger.
shortPress Choose what notification to send on a short press. See Notification Configuration below. Use undefined if nothing should trigger.

Notification Configuration

Each notification configuration is an object with the following properties:

Property Description
notification Notification name.
payload Notification payload. Can be anything, for example a string or an object.
title, message, and imageFA Optional (only for long press notifications): If you want to display a message before executing set its options here. See Alert documentation for their meaning.

License

The MIT License (MIT)

Copyright © 2016 Patrice Godard (MPR121 version), Joseph Bethge (GPIO version)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

mmm-mpr121's People

Contributors

patriceg avatar

Watchers

James Cloos avatar shbatm 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.