sim-modem/api/modem/gpio.go
2024-07-23 19:02:28 +03:00

46 lines
708 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()
}