This repository aims to provide handlers for the go-gpiocdev Library's gpiocdev.WithEventHandler
line option.
It's still under development with two sensor added to the library without tests are performed.
- Each handler is a stuct that implements
IEventHandlers
generic interface. Measure()
method is used as the main handler that does the logic/calculation/measurement for the sensor data. This should be passed toWithEeventHandler()
method.Subscribe()
is for listening measurement if immediate responses are needed when a measurement is done. It's a channel type.CloseChannels()
is the method that closes the above channel. Best to be called when usage is no more required.GetMeasurement()
is the method that return the latest measurement.
A simple example might look like the following:
lfs :=factory.InitializeEventHandlerFor(sensors.FLOW_SENSOR, "gpiochip0", "GPIO4", 0.002222222)
defer lfs.CloseChannels()
gpiocdev.RequestLine("gpiochip0", pin, gpiocdev.WithPullUp, gpiocdev.WithBothEdges, gpiocdev.WithEventHandler(lfs.Measure))
for {
fmt.Printf("%f Liters Flowed",<-lfs.Subscribe())
}
Please refer to the Examples section to see more details examples for each sensor.
Sensor | ID(sensors.go) | Image | Example |
---|---|---|---|
Water Flow Sensor | 0 | example | |
Photocell Sensor | 1 | example |