Skip to content

Commit

Permalink
coding Whatage
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanYoung-dev committed Dec 1, 2021
1 parent 353246d commit fd2f48f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
81 changes: 73 additions & 8 deletions modules/WhatAge/WhatAge.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
* MIT Licensed.
*/

Module.register("MMM-ImageSlideshow", {
var WhatAge;
Module.register("WhatAge", {
// Default module config.
defaults: {
// an array of strings, each is a path to a directory with images
imagePaths: [ 'modules/MMM-ImageSlideshow/exampleImages' ],
// the speed at which to switch between images, in milliseconds
slideshowSpeed: 10 * 1000,
slideshowSpeed: 10 * 50,
// if zero do nothing, otherwise set width to a pixel value
fixedImageWidth: 0,
// if zero do nothing, otherwise set height to a pixel value
Expand All @@ -28,35 +29,42 @@ Module.register("MMM-ImageSlideshow", {
// if true combine all images in all the paths
// if false each path with be viewed seperately in the order listed
treatAllPathsAsOne: false,
// if true reload the image list after each iteration
reloadImageList: true,
// if true, all images will be made grayscale, otherwise as they are
makeImagesGrayscale: false,
// list of valid file extensions, seperated by commas
validImageFileExtensions: 'bmp,jpg,gif,png',
// a delay timer after all images have been shown, to wait to restart (in ms)
delayUntilRestart: 0,
a:0,
},
// load function
start: function () {
WhatAge = this;
WhatAge.sendNotification("CAROUSEL_NEXT");
// add identifier to the config
this.config.identifier = this.identifier;
// ensure file extensions are lower case
this.config.validImageFileExtensions = this.config.validImageFileExtensions.toLowerCase();
// set no error
this.errorMessage = null;
if (this.config.imagePaths.length == 0) {
this.errorMessage = "MMM-ImageSlideshow: Missing required parameter."
}
this.errorMessage = "MMM-ImageSlideshow: Missing required parameter."
}
else {
// create an empty image list
this.imageList = [];
// set beginning image index to -1, as it will auto increment on start
this.imageIndex = -1;
// ask helper function to get the image list
console.log("MMM-ImageSlideshow sending socket notification");
this.sendSocketNotification('IMAGESLIDESHOW_REGISTER_CONFIG', this.config);
// do one update time to clear the html
this.updateDom();
// set a blank timer
this.interval = null;
this.loaded = false;
}
},
// Define required scripts.
Expand All @@ -66,16 +74,30 @@ Module.register("MMM-ImageSlideshow", {
},
// the socket handler
socketNotificationReceived: function(notification, payload) {
console.log("MMM-ImageSlideshow recieved a socket notification: " + notification);
// if an update was received
if (notification === "IMAGESLIDESHOW_FILELIST") {
// check this is for this module based on the woeid
if (payload.identifier === this.identifier)
{
// extract new list
var newImageList = payload.imageList;
// check if anything has changed. return if not.
if (newImageList.length == this.imageList.length) {
var unchanged = true;
for (var i = 0 ; i < newImageList.length; i++) {
unchanged = this.imageList[i] == newImageList[i];
if (!unchanged)
break;
}
if (unchanged)
return;
}
// set the image list
this.imageList = payload.imageList;
// if image list actually contains images
// set loaded flag to true and update dom
if (this.imageList.length > 0) {
if (this.imageList.length > 0 && !this.loaded) {
this.loaded = true;
this.updateDom();
// set the timer schedule to the slideshow speed
Expand All @@ -86,14 +108,24 @@ Module.register("MMM-ImageSlideshow", {
}
}
}
else if(notification =="Anaysis_success")
{
this.config.a=1;
console.log("fufufufufu 1: " + payload);

this.sendNotification("agecomplete",payload);
this.sendNotification("camera_start");
console.log("fufufufufufufufufu");
}

},
// Override dom generator.
getDom: function () {
var wrapper = document.createElement("div");
// if an error, say so (currently no errors can occur)
if (this.errorMessage != null) {
wrapper.innerHTML = this.errorMessage;
}
}
// if no errors
else {
// if the image list has been loaded
Expand All @@ -113,6 +145,10 @@ Module.register("MMM-ImageSlideshow", {
var showSomething = true;
// if exceeded the size of the list, go back to zero
if (this.imageIndex == this.imageList.length) {
// console.log("MMM-ImageSlideshow sending reload request");
// reload image list at end of iteration, if config option set
if (this.config.reloadImageList)
this.sendSocketNotification('IMAGESLIDESHOW_RELOAD_FILELIST', this.config);
// if delay after last image, set to wait
if (this.config.delayUntilRestart > 0) {
this.imageIndex = -2;
Expand All @@ -131,6 +167,7 @@ Module.register("MMM-ImageSlideshow", {
if (showSomething) {
// create the image dom bit
var image = document.createElement("img");
image.id="imgid";
// if set to make grayscale, flag the class set in the .css file
if (this.config.makeImagesGrayscale)
image.className = "desaturate";
Expand All @@ -144,8 +181,15 @@ Module.register("MMM-ImageSlideshow", {
// if style string has antyhing, set it
if (styleString != '')
image.style = styleString;
// set the image location
image.src = encodeURI(this.imageList[this.imageIndex]);
// imageList는 modules/MMM-Testpython/CognitiveFace로 설정
// 초기화 버튼 클릭
if(this.config.a==0){
image.src = this.imageList[0];
}
// 얼굴 인식 성공시
if(this.config.a==1){
image.src = this.imageList[this.imageList.length-1];
}
// ad the image to the dom
wrapper.appendChild(image);
}
Expand All @@ -155,7 +199,28 @@ Module.register("MMM-ImageSlideshow", {
wrapper.innerHTML = "&nbsp;";
}
}

// return the dom
return wrapper;
},
notificationReceived: function(notification, payload) {
Log.info(this.name + " - received notification: " + notification);
// 얼굴인식시 - Testpython 모듈로부터 받은 신호
if(notification === "ageresult_success"){
this.config.a=1;
}
// 초기화시
if(notification =="Modules All Change")
{
this.config.a=0;
}
// hide 버튼 클릭시
if(notification =="only_camera")
{
this.hide();
}
if (notification === "show_camera") {
this.show();
}
}
});
14 changes: 13 additions & 1 deletion modules/WhatAge/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
*/

// call in the required classes
var {PythonShell} = require('python-shell');
var NodeHelper = require("node_helper");
var FileSystemImageSlideshow = require("fs");
var socketWhatAge;

// the main module helper create
module.exports = NodeHelper.create({
// subclass start method, clears the initial config array
start: function() {
this.moduleConfigs = [];
console.log("Starting Node Helper for: " + this.name);
},
// shuffles an array at random and returns it
shuffleArray: function(array) {
Expand Down Expand Up @@ -117,7 +120,16 @@ module.exports = NodeHelper.create({
// send the image list back
self.sendSocketNotification('IMAGESLIDESHOW_FILELIST', returnPayload );
}
},
else if (notification === "IMAGESLIDESHOW_RELOAD_FILELIST") {
// gather Images according to latest config. The config did not change, but the content of the specified folders might have
var imageList = this.gatherImageList(this.moduleConfigs[this.moduleConfigs.length - 1]);
// build the return payload
var returnPayload = { identifier: payload.identifier, imageList: imageList };
// send the image list back
this.sendSocketNotification('IMAGESLIDESHOW_FILELIST', returnPayload );
}

},
});

//------------ end -------------

0 comments on commit fd2f48f

Please sign in to comment.