spi: using defer for cleanup

This commit is contained in:
kunalpowar 2014-05-22 01:11:45 +05:30
parent 9206358abe
commit f80e6f624d
1 changed files with 2 additions and 6 deletions

View File

@ -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