libpruio
0.0.2
AM33xx-PRU driver for digital input / output and analog input
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
oszi.bas
Go to the documentation of this file.
1
/'* \file oszi.bas
2
\brief Example: draw a graph of analog inputs.
3
4
This file contains an example on how to use libpruio to continuously
5
draw a graph of the sampled data from the analog input lines.
6
7
Licence: GPLv3
8
9
Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
10
11
12
Compile by:
13
14
fbc -w all oszi.bas
15
16
'/
17
18
'* include libpruio
19
#INCLUDE ONCE
"../pruio/pruio.bi"
20
'* include FreeBASIC grafics
21
#INCLUDE ONCE
"fbgfx.bi"
22
23
VAR
S_W
= 0,
S_H
= 0,
gap
= 2,
BPP
= 0,
full
= fb.GFX_FULLSCREEN
24
SCREENINFO
S_W
,
S_H
,
BPP
' get screen resolution
25
IF LEN
(
COMMAND
)
THEN
' customized resolution required?
26
VAR
p
=
INSTR
(
COMMAND
,
"x"
) _
27
,
w
=
VALINT
(
COMMAND
) _
28
,
h
=
VALINT
(
MID
(
COMMAND
,
p
+ 1))
29
IF
p
ANDALSO
w
ANDALSO
h
THEN
30
IF
w
<
S_W
- 4
ANDALSO
h
<
S_H
- 24
THEN
full
= fb.GFX_WINDOWED
31
S_W
=
IIF
(
w
<
S_W
,
w
,
S_W
)
' set maximum custom resolution
32
S_H
=
IIF
(
h
<
S_H
,
h
,
S_H
)
33
ELSE
34
PRINT
"set resolution like 640x400"
35
END
36
END IF
37
END IF
38
39
SCREENRES
S_W
,
S_H
,
BPP
, ,
full
' set screen resolution
40
IF 0
=
SCREENPTR THEN PRINT
"no grafic available"
:
END
41
42
DIM AS
uint32
_
43
last
(...) = { _
'*< the previous data of the channels
44
0 _
45
, 0 _
46
, 0 _
47
, 0 _
48
, 0 _
49
, 0 _
50
, 0 _
51
, 0 _
52
}, _
53
col
(...) = { _
'*< the colors for the lines (= channels)
54
RGBA
(255, 255, 255, 255) _
55
,
RGBA
(255, 0, 0, 255) _
56
,
RGBA
( 0, 255, 0, 255) _
57
,
RGBA
( 0, 0, 255, 255) _
58
,
RGBA
(255, 255, 0, 255) _
59
,
RGBA
(255, 0, 255, 255) _
60
,
RGBA
( 0, 255, 255, 255) _
61
,
RGBA
(127, 127, 127, 255) _
62
}
63
64
VAR
io
=
NEW
PruIo
()
65
66
WITH
*
io
67
DO
' pseudo loop, just to avoid GOTOs
68
IF
.Errr
THEN ?
"New failed ("
& *.Errr &
")"
:
EXIT DO
69
70
IF
.config()
THEN ?
"config failed ("
& *.Errr &
")"
:
EXIT DO
71
72
S_H
-= 1
73
VAR
scale
=
S_H
/ 65520
74
FOR
i
AS INTEGER
= 0
TO 7
75
last
(
i
) =
S_H
-
CUINT
(.Value[
i
+ 1] *
scale
)
76
NEXT
77
78
DO
79
VAR
k
=
ASC
(
INKEY
())
80
IF
k
THEN
' handle user input
81
VAR
m
= .StepMask
82
SELECT CASE
AS CONST
k
83
CASE ASC
(
"0"
) :
m
XOR
= 1
SHL 1
84
CASE ASC
(
"1"
) :
m
XOR
= 1
SHL 2
85
CASE ASC
(
"2"
) :
m
XOR
= 1
SHL 3
86
CASE ASC
(
"3"
) :
m
XOR
= 1
SHL 4
87
CASE ASC
(
"4"
) :
m
XOR
= 1
SHL 5
88
CASE ASC
(
"5"
) :
m
XOR
= 1
SHL 6
89
CASE ASC
(
"6"
) :
m
XOR
= 1
SHL 7
90
CASE ASC
(
"7"
) :
m
XOR
= 1
SHL 8
91
CASE ASC
(
"+"
) :
m
= &b111111110
92
CASE ELSE
:
EXIT DO
93
END SELECT
94
IF
m
THEN
95
.StepMask =
m
96
WHILE
.DRam[1] <> PRUIO_MSG_INIT_OK :
WEND
97
.DRam[1] = .StepMask
98
END IF
99
END IF
100
101
FOR
x
AS INTEGER
= 0
TO
S_W
-
gap
STEP
gap
' draw graph
102
LINE
(x + 1, 0) -
STEP
(
gap
,
S_H
), 0, BF
103
FOR
i
AS INTEGER
= 1
TO 8
104
IF 0
=
BIT
(.StepMask,
i
)
THEN CONTINUE FOR
105
VAR
neu
=
S_H
-
CUINT
(.Value[
i
] *
scale
) _
106
,
j
=
i
- 1
107
LINE
(x,
last
(
j
)) - (x +
gap
,
neu
),
col
(
j
)
108
last
(
j
) =
neu
109
NEXT
110
LINE
(0, 0) -
STEP
(
gap
,
S_H
), 0, BF
111
NEXT
112
LOOP
113
LOOP UNTIL 1
114
IF
.Errr
THEN ?
"press any key to quit"
:
SLEEP
115
END WITH
116
117
DELETE
io
118
119
120
src
examples
oszi.bas
Generated on Fri Jun 6 2014 13:22:54 for libpruio by
1.8.4