Documentation ¶
Overview ¶
Package periphflag integrates periph.io autodiscovery with flags, so that "yourcommand -help" makes more sense to the end user.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SPIDevVar ¶
SPIDevVar defines a flag that acceps the name of a SPI bus, with some information that is displayed to the end-user replaced with real discovered values. The arguments are the same as a standard flag.StringVar. The default value is looked up against discovered buses and their aliases, and the real device name is substituted. The usage message is changed to have a list of discovered bus names after the usage message.
In order to populate devices, you must have already initialized periph.io with host.Init() or hostextra.Init(). Because you need to check the error from that before proceeding, you will typically not declare these variables at the package level, and instead declare them near the top of your main function:
package main var ( someFlag = flag.String("send", "foo", "string to send to the device") spi string ) func main() { if _, err := host.Init(); err != nil { log.Fatal("periph init: %v", err) } periphflag.SPIDevVar(&spi, "spi", "", "spi bus to use") flag.Parse() port, err := spireg.Open(spi) if err != nil { flag.Usage() log.Fatal("open spi port %q: %v", spi, err) } defer port.Close() ... }
Types ¶
This section is empty.