-
Notifications
You must be signed in to change notification settings - Fork 3
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 #40 from MWLCDev/RFC31_RealyControlGPIO
RFC31_Control Relays through GPIO socket on Nano and Pi Change folders directory Add a python script wrapper to deal with balena CLI Update docker image for `pi` services
- Loading branch information
Showing
222 changed files
with
1,252 additions
and
1,631 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,41 @@ | ||
from __future__ import absolute_import | ||
|
||
import threading | ||
|
||
import Jetson.GPIO as GPIO # type: ignore | ||
|
||
|
||
class ThreadSafeJetsonGpioRelay(object): | ||
""" | ||
Thread-safe class for managing a GPIO relay on a Jetson Nano. | ||
""" | ||
|
||
def __init__(self, pin=15): | ||
self.pin = pin | ||
self.state = False # False for OFF, True for ON | ||
self.lock = threading.Lock() | ||
GPIO.setmode(GPIO.BOARD) # Set the pin numbering system to BOARD | ||
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.LOW) | ||
|
||
def open(self): | ||
"""Turns the relay ON (sets the GPIO pin LOW).""" | ||
with self.lock: | ||
GPIO.output(self.pin, GPIO.LOW) | ||
self.state = False | ||
|
||
def close(self): | ||
"""Turns the relay OFF (sets the GPIO pin HIGH).""" | ||
with self.lock: | ||
GPIO.output(self.pin, GPIO.HIGH) | ||
self.state = True | ||
|
||
def toggle(self): | ||
"""Toggles the relay state.""" | ||
with self.lock: | ||
self.state = not self.state | ||
GPIO.output(self.pin, GPIO.LOW if self.state else GPIO.HIGH) | ||
|
||
def states(self): | ||
"""Returns the current state of the relay.""" | ||
with self.lock: | ||
return self.state |
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 @@ | ||
import subprocess | ||
|
||
|
||
class Nano: | ||
@staticmethod | ||
def get_ip_address(): | ||
try: | ||
ip_addresses = ( | ||
subprocess.check_output( | ||
"hostname -I | awk '{for (i=1; i<=NF; i++) if ($i ~ /^192\\.168\\./) print $i}'", | ||
shell=True, | ||
) | ||
.decode() | ||
.strip() | ||
) | ||
# Split in case there are multiple local IP addresses | ||
return ip_addresses | ||
except subprocess.CalledProcessError as e: | ||
print(f"An error occurred: {e}") | ||
return None |
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,48 @@ | ||
from __future__ import absolute_import | ||
|
||
import threading | ||
|
||
import RPi.GPIO as GPIO # type: ignore | ||
|
||
|
||
class ThreadSafePi4GpioRelay: | ||
"""Thread-safe class for managing a GPIO relay on a Raspberry Pi.""" | ||
|
||
def __init__(self, pin=15): | ||
self.pin = pin | ||
self.state = False # False for OFF, True for ON | ||
self.lock = threading.Lock() | ||
GPIO.setmode(GPIO.BOARD) # Set the pin numbering system to BOARD | ||
GPIO.setwarnings(False) | ||
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.LOW) | ||
|
||
def open(self): | ||
"""Turns the relay ON (sets the GPIO pin LOW).""" | ||
with self.lock: | ||
print("opened the relay") | ||
GPIO.output(self.pin, GPIO.LOW) | ||
self.state = False | ||
|
||
def close(self): | ||
"""Turns the relay OFF (sets the GPIO pin HIGH).""" | ||
with self.lock: | ||
GPIO.output(self.pin, GPIO.HIGH) | ||
current_state = GPIO.input(self.pin) | ||
print(f"closed the relay, current state: {current_state}") | ||
self.state = True | ||
|
||
def toggle(self): | ||
"""Toggles the relay state.""" | ||
with self.lock: | ||
self.state = not self.state | ||
GPIO.output(self.pin, GPIO.LOW if self.state else GPIO.HIGH) | ||
|
||
def get_state(self): | ||
"""Returns the current state of the relay.""" | ||
with self.lock: | ||
return self.state | ||
|
||
def cleanup(self): | ||
"""Cleans up the GPIO state.""" | ||
GPIO.cleanup(self.pin) # Reset the specific pin before setup | ||
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.LOW) |
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 @@ | ||
import subprocess | ||
|
||
|
||
class RaspberryPi: | ||
@staticmethod | ||
def get_ip_address(): | ||
try: | ||
ip_addresses = ( | ||
subprocess.check_output( | ||
"hostname -I | awk '{for (i=1; i<=NF; i++) if ($i ~ /^192\\.168\\./) print $i}'", | ||
shell=True, | ||
) | ||
.decode() | ||
.strip() | ||
) | ||
# Split in case there are multiple local IP addresses | ||
return ip_addresses | ||
except subprocess.CalledProcessError as e: | ||
print(f"An error occurred: {e}") | ||
return None |
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
File renamed without changes.
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
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
common/byodr/utils/protocol.py → BYODR_utils/common/protocol.py
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.