Turn openDoor into value receiver
This commit is contained in:
		
							
								
								
									
										21
									
								
								wiegand.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								wiegand.go
									
									
									
									
									
								
							| @@ -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() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user