Skip to content

Latest commit

 

History

History
135 lines (117 loc) · 6.16 KB

README.md

File metadata and controls

135 lines (117 loc) · 6.16 KB

MMM-Navigate

A module to connect a rotary encoder to MagicMirror and use it for Navigation inside of MagicMirror I wanted to use interaction to the MagicMirror and decided to use a rotary encoder, which has 3 functions: Clockwise, Counterclockwise and Press. These functions where combined to a navigation, so you have some possibilities, f.e.: Page increment/decrement, Newsfeed Article more/less details and actions for notification system. The navigation fades out, if not used.

Magic-Mirror Module MMM-Navigate screenshot1

Magic-Mirror Module MMM-Navigate screenshot2

Connect rotary encoder to raspberry pi

Using capacitors for CLK, DT and SW Pin can be useful for debouncing. Magic-Mirror Module MMM-Navigate rotary encoder

Installing the module

Clone this repository in your ~/MagicMirror/modules/ folder ( $ cd ~MagicMirror/modules/ ):

git clone https://github.com/Ax-LED/MMM-Navigate
cd MMM-Navigate
npm install # this can take a while

Using the module

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

{
	module: "MMM-Navigate",
	header: "Navigation",
	position: "top_left",
	config: {
			Alias: [
				'Seiten blättern',
				'News (mehr/weniger Details)',
				'Test notification',
				'News - mehr Details',
				'News - weniger Details',
				'Neustart MagicMirror (PM2)',
				'Neustart',
				'Herunterfahren'
			],
			Action: [
				[{notification:'PAGE_INCREMENT',payload:''},{notification:'PAGE_DECREMENT',payload:''}],//action array, first press locks menu, after this rotation CW/CCW executes, second press release lock mode
				[{notification:'ARTICLE_MORE_DETAILS',payload:''},{notification:'ARTICLE_LESS_DETAILS',payload:''}],
				{notification: 'SHOW_ALERT', payload: {type:'notification',message:'Dies ist eine Testnachricht'}},//single action, execute on press
				{notification:'ARTICLE_MORE_DETAILS',payload:''},
				{notification:'ARTICLE_LESS_DETAILS',payload:''},
				{notification: 'SHELLCOMMAND', payload:'pm2 restart mm'},
				{notification: 'SHELLCOMMAND', payload:'sudo reboot'},
				{notification: 'SHELLCOMMAND', payload:'sudo shutdown -h now'}
			],
			GPIOPins: [26,20,19]//rotary cw, rotary ccw, rotary press (BCM Numbering)
			},
},

On some Raspberry Pis it is neccesary to put the following line to /boot/config.txt for the GPIO where "rotary press (SW)" is connected:

gpio=19=ip,pu

Background: Sets your GPIO 19 as input (ip) and pull up (pu) Change the entry according to the GPIO pin you use.

Configuration options

The following properties can be configured:

Option Description
Alias An Array of the Alias for the navigation entries.
Action An Array of Action of the Alias. There are two modes:
1. Execution of a single action, for Example {notification:'PAGE_INCREMENT',payload:''} to send page increment to MMM-Pages Module.
2. Execution of an array of action, as there are some actions, which belong together (like PAGE_INCREMENT and PAGE_DECREMENT), Example Config: [{notification:'PAGE_INCREMENT',payload:''},{notification:'PAGE_DECREMENT',payload:''}]
Behavior: First press locks menu (can be identified by the red css frame), after this rotation CW/CCW executes actions from config, second press release lock mode so you can select another navigation entry.
GPIOPins Array for Definition of GPIO-Pins (BMC) to connect the rotary encoder for the following actions: Clockwise, Counterclockwise and Press
SHELLCOMMAND Executes code in a terminal of you pi, so you can do almost everything you want. Example you want to shutdown your pi; Config: {notification: 'SHELLCOMMAND', payload:'sudo shutdown -h now'}
Further information:
In version 1.1 of the module, i added a 'second click confirmation notification' for the following SHELLCOMMAND.
This means, if you are using SHELLCOMMAND and press the rotary, you get a notification to do a second press to execute the selected entry.

Further options

You can communicate with this module also by sending notifications. Examples:
yourmmip:8080/MMM-Navigate/remote?action=NOTIFICATION&notification=CCW emulates turning rotary counterclockwise
yourmmip:8080/MMM-Navigate/remote?action=NOTIFICATION&notification=CW emulates turning rotary clockwise
yourmmip:8080/MMM-Navigate/remote?action=NOTIFICATION&notification=PRESSED emulates pressing rotary encoder
yourmmip:8080/MMM-Navigate/remote?notification=SHELLCOMMAND&action=sudo%20shutdown%20-h%20now send command to shutdown your pi

Version

1.6 Changelog:

  • fix rebuild step process (thanks to sdetweil) 1.5 Changelog:
  • minor bugfixes

1.4 Changelog:

  • changed code for better recognition of the rotary encoder
  • changed code enables faster movement of the rotary

1.3 Changelog:

  • added some functions to no longer have a dependency to MMM-Remote-Control
    • SHELLCOMMAND
    • module is now listening to yourmmip:8080/MMM-Navigate/remote?

1.2 Changelog:

  • added lock icon next to navigation alias, if locked
  • code cleaned

1.1 Changelog:

  • added ability to send notifications to MMM-Navigate by other modules
  • added locked mode, so you can put two(2) actions in one(1) navigation link which belong together (like PAGE_INCREMENT and PAGE_DECREMENT). More details see Configuration options (Action).
  • modified css, so locked mode is visual (red frame when locked) in MM
  • added second click confirmation notification for SHELLCOMMAND

1.0 initial release