summaryrefslogtreecommitdiff
path: root/report.c
blob: efcf011094612fd048962a9d78f0fcecb4c46da3 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 *
 * Compiz Nintendo(R) Wii(TM) Remote Interface Plugin
 *
 * Copyright : (C) 2008 by Sam Spilsbury
 * E-mail    : smspillaz@gmail.com
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 */

#include "compiz-wiimote.h"

int wiimoteDisplayPrivateIndex;

/* Value Reporting --------------------------------------------------- */

Bool sendReports(void *vs)
{
	CompScreen *s = vs;
	CompWiimote *wiimote;
	WIIMOTE_DISPLAY (s->display);

	for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next)
	{
		int j;

		if (wiimote->connected)
		{
			for (j = 0; j < wiimote->nReport; j++)
			{
			        float report[3] = { 0 };
				int sens = wiimote->report[j].sensitivity;

				switch (wiimote->report[j].type)
				{
					case WiimoteReportTypeNone:
					case WiimoteReportTypeLength:
					default:
						break;
					case WiimoteReportTypeIR:
						report[0] = wiimote->irMidX - (CWIID_IR_X_MAX / 4);
						report[1] = wiimote->irMidY - (CWIID_IR_Y_MAX / 4);
						report[2] = wiimote->irDistance;
						break;
					case WiimoteReportTypeAccellerometer:
						report[0] = (float) ( (int) (wiimote->acc.accDX / sens));
						report[1] = (float) ( (int) (wiimote->acc.accDY / sens));
						report[2] = (float) ( (int) (wiimote->acc.accDZ / sens));
						break;
					case WiimoteReportTypeNunchuckAccellerometer:
						report[0] = (float) ( (int) (wiimote->nunchuck.accDX / sens));
						report[1] = (float) ( (int) (wiimote->nunchuck.accDY / sens));
						report[2] = (float) ( (int) (wiimote->nunchuck.accDZ / sens));
						break;
					case WiimoteReportTypeNunchuckStick:
						report[0] = (float) ( (int) (wiimote->nunchuck.stickDX / sens));
						report[1] = (float) ( (int) (wiimote->nunchuck.stickDY / sens));
						report[2] = 0.0f;
						break;
				}

				CompOption argument[5];
				int nArgument = 0;

				argument[nArgument].name = "window";
				argument[nArgument].type = CompOptionTypeInt;
				argument[nArgument].value.i = s->display->activeWindow;
				nArgument++;

				argument[nArgument].name = "root";
				argument[nArgument].type = CompOptionTypeInt;
				argument[nArgument].value.i = s->root;
				nArgument++;

				if (wiimote->report[j].xarg)
					argument[nArgument].name = wiimote->report[j].xarg;
				else
					argument[nArgument].name = "x";
				
				if (wiimote->report[j].dataType == 0)
				{
					argument[nArgument].type = CompOptionTypeFloat;
					argument[nArgument].value.f = report[0];
				}
				else if (wiimote->report[j].dataType == 1)
				{
					argument[nArgument].type = CompOptionTypeInt;
					argument[nArgument].value.i = (int) report[0];
				}
				nArgument++;

				if (wiimote->report[j].yarg)
					argument[nArgument].name = wiimote->report[j].yarg;
				else
					argument[nArgument].name = "y";

				if (wiimote->report[j].dataType == 0)
				{
					argument[nArgument].type = CompOptionTypeFloat;
					argument[nArgument].value.f = report[1];
				}
				else if (wiimote->report[j].dataType == 1)
				{
					argument[nArgument].type = CompOptionTypeInt;
					argument[nArgument].value.i = (int) report[1];
				}
				nArgument++;

				if (wiimote->report[j].yarg)
					argument[nArgument].name = wiimote->report[j].yarg;
				else
					argument[nArgument].name = "z";

				if (wiimote->report[j].dataType == 0)
				{
					argument[nArgument].type = CompOptionTypeFloat;
					argument[nArgument].value.f = report[2];
				}
				else if (wiimote->report[j].dataType == 1)
				{
					argument[nArgument].type = CompOptionTypeInt;
					argument[nArgument].value.i = (int) report[2];
				}
				nArgument++;

				if (wiimote->report[j].pluginName && wiimote->report[j].actionName){
				sendInfoToPlugin (s->display, argument, nArgument,
						  wiimote->report[j].pluginName,
						  wiimote->report[j].actionName);
				}
			}
		}
		
	}

	return TRUE;

}