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 (
"fmt"
"github.com/warthog618/gpiod"
"time"
)
import (
"github.com/warthog618/gpiod"
)
type Wiegand struct {
aLine *gpiod.Line
bLine *gpiod.Line
@ -17,12 +20,12 @@ type Wiegand struct {
solenoidLine *gpiod.Line
}
func openDoor(l *gpiod.Line) {
func (w *Wiegand) OpenDoor() {
fmt.Println("Open")
l.SetValue(1)
w.solenoidLine.SetValue(1)
d, _ := time.ParseDuration("500ms")
time.Sleep(d)
l.SetValue(0)
w.solenoidLine.SetValue(0)
fmt.Println("Close")
}
@ -95,11 +98,17 @@ func WiegandSetup(a int, b int, bitTimeout time.Duration, solenoid int) *Wiegand
}
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 {
panic(err)
}
wiegand.solenoidLine = solenoid_line
wiegand.solenoidLine = solenoidLine
return &wiegand
}
func (w *Wiegand) WiegandClose() {
w.aLine.Close()
w.bLine.Close()
w.solenoidLine.Close()
}