smarthome-go / infrared

A Go library used for receiving signals from infrared remote controls

Home Page:https://pkg.go.dev/github.com/smarthome-go/infrared

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

import "github.com/smarthome-go/infrared"

Getting started

Creating a new instance

Before codes can be scanned, create a new module struct:

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)

ifScanner.Setup(4)

Make sure to implement proper error handling. For reference, take a look at the Example.

Using the scanner

To scan for codes, use the following function:

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

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)
}

About

A Go library used for receiving signals from infrared remote controls

https://pkg.go.dev/github.com/smarthome-go/infrared

License:GNU General Public License v2.0


Languages

Language:Go 100.0%