Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gnyblast/go-gpiocdev-eventhandlers
Helper library to provide event handlers to gpioc-dev library.
https://github.com/gnyblast/go-gpiocdev-eventhandlers
data-collection go go-gpiocdev golang gpio gpio-library gpio-pins library raspberry-pi sensor sensors
Last synced: 2 months ago
JSON representation
Helper library to provide event handlers to gpioc-dev library.
- Host: GitHub
- URL: https://github.com/gnyblast/go-gpiocdev-eventhandlers
- Owner: Gnyblast
- License: mit
- Created: 2024-08-02T08:06:44.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-04T12:52:39.000Z (5 months ago)
- Last Synced: 2024-10-31T13:04:53.319Z (2 months ago)
- Topics: data-collection, go, go-gpiocdev, golang, gpio, gpio-library, gpio-pins, library, raspberry-pi, sensor, sensors
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: License.md
Awesome Lists containing this project
README
# gpiocdev-eventhandlers
This repository aims to provide handlers for the [go-gpiocdev](https://github.com/warthog618/go-gpiocdev) Library's `gpiocdev.WithEventHandler` line option.
It's still under development with two sensor added to the library without tests are performed.
## Usage
- 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 to `WithEeventHandler()` 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:
```go
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](#examples) section to see more details examples for each sensor.
## Examples
|Sensor|ID(sensors.go)|Image|Example|
|------|--------------|-----|-------|
|Water Flow Sensor|0|![WaterFlowSensor](/images/water_flow_sensor.jpg)|[example](/examples/flow_sensor/main.go)|
|Photocell Sensor|1|![Photocell](/images/photocell.jpg)|[example](/examples/photocell_sensor/main.go)|