gobot
gobot copied to clipboard
Add INPUT_PULLUP support on firmdata platform
Add the availability to use INPUT_PULLUP on some GPIO driver:
- button
- direct_pin
- makey_button
- pir_motion_driver
INPUT_PULLUP on arduino is use to avoid to add some resistor when yous should to read the state of button. When INPUT_PULLUP is enable, the signal is inverted, so the platform invert signal to be transparent for user.
Sample to use it with button driver:
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
button := gpio.NewButtonDriverDriver(firmataAdaptor, "13")
err := button.SetInputPullup()
if err != nil {
panic("Not supported by plateforme")
}
work := func() {
buton.On(gpio.ButtonPush, func(data interface{}) {
fmt.Printf("Button pushed")
}
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{button},
work,
)
robot.Start()
}
Button must be plug on input pin and in GND instead of 5v
Hi,
there are some reason to not merge this PR ?
@disaster37 thank you for your PR. IMO this is a nice new feature, so I will try to make some suggestions to get some progress.
- please resolve conflicts by rebase to the current state of dev
- please revert all changes made by "go fmt" in unrelated packages, because this leads to harder review
- please revert the change in go.sum, if this is not important for the work of your new code
- please provide a working example in "gobot/examples" instead of (or in addition to) the sample in your description, this will help future users
Maybe I have not understand the code quite correctly, but would it be better to add an option for each input instead of introducing a new implementation for DigitalRead(), e.g. by an interface with "SetPullUp(pin string, state bool)" and "IsInputPullup()"? In general this should be possible, because the "f.Board.Pins()[p].Mode" is used in both "DigitalRead()" and "DigitalReadInputPullup()".
Instead of "go fmt" in unrelated packages and adjust/cleanup of "go.mod/go.sum" you can add an issue (maybe there is one for "go fmt") or try to solve such general format errors by a separate PR.
Although I have no firmata adaptor tested yet, thanks again for this new feature! IMO this could be also useful for other boards.
I will now revert the PR back to Draft as reference
accidentally closed - now reopen