Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play/Stop Music #19

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: "monthly"
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
82 changes: 39 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Magic Mirror Module: Buttons
# MMM-Buttons

This 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 @@ -13,9 +17,10 @@ For example this can be used to send notifications to the following modules:
## Installation

Clone this repository in your `modules` folder, and install 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