sim-modem/api/modem/gpio.go

50 lines
766 B
Go
Raw Normal View History

2024-07-18 16:34:26 +00:00
package modem
import (
2024-07-21 13:05:09 +00:00
"log"
2024-07-18 16:34:26 +00:00
"time"
2024-07-21 13:05:09 +00:00
gpio "github.com/stianeikeland/go-rpio/v4"
2024-07-18 16:34:26 +00:00
)
2024-07-21 13:05:09 +00:00
type gpioPin struct {
2024-07-23 16:02:28 +00:00
logger *log.Logger
Pin gpio.Pin
2024-07-18 16:34:26 +00:00
}
2024-07-21 13:05:09 +00:00
func (p gpioPin) Init() error {
return gpio.Open()
}
func (p gpioPin) sendOnOffSignal() {
p.Pin.Output()
2024-07-23 16:02:28 +00:00
p.logger.Println("Power on 0/3 + 100ms")
2024-07-21 13:05:09 +00:00
p.Pin.Low()
p.Pin.Toggle()
2024-07-18 16:34:26 +00:00
time.Sleep(100 * time.Millisecond)
2024-07-21 13:05:09 +00:00
2024-07-23 16:02:28 +00:00
p.logger.Println("Power on 1/3 + 3s")
2024-07-21 13:05:09 +00:00
p.Pin.High()
p.Pin.Toggle()
2024-07-18 16:34:26 +00:00
time.Sleep(3 * time.Second)
2024-07-21 13:05:09 +00:00
2024-07-23 16:02:28 +00:00
p.logger.Println("Power on 2/3 + 30s")
2024-07-21 13:05:09 +00:00
p.Pin.Low()
p.Pin.Toggle()
2024-07-18 16:34:26 +00:00
time.Sleep(30 * time.Second)
2024-07-21 13:05:09 +00:00
2024-07-23 16:02:28 +00:00
p.logger.Println("Power on 3/3")
2024-07-21 13:05:09 +00:00
}
func (p gpioPin) PowerOn() {
p.sendOnOffSignal()
}
func (p *gpioPin) PowerOff() {
p.sendOnOffSignal()
2024-07-18 16:34:26 +00:00
}
2024-07-25 13:58:09 +00:00
func (p *gpioPin) Close() error {
return gpio.Close()
}