Giter Club home page Giter Club logo

mmm-buttons's Introduction

Magic Mirror Module: Buttons

This a module for Magic Mirror² to act based on button presses via GPIO. It is capable of connecting multiple buttons at once, which can be individually configured. It is basically a generalized version of the Button module, original idea comes from @PtrBld. However it only 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/Jopyth/MMM-Buttons.git
cd MMM-Buttons
npm install # this can take a while

Configuration

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

Below is a simple example (needs Remote Control installed), with two buttons conneted, on pins 24 and 25. One switches on the display on a short press, and switches it off on a long press. The other does not do anything on a short press, but shuts down the system after keeping it pressed for 3 seconds with an explanatory user alert.

{
    module: 'MMM-Buttons',
    config: {
        buttons: [
            {
                pin: 25,
                name: "monitor_control",
                longPress: {
                    notification: "REMOTE_ACTION",
                    payload: {action: "MONITOROFF"}
                },
                shortPress: {
                    notification: "REMOTE_ACTION",
                    payload: {action: "MONITORON"}
                }
            },
            {
                pin: 24,
                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.
bounceTimeout Duration to ignore bouncing (unintentional doubble press on the button).

Button Configuration

Each button configuration is an object with the following properties:

Property Description
pin Pin number of the button input (use BCM numbering).
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 Joseph Bethge

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-buttons's People

Contributors

cederstrom avatar jopyth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mmm-buttons's Issues

post install script fails

fails with following output:

gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/pi/MagicMirror/modules/MMM-Button/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Linux 5.10.17-v7+
gyp ERR! command "/usr/bin/node" "/home/pi/MagicMirror/modules/MMM-Button/node_modules/.bin/node-gyp" "rebuild" "--target=15.3.0" "--arch=arm" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /home/pi/MagicMirror/modules/MMM-Button/node_modules/epoll
gyp ERR! node -v v17.0.1
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok

Failed with exit code: 1
    at SafeSubscriber._error (/home/pi/MagicMirror/modules/MMM-Button/node_modules/spawn-rx/lib/src/index.js:267:84)
    at SafeSubscriber.__tryOrUnsub (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.error (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:156:26)
    at Subscriber._error (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:92:26)
    at Subscriber.error (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:72:18)
    at MapSubscriber.Subscriber._error (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:92:26)
    at MapSubscriber.Subscriber.error (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:72:18)
    at SafeSubscriber._next (/home/pi/MagicMirror/modules/MMM-Button/node_modules/spawn-rx/lib/src/index.js:242:65)
    at SafeSubscriber.__tryOrUnsub (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.next (/home/pi/MagicMirror/modules/MMM-Button/node_modules/rxjs/internal/Subscriber.js:143:22)

any ideas?

Black screen after installing at run

Config:
MM 2.4.1
Raspie 3b+

installed modules
MMM-RemoteControl
MMM-howord
MMM-Assistantmk2
MMM-Notificationtrigger

workin in SERVERONLY mode

after installing screen goes black

Message in the console module compiled for a different NODE version
I rebuilt Buttons (npm rebuild in the directory)
still black screen but no error anymore
after removing all references to buttons screen comes back but assistant just answers first question then bails out with error

Notification when press the button or release

Hello the project is very nice.
I want to send notification play when I press the button and when I'm going to release the button to send notification pause.
Where I have to write this.

Error when installing

I'm receiving the following error when trying to install MMM-Buttons:

pi@MagicMirror:~/MagicMirror/modules/MMM-Buttons $ npm install

> [email protected] postinstall
> node_modules/.bin/electron-rebuild -e node_modules/electron

⠋ Searching dependency tree
An unhandled error occurred inside electron-rebuild
Could not detect abi for version 17.0.1 and runtime electron.  Updating "node-abi" might help solve this issue if it is a new release of electron

Error: Could not detect abi for version 17.0.1 and runtime electron.  Updating "node-abi" might help solve this issue if it is a new release of electron
    at Object.getAbi (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/node-abi/index.js:36:9)
    at new Rebuilder (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/rebuild.js:126:48)
    at rebuildWithOptions (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/rebuild.js:404:23)
    at Object.doRebuild [as rebuild] (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/rebuild.js:427:16)
    at /home/pi/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:124:33
    at Generator.next (<anonymous>)
    at fulfilled (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:6:58)
npm ERR! code 255
npm ERR! path /home/pi/MagicMirror/modules/MMM-Buttons
npm ERR! command failed
npm ERR! command sh -c node_modules/.bin/electron-rebuild -e node_modules/electron

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2022-02-18T11_12_17_532Z-debug-0.log

It seems that the sh -c node_modules/.bin/electron-rebuild -e node_modules/electron command causes problems.
Any solution to this?

help with Page-selector

can somebody help me to make it work with page-selector... what is the changes I have to make in witch file ? I want to use 2 buttons , 1 to increment page and the other to decrement (I've just begin learn javascript :-( )

No Short Press

Hello
I cannot get short presses intercepted
I am 100% sure the buttons work
I checked both outside of magicmirror and inside )added a couple of console.log to the module)
Button down is intercepted button up too ,
Long press is ok
just no short press.
tried modifying the default values
but no luck

How to set time off notification?

The notification pup-up and do not disappear. I want to set time the notification appear and disappear. I try to set timer: "10000" to visible notification in 10s. But the config.js file was not has affected.
Here the code:

longPress: {
title: "Power off",
message: "Keep pressed for 3 seconds to shut down",
imageFA: "power-off",
notification: "REMOTE_ACTION",
payload: {action: "REBOOT"},
timer: "10000",
},

PLease tell me how to set that time.

Can't change profile with buttons

Hi!
I have problem… When I connect the two pins (pin 9 and pin 11 / Ground & GPIO 17) it doesn’t change the profile…
Can you help out here? That would be great!
This is my config:

var config = {
address: "localhost", // Address to listen on, can be:
// - "localhost", "127.0.0.1", "::1" to listen on loopback interface
// - another specific IPv4/6 to listen on a specific interface
// - "", "0.0.0.0", "::" to listen on any interface
// Default, when address config is left out, is "localhost"
port: 8080,
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
// or add a specific IPv4 of 192.168.1.5 :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
// or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],

language: "de",
timeFormat: 24,
units: "metric",

modules: [
	{
		module: "alert",
			classes: "default everyone"


	},
	{
		module: "updatenotification",
		position: "top_bar",
		classes: "default everyone"


	},
	{
		module: "clock",
		position: "top_left",
		classes: "default everyone"
	},

	{
		module: "newsfeed",
		position: "bottom_bar",
		classes: "default",
		config: {
			feeds: [
				{
					title: "Neue Zürcher Zeitung",
					url: "https://www.nzz.ch/recent.rss"
				},


			],
			showSourceTitle: true,
			showPublishDate: true,
			broadcastNewsFeeds: true,
			broadcastNewsUpdates: true
		}
	},

	    {

  			module: "MMM-CalendarExt",
  			position: "top_left",
		classes: "default everyone",
		config: {
    		system: {
      				show: ["daily"],
      				locale: 'de',
      				redrawInterval:60000,
    			},
    			views: {
      				daily: {
        						position:'lower_third',
        						counts:7,
      					},

    				},

    			defaultCalendar: {
      						maxEntries:50,
      						maxDays:180,
      						interval: 1000*60*5,
    					},

    			calendars :[
      					{
        						name: "Tommaso",
        						url: "https://calendar.google.com/calendar/ical/tommaso.peduzzi%40gmx.ch/private-088063fff967db8474e57b3a7cdf176a/basic.ics",
						profiles: ['Tom'],
      					},
      					{
        						name: "Ferien",
        						url: "https://www.ferienwiki.ch/exports/ferien/2019/ch/basel-stadt",
						profiles: ['default'],
      					},


    				],
  				},
		},    						
	{
    		module: 'MMM-ProfileSwitcher',
		classes: "default everyone",
   				config: {
       					// See 'Configuration options' for more information.
					}
	},
    	{
	            module: "currentweather",
			classes: "default",
	            position: "top_right",
	            config: {
	              location: "Basel",
	              locationID: "6458763",  //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
	              appid: "4a58442ce61f6ae3de20fcfdecdb0327"
      				}
    	},
        {
            module: "weatherforecast",
	    classes: "default everyone",
            position: "top_right",
            header: "Weather Forecast",
            config: {
              location: "Basel",
              locationID: "6458763",  //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
              appid: "4a58442ce61f6ae3de20fcfdecdb0327"
          }
    	},
	

	/*{

	   	module: 'MMM-GPIO-Notifications',
		classes: "default everyone",

		    config: {

		        '17': {

		          gpio_state: 1,

		          gpio_debounce: 10,

		          notifications: [

		            {

				// see https://github.com/tosti007/MMM-ProfileSwitcher

				// Switching Profiles

				// this.sendNotification('CURRENT_PROFILE', 'DESIRED_PROFILE_NAME_HERE');

		              notification: 'CURRENT_PROFILE', 										

		              payload:  'Tom' 

		            },



		          ]

		        }

		    }

		},*/


		{
		    module: 'MMM-Buttons',
		    config: {
		        buttons: [
		            {
		                pin: 17,
		                name: "monitor_control",
		                shortPress: {
		                    notification: "CURRENT_PROFILE",
		                    payload: "Tom"
		                },

		            },


		        ]
		    }

},

]

};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = config;}

Thanks alot,

Tom

error when install npm

hi ,
i have node 11 and when i install with this command : sudo npm install

npm WARN lifecycle [email protected]~postinstall: cannot run in wd [email protected] electron-rebuild -e ../../node_modules/electron (wd=/home/yuval/Docker/MagicMirror/modules/MMM-Buttons)
audited 301 packages in 1.253s
found 0 vulnerabilities

and with this command : sudo npm -g install


> [email protected] postinstall /home/yuval/Docker/MagicMirror/modules/MMM-Buttons
> electron-rebuild


An unhandled error occurred inside electron-rebuild
Unable to find electron-prebuilt's version number, either install it or specify an explicit version

Error: Unable to find electron-prebuilt's version number, either install it or specify an explicit version
    at Object.<anonymous> (/home/yuval/Docker/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:81:19)
    at Generator.next (<anonymous>)
    at /home/yuval/Docker/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/yuval/Docker/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:4:12)
    at /home/yuval/Docker/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:70:8
    at Object.<anonymous> (/home/yuval/Docker/MagicMirror/modules/MMM-Buttons/node_modules/electron-rebuild/lib/src/cli.js:146:4)
    at Module._compile (internal/modules/cjs/loader.js:805:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
    at Module.load (internal/modules/cjs/loader.js:672:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! [email protected] postinstall: `electron-rebuild`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/yuval/.npm/_logs/2019-04-03T11_35_21_386Z-debug.log

Struggling to get button working with MMM-Carousel

I was wondering if you know how to get a physical button to work with MMM-carousel. I have been struggling to get the button to move the slides. Its been a while and i lost progress i had. tried this just to get one slide button working to no avail.

` {
module: 'MMM-Buttons',
config: {
buttons: [
{
pin: 25,
name: "monitor_control",
longPress: {
notification: "REMOTE_ACTION",
payload: {action: "MONITOROFF"}
},
shortPress: {
notification: "REMOTE_ACTION",
payload: {action: "MONITORON"}
}
},
{
pin: 18,
name: "ArrowRight",
shortPress: {

                notification: "CAROUSEL_NEXT",
                payload: {action: "CAROUSEL_NEXT"}
            },
            longPress: undefined
        }
    ]
}

},
`

npm rebuild fix

I got an error after installing the module.

Whoops! There was an uncaught exception...
Error: Module version mismatch. Expected 48, got 53.
    at Error (native)
    at Object.Module._extensions..node (module.js:597:18)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at bindings (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-Buttons/node_modules/epoll/epoll.js:1:99)
    at Module._compile (module.js:570:32)

So I googled a bit and found a solution:

npm rebuild

After I ran this in the MMM-Buttons-folder it works. I don't know exactly what it did, but I want to inform the contributors or other folks who want to install this.

press button twice to trigger

I have a strange issue with button press. I have to press it twice quickly to trigger action. Pressing it just once or holding it down does not work.

Anyone have the same strange issue I have?

Buttons don't work until I test from terminal

The plugin works fine for what I'm doing but in order for it to work I have to run a python based test program I have for testing the buttons. Once I do that it all works great. I have to do this every time the pi is rebooted. Any ideas?

shortpress never happens timer is wrong

I've been playing with the code and like another issue I can't get shortpresses ever.
only long presses and the timer seems to control all buttons, not just the one that was pressed.

Error after installing

I am running magic mirror in a docker container however, after fixing an error with electron by installing electron by hand and editing the path in the package.json see issue: #7

Now magic mirror can't start and i get the following docker logs:

[2020-12-16 18:34:53.575] [ERROR]  Error: The module '/opt/magic_mirror/modules/MMM-Buttons/node_modules/epoll/build/Release/epoll.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 85. This version of Node.js requires
NODE_MODULE_VERSION 72. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1208:18)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at bindings (/opt/magic_mirror/modules/MMM-Buttons/node_modules/bindings/bindings.js:112:48)
    at /opt/magic_mirror/modules/MMM-Buttons/node_modules/epoll/epoll.js:7:31
    at Object.<anonymous> (/opt/magic_mirror/modules/MMM-Buttons/node_modules/epoll/epoll.js:15:3)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)

i have already tried npm rebuild and ./node_modules/.bin/electron-rebuild
Does this has to do with the electron version? What can i possibly do to fix the issue?

Thank you for your support :)

excuse me, @Jopyth what electron version are you using? (It isn't specified in the package.json file)

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.