File: timerprec.c

package info (click to toggle)
libforms 1.0.93sp1-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,548 kB
  • sloc: ansic: 97,227; sh: 9,236; makefile: 858
file content (174 lines) | stat: -rw-r--r-- 4,031 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 *  This file is part of XForms.
 *
 *  XForms is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1, or
 *  (at your option) any later version.
 *
 *  XForms is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with XForms; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 *  MA 02111-1307, USA.
 */


/*
 * Test the accuracy of timer
 *
 *  This file is part of xforms package
 *  T.C. Zhao and M. Overmars  (1997)
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "include/forms.h"
#include <stdlib.h>
#include <unistd.h>

/**** Forms and Objects ****/

typedef struct {
	FL_FORM   * form0;
	void      * vdata;
	long        ldata;
	FL_OBJECT * timer;
	FL_OBJECT * restart;
	FL_OBJECT * report;
} FD_form0;

static FD_form0 * create_form_form0( void );


/***************************************
 ***************************************/

static void
exit_cb( FL_OBJECT * ob    FL_UNUSED_ARG,
			  long        data  FL_UNUSED_ARG )
{
   fl_finish( );
   exit( 0 );
}


/***************************************
 ***************************************/

static long start_sec,
            start_usec;
static long end_sec,
            end_usec;


/* timer expired */

/***************************************
 ***************************************/

static void
timer_cb( FL_OBJECT * ob,
		  long        data  FL_UNUSED_ARG )
{
   char buf[ 128 ];
   float df;
   FD_form0 *fd = ob->form->fdui;
   double timerval =  fd->ldata * 0.001;

   fl_gettime( &end_sec, &end_usec );

   df = end_sec - start_sec + ( end_usec - start_usec ) * 1.0e-6;

   sprintf( buf,"Timeout: %.3f  Actual: %.3f  DeltaE: %.3f",
			timerval, df, df - timerval );

   fl_set_object_label( fd->report, buf );

}


/***************************************
 ***************************************/

static void
start_timer( FL_OBJECT * ob,
			 long        data  FL_UNUSED_ARG )
{
   FD_form0 *fd = ob->form->fdui;
   char buf[ 128 ];

   fd->ldata += 200;
   sprintf( buf, "Timer accuracy testing %.3f sec ...", fd->ldata * 0.001 );
   fl_set_object_label( fd->report, buf );
   fl_gettime( &start_sec, &start_usec );
   fl_set_timer( fd->timer, fd->ldata * 0.001 );
}


/***************************************
 ***************************************/

int
main( int    argc,
	  char * argv[ ] )
{
   FD_form0 *fd_form0;

   fl_initialize( &argc, argv, 0, 0, 0 );
   fd_form0 = create_form_form0( );

   /* fill-in form initialization code */

   fd_form0->ldata = 2800;
   start_timer( fd_form0->timer, 0 );

   /* show the first form */

   fl_show_form( fd_form0->form0, FL_PLACE_CENTER, FL_FULLBORDER,
				 "Timer object precision" );
   fl_do_forms( );
   return 0;
}


/* Form definition file generated with fdesign. */

/***************************************
 ***************************************/

static FD_form0 *
create_form_form0( void )
{
	FL_OBJECT *obj;
	FD_form0 *fdui = fl_calloc( 1, sizeof *fdui );

	fdui->form0 = fl_bgn_form( FL_NO_BOX, 320, 130 );

	obj = fl_add_box( FL_UP_BOX, 0, 0, 320, 130, "" );

	obj = fl_add_button( FL_NORMAL_BUTTON, 210, 80, 90, 35, "Done" );
	fl_set_object_callback( obj, exit_cb, 0 );

	fdui->restart = obj = fl_add_button( FL_TOUCH_BUTTON, 110, 80, 90, 35,
										 "Restart" );
    fl_set_object_callback( obj, start_timer, 0 );

	fdui->timer = obj = fl_add_timer( FL_HIDDEN_TIMER, 10, 40, 100, 40,
									  "Timer" );
    fl_set_object_callback( obj, timer_cb, 0 );

	fdui->report = obj = fl_add_text( FL_NORMAL_TEXT, 10, 20, 290, 50,"" );

	fl_end_form( );

	fdui->form0->fdui = fdui;

	return fdui;
}