Skip to content

Commit

Permalink
eslint fix (screenTouch.js)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsounet committed Feb 17, 2024
1 parent e0952e3 commit ab7ed4b
Showing 1 changed file with 54 additions and 48 deletions.
102 changes: 54 additions & 48 deletions components/screenTouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,82 @@
* screenTouch *
* Bugsounet *
***************/

/* global window */

class screenTouch {
constructor(mode,Tools) {
this.mode = mode
this.sendSocketNotification = (...args) => Tools.sendSocketNotification(...args)
this.hidden = () => Tools.hidden()
if (this.mode > 3 || this.mode < 0 || isNaN(this.mode)) this.mode = 3
this.clickTimer = null
this.clickCount = 0
console.log("[MMM-Pir] screenTouch Ready")
constructor (mode, Tools) {
this.mode = mode;
this.sendSocketNotification = (...args) => Tools.sendSocketNotification(...args);
this.hidden = () => Tools.hidden();
if (this.mode > 3 || this.mode < 0 || isNaN(this.mode)) this.mode = 3;
this.clickTimer = null;
this.clickCount = 0;
console.log("[MMM-Pir] screenTouch Ready");
}

touch() {
let TouchScreen = document.getElementById("MMM-PIR")
touch () {
let TouchScreen = document.getElementById("MMM-PIR");

switch (this.mode) {
case 1:
/** mode 1 **/
window.addEventListener('click', () => {
this.clickCount++

/** mode 1 **/
window.addEventListener("click", () => {
this.clickCount++;
if (this.clickCount === 1) {
this.clickTimer = setTimeout(() => {
this.clickCount = 0
this.sendSocketNotification("LOCK_FORCE_WAKEUP")
}, 400)
this.clickCount = 0;
this.sendSocketNotification("LOCK_FORCE_WAKEUP");
}, 400);
} else if (this.clickCount === 2) {
clearTimeout(this.clickTimer)
this.clickCount = 0
this.sendSocketNotification("LOCK_FORCE_END")
clearTimeout(this.clickTimer);
this.clickCount = 0;
this.sendSocketNotification("LOCK_FORCE_END");
}
}, false)
break
}, false);
break;
case 2:
/** mode 2 **/
TouchScreen.addEventListener('click', () => {
if (!this.hidden()) this.sendSocketNotification("LOCK_FORCE_WAKEUP")
}, false)

window.addEventListener('long-press', () => {
if (this.hidden()) this.sendSocketNotification("LOCK_FORCE_WAKEUP")
/** mode 2 **/
TouchScreen.addEventListener("click", () => {
if (!this.hidden()) this.sendSocketNotification("LOCK_FORCE_WAKEUP");
}, false);

window.addEventListener("long-press", () => {
if (this.hidden()) this.sendSocketNotification("LOCK_FORCE_WAKEUP");
else {
this.sendSocketNotification("LOCK_FORCE_END")
this.sendSocketNotification("LOCK_FORCE_END");
}
}, false)
break
}, false);
break;
case 3:
/** mode 3 **/
TouchScreen.addEventListener('click', () => {
this.clickCount++

/** mode 3 **/
TouchScreen.addEventListener("click", () => {
this.clickCount++;
if (this.clickCount === 1) {
this.clickTimer = setTimeout(() => {
this.clickCount = 0
this.sendSocketNotification("LOCK_FORCE_WAKEUP")
}, 400)
this.clickCount = 0;
this.sendSocketNotification("LOCK_FORCE_WAKEUP");
}, 400);
} else if (this.clickCount === 2) {
clearTimeout(this.clickTimer)
this.clickCount = 0
this.sendSocketNotification("LOCK_FORCE_END")
clearTimeout(this.clickTimer);
this.clickCount = 0;
this.sendSocketNotification("LOCK_FORCE_END");
}
}, false)
}, false);

window.addEventListener('click', () => {
window.addEventListener("click", () => {
if (this.hidden()) {
clearTimeout(this.clickTimer)
this.clickCount = 0
this.sendSocketNotification("LOCK_FORCE_WAKEUP")
clearTimeout(this.clickTimer);
this.clickCount = 0;
this.sendSocketNotification("LOCK_FORCE_WAKEUP");
}
}, false)
break
}, false);
break;
}
if (!this.mode) console.log("[MMM-Pir] Touch Screen Function disabled.")
else console.log(`[MMM-Pir] Touch Screen Function added. [mode ${this.mode}]`)
if (!this.mode) console.log("[MMM-Pir] Touch Screen Function disabled.");
else console.log(`[MMM-Pir] Touch Screen Function added. [mode ${this.mode}]`);
}
}

0 comments on commit ab7ed4b

Please sign in to comment.