-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncoes.lisp
70 lines (60 loc) · 2.55 KB
/
funcoes.lisp
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
65
66
67
68
69
(defparameter SYSFS_GPIO_DIR "/sys/class/gpio")
(defparameter SYSFS_ADC_DIR "/sys/bus/iio/devices/iio:device0")
(defparameter SYSFS_PWM_DIR "/sys/devices/ocp.3/pwm_test_" )
(defparameter LED "38")
(defparameter motor1 "P8_13.16")
(defparameter motor2 "P9_16.12")
(defparameter motor3 "P9_28.13")
(defparameter motor4 "P9_29.14")
(defparameter motor5 "P9_42.15")
(defun setValue (gpio value)
(let ((buf (concatenate 'string SYSFS_GPIO_DIR "/gpio" (write-to-string gpio) "/value")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(cond
((string= value "LOW") (format fd "0"))
((string= value "HIGH") (format fd "1"))
(t (format fd "0"))
)
)
))
(defun setDirection (gpio direction)
(let ((buf (concatenate 'string SYSFS_GPIO_DIR "/gpio" (write-to-string gpio) "/direction")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(cond
((string= direction "IN") (format fd "in"))
((string= direction "OUT") (format fd "out"))
(t (format fd "in"))
)
)
))
(defun GPIO_export (gpio)
(let ((buf (concatenate 'string SYSFS_GPIO_DIR "/export")))
(with-open-file (fd buf :direction :output :if-exists :append :if-does-not-exist nil)
(format fd "~s" (write-to-string gpio))
)
))
(defun getAD (porta)
(let ((buf (concatenate 'string SYSFS_ADC_DIR "/in_voltage" (write-to-string porta) "_raw")))
(with-open-file (fd buf)
(parse-integer (read-line fd)))))
(defun configPWM(pino periodo duty polaridade)
(let ((buf (concatenate 'string SYSFS_PWM_DIR pino "/period")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(format fd "~s" periodo)))
(let ((buf (concatenate 'string SYSFS_PWM_DIR pino "/duty")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(format fd "~s" duty)))
(let ((buf (concatenate 'string SYSFS_PWM_DIR pino "/polarity")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(format fd "~s" polaridade)))
(let ((buf (concatenate 'string SYSFS_PWM_DIR pino "/run")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(format fd "1")))
)
(defun setDuty (pino duty)
(let ((buf (concatenate 'string SYSFS_PWM_DIR pino "/duty")))
(with-open-file (fd buf :direction :output :if-exists :supersede :if-does-not-exist nil)
(format fd "~s"
duty
))
))