Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Scripts/GpioManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GpioManager:
def __init__(self):
if RPI_ENV:
print("Running on Raspberry Pi environment.")
GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.BOARD)
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the global GPIO mode to BOARD is a breaking change for any callers that may still provide BCM pin numbers. Consider making the numbering mode configurable (e.g., via config/env) and validating at startup, or clearly documenting this change and enforcing it with an assertion/log so misconfigurations are caught early.

Copilot uses AI. Check for mistakes.
else:
print("Running in a non-Raspberry Pi environment. GPIO operations will be simulated.")
self.state = {}
Expand Down
25 changes: 14 additions & 11 deletions Scripts/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,28 @@ def cleanupGpio(gpio:GpioManager):


def readDistance(gpio:GpioManager, trig, echo):
# Ensure trigger is low
gpio.output(trig, False)
time.sleep(0.05)

# Send a 10us pulse to trigger
gpio.output(trig, True)
time.sleep(0.00001)
gpio.output(trig, False)

pulseStart = None
pulseEnd = None
timeout = time.time() + 1
# Wait for the echo pin to go high
startTime = time.monotonic()
while gpio.input(echo) == 0:
pulseStart = time.time()
if time.time() > timeout:
return -1
if time.monotonic() - startTime > 1:
return -1 # Timeout waiting for echo to start
Comment on lines +35 to +36
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout value 1 is duplicated and acts as a magic number. Extract it to a named constant (e.g., TIMEOUT_S = 1.0) and consider also defining a named error sentinel (e.g., DISTANCE_TIMEOUT = -1) to make the intent and usage clearer.

Copilot uses AI. Check for mistakes.
pulseStart = time.monotonic()

# Wait for the echo pin to go low
while gpio.input(echo) == 1:
pulseEnd = time.time()
if time.time() > timeout:
return -1
if pulseStart is None or pulseEnd is None:
return -1
if time.monotonic() - pulseStart > 1:
return -1 # Timeout waiting for echo to end
Comment on lines +41 to +42
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout value 1 is duplicated and acts as a magic number. Extract it to a named constant (e.g., TIMEOUT_S = 1.0) and consider also defining a named error sentinel (e.g., DISTANCE_TIMEOUT = -1) to make the intent and usage clearer.

Copilot uses AI. Check for mistakes.
pulseEnd = time.monotonic()

pulseDuration = pulseEnd - pulseStart
distance = pulseDuration * 17150
distance = round(distance, 2)
Expand Down
6 changes: 3 additions & 3 deletions Scripts/PinDescription.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MOTOR_PIN = 17
ULTRASONIC_TRIG = 23
ULTRASONIC_ECHO = 24
MOTOR_PIN = 32
ULTRASONIC_TRIG = 40
ULTRASONIC_ECHO = 38
Comment thread
arghyabi marked this conversation as resolved.
Comment on lines +1 to +3
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants are now physical BOARD pin numbers. Add a brief module-level comment stating that PinDescription uses GPIO.BOARD numbering to avoid confusion with BCM.

Copilot uses AI. Check for mistakes.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
appVersion: 1.0.1.1001
appVersion: 1.1.0.1002