summaryrefslogtreecommitdiff
path: root/wiimote-internal.h
blob: 2151e4508b279c34ee40b70e32861796ae9bfcfc (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
149
150
151
152
153
154
155
156
157
158
159
160
/**
 *
 * 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"
#include "wiimote_options.h"

#define MAX_GESTURES 32
#define MAX_REPORTS  16
#define MAX_WIIMOTES 10

/* Core / Display / Screen structs */

typedef struct _WiimoteDisplay
{
    int screenPrivateIndex;
    int count;
    
    int nWiimote;
    CompWiimote *wiimotes;
    /* Hack */

    int firstRoot;

    Bool report;
    
    Bool CallbackSet;
    
    CompTimeoutHandle infoTimeoutHandle;
    CompTimeoutHandle gestureTimeoutHandle;
    CompTimeoutHandle checkingTimeoutHandle;
    
} WiimoteDisplay;

typedef struct _WiimoteScreen
{
    PaintOutputProc        paintOutput;
} WiimoteScreen;

#define GET_WIIMOTE_DISPLAY(d)                            \
    ((WiimoteDisplay *) (d)->base.privates[wiimoteDisplayPrivateIndex].ptr)
#define WIIMOTE_DISPLAY(d)                                \
    WiimoteDisplay *ad = GET_WIIMOTE_DISPLAY (d)
#define GET_WIIMOTE_SCREEN(s, ad)                         \
    ((WiimoteScreen *) (s)->base.privates[(ad)->screenPrivateIndex].ptr)
#define WIIMOTE_SCREEN(s)                                 \
    WiimoteScreen *as = GET_WIIMOTE_SCREEN (s, GET_WIIMOTE_DISPLAY (s->display))
#define GET_WIIMOTE_WINDOW(w, as) \
    ((WiimoteWindow *) (w)->base.privates[ (as)->windowPrivateIndex].ptr)
#define WIIMOTE_WINDOW(w) \
    WiimoteWindow *aw = GET_WIIMOTE_WINDOW (w,          \
			  GET_WIIMOTE_SCREEN  (w->screen, \
			  GET_WIIMOTE_DISPLAY (w->screen->display)))

extern int wiimoteDisplayPrivateIndex;
cwiid_mesg_callback_t wiimoteCWiiDCallback;
cwiid_err_t err;
CompDisplay *firstDisplay;

/* Function Prototypes */

/* util.c*/

int findMinIR (CompDisplay *, CompWiimote *, int, int, int, int); // No you can't have fminf
int findMaxIR (CompDisplay *, CompWiimote *, int, int, int, int); // Or fmaxf
Bool wiimoteChangeLights(void *Wiimote);
void set_led_state(cwiid_wiimote_t *wiimote, unsigned char led_state);
void set_rpt_mode(cwiid_wiimote_t *wiimote, unsigned char rpt_mode);

/* communicate.c */

Bool sendInfoToPlugin (CompDisplay *, CompOption *, int, char *, char *);

/* gesture.c */

void wiimoteProcessButtons (CompDisplay *, CompWiimote *, struct cwiid_btn_mesg *);
void wiimoteProcessNunchuckButtons (CompDisplay *, CompWiimote *, struct cwiid_nunchuk_mesg *);
Bool wiimoteCheckForGestures (void *vs);

/* connect.c */

Bool find_wiimote(bdaddr_t *bdaddr, int timeout);
void* connectWiimote (void *vd);
Bool checkConnected (void *vd);

/* report.c */

Bool sendReports(void *vs);

/* option.c */

void
reloadReportersForWiimote (CompDisplay *d,
			   CompWiimote *wiimote);

void
reloadReportersForWiimoteNumber (CompDisplay *d,
				 int wiimoteNumber);

void
reloadGesturesForWiimote (CompDisplay *d,
			  CompWiimote *wiimote);

void
reloadGesturesForWiimoteNumber (CompDisplay *d,
				int wiimoteNumber);

void
reloadOptionsForWiimote (CompDisplay *d,
			 CompWiimote *wiimote);

void
reloadOptionsForWiimoteNumber (CompDisplay *d,
			       int wiimoteNumber);

/* action.c */

Bool
wiimoteToggle (CompDisplay     *d,
		 CompAction      *action,
		 CompActionState cstate,
		 CompOption      *option,
		 int             nOption);

Bool
wiimoteDisable (CompDisplay     *d,
		 CompAction      *action,
		 CompActionState cstate,
		 CompOption      *option,
		 int             nOption);

Bool
wiimoteSendInfo (CompDisplay     *d,
		 CompAction      *action,
		 CompActionState cstate,
		 CompOption      *option,
		 int             nOption);

/* wiimote.c */
CompWiimote *
wiimoteAddWiimote (CompDisplay *d);
void
wiimoteRemoveWiimote (CompDisplay *d,
		      CompWiimote *wiimote);