Skip to content

Commit 3d8eda3

Browse files
author
Jbamford
committed
first commit
0 parents  commit 3d8eda3

24 files changed

+1491
-0
lines changed

.gitignore

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Adam Moses
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MMM-ImageSlideshow.js

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/* global Module */
2+
3+
/* MMM-PenPlotter.js
4+
*
5+
* Magic Mirror
6+
* Module: MMM-PenPlotter
7+
*
8+
*
9+
* Magic Mirror By Michael Teeuw http://michaelteeuw.nl
10+
* MIT Licensed.
11+
*
12+
* MMM-PenPlotter.js by Jason Bamford https://jbamford.github.io/
13+
*
14+
* Derivate work of
15+
* Module MMM-ImageSlideshow By Adam Moses http://adammoses.com
16+
* MIT Licensed.
17+
*/
18+
19+
Module.register("MMM-ImageSlideshow", {
20+
// Default module config.
21+
defaults: {
22+
// an array of strings, each is a path to a directory with images
23+
// imagePaths: [ 'modules/MMM-ImageSlideshow/exampleImages' ],
24+
imagePaths:[],
25+
// the speed at which to switch between images, in milliseconds 300000 = 5mins
26+
slideshowSpeed: 65000,
27+
// if zero do nothing, otherwise set width to a pixel value
28+
fixedImageWidth: 0,
29+
// if zero do nothing, otherwise set height to a pixel value
30+
fixedImageHeight: 0,
31+
// if true randomize image order, otherwise do alphabetical
32+
randomizeImageOrder: false,
33+
// if true combine all images in all the paths
34+
// if false each path with be viewed seperately in the order listed
35+
treatAllPathsAsOne: false,
36+
// if true, all images will be made grayscale, otherwise as they are
37+
makeImagesGrayscale: false,
38+
// list of valid file extensions, seperated by commas
39+
validImageFileExtensions: 'bmp,jpg,gif,png,svg',
40+
// a delay timer after all images have been shown, to wait to restart (in ms)
41+
delayUntilRestart: 0,
42+
},
43+
// load function
44+
start: function () {
45+
46+
47+
// add identifier to the config
48+
this.config.identifier = this.identifier;
49+
// ensure file extensions are lower case
50+
this.config.validImageFileExtensions = this.config.validImageFileExtensions.toLowerCase();
51+
// set no error
52+
this.errorMessage = null;
53+
if (this.config.imagePaths.length == 0) {
54+
this.errorMessage = "MMM-ImageSlideshow: Missing required parameter."
55+
}
56+
else {
57+
// create an empty image list
58+
this.imageList = [];
59+
// set beginning image index to -1, as it will auto increment on start
60+
this.imageIndex = -1;
61+
// ask helper function to get the image list
62+
this.sendSocketNotification('IMAGESLIDESHOW_REGISTER_CONFIG', this.config);
63+
// do one update time to clear the html
64+
this.updateDom();
65+
// set a blank timer
66+
this.interval = null;
67+
}
68+
},
69+
// Define required scripts.
70+
getStyles: function() {
71+
// the css contains the make grayscale code
72+
return ["imageslideshow.css"];
73+
},
74+
// the socket handler
75+
socketNotificationReceived: function(notification, payload) {
76+
// if an update was received
77+
if (notification === "IMAGESLIDESHOW_FILELIST") {
78+
// check this is for this module based on the woeid
79+
if (payload.identifier === this.identifier)
80+
{
81+
// set the image list
82+
this.imageList = payload.imageList;
83+
// if image list actually contains images
84+
// set loaded flag to true and update dom
85+
if (this.imageList.length > 0) {
86+
this.loaded = true;
87+
this.updateDom();
88+
// set the timer schedule to the slideshow speed
89+
var self = this;
90+
this.interval = setInterval(function() {
91+
self.updateDom();
92+
}, this.config.slideshowSpeed);
93+
}
94+
}
95+
}
96+
},
97+
// Override dom generator.
98+
getDom: function () {
99+
var wrapper = document.createElement("div");
100+
// if an error, say so (currently no errors can occur)
101+
if (this.errorMessage != null) {
102+
wrapper.innerHTML = this.errorMessage;
103+
}
104+
// if no errors
105+
else {
106+
// if the image list has been loaded
107+
if (this.loaded === true) {
108+
// if was delayed until restart, reset index reset timer
109+
if (this.imageIndex == -2) {
110+
this.imageIndex = -1;
111+
clearInterval(this.interval);
112+
var self = this;
113+
this.interval = setInterval(function() {
114+
self.updateDom(0);
115+
}, this.config.slideshowSpeed);
116+
}
117+
// iterate the image list index
118+
this.imageIndex += 1;
119+
// set flag to show stuff
120+
var showSomething = true;
121+
// if exceeded the size of the list, go back to zero
122+
if (this.imageIndex == this.imageList.length) {
123+
// if delay after last image, set to wait
124+
if (this.config.delayUntilRestart > 0) {
125+
this.imageIndex = -2;
126+
wrapper.innerHTML = " ";
127+
showSomething = false;
128+
clearInterval(this.interval);
129+
var self = this;
130+
this.interval = setInterval(function() {
131+
self.updateDom(0);
132+
}, this.config.delayUntilRestart);
133+
}
134+
// if not reset index
135+
else
136+
this.imageIndex = 0;
137+
}
138+
if (showSomething) {
139+
140+
// create the image dom bit
141+
142+
var obj = document.createElement('object');
143+
144+
// obj.data = "modules/MMM-ImageSlideshow/example_svg/spiralbezier.svg"
145+
obj.data = encodeURI(this.imageList[this.imageIndex]);
146+
obj.type = "image/svg+xml"
147+
obj.width ="100%"
148+
obj.height ="100%"
149+
obj.id = "alphasvg"
150+
151+
wrapper.appendChild(obj);
152+
153+
}
154+
}
155+
else {
156+
// if no data loaded yet, empty html
157+
wrapper.innerHTML = " ";
158+
}
159+
}
160+
// return the dom
161+
return wrapper;
162+
}
163+
});

README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Module: Image Slideshow
2+
The `MMM-ImageSlideshow` module is designed to display images, one at a time on a fixed interval, from one or many directories. These images can be shown in order or at random, one directory at a time or all at time. The image heights and widths can be fixed, and the images can be made to be shown in grayscale.
3+
4+
## Dependencies / Requirements
5+
6+
This module requires no special dependencies. The only requirement is that the image directories you path to are fixed paths accessible to the Magic Mirror instance.
7+
8+
## Operation
9+
10+
This module will take in a list of directory paths, one or more, containing image files. The module will display those images in either alphabetical or random order, across either each path one at time or across all the paths at once. Once all the images have been shown, it will loop back and start again.
11+
12+
Extra configurations include setting the amount of time an image is shown for, rendering the images in grayscale, selecting which file extensions are valid, and using a fixed image height and/or width.
13+
14+
15+
## Using the module
16+
17+
To use this module, add it to the modules array in the `config/config.js` file:
18+
````javascript
19+
modules: [
20+
{
21+
module: 'MMM-ImageSlideshow',
22+
position: 'bottom_left',
23+
config: {
24+
imagePaths: ['modules/MMM-ImageSlideshow/example1']
25+
}
26+
}
27+
]
28+
````
29+
30+
## Configuration options
31+
32+
The following properties can be configured:
33+
34+
<table width="100%">
35+
<!-- why, markdown... -->
36+
<thead>
37+
<tr>
38+
<th>Option</th>
39+
<th width="100%">Description</th>
40+
</tr>
41+
<thead>
42+
<tbody>
43+
<tr>
44+
<td><code>imagePaths</code></td>
45+
<td>Array value containing strings. Each string should be a path to a directory where image files can be found.<br>
46+
<br><b>Example:</b> <code>['modules/MMM-ImageSlideshow/example1']</code>
47+
<br>This value is <b>REQUIRED</b>
48+
</td>
49+
</tr>
50+
<tr>
51+
<td><code>slideshowSpeed</code></td>
52+
<td>Integer value, the length of time to show one image before switching to the next, in milliseconds.<br>
53+
<br><b>Example:</b> <code>6000</code>
54+
<br><b>Default value:</b> <code>10000</code>
55+
<br>This value is <b>OPTIONAL</b>
56+
</td>
57+
</tr>
58+
<tr>
59+
<td><code>delayUntilRestart</code></td>
60+
<td>Integer value, the length of time to restart the slideshow after the last image has been shown, in milliseconds. The module will go blank will waits to restart. This value defaults to zero, meaning no delay until restarting.<br>
61+
<br><b>Example:</b> <code>6000</code>
62+
<br><b>Default value:</b> <code>0</code>
63+
<br>This value is <b>OPTIONAL</b>
64+
</td>
65+
</tr>
66+
<tr>
67+
<td><code>fixedImageWidth</code></td>
68+
<td>Integer value, sets a fixed pixel width for all the images to be shown. If set to 0, the image's actual width is used.<br>
69+
<br><b>Example:</b> <code>250</code>
70+
<br><b>Default value:</b> <code>0</code>
71+
<br>This value is <b>OPTIONAL</b>
72+
</td>
73+
</tr>
74+
<tr>
75+
<td><code>fixedImageHeight</code></td>
76+
<td>Integer value, sets a fixed pixel height for all the images to be shown. If set to 0, the image's actual height is used.<br>
77+
<br><b>Example:</b> <code>300</code>
78+
<br><b>Default value:</b> <code>0</code>
79+
<br>This value is <b>OPTIONAL</b>
80+
</td>
81+
</tr>
82+
<tr>
83+
<td><code>randomizeImageOrder</code></td>
84+
<td>Boolean value, if true will randomize the order of the images, if false will use an alphabetical sorting by filename.<br>
85+
<br><b>Example:</b> <code>true</code>
86+
<br><b>Default value:</b> <code>false</code>
87+
<br>This value is <b>OPTIONAL</b>
88+
</td>
89+
</tr>
90+
<tr>
91+
<td><code>treatAllPathsAsOne</code></td>
92+
<td>Boolean value, if true will treat all the paths specified in <code>imagePaths</code> as one path. Otherwise, if false, images will only be shown from one path at a time in the order of <code>imagePaths</code>, until all the images in that path are exhausted, before continuing to the next path.<br>
93+
<br><b>Example:</b> <code>true</code>
94+
<br><b>Default value:</b> <code>false</code>
95+
<br>This value is <b>OPTIONAL</b>
96+
</td>
97+
</tr>
98+
<tr>
99+
<td><code>makeImagesGrayscale</code></td>
100+
<td>Boolean value, if true images will be rendered in grayscale (i.e black and white) instead of color. If false they will be rendered as just they are without change.<br>
101+
<br><b>Example:</b> <code>true</code>
102+
<br><b>Default value:</b> <code>false</code>
103+
<br>This value is <b>OPTIONAL</b>
104+
</td>
105+
</tr>
106+
<tr>
107+
<td><code>validImageFileExtensions</code></td>
108+
<td>String value, a list of image file extensions, seperated by commas, that should be included. Files found without one of the extensions will be ignored.<br>
109+
<br><b>Example:</b> <code>'png,jpg'</code>
110+
<br><b>Default value:</b> <code>'bmp,jpg,gif,png'</code>
111+
<br>This value is <b>OPTIONAL</b>
112+
</td>
113+
</tr>
114+
</tbody>
115+
</table>

README_PenPlotter.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# MMM-PenPlotter

exampleImages/jurassicpark.jpg

14 KB
Loading

exampleImages/matrix.jpg

80.2 KB
Loading

exampleImages/office.gif

507 KB
Loading

exampleImages/test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)