https://github.com/smarthome-go/infrared
A Go library used for receiving signals from infrared remote controls
https://github.com/smarthome-go/infrared
golang-library hardware-libraries infrared-control infrared-decoder raspberry-pi
Last synced: 12 months ago
JSON representation
A Go library used for receiving signals from infrared remote controls
- Host: GitHub
- URL: https://github.com/smarthome-go/infrared
- Owner: smarthome-go
- License: gpl-2.0
- Created: 2022-05-06T19:36:51.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-08T22:25:21.000Z (almost 4 years ago)
- Last Synced: 2025-04-28T11:15:30.387Z (12 months ago)
- Topics: golang-library, hardware-libraries, infrared-control, infrared-decoder, raspberry-pi
- Language: Go
- Homepage: https://pkg.go.dev/github.com/smarthome-go/infrared
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Raspberry-Pi infrared
A library used for interacting with infrared remote controls via Go.
## Installation / Setup
To install the library, issue the following command
```
go get github.com/smarthome-go/infrared
```
You can then import the library in your project using following code
```go
import "github.com/smarthome-go/infrared"
```
## Getting started
### Creating a new *instance*
Before codes can be scanned, create a new module struct:
```go
ifScanner := infrared.Scanner{}
```
The `ifScanner` struct now allows you to use the library
### Setting up the input pin
After you have created a new struct, run the `Setup` function to tell the library on which pin in should listen to incoming infrared signals
This can be achieved by using `Scanner.Setup(pin)`
```go
ifScanner.Setup(4)
```
Make sure to implement proper error handling.
For reference, take a look at the [Example](#example).
### Using the scanner
To scan for codes, use the following function:
```go
receivedCode, err := ifScanner.Scan()
```
The scan function will wait until a code is received, then return it.
Due to this, it is to be noted that the `Scan` function is blocking, which means you probably want to run this in a separate goroutine.
The `Scan` method returns the received code as a `hex` string.
Make sure to implement proper error handling.
For another reference, take a look at the [Example](#example).
## Example
```go
package main
import (
"fmt"
"github.com/smarthome-go/infrared"
)
func main() {
ifScanner := infrared.Scanner
if err := ifScanner.Setup(4); err != nil {
panic(err.Error())
}
receivedCode, err := ifScanner.Scan()
if err != nil {
panic(err)
}
fmt.Println(receivedCode)
}
```