
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
github.com/yamamotoworksdev/button-shim-go
Provides a Go implementation for interfacing with Pimoroni's Button SHIM. The top-level library provides a lot of the same functionality as the reference Python library, including:
First, clone the project into your Go path:
go get github.com/tomnz/button-shim-go
The library depends on the periph.io framework for low level device communication. You can install this manually with go get
, or (preferred) use dep
:
go get -u github.com/golang/dep/cmd/dep
cd $GOPATH/src/github.com/tomnz/button-shim-go
dep ensure
First, initialize a periph.io I2C bus, and instantiate the device with it:
package main
import (
"github.com/tomnz/button-shim-go"
"periph.io/x/periph/conn/i2c/i2creg"
"periph.io/x/periph/host"
)
func main() {
// TODO: Handle errors
_, _ := host.Init()
bus, _ := i2creg.Open("1")
shim, _ := buttonshim.New(bus)
}
The library implements button press and release handlers using channels. For example:
aPress := shim.ButtonPressChan(buttonshim.ButtonA)
bPress := shim.ButtonPressChan(buttonshim.ButtonB)
aRelease := shim.ButtonReleaseChan(buttonshim.ButtonA)
go func() {
for {
select {
case <-aPress:
fmt.Println("Button A pressed!")
case <-bPress:
fmt.Println("Button B pressed!")
case holdDuration := <-aRelease:
fmt.Printf("Button A held for %s!", holdDuration)
}
}
}()
The color and brightness of the pixel can also be changed:
shim.SetColor(255, 0, 0)
shim.SetBrightness(127)
Please refer to the godocs for full API reference.
Contributions welcome! Please refer to the contributing guide.
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.