From f80e6f624d74f6d0ffa5da06c86aa6390a9801c0 Mon Sep 17 00:00:00 2001 From: kunalpowar Date: Thu, 22 May 2014 01:11:45 +0530 Subject: [PATCH] spi: using defer for cleanup --- samples/spimcp3008.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/samples/spimcp3008.go b/samples/spimcp3008.go index 0f2419b..e35b09d 100644 --- a/samples/spimcp3008.go +++ b/samples/spimcp3008.go @@ -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