mirror of
https://github.com/kidoman/embd
synced 2025-01-06 19:54:26 +01:00
spi: using defer for cleanup
This commit is contained in:
parent
9206358abe
commit
f80e6f624d
@ -16,9 +16,10 @@ func main() {
|
||||
if err := embd.InitSPI(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer embd.CloseSPI()
|
||||
|
||||
bus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
|
||||
defer clean(bus)
|
||||
defer bus.Close()
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
@ -28,11 +29,6 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
func clean(bus embd.SPIBus) {
|
||||
bus.Close()
|
||||
embd.CloseSPI()
|
||||
}
|
||||
|
||||
func getSensorValue(bus embd.SPIBus) (uint16, error) {
|
||||
data := make([]uint8, 3)
|
||||
data[0] = 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user