summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/mouse.hcc
blob: 8db9c5183a28850abb4a9b8e30c4bb257486f840 (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
/*! \file mousedriver.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 "mouse_shared.hch"
#include "mouse.hch"



/*! \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 the shared mpram.
 * 
 * \param	void	None.
 *
 * \return	Never Returns.
 * \retval	void
 */
macro proc mouse_main(mousedata)
{
	unsigned 14 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^14 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 due
	 * or sampling all together will be redundant.
	 */
	for(touch_sampler = 1;;touch_sampler++) {
		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;

			/*
			 * 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.
			 */
			if ((oldmousestate != mousestate) || (oldx != x) || (oldy != y)) {
				mousedata.x = x;
				mousedata.y = y;
				mousedata.state = mousestate;
				mousedata.status = MOUSE_UPDATED;
				oldx = x;
				oldy = y;
				oldmousestate = mousestate;
			}
		}

		/*
		 * 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;
		}
	}
} /* --- mouse_main_loop() --- */