sim-modem/api/modem/gpio.go
Andrey Egorov 12555f2f46 Merging.
2024-07-25 17:05:15 +03:00

50 lines
766 B
Go

package modem
import (
"log"
"time"
gpio "github.com/stianeikeland/go-rpio/v4"
)
type gpioPin struct {
Logger *log.Logger
Pin gpio.Pin
}
func (p gpioPin) Init() error {
return gpio.Open()
}
func (p gpioPin) sendOnOffSignal() {
p.Pin.Output()
p.Logger.Println("Power on 0/3 + 100ms")
p.Pin.Low()
p.Pin.Toggle()
time.Sleep(100 * time.Millisecond)
p.Logger.Println("Power on 1/3 + 3s")
p.Pin.High()
p.Pin.Toggle()
time.Sleep(3 * time.Second)
p.Logger.Println("Power on 2/3 + 30s")
p.Pin.Low()
p.Pin.Toggle()
time.Sleep(30 * time.Second)
p.Logger.Println("Power on 3/3")
}
func (p gpioPin) PowerOn() {
p.sendOnOffSignal()
}
func (p *gpioPin) PowerOff() {
p.sendOnOffSignal()
}
func (p *gpioPin) Close() error {
return gpio.Close()
}