libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
rb_oszi.bas
Go to the documentation of this file.
1 
16 
17 ' include libpruio
18 #INCLUDE ONCE "BBB/pruio.bi"
19 ' include FreeBASIC grafics
20 #INCLUDE ONCE "fbgfx.bi"
21 
22 VAR S_W = 0 _
23  , S_H = 0 _
24  , BPP = 0 _
25  , full = fb.GFX_FULLSCREEN
26 SCREENINFO S_W, S_H, BPP ' get screen resolution
27 IF LEN(COMMAND) THEN ' customized resolution required?
28  VAR p = INSTR(COMMAND, "x") _
29  , w = VALINT(COMMAND) _
30  , h = VALINT(MID(COMMAND, p + 1))
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 
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 
58 #MACRO DRAW_GRAF()
59  LINE (0, 0) - (S_W, S_H), RGB(250, 250, 250), BF
60  FOR c AS INTEGER = 0 TO .Adc->ChAz - 1
61  VAR i = c + .Adc->ChAz
62  LINE (0, S_H - CUINT(p[c] * scale)) - _
63  (1, S_H - CUINT(p[i] * scale)), col(c)
64  FOR x AS INTEGER = 2 TO S_W
65  i += .Adc->ChAz
66  LINE - (x, S_H - CUINT(p[i] * scale)), col(c)
67  NEXT
68  NEXT
69 #ENDMACRO
70 
71 VAR io = NEW PruIo()
72 
73 WITH *io
74  DO
75  IF .Errr THEN ?"NEW failed: " & *.Errr : EXIT DO
76 
77  VAR samp = S_W SHL 1
78  S_W -= 1
79  S_H -= 1
80  VAR scale = S_H / 65520
81 
82  IF .config(samp, &b100100000, 4e5) THEN _ ' configure steps 5+8
83  ?"config failed: " & *.Errr : EXIT DO
84 
85  VAR half = .Adc->Samples SHR 1 _
86  , p = .Adc->Value
87  IF .rb_start() THEN _ ' start ring buffer mode
88  ?"rb_start failed: " & *.Errr : EXIT DO
89  DO ' read ring buffer and draw graf
90  WHILE .DRam[0] < half : SLEEP 1 : WEND
91  DRAW_GRAF()
92  p += half
93  SCREENSET 0, 1
94 
95  WHILE .DRam[0] > half : SLEEP 1 : WEND
96  DRAW_GRAF()
97  p -= half
98  SCREENSET 1, 0
99  LOOP UNTIL LEN(INKEY()) : ?
100  LOOP UNTIL 1
101  IF .Errr THEN SLEEP
102 END WITH
103 
104 DELETE(io)
105 
106 '' help Doxygen to document the main code
107 '&/** The main function. */
108 '&int main() {PruIo::PruIo(); PruIo::config(); PruIo::~PruIo();}
109