-
Notifications
You must be signed in to change notification settings - Fork 1
/
wiringpifuncs.go
64 lines (56 loc) · 1.39 KB
/
wiringpifuncs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package gopio
/*
#cgo LDFLAGS: -lwiringPi
#include <wiringPi.h>
#include "local_lib.h"
*/
import "C"
// initial function for wiringpi(call this function if you're going to use wiringpi)
func GopioSetUp() {
C.wiringPiSetupPhys()
}
// define a wiringpi pin using this function
// pnum : physical pin number, d direction
func PinMode(pnum int, d DIR) WiringPiPin {
if d == OUT {
C.pinMode(C.int(pnum), C.OUTPUT)
} else {
C.pinMode(C.int(pnum), C.INPUT)
}
return WiringPiPin{Num: pnum, Dir: d}
}
// digital write accept two values HIGH and LOW
func (p *WiringPiPin) DigitalWrite(v VALUE) {
if v == HIGH {
C.digitalWrite(C.int(p.Num), C.HIGH)
} else {
C.digitalWrite(C.int(p.Num), C.LOW)
}
}
// digitalread function returns the current value for a specific pin
func (p *WiringPiPin) DigitalRead() VALUE {
v := int(C.digitalRead(C.int(p.Num)))
if v == 1 {
return HIGH
} else {
return LOW
}
}
// this function takes a value(HIGH, LOW) and writes it to the pin on program interruption
func (p *WiringPiPin) WriteOnInterrupt(v VALUE) {
var val int
if v == HIGH {
val = 1
} else {
val = 0
}
C.close_pin(C.int(p.Num), C.int(val))
}
// returns the analog value for pin(not tested)
func (p *WiringPiPin) AnalogRead() int {
return int(C.analogRead(C.int(p.Num)))
}
// writes analog value to pin(not tested)
func (p *WiringPiPin) AnalogWrite(val int) {
C.analogWrite(C.int(p.Num), C.int(val))
}