gluaperiphery

package module
v0.0.0-...-28fde1b Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Periphery for GopherLua

A native Go implementation of lua-periphery for the GopherLua VM.

Feature Status

  • I²C
  • GPIO
  • SPI
  • MMIO
  • Serial

Using

Loading Modules
import (
	"github.com/nubix-io/gluaperiphery"
)

// Bring up a GopherLua VM
L := lua.NewState()
defer L.Close()

// Preload periphery modules
gluaperiphery.Preload(L)
Blinking an LED via a GPIO pin

The following code blinks an LED connected to GPIO18 (header J8 pin #12) of a Raspberry Pi 3 B+:

import (
	"github.com/nubix-io/gluaperiphery"
	"github.com/nubix-io/gluasocket"
)

L := lua.NewState()
defer L.Close()
gluaperiphery.Preload(L)
gluasocket.Preload(L)
L.DoString(`
	local periphery = require 'periphery'
	local socket = require 'socket'
	local gpio18 = periphery.GPIO(18, 'out')
	for j=1,10 do
		gpio18:write(true)
		socket.sleep(.5)
		gpio18:write(false)
		socket.sleep(.5)
	end`)
Reading a GPIO pin

Using a Raspberry Pi 3 B+ with a jumper bridge between GPIO17 and GPIO18, the following code sets a high and low state at GPIO18 used as an output, then reads the state back using GPIO17 used as an input.

import (
	"github.com/nubix-io/gluaperiphery"
)

L := lua.NewState()
defer L.Close()
gluaperiphery.Preload(L)
L.DoString(`
	local periphery = require 'periphery'
	local gpio17 = periphery.GPIO(17, 'in')
	local gpio18 = periphery.GPIO(18, 'out')
	
	gpio18:write(false)
	assert(gpio17:read() == false)
	
	gpio18:write(true)
	assert(gpio17:read() == true)
`)
Opening an I²C bus device
import (
	"github.com/nubix-io/gluaperiphery"
)

L := lua.NewState()
defer L.Close()
gluaperiphery.Preload(L)
L.DoString(`
	local periphery = require 'periphery';
	local i2c = periphery.I2C('/dev/i2c-1');
	return i2c`)
i2c := L.CheckUserData(-1)
Using with lua-bme280
import (
	"github.com/nubix-io/gluaperiphery"
)

L := lua.NewState()
defer L.Close()
gluaperiphery.Preload(L)
L.DoString(`package.preload['bme280'] = function(...)
	(... full inline contents of https://github.com/nubix-io/lua-bme280/blob/0.1.0/src/bme280.lua ...)
end`)
L.DoString(`
	local bme280 = require 'bme280'
	local periphery = require 'periphery'
	local i2c = periphery.I2C('/dev/i2c-1')
	local coeff = bme280.readCoefficients(i2c)
	local tempC = bme280.readTemperatureC(i2c, bme280.AccuracyMode.STANDARD, coeff)
	local pressPa = bme280.readPressurePa(i2c, bme280.AccuracyMode.STANDARD, coeff)
	local humRH = bme280.readHumidityRH(i2c, bme280.AccuracyMode.STANDARD, coeff)
	return tempC, pressPa, humRH`)
tempC, pressPa, humRH := L.CheckNumber(-3), L.CheckNumber(-2), L.CheckNumber(-1)

Testing

$ dep ensure
$ go test -v github.com/nubix-io/gluaperiphery...
=== RUN   TestModuleTableExportsI2C
--- PASS: TestModuleTableExportsI2C (0.00s)
PASS
ok  	github.com/nubix-io/gluaperiphery	(cached)
=== RUN   TestBME280
--- SKIP: TestBME280 (0.00s)
	bme280_test.go:16: A BME280 is not detected
=== RUN   TestLoader
--- PASS: TestLoader (0.00s)
=== RUN   TestConstantExports
--- PASS: TestConstantExports (0.00s)
=== RUN   TestOpenMalformedDevice
--- PASS: TestOpenMalformedDevice (0.00s)
=== RUN   TestOpenNonExistentDevice
--- PASS: TestOpenNonExistentDevice (0.00s)
PASS
ok  	github.com/nubix-io/gluaperiphery/i2c	0.021s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loader

func Loader(L *lua.LState) int

func Preload

func Preload(L *lua.LState)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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