A Virtual Oscilloscope with GTK+
EE 5340/7340
Biomedical Instrumentation
Electrical
Engineering Dept, SMU
Objectives: In this module, we will design a virtual
oscilloscope using the gtkdatabox widget and GTK+
under cygwin. This “scope” will ultimately be used to
read ECG data from the serial port of the PC.
- You
will want to familiarize yourself with radio buttons (and as a
consequence, with toggle buttons), see the GTK+-2.0 Tutorial.
- Take a
look at the GTK+-2.0 Tutorial section on
frames.
- Look
at the gtkdatabox
site as well as some of the gtkdatabox examples. Additional documentation on gtkdatabox can be found in gtkdatabox.h,
located in /usr/local/include in the cygwin filesystem.
This module involves writing your own C code that implements
a virtual “scope” having the following appearance:
Download and run the executable
program. You will see that the program brings up an X window which, after
pressing the “start” button will display a 1 Hz sinusoidal signal. The sampling
rate can be adjusted by picking one of the sampling rate radio buttons. In
terms of behavior, your program should be as close to the above virtual scope
as possible and should:
- Have a
timeout function which mimics periodic reads from the serial port. Assume
that a single data point is available at the serial port each time the
timeout function is called. The sine wave data is contained in an array,
and each time a new sample is available, it goes into, say, Y[0], after
having shifted all the other previously collected samples down one, i.e.
Y[n] = Y[n-1], n = 1, …, POINTS-1, where POINTS = 1000 is a constant
indicating the number of stored samples.
You can read more about timeout functions here
(see also the GTK+ tutorial). You can only change sampling rate when the
scope is paused. If the scope is running, changing the sampling rate will
have no effect.
- Notice
that when the sampling rate is changed, the x axis labels change
accordingly to reflect the change in sampling rate.
- A
change in sampling rate should also change the interval for calling the
timeout function.
- Finally,
add your name in the scope windowJ
- To
compile your program:
gcc -Wall -g scope.c -o
scope -L/usr/local/lib -lgtkdatabox
`pkg-config --cflags
gtk+-2.0` `pkg-config --libs
gtk+-2.0`
the “-L” option indicates the directory for local library
files and the “-l” option indicates the name of the gtkdatabox
library.
Answer the following questions:
- Sketch
a diagram indicating the relative location of the various widgets,
including packing boxes. Label each widget in the order that it was
inserted into the main window.
- For
each widget described in 1, show the program code that was used to create
the widget and to insert it into the GUI.
- Indicate
how the program mimics periodic reads from the serial port at the sampling
rate.
- What
do the callback functions for the “start” and “pause” buttons do?
- Describe
what happens when, during pause mode, a new sampling rate is selected.