summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/mouse.hcc
blob: 84c324f0d73f60bbdfb31c011813fa8dbd77fc06 (plain)
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
/*! \file mouse.hcc
 *
 * \section generic	This module takes care of mouse input. The mouse
 *			input function itself is however performed by the
 *			touchscreen of the RC200.
 *
 * \section project Project information.
 * Project Graphic Equalizer\n
 * \author O.M. Schinagl
 * \date 20041011
 * \version 0.1
 *
 * \section copyright Copyright
 * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
 *
 * \section history Change history
 * 20041011: O.M. Schinagl\n	Initial version
 *
 ********************************************************************/

/******** System Includes *************/
#include <stdlib.hch>

#include "pal_master.hch"
#include "pal_mouse.hch"

/******** Application Includes ********/
#include "configuration.hch"
#include "mouse_shared.hch"
#include "mouse.hch"

#if HAVE_DEBUG
	#include "debug.hch"
#endif



/*! \fn		void mouse_main(mousedata_t *mousedata);
 * \brief	Main mousedriver. This function never returns! It calls the
 *		main mousehandler and returns the States and coordinates
 *		into a shared store.
 * 
 * \param	*mousedata	Storage for all mousedata and states.
 *
 * \return	Never Returns.
 * \retval	void
 */
inline void mouse_main(mousedata_t *mousedata) {
	unsigned 18 touch_sampler;
	unsigned 10 x, oldx;
	unsigned 9 y, oldy;
	unsigned 3 mousestate, oldmousestate;
	unsigned 1 touch, touched, oldtouched;

	/*
	 * We only check for mouse states once every 2^18 time. This to
	 * overcome the sampling of the 'Touch' state of the RC200 libs. When
	 * using newer libs this might be overkill, e.g. smaller values may
	 * work or sampling all together will be redundant.
	 */
	touch_sampler = 1;
	while (TRUE) {
		if (!touch_sampler) {
			/*
			 * We are here ready to set mouse states. We compare
			 * current and previous states and thereby determine
			 * the state to send to others
			 */
			if (touched) {
				if(oldtouched) {
					mousestate = MOUSE_STATE_DOWN;
				} else {
					mousestate = MOUSE_STATE_ON_PRESS;
				}
				oldtouched = TRUE;
			} else {
				if(oldtouched) {
					mousestate = MOUSE_STATE_ON_RELEASE;
				} else {
					mousestate = MOUSE_STATE_UP;
				}
				oldtouched = FALSE;
			}
			/*
			 * We have now processed our Touch. Reset it for the
			 * next run.
			 */
			touched = FALSE;

			/*
			 * In the rare occurance that we receive values
			 * beyond our range, we set them to some sane
			 * values here.
			 */
			 x = (x > 639) ? 0 : x;
			 y = (y > 479) ? 0 : y;

			/*
			 * Compare Previous States and Coordinates to determine
			 * wether they have changed. If so, Copy them into
			 * shared memory, notify the listening processes and
			 * Set the new as previous values for the next run. We
			 * can only do this when the display has handled all
			 * changes.
			 */
			if (((oldmousestate != mousestate) || (oldx != x) || (oldy != y)) && (MOUSE_NOT_UPDATED == mousedata->status)) {
				//par {
					oldx = x;
					oldy = y;
					oldmousestate = mousestate;
					mousedata->x = 0 @ x;
					mousedata->y = 0 @ y;
					mousedata->state = mousestate;
					mousedata->status = MOUSE_UPDATED;
				//}
			}
		}

		/*
		 * Read the current X and Y of the 'cursor' and register wether
		 * the display was touched. If touched store this in a local
		 * store. This we do to catch the sampling of the RC200 lib.
		 */
		RC200TouchScreenReadScaled(&x, &y, &touch);
		if (touch) {
			touched = TRUE;
		}

		touch_sampler++;
	}
} /* --- mouse_main() --- */