Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsounet authored Feb 9, 2024
2 parents 8ae1404 + f3cde9c commit 24f1150
Show file tree
Hide file tree
Showing 15 changed files with 3,199 additions and 705 deletions.
15 changes: 3 additions & 12 deletions MMM-Pir.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#MMM-PIR {
font-size: large;
user-select: none;
line-height: 99%;
min-width: 250px;
}

Expand Down Expand Up @@ -34,6 +32,8 @@
#MMM-PIR_SCREEN_BAR {
font-size: large;
min-width: 100px;
margin-left: auto;
margin-right: auto;
}

#MMM-PIR_SCREEN_BAR.Line {
Expand All @@ -43,18 +43,9 @@
#MMM-PIR_SCREEN_BAR.Circle {
width: 100px;
height: 93px;
top: 10px;
margin-bottom: 10px;
}

#MMM-PIR_SCREEN_BAR.SemiCircle {
width: 100px;
top: 10px;
}

#MMM-PIR_SCREEN_BAR.Bar {
margin-bottom:4px;
height: 4px;
width: 100%;
position:relative;
}

59 changes: 37 additions & 22 deletions MMM-Pir.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************
* MMM-Pir v1.1 *
/*!**************
* MMM-Pir v1.2 *
* Bugsounet *
* 10/2023 *
* 02/2024 *
*****************/

var _logPIR = (...args) => { /* do nothing */ }
Expand All @@ -11,9 +11,8 @@ Module.register("MMM-Pir", {
defaults: {
debug: false,
delay: 2 * 60 * 1000,
turnOffDisplay: true,
mode: 1,
ecoMode: true,
touchMode: 3,
displayCounter: true,
displayBar: true,
displayStyle: "Text",
Expand All @@ -24,23 +23,38 @@ Module.register("MMM-Pir", {
pir_gpio: 21,
pir_reverseValue: false,
xrandrForceRotation: "normal",
wrandrForceRotation: "normal"
wrandrForceRotation: "normal",
wrandrForceMode: null
},

start: function () {
if (this.config.debug) _logPIR = (...args) => { console.log("[MMM-Pir]", ...args) }
this.userPresence = null
this.lastPresence = null
this.ready = false
this.screenDisplay = new screenDisplayer(this)
let Tools = {
sendSocketNotification: (...args) => this.sendSocketNotification(...args),
hidden: () => { return this.hidden },
translate: (...args) => this.translate(...args)
}
let displayConfig = {
displayCounter: this.config.displayCounter,
displayBar: this.config.displayBar,
displayStyle: this.config.displayStyle,
displayLastPresence: this.config.displayLastPresence,
delay: this.config.delay
}
this.screenDisplay = new screenDisplayer(displayConfig, Tools)
this.screenDisplay.checkStyle()
this.screenTouch = new screenTouch(this.config.touchMode, Tools)
_logPIR("is now started!")
},

socketNotificationReceived: function (notification, payload) {
switch(notification) {
case "INITIALIZED":
_logPIR("Ready to fight MagicMirror²!")
this.screenTouch.touch()
this.ready = true
break
case "SCREEN_SHOWING":
Expand All @@ -49,33 +63,27 @@ Module.register("MMM-Pir", {
case "SCREEN_HIDING":
this.screenDisplay.screenHiding()
break
case "SCREEN_TIMER":
case "SCREEN_OUTPUT":
if (this.config.displayStyle == "Text") {
let counter = document.getElementById("MMM-PIR_SCREEN_COUNTER")
counter.textContent = payload
}
break
case "SCREEN_BAR":
if (this.config.displayStyle == "Bar") {
let bar = document.getElementById("MMM-PIR_SCREEN_BAR")
bar.value= this.config.delay - payload
}
else if (this.config.displayStyle != "Text") {
this.screenDisplay.barAnimate(payload)
counter.textContent = payload.timer
} else {
this.screenDisplay.barAnimate(payload.bar)
}
break
case "SCREEN_PRESENCE":
if (!this.config.displayLastPresence) return
if (payload) this.lastPresence = moment().format(this.config.lastPresenceTimeFormat)
else this.userPresence = this.lastPresence
if (this.userPresence && this.config.displayLastPresence) {
if (this.userPresence) {
let presence= document.getElementById("MMM-PIR_PRESENCE")
presence.classList.remove("hidden")
presence.classList.add("bright")
let userPresence= document.getElementById("MMM-PIR_PRESENCE_DATE")
userPresence.textContent = this.userPresence
}
break
case "SCREEN_POWER":
case "SCREEN_POWERSTATUS":
if (payload) this.sendNotification("USER_PRESENCE", true)
else this.sendNotification("USER_PRESENCE", false)
break
Expand All @@ -99,7 +107,7 @@ Module.register("MMM-Pir", {
this.sendNotification("SHOW_ALERT", {
type: "notification",
title: "MMM-Pir",
message: `Error detected: ${payload}`,
message: `Pir Error detected: ${payload}`,
timer: 15000
})
}
Expand All @@ -113,18 +121,23 @@ Module.register("MMM-Pir", {
if (!this.ready) return
switch(notification) {
case "MMM_PIR-END":
/** only available if not force-locked by touch **/
this.sendSocketNotification("FORCE_END")
break
case "MMM_PIR-WAKEUP":
/** only available if not force-locked by touch **/
this.sendSocketNotification("WAKEUP")
break
case "MMM_PIR-LOCK":
/** only available if not force-locked by touch **/
this.sendSocketNotification("LOCK")
break
case "MMM_PIR-UNLOCK":
/** only available if not force-locked by touch **/
this.sendSocketNotification("UNLOCK")
break
case "USER_PRESENCE":
/** only available if not force-locked by touch **/
if (payload) this.sendSocketNotification("WAKEUP")
else this.sendSocketNotification("FORCE_END")
}
Expand All @@ -141,7 +154,9 @@ Module.register("MMM-Pir", {
getScripts: function () {
return [
"/modules/MMM-Pir/components/progressbar.js",
"/modules/MMM-Pir/components/screenDisplayer.js"
"/modules/MMM-Pir/components/screenDisplayer.js",
"/modules/MMM-Pir/components/long-press-event.js",
"/modules/MMM-Pir/components/screenTouch.js"
]
},

Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MMM-Pir

After a configurated time without any user interaction the display will turn off and hide all modules for economy mode.<br>
After a configured time without any user interaction the display will turn off and hide all modules for economy mode.<br>
It will wake up with a Pir sensor

## Screenshot
Expand All @@ -13,8 +13,8 @@ It will wake up with a Pir sensor

**Minimal node version requirement: v18**

Clone the module into your MagicMirror module folder and execute `npm intall` in the module's directory.
```
Clone the module into your MagicMirror module folder and execute `npm install` in the module's directory.
```sh
cd ~/MagicMirror/modules
git clone https://github.com/bugsounet/MMM-Pir
cd MMM-Pir
Expand All @@ -35,9 +35,7 @@ To display the module insert it in the config.js file.
config: {
debug: false,
delay: 2 * 60 * 1000,
turnOffDisplay: true,
mode: 1,
ecoMode: true,
displayCounter: true,
displayBar: true,
displayStyle: "Text",
Expand All @@ -48,7 +46,9 @@ To display the module insert it in the config.js file.
pir_gpio: 21,
pir_reverseValue: false,
xrandrForceRotation: "normal",
wrandrForceRotation: "normal"
wrandrForceRotation: "normal",
wrandrForceMode: "1920x1080",
touchMode: 3
}
},
```
Expand All @@ -57,14 +57,12 @@ To display the module insert it in the config.js file.

| Option | Description | Type | Default |
| ------- | --- | --- | --- |
| debuf | enable or not debug mode | Boolean | false |
| debug | enable or not debug mode | Boolean | false |
| delay | Time before the mirror turns off the display if no user activity is detected. (in ms) | Number | 120000 |
| turnOffDisplay | Should the display turn off after timeout? | Boolean | true |
| mode | mode for turn on/off your screen (see bellow) | number ||
| ecoMode | Should the MagicMirror hide all module after timeout ? | Boolean | true |
| displayCounter | Should display Count-down in screen ? | Boolean | true |
| displayBar| Should display Count-up bar in screen ? | Boolean | true |
| displayStyle| Style of the Count-down. Available: "Text", "Line", "SemiCircle", "Circle", "Bar" | String | Text |
| displayStyle| Style of the Count-down. Available: "Text", "Line", "SemiCircle", "Circle" | String | Text |
| displayLastPresence| Display the date of the last user presence | Boolean | true |
| lastPresenceTimeFormat| Change the date format (moment.js format) of the last presence | String | LL H:mm |
| mode6_gpio| GPIO number for control the relay (mode 6 only) | Number | 20 |
Expand All @@ -73,6 +71,8 @@ To display the module insert it in the config.js file.
| pir_reverseValue | Reverse sensor received value | Boolean | false |
| xrandrForceRotation | **-mode 9 only-** Forces screen rotation according to the defined value (possible value: "normal", "left", "right", "inverted") | String | normal |
| wrandrForceRotation | **-mode 10 only-** Forces screen rotation according to the defined value (possible value: "normal", "90", "180", "270", "flipped", "flipped-90", "flipped-180", "flipped-270") | String | normal |
| wrandrForceMode | **-mode 10 only-** Force screen resolution mode | String | null |
| touchMode | Selected mode for enable/disable the screen with touch (see below) | Number | 3 |

* Available mode:
- `mode: 1` - use vgencmd (For raspbian 10/11)
Expand All @@ -87,6 +87,20 @@ To display the module insert it in the config.js file.
- `mode: 10` - use wlr-randr (For rapsbian 12 with wayland compositor)
- `mode: 0` - disabled mode and disable turnOffDisplay too

* Available touchMode:
- `touchMode: 0`
- disabled
- `touchMode: 1`
- One click on the screen will restart the timer (or Wake up the screen if needed)
- Double Click on the screen will shutdown the screen
- `touchMode: 2`
- One Click on the MMM-Pir area will restart the timer
- Long Click on the screen will shutdown or wake up the screen (toogle)
- `touchMode: 3`
- One Click on the MMM-Pir area will restart the timer
- Doucle Click on the MMM-Pir area will shutdown the screen
- One Click on the screen will wake up if shutdown

## Developer Notes

- This module broadcasts:
Expand Down
36 changes: 0 additions & 36 deletions components/loadLibraries.js

This file was deleted.

Loading

0 comments on commit 24f1150

Please sign in to comment.