-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Create hcsr04_driver.go #872
Conversation
Trting to translate HCSR04 from another lib that uses go-rpio.
related to #865 |
drivers/gpio/hcsr04_driver.go
Outdated
for { | ||
// readedValue, _ := pin.DigitalRead() | ||
readedValue := 1 | ||
// fmt.Println("Lectura: ", readedValue, state, *quit) | ||
if readedValue != state && !*quit { | ||
break | ||
} | ||
} |
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.
this loop waits for "an ongoing measurement is finished", so it will possibly not work, if the pin.DigitalRead() is substituted by a constant of "1" (especially for the first call)
drivers/gpio/hcsr04_driver.go
Outdated
readedValue, _ := hcsr04.echoPin.DigitalRead() | ||
if readedValue == 1 { | ||
return 0, errors.New("already receiving echo") | ||
} |
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.
this part looks "duplicated" to me (because the go - routine already waits for pin != 1), please try without them to save some time
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.
In general I would remove all monitoring stuff first. This simplifies further reviews and also gobot normally use other methods for continuous reading.
Start working. I thought it needs to be more stable. Good reads.
Thank you @gen2thomas I make all suggested changes and change a condition and starts working. I think it needs a review for clean code and write some tests, but it start working. I upload changes to my branch If you want to review. |
@Juan1ll0 I have added some new comments. |
Move private functions to end of file
I make all your suggested changes. |
@Juan1ll0 thanks - I will have a look in the next days, meanwhile:
don't care on errors in other files, fix your issues is sufficient |
type HCSR04 struct { | ||
name string | ||
connection gobot.Adaptor | ||
triggerPin *gpio.DirectPinDriver |
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.
Because the file is already part of package "gpio", all this "gpio." needs to be removed. Otherwise an import cycle failure occurs.
Write some example test fot HC-SR04 dirver.
accidentally closed - now reopen |
Trying to translate HCSR04 from another lib that uses go-rpio.