From 96dcdb4c86fe94b7928a82be9a52926f70f6e659 Mon Sep 17 00:00:00 2001 From: Josh Finlay Date: Wed, 8 Jan 2025 09:28:00 +1000 Subject: [PATCH] fix: update GPIO for voltage input - Removed pull-up resistor since we're receiving voltage - Changed logic to match voltage input (HIGH = open) - Updated comments and documentation --- backend/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/main.py b/backend/main.py index 7dba7af..64a4668 100644 --- a/backend/main.py +++ b/backend/main.py @@ -312,7 +312,7 @@ async def update_gate_status(): logger.warning("No settings available, using default settings") settings = Settings() - # Check current status (LOW = closed, HIGH = open) + # Check current status (HIGH = open, LOW = closed) is_open = GPIO.input(settings.gpio.statusPin) == GPIO.HIGH # Update state machine @@ -437,7 +437,8 @@ async def get_status(): """Get current gate status""" try: settings = app.state.current_settings or Settings() - # LOW (0V) means gate is closed, HIGH (3.3V) means gate is open + # HIGH (3.3V) means gate is open (receiving voltage) + # LOW (0V) means gate is closed (no voltage) is_open = GPIO.input(settings.gpio.statusPin) == GPIO.HIGH gate_status.update(is_open) @@ -563,9 +564,9 @@ def setup_gpio(): GPIO.setup(gate_pin, GPIO.OUT) GPIO.output(gate_pin, GPIO.LOW) - # Setup status pin if needed + # Setup status pin as input without pull-up status_pin = settings.gpio.statusPin - GPIO.setup(status_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + GPIO.setup(status_pin, GPIO.IN) logger.info(f"GPIO initialized (Gate Pin: Physical {gate_pin}, Status Pin: Physical {status_pin})") except Exception as e: