]>
code.octet-stream.net Git - broadcaster/blob - radio/gpio.go
4 gpio
"github.com/warthog618/go-gpiocdev"
5 "github.com/warthog618/go-gpiocdev/device/rpi"
20 var ptt PTT
= &DefaultPTT
{}
21 var cos COS
= &DefaultCOS
{}
32 func InitRaspberryPiPTT(pttNum
int, chipName
string) {
33 pttPin
, err
:= rpi
.Pin("GPIO" + strconv
.Itoa(pttNum
))
35 log
.Fatal("invalid PTT pin configured", ptt
)
37 pttLine
, err
:= gpio
.RequestLine(chipName
, pttPin
, gpio
.AsOutput(0))
39 log
.Fatal("unable to open requested pin for PTT GPIO:", ptt
, ". Are you running as root?")
46 func InitRaspberryPiCOS(cosNum
int, chipName
string) {
48 piCOS
.clearWait
= make(chan bool)
49 cosPin
, err
:= rpi
.Pin("GPIO" + strconv
.Itoa(cosNum
))
51 log
.Fatal("invalid COS Pin configured", cos
)
53 cosHandler
:= func(event gpio
.LineEvent
) {
54 if event
.Type
== gpio
.LineEventFallingEdge
{
55 log
.Println("COS: channel clear")
56 close(piCOS
.clearWait
)
57 piCOS
.clearWait
= make(chan bool)
58 statusCollector
.COS
<- false
60 if event
.Type
== gpio
.LineEventRisingEdge
{
61 log
.Println("COS: channel in use")
62 statusCollector
.COS
<- true
65 cosLine
, err
:= gpio
.RequestLine(chipName
, cosPin
, gpio
.AsInput
, gpio
.WithBothEdges
, gpio
.WithEventHandler(cosHandler
))
67 log
.Fatal("unable to open requested pin for COS GPIO:", cos
, ". Are you running as root?")
69 piCOS
.cosLine
= cosLine
73 func (g
*PiCOS
) COSValue() bool {
74 val
, err
:= g
.cosLine
.Value()
76 log
.Fatal("Unable to read COS value")
81 func (g
*PiCOS
) WaitForChannelClear() {
83 val
, err
:= g
.cosLine
.Value()
84 if err
!= nil || val
== 0 {
91 func (g
*PiPTT
) EngagePTT() {
92 log
.Println("PTT: on")
94 statusCollector
.PTT
<- true
97 func (g
*PiPTT
) DisengagePTT() {
98 log
.Println("PTT: off")
100 statusCollector
.PTT
<- false
103 type DefaultPTT
struct {
106 func (g
*DefaultPTT
) EngagePTT() {
107 statusCollector
.PTT
<- true
110 func (g
*DefaultPTT
) DisengagePTT() {
111 statusCollector
.PTT
<- false
114 type DefaultCOS
struct {
117 func (g
*DefaultCOS
) WaitForChannelClear() {
118 log
.Println("Assuming channel is clear since COS GPIO is not configured")
121 func (g
*DefaultCOS
) COSValue() bool {