-
Notifications
You must be signed in to change notification settings - Fork 0
Update pin config and fix the distance measure logic #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
| 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
|
||
| pulseEnd = time.monotonic() | ||
|
|
||
| pulseDuration = pulseEnd - pulseStart | ||
| distance = pulseDuration * 17150 | ||
| distance = round(distance, 2) | ||
|
|
||
| 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 | ||
|
arghyabi marked this conversation as resolved.
Comment on lines
+1
to
+3
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| appVersion: 1.0.1.1001 | ||
| appVersion: 1.1.0.1002 | ||
|
|
There was a problem hiding this comment.
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.