rpiif

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2022 License: GPL-2.0 Imports: 5 Imported by: 0

README

rpi-infrared

A library used for interacting with infrared remote controls in go

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInitialized      = errors.New("cannot initialize scanner: scanner is already initialized")
	ErrNotInitialized   = errors.New("cannot scan: not initialized: use Setup() before scanning")
	ErrAlreadyScanning  = errors.New("cannot concurrently scan: wait until scanning is finished before starting another scan")
	ErrCannotInitialize = errors.New("failed to initialize: hardware failure")
)
View Source
var (
	Scanner = IfScanner{
		Pin:         0,
		Initialized: false,
		Scanning:    false,
	}
)

Functions

This section is empty.

Types

type IfScanner

type IfScanner struct {
	Pin         rpio.Pin
	Initialized bool
	Scanning    bool
}

Main module struct

func (*IfScanner) Scan

func (scanner *IfScanner) Scan() (string, error)

Scans for received codes, this method is blocking Can return errors ErrNotInitialized or ErrAlreadyScanning Returns the received code as a hexadecimal string

func (*IfScanner) Setup

func (scanner *IfScanner) Setup(pinNumber uint8) error

Initializes the scanner and binds it to a certain pin Example: `scanner.Setup(4)` This function has to be called before using `scanner.Scan()`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL