0.1.1
by Reinhard Tartler
Import upstream version 0.11.0~svn1143 |
1 |
/* $Id: plugin_test.c 840 2007-09-09 12:17:42Z michael $
|
2 |
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_test.c $
|
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
3 |
*
|
4 |
* Handy functions for testing displays and debugging code.
|
|
5 |
*
|
|
508
by reinelt
[lcd4linux @ 2005-01-18 06:30:21 by reinelt] |
6 |
* Copyright (C) 2004 Andy Baxter.
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
7 |
*
|
508
by reinelt
[lcd4linux @ 2005-01-18 06:30:21 by reinelt] |
8 |
* Based on sample plugin which is
|
0.1.1
by Reinhard Tartler
Import upstream version 0.11.0~svn1143 |
9 |
* Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
|
508
by reinelt
[lcd4linux @ 2005-01-18 06:30:21 by reinelt] |
10 |
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
11 |
*
|
12 |
* This file is part of LCD4Linux.
|
|
13 |
*
|
|
14 |
* LCD4Linux is free software; you can redistribute it and/or modify
|
|
15 |
* it under the terms of the GNU General Public License as published by
|
|
16 |
* the Free Software Foundation; either version 2, or (at your option)
|
|
17 |
* any later version.
|
|
18 |
*
|
|
19 |
* LCD4Linux is distributed in the hope that it will be useful,
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 |
* GNU General Public License for more details.
|
|
23 |
*
|
|
24 |
* You should have received a copy of the GNU General Public License
|
|
25 |
* along with this program; if not, write to the Free Software
|
|
26 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27 |
*
|
|
28 |
*/
|
|
29 |
||
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
30 |
int plugin_init_test(void); |
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
31 |
|
32 |
#include "config.h" |
|
33 |
||
34 |
#include <stdlib.h> |
|
35 |
#include <string.h> |
|
36 |
#include <math.h> |
|
37 |
#include <ctype.h> |
|
38 |
||
39 |
#include "debug.h" |
|
40 |
#include "plugin.h" |
|
41 |
||
42 |
#ifdef WITH_DMALLOC
|
|
43 |
#include <dmalloc.h> |
|
44 |
#endif
|
|
45 |
||
46 |
||
479
by reinelt
[lcd4linux @ 2004-06-26 09:27:20 by reinelt] |
47 |
/* used for testing bars - keeps values for a series of 10 bars,
|
48 |
* which are incremented and decremented between 0 and rmax by
|
|
49 |
* amount rdelta every time they are read. Starting value is rstart.
|
|
50 |
* rbar gives the number of the test bar.
|
|
51 |
*/
|
|
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
52 |
static void my_test_bar(RESULT * result, RESULT * rbar, RESULT * rmax, RESULT * rstart, RESULT * rdelta) |
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
53 |
{
|
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
54 |
static double values[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; |
55 |
static double deltas[10]; |
|
56 |
int bar; |
|
57 |
double max, delta, value; |
|
58 |
||
59 |
max = R2N(rmax); |
|
60 |
delta = R2N(rdelta); |
|
61 |
||
62 |
/* the maths is just to stop double rounding errors and bad values. */
|
|
63 |
bar = ((int) floor(R2N(rbar) + 0.1)) % 10; |
|
64 |
if (fabs(delta) > 0.1) { |
|
65 |
/* don't move or init the bar if delta=0 (the widget is only browsing) */
|
|
66 |
if (values[bar] == -1) { |
|
67 |
/* first time called. */
|
|
68 |
values[bar] = R2N(rstart); |
|
69 |
deltas[bar] = delta; |
|
70 |
};
|
|
71 |
values[bar] += deltas[bar]; |
|
72 |
};
|
|
73 |
if (values[bar] < 0 || values[bar] > max) { |
|
74 |
/* turn around. */
|
|
75 |
deltas[bar] = -deltas[bar]; |
|
76 |
values[bar] += deltas[bar]; |
|
77 |
};
|
|
78 |
value = values[bar]; |
|
79 |
SetResult(&result, R_NUMBER, &value); |
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
80 |
}
|
81 |
||
82 |
||
479
by reinelt
[lcd4linux @ 2004-06-26 09:27:20 by reinelt] |
83 |
/* like above, but just switches a value between 1 and -1. Can use to test
|
84 |
* visibility of icons.
|
|
85 |
*/
|
|
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
86 |
static void my_test_onoff(RESULT * result, RESULT * arg1) |
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
87 |
{
|
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
88 |
static int on[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
89 |
int i; |
|
90 |
double val; |
|
91 |
||
92 |
i = ((int) floor(R2N(arg1) + 0.1)) % 10; |
|
93 |
on[i] = -on[i]; |
|
94 |
val = (double) on[i]; |
|
95 |
||
96 |
SetResult(&result, R_NUMBER, &val); |
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
97 |
}
|
98 |
||
99 |
||
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
100 |
int plugin_init_test(void) |
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
101 |
{
|
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
102 |
|
103 |
AddFunction("test::bar", 4, my_test_bar); |
|
104 |
AddFunction("test::onoff", 1, my_test_onoff); |
|
105 |
||
106 |
return 0; |
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
107 |
}
|
108 |
||
109 |
void plugin_exit_test(void) |
|
110 |
{
|
|
546
by reinelt
[lcd4linux @ 2005-05-08 04:32:43 by reinelt] |
111 |
/* empty */
|
466
by reinelt
[lcd4linux @ 2004-06-07 06:56:55 by reinelt] |
112 |
}
|