Skip to content
This repository was archived by the owner on Dec 14, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
180127d
update package.json to fix compilation of epoll
MarcLandis Jan 4, 2023
7a48b5f
Update README.md
MarcLandis Jan 4, 2023
63a21f3
add possibility to send more than one notification
MarcLandis Sep 13, 2024
af9d4c3
Add symbolization image
KristjanESPERANTO Sep 24, 2024
31d594c
Magic Mirror -> MagicMirror²
KristjanESPERANTO Sep 24, 2024
2e6ee6b
Update URL
KristjanESPERANTO Sep 24, 2024
c18eaf2
Fix name and contributors
KristjanESPERANTO Sep 24, 2024
73e3751
Add missing LICENSE file
KristjanESPERANTO Sep 24, 2024
002b355
console -> Log
KristjanESPERANTO Sep 24, 2024
5eeaeee
Use method shorthand and uniform quotes
KristjanESPERANTO Sep 24, 2024
5a6919f
Moved license to LICENSE file
KristjanESPERANTO Sep 24, 2024
2be5e90
Remove superflous .git
KristjanESPERANTO Sep 24, 2024
431230a
Format
KristjanESPERANTO Sep 24, 2024
26d839c
Merge pull request #1 from KristjanESPERANTO/main
MarcLandis Sep 24, 2024
f2617ab
Create dependabot.yml
MarcLandis Sep 24, 2024
3ad0807
update node_helper with recommendation
MarcLandis Sep 25, 2024
ed894d5
Wording
KristjanESPERANTO Oct 6, 2024
fa6ba3e
Update dependabot.yml
MarcLandis Oct 7, 2024
c12de97
Bump @electron/rebuild from 3.6.0 to 3.6.2
dependabot[bot] Oct 7, 2024
2b290a9
Merge pull request #3 from KristjanESPERANTO/main
MarcLandis Oct 7, 2024
68761cb
Merge pull request #4 from MarcLandis/dependabot/npm_and_yarn/electro…
MarcLandis Oct 7, 2024
f2cb855
Bump nan from 2.20.0 to 2.22.0
dependabot[bot] Oct 14, 2024
b23f36a
Merge pull request #5 from MarcLandis/dependabot/npm_and_yarn/nan-2.22.0
MarcLandis Oct 22, 2024
d8aeb3e
Bump @electron/rebuild from 3.6.2 to 3.7.0
dependabot[bot] Oct 22, 2024
a40fb16
Merge pull request #6 from MarcLandis/dependabot/npm_and_yarn/electro…
MarcLandis Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 0 additions & 16 deletions CHANGELOG.md

This file was deleted.

25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# The MIT License (MIT)

Copyright © 2016 Joseph Bethge
Copyright © 2024 Marc Landis

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.
58 changes: 41 additions & 17 deletions MMM-Buttons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Module */

/* Magic Mirror
/* MagicMirror²
* Module: Buttons
*
* By Joseph Bethge
Expand All @@ -9,19 +9,41 @@

Module.register("MMM-Buttons", {

requiresVersion: "2.1.0",

// Default module config.
defaults: {
buttons: [],
buttons: [
{
pin: 24,
activeLow: false,
name: "Button",
shortPress: [
{
title: "",
message: "",
imageFA: "",
notification: "",
payload: ""
}
],
longPress: [
{
title: "",
message: "",
imageFA: "",
notification: "",
payload: ""
}
],
}
],
minShortPressTime: 0,
maxShortPressTime: 500,
minLongPressTime: 3000,
bounceTimeout: 300
},

// Define start sequence.
start: function() {
start () {
Log.info("Starting module: " + this.name);

this.sendConfig();
Expand All @@ -36,22 +58,22 @@ Module.register("MMM-Buttons", {
},

// Override dom generator.
getDom: function() {
getDom () {
var wrapper = document.createElement("div");

return wrapper;
},

/* sendConfig()
* intialize backend
*/
sendConfig: function() {
* intialize backend
*/
sendConfig () {
this.sendSocketNotification("BUTTON_CONFIG", {
config: this.config
});
},

buttonUp: function(index, duration) {
buttonUp (index, duration) {
if (this.alerts[index]) {
// alert already shown, clear interval to update it and hide it
if (this.intervals[index] !== undefined) {
Expand Down Expand Up @@ -84,11 +106,13 @@ Module.register("MMM-Buttons", {
}
},

sendAction: function(description) {
this.sendNotification(description.notification, description.payload);
sendAction (description) {
for (var i = 0; i < description.length; i++) {
this.sendNotification(description[i].notification, description[i].payload);
}
},

buttonDown: function(index) {
buttonDown (index) {
var self = this;

if (self.config.buttons[index].longPress && self.config.buttons[index].longPress.title)
Expand All @@ -99,22 +123,22 @@ Module.register("MMM-Buttons", {
}
},

showAlert: function (index) {
// display the message
showAlert (index) {
// display the message
this.sendNotification("SHOW_ALERT", {
title: this.config.buttons[index].longPress.title,
message: this.config.buttons[index].longPress.message,
imageFA: this.config.buttons[index].longPress.imageFA
});
},

startAlert: function(index) {
startAlert (index) {
this.alerts[index] = true;
this.showAlert(index);
},

// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
socketNotificationReceived (notification, payload) {
if (notification === "BUTTON_UP")
{
this.buttonUp(payload.index, payload.duration);
Expand Down
84 changes: 40 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Magic Mirror Module: Buttons
# MMM-Buttons

This is a module for [MagicMirror²](https://github.com/MagicMirrorOrg/MagicMirror) to act based on button presses via GPIO.

![symbolization](symbolization.png)

This a module for [Magic Mirror²](https://github.com/MichMich/MagicMirror) 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](https://github.com/PtrBld/MMM-Button), 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:
Expand All @@ -12,10 +16,11 @@ For example this can be used to send notifications to the following modules:

## Installation

Clone this repository in your `modules` folder, and install dependencies:
Clone this repository into your `modules` directory and install the dependencies:

```bash
cd ~/MagicMirror/modules # adapt directory if you are using a different one
git clone https://github.com/Jopyth/MMM-Buttons.git
git clone https://github.com/MarcLandis/MMM-Buttons
cd MMM-Buttons
npm install # this can take a while
```
Expand All @@ -25,41 +30,52 @@ npm install # this can take a while
Add the module to your modules array in your `config.js`.

Below is a simple example (needs [Remote Control](https://forum.magicmirror.builders/topic/735/remote-control-shutdown-configure-and-update-your-magicmirror) 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.
```

```js
{
module: 'MMM-Buttons',
module: "MMM-Buttons",
config: {
buttons: [
{
pin: 25,
name: "monitor_control",
longPress: {
notification: "REMOTE_ACTION",
payload: {action: "MONITOROFF"}
},
shortPress: {
notification: "REMOTE_ACTION",
payload: {action: "MONITORON"}
}
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
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:
Expand All @@ -85,30 +101,10 @@ Each button configuration is an object with the following properties:

### Notification Configuration

Each notification configuration is an object with the following properties:
Each notification configuration is an array of objects 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](https://github.com/MichMich/MagicMirror/tree/master/modules/default/alert#alert-params) 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.**
| `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](https://github.com/MagicMirrorOrg/MagicMirror/tree/master/modules/default/alert#alert-params) for their meaning. |
Loading