libpruio
0.2
Input/Output driver for digital/analog lines on Beagleboard hardware
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: `fbc -w all oszi.bas`
13
14
'/
15
16
' include libpruio
17
#INCLUDE ONCE
"../pruio/pruio.bi"
18
' include FB grafics
19
#INCLUDE ONCE
"fbgfx.bi"
20
21
VAR
S_W
= 0 _
'*< The screen width.
22
,
S_H
= 0 _
'*< The srceen hight
23
,
BPP
= 0 _
'*< The bits per plain number.
24
,
full
= fb.GFX_FULLSCREEN
'*< Fullscreen or windowed mode.
25
SCREENINFO
S_W
,
S_H
,
BPP
' get screen resolution
26
27
IF LEN
(
COMMAND
)
THEN
' customized resolution required?
28
VAR
p
=
INSTR
(
COMMAND
,
"x"
) _
'*< The position of the 'x' character (if any).
29
,
w
=
VALINT
(
COMMAND
) _
'*< The required window width.
30
,
h
=
VALINT
(
MID
(
COMMAND
,
p
+ 1))
'*< The required window hight.
31
IF
p
ANDALSO
w
ANDALSO
h
THEN
32
IF
w
<
S_W
- 4
ANDALSO
h
<
S_H
- 24
THEN
full
= fb.GFX_WINDOWED
33
S_W
=
IIF
(
w
<
S_W
,
w
,
S_W
)
' set maximum custom resolution
34
S_H
=
IIF
(
h
<
S_H
,
h
,
S_H
)
35
ELSE
36
PRINT
"set resolution like 640x400"
37
END
38
END IF
39
END IF
40
41
SCREENRES
S_W
,
S_H
,
BPP
, 2,
full
' set screen resolution
42
IF 0
=
SCREENPTR THEN PRINT
"no grafic available"
:
END
43
44
'* The colors for the lines (= channels).
45
DIM AS
UInt32
_
46
col
(...) = { _
47
RGBA
( 0, 0, 0, 255) _
48
,
RGBA
(255, 0, 0, 255) _
49
,
RGBA
( 0, 255, 0, 255) _
50
,
RGBA
( 0, 0, 255, 255) _
51
,
RGBA
(255, 255, 0, 255) _
52
,
RGBA
(255, 0, 255, 255) _
53
,
RGBA
( 0, 255, 255, 255) _
54
,
RGBA
(127, 127, 127, 255) _
55
}
56
57
'* The previous data of the channels.
58
DIM AS
UInt32
_
59
last
(...) = { _
60
0 _
61
, 0 _
62
, 0 _
63
, 0 _
64
, 0 _
65
, 0 _
66
, 0 _
67
, 0 _
68
}
69
70
VAR
io
=
NEW
PruIo
'*< Create a PruIo structure, wakeup subsystems.
71
72
WITH
*
io
73
DO
' pseudo loop, just to avoid GOTOs
74
IF
.Errr
THEN ?
"New failed ("
& *.Errr &
")"
:
EXIT DO
75
76
IF
.config()
THEN ?
"config failed ("
& *.Errr &
")"
:
EXIT DO
77
78
WITH
*.Adc
79
S_H
-= 1
80
VAR
scale
=
S_H
/ 65520 _
'*< The factor to scale values.
81
,
gap
= 2 _
'*< The gap between x values.
82
,
fg
=
RGB
(0, 0, 0) _
'*< The foreground color.
83
,
bg
=
RGB
(250, 250, 250)
'*< The background color.
84
FOR
i
AS INTEGER
= 0
TO 7
85
last
(
i
) =
S_H
-
CUINT
(.Value[
i
+ 1] *
scale
)
86
NEXT
87
88
COLOR
fg
,
bg
89
CLS
90
DO
91
VAR
k
=
ASC
(
INKEY
())
'*< The key code.
92
IF
k
THEN
' handle user input
93
VAR
m
= .Conf->STEPENABLE
'*< The step mask.
94
SELECT CASE
AS CONST
k
95
CASE ASC
(
"0"
) :
m
XOR
= 1
SHL 1
96
CASE ASC
(
"1"
) :
m
XOR
= 1
SHL 2
97
CASE ASC
(
"2"
) :
m
XOR
= 1
SHL 3
98
CASE ASC
(
"3"
) :
m
XOR
= 1
SHL 4
99
CASE ASC
(
"4"
) :
m
XOR
= 1
SHL 5
100
CASE ASC
(
"5"
) :
m
XOR
= 1
SHL 6
101
CASE ASC
(
"6"
) :
m
XOR
= 1
SHL 7
102
CASE ASC
(
"7"
) :
m
XOR
= 1
SHL 8
103
CASE ASC
(
"+"
) :
m
= &b111111110
104
CASE ELSE
:
EXIT DO
105
END SELECT
106
IF
m
THEN
107
.Conf->STEPENABLE =
m
108
WHILE
.Top->DRam[1] :
WEND
' PRU is busy (should not happen)
109
.Top->DRam[2] =
m
110
.Top->DRam[1] = PRUIO_COM_ADC
111
END IF
112
END IF
113
114
FOR
x
AS INTEGER
= 0
TO
S_W
-
gap
STEP
gap
' draw graph
115
LINE
(x + 1, 0) -
STEP
(
gap
,
S_H
),
bg
, BF
116
FOR
i
AS INTEGER
= 1
TO 8
117
IF 0
=
BIT
(.Conf->STEPENABLE,
i
)
THEN CONTINUE FOR
118
VAR
neu
=
S_H
-
CUINT
(.Value[
i
] *
scale
) _
'*< The new sample.
119
,
j
=
i
- 1
'*< The channel index.
120
LINE
(x,
last
(
j
)) - (x +
gap
,
neu
),
col
(
j
)
121
last
(
j
) =
neu
122
NEXT
123
LINE
(0, 0) -
STEP
(
gap
,
S_H
),
bg
, BF
124
NEXT
125
LOOP
126
END WITH
127
LOOP UNTIL 1
128
IF
.Errr
THEN ?
"press any key to quit"
:
SLEEP
129
END WITH
130
131
DELETE
io
132
133
'' help Doxygen to dokument the main code
134
'&/** The main function. */
135
'&int main() {PruIo::PruIo(); PruIo::config(); PruIo::~PruIo();}
136
src
examples
oszi.bas
Generated on Sun Oct 26 2014 16:53:02 for libpruio by
1.8.6