-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from AvaPL/PawelC
Might be the final version.
- Loading branch information
Showing
11 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Signals arm.service activity via led diode and provides a way of manual restart. | ||
After=multi-user.target | ||
|
||
[Service] | ||
Type=idle | ||
ExecStart=/usr/bin/python3 /home/pi/Projects/PyCharm/ARM/support/ARMServiceActivity.py | ||
StandardOutput=file:/home/pi/Projects/PyCharm/ARM/support/ARMServiceActivity.out.log | ||
StandardError=file:/home/pi/Projects/PyCharm/ARM/support/ARMServiceActivity.err.log | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Signals system activity via led diode and provides a way of manual shutdown. | ||
After=multi-user.target | ||
|
||
[Service] | ||
Type=idle | ||
ExecStart=/usr/bin/python3 /home/pi/Projects/PyCharm/ARM/support/SystemActivity.py | ||
StandardOutput=file:/home/pi/Projects/PyCharm/ARM/support/SystemActivity.out.log | ||
StandardError=file:/home/pi/Projects/PyCharm/ARM/support/SystemActivity.err.log | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=ARM - Bluetooth-controlled robotic arm | ||
After=bluetooth.target | ||
|
||
[Service] | ||
Type=idle | ||
ExecStart=/usr/bin/python3 /home/pi/Projects/PyCharm/ARM/Main.py | ||
StandardOutput=file:/home/pi/Projects/PyCharm/ARM/ARM.out.log | ||
StandardError=file:/home/pi/Projects/PyCharm/ARM/ARM.err.log | ||
|
||
[Install] | ||
WantedBy=bluetooth.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from threading import Thread | ||
|
||
import RPi.GPIO as GPIO | ||
import subprocess | ||
|
||
from Common import blinkLed, isButtonHeld | ||
|
||
GPIO.setmode(GPIO.BCM) | ||
restartServicePin = 26 | ||
GPIO.setup(restartServicePin, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||
activityLedPin = 16 | ||
GPIO.setup(activityLedPin, GPIO.OUT) | ||
|
||
|
||
def restartService(): | ||
while True: | ||
if isButtonHeld(restartServicePin, bouncetimeMillis=200, holdtimeMillis=2000): | ||
callRestartSubprocess() | ||
|
||
|
||
def callRestartSubprocess(): | ||
for i in range(5): | ||
blinkLed(activityLedPin, onTimeMillis=100, offTimeMillis=100) | ||
subprocess.call("sudo systemctl restart arm.service", shell=True) | ||
|
||
|
||
restartServiceThread = Thread(target=restartService, daemon=True) | ||
restartServiceThread.start() | ||
|
||
try: | ||
while True: | ||
serviceStatus = subprocess.call("systemctl is-active --quiet arm.service", shell=True) | ||
if serviceStatus == 0: | ||
blinkLed(activityLedPin, onTimeMillis=200, offTimeMillis=2800) | ||
finally: | ||
GPIO.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from time import sleep | ||
|
||
import RPi.GPIO as GPIO | ||
|
||
|
||
def isButtonHeld(pin, bouncetimeMillis, holdtimeMillis): | ||
GPIO.wait_for_edge(pin, GPIO.FALLING) | ||
sleep(bouncetimeMillis / 1000) # Debounce | ||
if GPIO.input(pin) == GPIO.LOW: | ||
edgeDetected = GPIO.wait_for_edge(pin, GPIO.RISING, timeout=holdtimeMillis - bouncetimeMillis) | ||
if edgeDetected is None: | ||
return True | ||
return False | ||
|
||
|
||
def blinkLed(pin, onTimeMillis, offTimeMillis): | ||
GPIO.output(pin, GPIO.HIGH) | ||
sleep(onTimeMillis / 1000) | ||
GPIO.output(pin, GPIO.LOW) | ||
sleep(offTimeMillis / 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from threading import Thread | ||
|
||
import RPi.GPIO as GPIO | ||
import subprocess | ||
|
||
from Common import blinkLed, isButtonHeld | ||
|
||
GPIO.setmode(GPIO.BCM) | ||
shutdownPin = 21 | ||
GPIO.setup(shutdownPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||
activityLedPin = 19 | ||
GPIO.setup(activityLedPin, GPIO.OUT) | ||
|
||
|
||
def shutdown(): | ||
while True: | ||
if isButtonHeld(shutdownPin, bouncetimeMillis=200, holdtimeMillis=2000): | ||
callShutdownSubprocess() | ||
|
||
|
||
def callShutdownSubprocess(): | ||
for i in range(5): | ||
blinkLed(activityLedPin, onTimeMillis=100, offTimeMillis=100) | ||
GPIO.cleanup() | ||
subprocess.call("sudo shutdown -h now", shell=True) | ||
|
||
|
||
shutdownThread = Thread(target=shutdown, daemon=True) | ||
shutdownThread.start() | ||
|
||
try: | ||
while True: | ||
blinkLed(activityLedPin, onTimeMillis=200, offTimeMillis=2800) | ||
finally: | ||
GPIO.cleanup() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.