gosmartknob

package module
v0.0.0-...-b6833b6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

GoSmartKnob

A Go port of the software for Scott Bezek's SmartKnob.

Dependencies

For generating the SmartKnob protocol implementation: Protobuf NanoPB

If the version in this repo is the version you're working with, there is no need to regenerate it.

On my Mac, these dependencies were installed as follows:

brew install protobuf
brew install nanopb-generator
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

Also on my Mac, generating the protobuf code for the SmartKnob protocol was done with the following command line:

protoc -I=pb -I=/usr/local/Cellar/nanopb-generator/0.4.8/libexec/proto/ --plugin=protoc-gen-nanopb=/usr/local/Cellar/nanopb-enerator/0.4.8/bin/protoc-gen-nanopb --go_out=pb --go_opt=paths=source_relative --go_opt=Msmartknob.proto=github.com/marcuswu/gosmartknob/pb --go_opt=Mnanopb.proto=github.com/marcuswu/gosmartknob/pb pb/smartknob.proto

Use

A new SmartKnob can be initialized with the New method:

func New(connection io.ReadWriteCloser, onMessage MessageCallback) *SmartKnob

The SmartKnob instance will begin to use the io.ReadWriteCloser for communication with the SmartKnob. If the port is closed for any reason calling SetReadWriter with a new io.ReadWriteCloser will allow it to continue with the new connection.

func (skc *SmartKnob) SetReadWriter(readWriter io.ReadWriteCloser)

Sending a message to the SmartKnob is done via the EnqueueMessage method.

func (skc *SmartKnob) EnqueueMessage(message *pb.ToSmartknob) error

Documentation

Index

Constants

View Source
const (
	Baud             = 115200
	Ch340VendorId    = 0x1a86
	Ch340ProductId   = 0x7523
	Esp32s3VendorId  = 0x303a
	Esp32s3ProductId = 0x1001
)

Variables

View Source
var DefaultDeviceFilters = []core.UsbFilter{
	core.UsbFilter{
		VendorId:  Ch340VendorId,
		ProductId: Ch340ProductId,
	},
	core.UsbFilter{
		VendorId:  Esp32s3VendorId,
		ProductId: Esp32s3ProductId,
	},
}

Functions

This section is empty.

Types

type MessageCallback

type MessageCallback func(message *pb.FromSmartKnob)

type OnClosedCallback

type OnClosedCallback func()

type OnCreatedCallback

type OnCreatedCallback func(sk *SmartKnob)

type QueueEntry

type QueueEntry struct {
	// contains filtered or unexported fields
}

type SendBytes

type SendBytes func(packet []uint8)

type SmartKnob

type SmartKnob struct {
	// contains filtered or unexported fields
}

func New

func New(connection io.ReadWriteCloser, onMessage MessageCallback, onClosed OnClosedCallback) *SmartKnob

func (*SmartKnob) EnqueueMessage

func (skc *SmartKnob) EnqueueMessage(message *pb.ToSmartknob) (uint32, error)

func (*SmartKnob) SendConfig

func (skc *SmartKnob) SendConfig(message *pb.SmartKnobConfig) (uint32, error)

func (*SmartKnob) SetReadWriter

func (skc *SmartKnob) SetReadWriter(readWriter io.ReadWriteCloser)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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