Debounce, Service
This commit is contained in:
+20
-5
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Generate systemd service file
|
# Generate systemd service file
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
FILE=/etc/systemd/system/buttond.service
|
FILE=/etc/systemd/system/buttond.service
|
||||||
|
|
||||||
button=$(realpath button.py)
|
button=$(realpath button.py)
|
||||||
@@ -10,20 +12,33 @@ if [[ ! -f $button ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
vpython=$(realpath venv/)/bin/python
|
vpython=$(realpath venv/)/bin/python
|
||||||
if [[ ! -e $vpython ]]; then
|
if [[ ! -x $vpython ]]; then
|
||||||
echo venv not found
|
echo venv not found
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat > "$FILE" << EOF
|
cat > "$FILE" << EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description = buttonctl
|
Description=Button Service 1. OG
|
||||||
|
StartLimitIntervalSec=60s
|
||||||
|
StartLimitBurst=10
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type = simple
|
Type=exec
|
||||||
ExecStart = $vpython $button
|
ExecStart=$vpython -u $button
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=$(dirname "$button")
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=3s
|
||||||
|
NoNewPrivileges=yes
|
||||||
|
PrivateTmp=yes
|
||||||
|
ProtectSystem=full
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
Alias=buttond.service
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
service=$(basename "$FILE")
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now "$service"
|
||||||
|
systemctl --no-pager status "$service"
|
||||||
|
|||||||
+5
-5
@@ -298,20 +298,20 @@ def main():
|
|||||||
door_sense.switch_to_input(digitalio.Pull.UP)
|
door_sense.switch_to_input(digitalio.Pull.UP)
|
||||||
|
|
||||||
menu = StateMenu()
|
menu = StateMenu()
|
||||||
btn_locked = False
|
btn_locked = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if not btn_oben.value:
|
if not btn_oben.value:
|
||||||
if not btn_locked:
|
if not btn_locked:
|
||||||
menu.button_pressed("oben")
|
menu.button_pressed("oben")
|
||||||
btn_locked = True
|
btn_locked = 10
|
||||||
elif not btn_unten.value:
|
elif not btn_unten.value:
|
||||||
if not btn_locked:
|
if not btn_locked:
|
||||||
menu.button_pressed("unten")
|
menu.button_pressed("unten")
|
||||||
btn_locked = True
|
btn_locked = 10
|
||||||
else:
|
elif btn_locked:
|
||||||
btn_locked = False
|
btn_locked -= 1
|
||||||
|
|
||||||
if door_sense.value != menu.doors["unten"].door_sense_state:
|
if door_sense.value != menu.doors["unten"].door_sense_state:
|
||||||
menu.doors["unten"].door_sense_state = door_sense.value
|
menu.doors["unten"].door_sense_state = door_sense.value
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Generate systemd service file
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
FILE=/etc/systemd/system/buttond.service
|
||||||
|
|
||||||
|
button=$(realpath button.py)
|
||||||
|
if [[ ! -f $button ]]; then
|
||||||
|
echo button.py not found
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
vpython=$(realpath venv/)/bin/python
|
||||||
|
if [[ ! -x $vpython ]]; then
|
||||||
|
echo venv not found
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat > "$FILE" << EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Button Service UG
|
||||||
|
StartLimitIntervalSec=60s
|
||||||
|
StartLimitBurst=10
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=exec
|
||||||
|
ExecStart=$vpython -u $button
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=$(dirname "$button")
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=3s
|
||||||
|
NoNewPrivileges=yes
|
||||||
|
PrivateTmp=yes
|
||||||
|
ProtectSystem=full
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
service=$(basename "$FILE")
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now "$service"
|
||||||
|
systemctl --no-pager status "$service"
|
||||||
Reference in New Issue
Block a user