libpruio
0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
oszi.bas
Go to the documentation of this file.
1
14
15
' include libpruio
16
#INCLUDE ONCE
"BBB/pruio.bi"
17
' include FB grafics
18
#INCLUDE ONCE
"fbgfx.bi"
19
20
VAR
S_W
= 0 _
21
,
S_H
= 0 _
22
,
BPP
= 0 _
23
,
full
= fb.GFX_FULLSCREEN
24
SCREENINFO
S_W
,
S_H
,
BPP
' get screen resolution
25
26
IF LEN
(
COMMAND
)
THEN
' customized resolution required?
27
VAR
p
=
INSTR
(
COMMAND
,
"x"
) _
28
,
w
=
VALINT
(
COMMAND
) _
29
,
h
=
VALINT
(
MID
(
COMMAND
,
p
+ 1))
30
IF
p
ANDALSO
w
ANDALSO
h
THEN
31
IF
w
<
S_W
- 4
ANDALSO
h
<
S_H
- 24
THEN
full
= fb.GFX_WINDOWED
32
S_W
=
IIF
(
w
<
S_W
,
w
,
S_W
)
' set maximum custom resolution
33
S_H
=
IIF
(
h
<
S_H
,
h
,
S_H
)
34
ELSE
35
PRINT
"set resolution like 640x400"
36
END
37
END IF
38
END IF
39
40
SCREENRES
S_W
,
S_H
,
BPP
, 2,
full
' set screen resolution
41
IF 0
=
SCREENPTR THEN PRINT
"no grafic available"
:
END
42
43
44
DIM AS
UInt32
_
45
col
(...) = { _
46
RGBA
( 0, 0, 0, 255) _
47
,
RGBA
(255, 0, 0, 255) _
48
,
RGBA
( 0, 255, 0, 255) _
49
,
RGBA
( 0, 0, 255, 255) _
50
,
RGBA
(255, 255, 0, 255) _
51
,
RGBA
(255, 0, 255, 255) _
52
,
RGBA
( 0, 255, 255, 255) _
53
,
RGBA
(127, 127, 127, 255) _
54
}
55
56
57
DIM AS
UInt32
_
58
last
(...) = { _
59
0 _
60
, 0 _
61
, 0 _
62
, 0 _
63
, 0 _
64
, 0 _
65
, 0 _
66
, 0 _
67
}
68
69
VAR
io
=
NEW
PruIo
70
71
WITH
*
io
72
DO
' pseudo loop, just to avoid GOTOs
73
IF
.Errr
THEN ?
"New failed ("
& *.Errr &
")"
:
EXIT DO
74
75
IF
.config()
THEN ?
"config failed ("
& *.Errr &
")"
:
EXIT DO
76
77
WITH
*.Adc
78
S_H
-= 1
79
VAR
scale
=
S_H
/ 65520 _
80
,
gap
= 2 _
81
,
fg
=
RGB
(0, 0, 0) _
82
,
bg
=
RGB
(250, 250, 250)
83
FOR
i
AS INTEGER
= 0
TO 7
84
last
(
i
) =
S_H
-
CUINT
(.Value[
i
+ 1] *
scale
)
85
NEXT
86
87
COLOR
fg
,
bg
88
CLS
89
DO
90
VAR
k
=
ASC
(
INKEY
())
91
IF
k
THEN
' handle user input
92
VAR
m
= .Conf->STEPENABLE
93
SELECT CASE
AS CONST
k
94
CASE ASC
(
"0"
) :
m
XOR
= 1
SHL 1
95
CASE ASC
(
"1"
) :
m
XOR
= 1
SHL 2
96
CASE ASC
(
"2"
) :
m
XOR
= 1
SHL 3
97
CASE ASC
(
"3"
) :
m
XOR
= 1
SHL 4
98
CASE ASC
(
"4"
) :
m
XOR
= 1
SHL 5
99
CASE ASC
(
"5"
) :
m
XOR
= 1
SHL 6
100
CASE ASC
(
"6"
) :
m
XOR
= 1
SHL 7
101
CASE ASC
(
"7"
) :
m
XOR
= 1
SHL 8
102
CASE ASC
(
"+"
) :
m
= &b111111110
103
CASE ELSE
:
EXIT DO
104
END SELECT
105
IF
m
THEN
106
.Conf->STEPENABLE =
m
107
WHILE
.Top->DRam[1] :
WEND
' PRU is busy (should not happen)
108
.Top->DRam[2] =
m
109
.Top->DRam[1] = PRUIO_COM_ADC
110
END IF
111
END IF
112
113
FOR
x
AS INTEGER
= 0
TO
S_W
-
gap
STEP
gap
' draw graph
114
LINE
(x + 1, 0) -
STEP
(
gap
,
S_H
),
bg
, BF
115
FOR
i
AS INTEGER
= 1
TO 8
116
IF 0
=
BIT
(.Conf->STEPENABLE,
i
)
THEN CONTINUE FOR
117
VAR
neu
=
S_H
-
CUINT
(.Value[
i
] *
scale
) _
118
,
j
=
i
- 1
119
LINE
(x,
last
(
j
)) - (x +
gap
,
neu
),
col
(
j
)
120
last
(
j
) =
neu
121
NEXT
122
LINE
(0, 0) -
STEP
(
gap
,
S_H
),
bg
, BF
123
NEXT
124
LOOP
125
END WITH
126
LOOP UNTIL 1
127
IF
.Errr
THEN ?
"press any key to quit"
:
SLEEP
128
END WITH
129
130
DELETE
io
131
132
'' help Doxygen to document the main code
133
'&/** The main function. */
134
'&int main() {PruIo::PruIo(); PruIo::config(); PruIo::~PruIo();}
135
src
examples
oszi.bas
Generated on Thu May 11 2023 12:42:51 for libpruio by
1.9.1