Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

MikMuellerDev/rpiif

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpi-infrared

A library used for interacting with infrared remote controls in go

This repository has been transferred to the Smarthome organization.

Installation / Setup

To install the library, execute the following command

go get github.com/MikMuellerDev/rpiif  

You can then import the library in your project using following code

import "github.com/MikMuellerDev/rpiif"

Getting started

Creating a new instance

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

ifScanner := rpiif.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/MikMuellerDev/rpiif"
)

func main() {
	ifScanner := rpiif.Scanner
	if err := ifScanner.Setup(4); err != nil {
		panic(err.Error())
	}
	receivedCode, err := ifScanner.Scan()
	if err != nil {
		panic(err)
	}
	fmt.Println(receivedCode)
}