Giter VIP home page Giter VIP logo

mmm-button's Introduction

MMM-Button

This is an extension for the MagicMirror. It can monitor a button click and change for example the visibility of some of your modules (at the moment just works with my MMM-Podcast module). Special thanks goes to Paviro as this module is heavily based on his PIR-Sensor module.

Installation

  1. Navigate into your MagicMirror's modules folder and execute git clone https://github.com/ptrbld/MMM-Button.git. A new folder will appear navigate into it.
  2. Execute npm install to install the node dependencies.

Using the module

First of all connect a button to your Raspberry PI: How to connect a button.

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

modules: [
	{
		module: 'MMM-Button',
		config: {
			// See 'Configuration options' for more information.
		}
	}
]

Configuration options

The following properties can be configured:

Option Description
buttonPIN The pin your button is connected to.

Possible values: int
Default value: 5
clickDelay The time in miliseconds before another button click is recognized

Possible values: int
Default value: 500
notificationMessage The message broadcasted to other modules

Possible values: string
Default value: BUTTON_PRESSED

Developer Notes

This module broadcasts a BUTTON_PRESSED (as default; specified in the module config) notification with the payload beeing true you can use it to show/hide your module (e.g. MMM-Podcast).

Dependencies

  • onoff (installed via npm install)

The MIT License (MIT)

Copyright © 2016 PtrBld

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

Contributors

balassy avatar ptrbld avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mmm-button's Issues

More than one button

I changed the code for more two buttons as follows:

'use strict';

/* Magic Mirror

  • Module: MMM-Button
  • MIT Licensed.
    */

const NodeHelper = require('node_helper');
const gpio = require('onoff');
module.exports = NodeHelper.create({
start: function () {
this.started = false
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
const self = this;
if (notification === 'BUTTON_CONFIG' && this.started == false) {
const self = this
this.config = payload
var GPIO = require('onoff').Gpio,
button = new GPIO(this.config.buttonPIN, 'in', 'both',{ persistentWatch: true, debounceTimeout: this.config.clickDelay });
buttonn = new GPIO(this.config.buttonPINN, 'in', 'both',{ persistentWatch: true, debounceTimeout: this.config.clickDelay });
button.watch(function(err, state) {
// check the state of the button
// 1 == pressed, 0 == not pressed
if(state == 1) {
// send notification for broadcast
self.sendSocketNotification("BUTTON_PRESSED", true);
console.log("button pressed");
}
});
buttonn.watch(function(err, state) {
// check the state of the button
// 1 == pressed, 0 == not pressed
if(state == 1) {
// send notification for broadcast
self.sendSocketNotification("BUTTON_PRESSED", true);
console.log("button 2 pressed");
}
});
this.started = true
};
}

});

But it says, button is not defined in console. Can you please help me out with error?

This is main file:

/* global Module */

/* Magic Mirror

  • Module: MMM-Button
  • MIT Licensed.
    */

Module.register('MMM-Button',{
requiresVersion: "2.1.0",
defaults: {
buttonPIN: 4,
buttonPINN: 5,
//time in miliseconds before another button click is recognized
clickDelay: 500,
},
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === "BUTTON_PRESSED"){
this.sendNotification(notification, payload)
}
},
start: function() {
this.sendSocketNotification('BUTTON_CONFIG', this.config);
Log.info('Starting module: ' + this.name);
}
});

npm install fails

Hi, i cloned the module right now but:

- ~/MagicMirror/modules/MMM-Button $ npm install
- npm WARN Failed to parse json
- npm WARN Trailing comma in array at 13:3
- npm WARN   ],
- npm WARN   ^
- npm WARN File: /home/pi/MagicMirror/modules/MMM-Button/package.json
- npm WARN MMM-Button No description
- npm WARN MMM-Button No repository field.
- npm WARN MMM-Button No README data
- npm WARN MMM-Button No license field.

Change pull_up_down-resistor

Hello,
at the first thanks for this module and your work and engineering.
My question is, where I can change the pull_up_down resistor?!
Background is that I have a PIR sensor and which this I will start your other Module MMM-Podcast on my mirror. But the PIR sensor work with 3,3 V and not with GND I think. And for this I must change the resistor Level.
I hope I´m right with my Idea ;)
Thanks a lot for your Help

Black screen, no module displayed

Hy there,

i installed your MMM-Button and your MMM-Podcast program as mentioned. If I add the module MMM-Button to my config.js file with all default values and restart the mirror with
DISPLAY=:0 npm start
The screen gets black and no module does show up. Even nothing with clicking the button. The modules worked all correctly before I added the MMM-Button module. If I delete the MMM-Button from my config.js file the mirror works like a charm. So I do not get your module started.

Best regards
Michael

Button not working

I've installed the Button module and connected the button to the Pi. In the config file I added the required lines to include the module (Pin number). Unfortunately the Pi doesn't recognise the button-press: there is no message appearing in the console log or console info.
What is the issue?
Do I have to implement the python file, described in the link, into the .js file of the button module?

No Video played

Hello
The button is pressed and also realized that it was pressed but no video is played. Only the following error message occurs

0|mm | ReferenceError: socketNotificationReceived is not defined
0|mm | at Timeout._onTimeout (/home/pi/MagicMirror/modules/MMM-Podcast/node_helper.js:32:27)
0|mm | at ontimeout (timers.js:365:14)
0|mm | at tryOnTimeout (timers.js:237:5)
0|mm | at Timer.listOnTimeout (timers.js:207:5)

Hope for help.

Best regards

Update node module version

Hi !
I install your module but have a blanck screen. I am also a noob in raspberry.
Apparently, the version of "node-module" is 46, and it would require version 53. After reinstalling and updating, nothing is done. An error occurs.
"The module '/home/pi.../MM-button/node_modules/epoll/build/Release/epoll.node' was compiled against a different Node.JS version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 53. ...

If you have an issues ...

Thank you !

Where do I change what module is loaded?

Hello, I am not great with Javascript, more of a Python guy, I have been trying to figure out for hours where you change which module the button press will load. Can you help?

button pressed, but I did nothing

Hi PtrBld,

Im running your MMM-Button Modul und GPIO PIN 9. Everything is working fine. But sometimes my Tagesschauvideo starts without my hand. I did nothing and "pm2 logs mm" sad to me: button pressed. Any idea why this happens?

Best regards

EDIT: Attached a picture from my pm2 logs last night

bildschirmfoto 2016-07-25 um 17 27 13

MMM-Button doesnt work - NODE_MODULE_VERSION missmatch

Hello,

i got my MagicMirror run and now want to use the Button Module. Unfortunatly it doesnt’t work. And sorry for my english, it isnt very well.

I use a RPi 2

I did the “Complete Setup Tutorial” to set up the pi. Now when i try to put the module-code from the Button-Module into the config.js and do a “pm2 restart mm” the screen went to the desktop and then it will show just a blank, white page on the monitor. Button is used like this, but with GPIO-5 : https://dracarysdiy.files.wordpress.com/2016/03/button.jpg?w=474
I can see that the Button works as i used “gpio read” to check it

Any idea? All other modules working fine

Also its NOT possible to get the webUI with connecting via another pc (192.168.178.230:8080). Here is a screen of my config: https://forum.magicmirror.builders/uploads/files/1474909812019-mmm-button-resized.png

Still Button not working...

Thank you so much for your Bugfix.
But i've still while pressing the Button a black screen.

I've checked by gpio readall my button - it works so far.

Maybe you guys have any tips

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.