rpi

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

rpi

This package helps you to develop software for the Raspberry Pi that does IO operations on the Raspberry PI. It enables you to develop your code locally on any type of architecture, by using gRPC to control a Raspberry PI remotely. This is very convenient in conjunction with services like balena.io.

This makes developing applications for the RaspberryPi extremely easy. Once your software is ready, you have the option of continuing to use gRPC calls, or switch over to a local version of the interfaces to compile a binary that runs directly on the RaspberryPi.

If you have any suggestion or comments, please feel free to open an issue on this GitHub page.

Installing

Pushing server to balena.io

Add your balena remote to the git repo:

git add remote balena <URL>
make balena

Cli usage

Run the program using help to get documentation

rpi-client help

Server modules

GPIO

To enable on balena.io:

  • Device Service variables
    • RPI_GPIO: true
Pi Camera

To enable on balena.io:

  • Device Configuration
    • RESIN_HOST_CONFIG_gpu_mem: 128
    • RESIN_HOST_CONFIG_start_x: 1
  • Device Service variables
    • RPI_PICAM: true
    • RPI_MODPROBE: bcm2835-v4l2
Ngrok tunnel
  • Device Service variables
    • RPI_NGROK: true
    • RPI_NGROK_TOKEN: <your ngrok token>

Using another languages

Generate a client with protoc from ./pkg/proto/*.proto files.

Documentation

Overview

Package rpi helps you to develop software for the Raspberry Pi that does IO operations on the Raspberry PI. It enables you to develop your code locally on any type of architecture, by using gRPC to control a Raspberry PI remotely. This is very convenient in conjunction with services like balena.io.

This makes developing applications for the RaspberryPi extremely easy. Once your software is ready, you have the option of continuing to use gRPC calls, or switch over to a local version of the interfaces to compile a binary that runs directly on the RaspberryPi.

If you have any suggestion or comments, please feel free to open an issue on the projects GitHub page.

Index

Constants

View Source
const (
	// Input is the constant used to set a pin to input mode
	Input = rpio.Input
	// Output is the constant used to set a pin to output mode
	Output = rpio.Output
	// Low is the constant used to set a pin to low (0v)
	Low = rpio.Low
	// High is the constant used to set a pin to high (+5v)
	High = rpio.High
)

Variables

This section is empty.

Functions

func NewCommonServer

func NewCommonServer(common Common) proto.CommonServer

NewCommonServer creates a new common server using the common interface provided

func NewGpioServer

func NewGpioServer(gpio Gpio) proto.GpioServer

NewGpioServer creates a new gpio server that uses the gpio interface provided

func NewGrpcClientConnectionInsecure

func NewGrpcClientConnectionInsecure(host, port string) (*grpc.ClientConn, error)

NewGrpcClientConnectionInsecure creates a new insecure grpc client connection that can used by grpc clients

func NewGrpcServerInsecure

func NewGrpcServerInsecure(host, port string) (*grpc.Server, net.Listener, error)

NewGrpcServerInsecure creates a new insecure grpc server that can serve grpc services

func NewPicamServer

func NewPicamServer(cam PiCam) proto.PiCamServer

NewPicamServer creates a picam server that uses the picam interface provided

Types

type Common

type Common interface {
	GetVersion(ctx context.Context) (string, string, error)
	Modprobe(ctx context.Context, mod string) error
}

Common interface are the basic operations sometimes needed to use other the other interfaces

func NewCommonLocal

func NewCommonLocal() Common

NewCommonLocal creates a new common interface that operates locally

func NewCommonRemote

func NewCommonRemote(connection *grpc.ClientConn) (Common, error)

NewCommonRemote creates a new common interface that operates on a remote server

type Gpio

type Gpio interface {
	Open(ctx context.Context) error
	Close(ctx context.Context) error

	Input(ctx context.Context, pin Pin) error
	Output(ctx context.Context, pin Pin) error
	Clock(ctx context.Context, pin Pin) error
	Pwm(ctx context.Context, pin Pin) error
	PullUp(ctx context.Context, pin Pin) error
	PullDown(ctx context.Context, pin Pin) error
	PullOff(ctx context.Context, pin Pin) error

	High(ctx context.Context, pin Pin) error
	Low(ctx context.Context, pin Pin) error
	Toggle(ctx context.Context, pin Pin) error
	Write(ctx context.Context, pin Pin, state PinState) error
	Read(ctx context.Context, pin Pin) (PinState, error)

	Freq(ctx context.Context, pin Pin, freq int32) error
	DutyCycle(ctx context.Context, pin Pin, dutyLen, cycleLen int32) error
	Detect(ctx context.Context, pin Pin, edge PinEdge) error
	EdgeDetected(ctx context.Context, pin Pin) (bool, error)
}

Gpio interface provides a way to control and read from the GPIO pins on a RaspberryPi

func NewGpioLocal

func NewGpioLocal() Gpio

NewGpioLocal creates a new Gpio interface that uses local gpio pins

func NewGpioRemote

func NewGpioRemote(connection *grpc.ClientConn) Gpio

NewGpioRemote creates a new Gpio interface that uses remote gpio pins

type Ngrok

type Ngrok interface {
	Open(ctx context.Context) error
	Close(ctx context.Context) error
}

Ngrok interface provides a way to create an Ngrok tunnel to expose services to the internet

func NewNgrokLocal

func NewNgrokLocal(tunnelType, port, token, region string) (Ngrok, error)

NewNgrokLocal creates a new local Ngrok interface

type PiCam

type PiCam interface {
	Open(ctx context.Context) error
	Close(ctx context.Context) error
	GetFrame(ctx context.Context) ([]byte, error)
	GetFrames(ctx context.Context, byteCh chan<- []byte, errCh chan<- error) (<-chan struct{}, error)
}

PiCam interface provides a way to fetch frames from a PiCam connected to a RaspberryPi

func NewPiCamLocal

func NewPiCamLocal(args *PiCamArgs) (PiCam, error)

NewPiCamLocal creates a new local PiCam

func NewPiCamRemote

func NewPiCamRemote(connection *grpc.ClientConn) (PiCam, error)

NewPiCamRemote creates a new remote PiCam

type PiCamArgs

type PiCamArgs = picamera.RaspividArgs

PiCamArgs is a struct of arguments when initializing the PiCamera

func NewPiCamArgs

func NewPiCamArgs() *PiCamArgs

NewPiCamArgs creates the default arguments for the PiCam

type Pin

type Pin = rpio.Pin

Pin is the raw BCM2835 pinout of a GPIO pin

type PinEdge

type PinEdge = rpio.Edge

PinEdge is edge events detection modes

type PinState

type PinState = rpio.State

PinState is either high or low

Directories

Path Synopsis
cmd
rpi-client command
rpi-server command
pkg

Jump to

Keyboard shortcuts

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