Turn openDoor into value receiver

This commit is contained in:
Arti Zirk 2022-04-03 19:30:56 +03:00
parent fcd8d3fbfd
commit 092e44cfa5

View File

@ -2,10 +2,13 @@ package main
import ( import (
"fmt" "fmt"
"github.com/warthog618/gpiod"
"time" "time"
) )
import (
"github.com/warthog618/gpiod"
)
type Wiegand struct { type Wiegand struct {
aLine *gpiod.Line aLine *gpiod.Line
bLine *gpiod.Line bLine *gpiod.Line
@ -17,12 +20,12 @@ type Wiegand struct {
solenoidLine *gpiod.Line solenoidLine *gpiod.Line
} }
func openDoor(l *gpiod.Line) { func (w *Wiegand) OpenDoor() {
fmt.Println("Open") fmt.Println("Open")
l.SetValue(1) w.solenoidLine.SetValue(1)
d, _ := time.ParseDuration("500ms") d, _ := time.ParseDuration("500ms")
time.Sleep(d) time.Sleep(d)
l.SetValue(0) w.solenoidLine.SetValue(0)
fmt.Println("Close") fmt.Println("Close")
} }
@ -95,11 +98,17 @@ func WiegandSetup(a int, b int, bitTimeout time.Duration, solenoid int) *Wiegand
} }
wiegand.bLine = wb wiegand.bLine = wb
solenoid_line, err := gpiod.RequestLine("gpiochip0", solenoid, gpiod.AsOutput(0)) solenoidLine, err := gpiod.RequestLine("gpiochip0", solenoid, gpiod.AsOutput(0))
if err != nil { if err != nil {
panic(err) panic(err)
} }
wiegand.solenoidLine = solenoid_line wiegand.solenoidLine = solenoidLine
return &wiegand return &wiegand
} }
func (w *Wiegand) WiegandClose() {
w.aLine.Close()
w.bLine.Close()
w.solenoidLine.Close()
}