27 #INCLUDE ONCE "BBB/pruio.bi"
29 #INCLUDE ONCE "BBB/pruio_pins.bi"
56 SUB MaskInit(
BYVAL Io
AS PruIo PTR)
58 SUSYS = .BallGpio(P4)
SHR 5
59 VAR m0 = 1
SHL (.BallGpio(P1)
AND &b11111)
60 VAR m1 = 1
SHL (.BallGpio(P2)
AND &b11111)
61 VAR m2 = 1
SHL (.BallGpio(P3)
AND &b11111)
62 VAR m3 = 1
SHL (.BallGpio(P4)
AND &b11111)
63 MASKS(0, 0) = m0 : MASKS(0, 1) = m1 + m2 + m3
64 MASKS(1, 0) = m0 + m1 : MASKS(1, 1) = m2 + m3
65 MASKS(2, 0) = m1 : MASKS(2, 1) = m0 + m2 + m3
66 MASKS(3, 0) = m1 + m2 : MASKS(3, 1) = m0 + m3
67 MASKS(4, 0) = m2 : MASKS(4, 1) = m0 + m1 + m3
68 MASKS(5, 0) = m2 + m3 : MASKS(5, 1) = m0 + m1
69 MASKS(6, 0) = m3 : MASKS(6, 1) = m0 + m1 + m2
70 MASKS(7, 0) = m3 + m0 : MASKS(7, 1) = m1 + m2
71 MASKS(8, 0) = 0 : MASKS(8, 1) = m0 + m1 + m2 + m3
90 SUB move(
BYVAL Io
AS PruIo PTR,
BYVAL Rot
AS BYTE = 1)
94 p
AND=
IIF(Rot
AND &b1, &b111, &b110)
96 WITH *.Gpio->Conf(SUSYS)
97 .SETDATAOUT = MASKS(p, 0)
98 .CLEARDATAOUT = MASKS(p, 1)
112 IF .Errr
THEN ?"initialisation failed (" & *.Errr &
")" :
EXIT DO
115 IF .Gpio->config(P1, PRUIO_GPIO_OUT1)
THEN ?"failed setting P1 (" & *.Errr &
")"
116 IF .Gpio->config(P2, PRUIO_GPIO_OUT0)
THEN ?"failed setting P2 (" & *.Errr &
")"
117 IF .Gpio->config(P3, PRUIO_GPIO_OUT0)
THEN ?"failed setting P3 (" & *.Errr &
")"
118 IF .Gpio->config(P4, PRUIO_GPIO_OUT1)
THEN ?"failed setting P4 (" & *.Errr &
")"
119 IF .Errr
THEN EXIT DO
123 IF .config()
THEN ?"config failed (" & *.Errr &
")" :
EXIT DO
126 ?"Controls: (other keys quit, 1 and 3 only when Direction = 0)"
128 ?" 4 = rotate CW 5 = stop, hold position 6 = rotate CCW"
129 ?" 1 = single step CW 2 = slower 3 = single step CCW"
130 ?" 0 = stop, power off"
132 ?"Pins",
"Direction",
"Sleep" :
?
138 LOCATE y,
x, 0 :
?RIGHT(
" " &
d, 2),
RIGHT(
" " &
w, 3);
142 SELECT CASE AS CONST k
143 CASE ASC(
"2") :
IF w < 512
THEN w SHL= 1
144 CASE ASC(
"8") :
IF w > 1
THEN w SHR= 1
145 CASE ASC(
"4") :
d = -1
146 CASE ASC(
"7") :
d = -2
147 CASE ASC(
"9") :
d = 2
148 CASE ASC(
"6") :
d = 1
150 CASE ASC(
"1") :
IF 0 =
d THEN move(
io, -1)
151 CASE ASC(
"3") :
IF 0 =
d THEN move(
io, 1)
152 CASE ASC(
"0") :
d = 0
153 WITH *.Gpio->Conf(SUSYS)
154 .SETDATAOUT = MASKS(8, 0)
155 .CLEARDATAOUT = MASKS(8, 1)
162 ?RIGHT(
" " &
d, 2),
RIGHT(
" " &
w, 3);
166 ? .Gpio->Value(P1) &
"-" _
167 & .Gpio->Value(P2) &
"-" _
168 & .Gpio->Value(P3) &
"-" _
172 IF .Errr
THEN ?"abborted: " & *.Errr
174 WITH *.Gpio->Conf(SUSYS)
175 .SETDATAOUT = MASKS(8, 0)
176 .CLEARDATAOUT = MASKS(8, 1)
179 IF .Errr
THEN ?"zeroing pins failed: : " & *.Errr
181 IF .Errr
THEN ?"re-setting pins failed: : " & *.Errr