This a module for Magic Mirror² to act based on touch (capacitive) buttons via the CAP1188 touch-button controller. It is capable of connecting up to 8 buttons, which can be individually configured. This module is forked from the module for the MPR121 MMM-MPR121 which is based on the awesome MMM-Buttons module
This module sends out notifications to other modules.
For example this can be used to send notifications to the following modules:
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/ASCIIcat/MMM-CAP1188.git
cd MMM-CAP1188
npm install
Note: On some installations you may need to use this command instead:
npm install --unsafe-perm
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 CAP1188. 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-CAP1188',
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
}
]
}
},
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. |
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. |
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. |