Init
This commit is contained in:
commit
ffa2fc96d7
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
godoor
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 Arti Zirk <arti.zirk@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
14
README.md
Normal file
14
README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# GoDoor
|
||||||
|
|
||||||
|
[kdoorpi](https://git.k-space.ee/arti/kdoorpi) but in Go
|
||||||
|
|
||||||
|
Uses Go native [libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/)
|
||||||
|
library to access the gpio pins in cross platform way.
|
||||||
|
|
||||||
|
# Cross compile
|
||||||
|
|
||||||
|
GOOS=linux GOARCH=arm64 go build
|
||||||
|
|
||||||
|
# Test deploy
|
||||||
|
|
||||||
|
scp godoor rpi4b:
|
3
build.sh
Normal file
3
build.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
GOOS=linux GOARCH=arm64 go build && scp godoor rpi4b:
|
8
go.mod
Normal file
8
go.mod
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module godoor
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/warthog618/gpiod v0.8.0 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
|
||||||
|
)
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
github.com/warthog618/gpiod v0.8.0 h1:qxH9XVvWHpTxzWFSndBcujFyNH5zVRzHM63tcmm85o4=
|
||||||
|
github.com/warthog618/gpiod v0.8.0/go.mod h1:a7Csa+IJtDBZ39++zC/6Srjo01qWejt/5velrDWuNkY=
|
||||||
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||||
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
84
godoor.go
Normal file
84
godoor.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "time"
|
||||||
|
import "github.com/warthog618/gpiod"
|
||||||
|
|
||||||
|
const wiegand_a = 17
|
||||||
|
const wiegand_b = 18
|
||||||
|
const solenoid = 21
|
||||||
|
|
||||||
|
var bits [64]bool
|
||||||
|
var card uint64 = 0
|
||||||
|
var bitnr uint64 = 0
|
||||||
|
|
||||||
|
func openDoor(l *gpiod.Line) {
|
||||||
|
fmt.Println("Open")
|
||||||
|
l.SetValue(1)
|
||||||
|
time.Sleep(500000000)
|
||||||
|
l.SetValue(0)
|
||||||
|
fmt.Println("Close")
|
||||||
|
}
|
||||||
|
|
||||||
|
func printCardId() {
|
||||||
|
fmt.Printf("%d, ", bitnr)
|
||||||
|
for i := 0; i < 7; i++ {
|
||||||
|
fmt.Printf("%02x", (card>>(8*i))&0xff)
|
||||||
|
}
|
||||||
|
fmt.Printf("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func cardEvent() {
|
||||||
|
for i := 63; i != 0; i-- {
|
||||||
|
if bits[i] == true {
|
||||||
|
card |= 1 << (63 - i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printCardId()
|
||||||
|
|
||||||
|
bitnr = 0
|
||||||
|
card = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func wiegandEvent(evt gpiod.LineEvent) {
|
||||||
|
if evt.Offset == wiegand_b {
|
||||||
|
bits[bitnr] = true
|
||||||
|
fmt.Printf("1")
|
||||||
|
} else {
|
||||||
|
bits[bitnr] = false
|
||||||
|
fmt.Printf("0")
|
||||||
|
}
|
||||||
|
bitnr += 1
|
||||||
|
|
||||||
|
if bitnr == 64 {
|
||||||
|
fmt.Printf("\n")
|
||||||
|
cardEvent()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
wa, err := gpiod.RequestLine("gpiochip0", wiegand_a, gpiod.AsInput,
|
||||||
|
gpiod.WithFallingEdge, gpiod.WithEventHandler(wiegandEvent))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
wb, err := gpiod.RequestLine("gpiochip0", wiegand_b, gpiod.AsInput,
|
||||||
|
gpiod.WithFallingEdge, gpiod.WithEventHandler(wiegandEvent))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
solenoid_line, err := gpiod.RequestLine("gpiochip0", solenoid, gpiod.AsOutput(0))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
openDoor(solenoid_line)
|
||||||
|
|
||||||
|
time.Sleep(time.Minute)
|
||||||
|
wa.Close()
|
||||||
|
wb.Close()
|
||||||
|
fmt.Println("Done")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user