26 #INCLUDE ONCE "BBB/pruio.bi"
28 #INCLUDE ONCE "BBB/pruio_pins.bi"
50 SUB move(
BYVAL Io
AS PruIo PTR,
BYVAL Rot
AS BYTE = 1)
51 STATIC AS INTEGER p = 0
55 p
AND=
IIF(Rot
AND &b1, &b111, &b110)
57 SELECT CASE AS CONST p
58 CASE 1 : .Gpio->setValue(P1, 1) : .Gpio->setValue(P2, 0) : .Gpio->setValue(P3, 0) : .Gpio->setValue(P4, 0)
59 CASE 2 : .Gpio->setValue(P1, 1) : .Gpio->setValue(P2, 1) : .Gpio->setValue(P3, 0) : .Gpio->setValue(P4, 0)
60 CASE 3 : .Gpio->setValue(P1, 0) : .Gpio->setValue(P2, 1) : .Gpio->setValue(P3, 0) : .Gpio->setValue(P4, 0)
61 CASE 4 : .Gpio->setValue(P1, 0) : .Gpio->setValue(P2, 1) : .Gpio->setValue(P3, 1) : .Gpio->setValue(P4, 0)
62 CASE 5 : .Gpio->setValue(P1, 0) : .Gpio->setValue(P2, 0) : .Gpio->setValue(P3, 1) : .Gpio->setValue(P4, 0)
63 CASE 6 : .Gpio->setValue(P1, 0) : .Gpio->setValue(P2, 0) : .Gpio->setValue(P3, 1) : .Gpio->setValue(P4, 1)
64 CASE 7 : .Gpio->setValue(P1, 0) : .Gpio->setValue(P2, 0) : .Gpio->setValue(P3, 0) : .Gpio->setValue(P4, 1)
65 CASE ELSE : .Gpio->setValue(P1, 1) : .Gpio->setValue(P2, 0) : .Gpio->setValue(P3, 0) : .Gpio->setValue(P4, 1)
77 IF .Errr
THEN ?"initialisation failed (" & *.Errr &
")" :
EXIT DO
80 IF .Gpio->config(P1, PRUIO_GPIO_OUT1)
THEN ?"failed setting P1 (" & *.Errr &
")"
81 IF .Gpio->config(P2, PRUIO_GPIO_OUT0)
THEN ?"failed setting P2 (" & *.Errr &
")"
82 IF .Gpio->config(P3, PRUIO_GPIO_OUT0)
THEN ?"failed setting P3 (" & *.Errr &
")"
83 IF .Gpio->config(P4, PRUIO_GPIO_OUT1)
THEN ?"failed setting P4 (" & *.Errr &
")"
87 IF .config()
THEN ?"config failed (" & *.Errr &
")" :
EXIT DO
90 ?"Controls: (other keys quit, 1 and 3 only when Direction = 0)"
92 ?" 4 = rotate CW 5 = stop, hold position 6 = rotate CCW"
93 ?" 1 = single step CW 2 = slower 3 = single step CCW"
94 ?" 0 = stop, power off"
96 ?"Pins",
"Direction",
"Sleep" :
?
102 LOCATE y,
x, 0 :
?RIGHT(
" " &
d, 2),
RIGHT(
" " &
w, 3);
106 SELECT CASE AS CONST k
107 CASE ASC(
"2") :
IF w < 512
THEN w SHL= 1
108 CASE ASC(
"8") :
IF w > 1
THEN w SHR= 1
109 CASE ASC(
"4") :
d = -1
110 CASE ASC(
"7") :
d = -2
111 CASE ASC(
"9") :
d = 2
112 CASE ASC(
"6") :
d = 1
114 CASE ASC(
"1") :
IF 0 =
d THEN move(
io, -1)
115 CASE ASC(
"3") :
IF 0 =
d THEN move(
io, 1)
116 CASE ASC(
"0") :
d = 0
117 .Gpio->setValue(P1, 0)
118 .Gpio->setValue(P2, 0)
119 .Gpio->setValue(P3, 0)
120 .Gpio->setValue(P4, 0)
125 ?RIGHT(
" " &
d, 2),
RIGHT(
" " &
w, 3);
129 ? .Gpio->Value(P1) &
"-" _
130 & .Gpio->Value(P2) &
"-" _
131 & .Gpio->Value(P3) &
"-" _
135 IF .Errr
THEN ?"abborted: " & *.Errr
137 .Gpio->setValue(P1, 0)
138 .Gpio->setValue(P2, 0)
139 .Gpio->setValue(P3, 0)
140 .Gpio->setValue(P4, 0)
141 IF .Errr
THEN ?"zeroing pins failed: : " & *.Errr
143 IF .Errr
THEN ?"re-setting pins failed: : " & *.Errr