~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/input/wiimote.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-02-28 19:44:25 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080228194425-e8ilohlijv02kgcf
Tags: 0.7.2-2
* Fix FTBFS with gcc-4.3 by adding the missing include in
  src/input/evdev_device.cpp (Closes: #462238):
   + debian/patches/20_fix_FTBFS_with_gcc-4.3.
* Rename former patch so that the filename reflects the order in which
  the patches are applied:
   - debian/patches/data_dir.patch
   + debian/patches/10_fix_data_directory.
* Bump Standards-Version from 3.7.2 to 3.7.3, no changes needed.
* Add a dh_desktop call in the arch-dep part of debian/rules.
* Adjust the “missing-dep-for-interpreter guile” override since lintian
  now lists an alternative for that dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: wiimote.cpp 3192 2007-09-20 03:06:10Z grumbel $
 
2
//
 
3
//  Pingus - A free Lemmings clone
 
4
//  Copyright (C) 2007 Ingo Ruhnke <grumbel@gmx.de>
 
5
//
 
6
//  This program is free software; you can redistribute it and/or
 
7
//  modify it under the terms of the GNU General Public License
 
8
//  as published by the Free Software Foundation; either version 2
 
9
//  of the License, or (at your option) any later version.
 
10
//
 
11
//  This program is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; if not, write to the Free Software
 
18
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
#include <iostream>
 
21
#include <assert.h>
 
22
#include <pthread.h>
 
23
#include "math.hpp"
 
24
#include "wiimote.hpp"
 
25
 
 
26
Wiimote* wiimote = 0;
 
27
 
 
28
std::string
 
29
Wiimote::id2str(int id)
 
30
{
 
31
  if      (id == WIIMOTE_A)     return "a";
 
32
  else if (id == WIIMOTE_B)     return "b";
 
33
  else if (id == WIIMOTE_LEFT)  return "left";
 
34
  else if (id == WIIMOTE_RIGHT) return "right";
 
35
  else if (id == WIIMOTE_UP)    return "up";
 
36
  else if (id == WIIMOTE_DOWN)  return "down";
 
37
  else if (id == WIIMOTE_PLUS)  return "plus";
 
38
  else if (id == WIIMOTE_MINUS) return "minus";
 
39
  else if (id == WIIMOTE_HOME)  return "home";
 
40
  else if (id == WIIMOTE_1)     return "1";
 
41
  else if (id == WIIMOTE_2)     return "2";
 
42
 
 
43
  else if (id == NUNCHUK_C) return "nunchuk:c";
 
44
  else if (id == NUNCHUK_Z) return "nunchuk:z";
 
45
 
 
46
  else if (id == CLASSIC_LEFT)  return "classic:left";
 
47
  else if (id == CLASSIC_RIGHT) return "classic:right";
 
48
  else if (id == CLASSIC_UP)    return "classic:up";
 
49
  else if (id == CLASSIC_DOWN)  return "classic:down";
 
50
  else if (id == CLASSIC_PLUS)  return "classic:plus";
 
51
  else if (id == CLASSIC_MINUS) return "classic:minus";
 
52
  else if (id == CLASSIC_HOME)  return "classic:home";
 
53
  else if (id == CLASSIC_A)     return "classic:a";
 
54
  else if (id == CLASSIC_B)     return "classic:b";
 
55
  else if (id == CLASSIC_X)     return "classic:x";
 
56
  else if (id == CLASSIC_Y)     return "classic:y";
 
57
  else if (id == CLASSIC_L)     return "classic:l";
 
58
  else if (id == CLASSIC_R)     return "classic:r";
 
59
  else if (id == CLASSIC_ZL)    return "classic:zl";
 
60
  else if (id == CLASSIC_ZR)    return "classic:zr";
 
61
  else 
 
62
    return "unknown";
 
63
}
 
64
 
 
65
int
 
66
Wiimote::str2id(const std::string& str)
 
67
{
 
68
  if      (str == "a")     return WIIMOTE_A;
 
69
  else if (str == "b")     return WIIMOTE_B;
 
70
  else if (str == "left")  return WIIMOTE_LEFT;
 
71
  else if (str == "right") return WIIMOTE_RIGHT;
 
72
  else if (str == "up")    return WIIMOTE_UP;
 
73
  else if (str == "down")  return WIIMOTE_DOWN;
 
74
  else if (str == "plus"  || str == "+") return WIIMOTE_PLUS;
 
75
  else if (str == "minus" || str == "-") return WIIMOTE_MINUS;
 
76
  else if (str == "home")  return WIIMOTE_HOME;
 
77
  else if (str == "1")     return WIIMOTE_1;
 
78
  else if (str == "2")     return WIIMOTE_2;
 
79
 
 
80
  else if (str == "nunchuk:c") return NUNCHUK_C;
 
81
  else if (str == "nunchuk:z") return NUNCHUK_Z;
 
82
 
 
83
  else if (str == "classic:left")  return CLASSIC_LEFT;
 
84
  else if (str == "classic:right") return CLASSIC_RIGHT;
 
85
  else if (str == "classic:up")    return CLASSIC_UP;
 
86
  else if (str == "classic:down")  return CLASSIC_DOWN;
 
87
  else if (str == "classic:plus"  || str == "classic:+") return CLASSIC_PLUS;
 
88
  else if (str == "classic:minus" || str == "classic:-") return CLASSIC_MINUS;
 
89
  else if (str == "classic:home")  return CLASSIC_HOME;
 
90
  else if (str == "classic:a")     return CLASSIC_A;
 
91
  else if (str == "classic:b")     return CLASSIC_B;
 
92
  else if (str == "classic:x")     return CLASSIC_X;
 
93
  else if (str == "classic:y")     return CLASSIC_Y;
 
94
  else if (str == "classic:l")     return CLASSIC_L;
 
95
  else if (str == "classic:r")     return CLASSIC_R;
 
96
  else if (str == "classic:zl")    return CLASSIC_ZL;
 
97
  else if (str == "classic:zr")    return CLASSIC_ZR;
 
98
  else 
 
99
    return UNKNOWN;
 
100
}
 
101
 
 
102
void
 
103
Wiimote::init()
 
104
{
 
105
  if (!wiimote)
 
106
    wiimote = new Wiimote();
 
107
}
 
108
 
 
109
void
 
110
Wiimote::deinit()
 
111
{
 
112
  delete wiimote;
 
113
  wiimote = 0;
 
114
}
 
115
 
 
116
Wiimote::Wiimote()
 
117
  : m_wiimote(0),
 
118
    m_rumble(false),
 
119
    m_led_state(0),
 
120
    m_nunchuk_btns(0),
 
121
    m_nunchuk_stick_x(0),
 
122
    m_nunchuk_stick_y(0),
 
123
    m_buttons(0)
 
124
{
 
125
  pthread_mutex_init(&mutex, NULL);
 
126
 
 
127
  assert(wiimote == 0);
 
128
  wiimote = this;
 
129
  
 
130
  cwiid_set_err(&Wiimote::err_callback);
 
131
}
 
132
 
 
133
Wiimote::~Wiimote()
 
134
{
 
135
  disconnect();
 
136
  pthread_mutex_destroy(&mutex);
 
137
}
 
138
 
 
139
void
 
140
Wiimote::connect()
 
141
{
 
142
  assert(m_wiimote == 0);
 
143
 
 
144
  /* Connect to any wiimote */
 
145
  bdaddr_t bdaddr = *BDADDR_ANY;
 
146
 
 
147
  /* Connect to address in string WIIMOTE_BDADDR */
 
148
  /* str2ba(WIIMOTE_BDADDR, &bdaddr); */
 
149
 
 
150
  /* Connect to the wiimote */
 
151
  printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
 
152
 
 
153
  if (!(m_wiimote = cwiid_connect(&bdaddr, CWIID_FLAG_MESG_IFC))) 
 
154
    {
 
155
      fprintf(stderr, "Unable to connect to wiimote\n");
 
156
    }
 
157
  else 
 
158
    {
 
159
      std::cout << "Wiimote connected: " << m_wiimote << std::endl;
 
160
      if (cwiid_set_mesg_callback(m_wiimote, &Wiimote::mesg_callback))
 
161
        {
 
162
          std::cerr << "Unable to set message callback" << std::endl;
 
163
        }
 
164
 
 
165
      // FIXME: Could init this depending on what events are actually bound
 
166
      if (cwiid_command(m_wiimote, CWIID_CMD_RPT_MODE, 
 
167
                        CWIID_RPT_STATUS  |
 
168
                        CWIID_RPT_NUNCHUK |
 
169
                        CWIID_RPT_ACC     |
 
170
                        CWIID_RPT_IR      |
 
171
                        CWIID_RPT_BTN))
 
172
        {
 
173
          std::cerr << "Wiimote: Error setting report mode" << std::endl;
 
174
        }
 
175
 
 
176
      { // read calibration data
 
177
        uint8_t buf[7];
 
178
 
 
179
        if (cwiid_read(m_wiimote, CWIID_RW_EEPROM, 0x16, 7, buf))
 
180
          {
 
181
            std::cout << "Wiimote: Unable to retrieve accelerometer calibration" << std::endl;
 
182
          }
 
183
        else
 
184
          {
 
185
            wiimote_zero.x = buf[0];
 
186
            wiimote_zero.y = buf[1];
 
187
            wiimote_zero.z = buf[2];
 
188
 
 
189
            wiimote_one.x  = buf[4];
 
190
            wiimote_one.y  = buf[5];
 
191
            wiimote_one.z  = buf[6];
 
192
          }
 
193
 
 
194
        if (cwiid_read(m_wiimote, CWIID_RW_REG | CWIID_RW_DECODE, 0xA40020, 7, buf))
 
195
          {
 
196
            std::cout << "Wiimote: Unable to retrieve wiimote accelerometer calibration" << std::endl;
 
197
          }
 
198
        else
 
199
          {
 
200
            nunchuk_zero.x = buf[0];
 
201
            nunchuk_zero.y = buf[1];
 
202
            nunchuk_zero.z = buf[2];
 
203
            
 
204
            nunchuk_one.x  = buf[4];
 
205
            nunchuk_one.y  = buf[5];
 
206
            nunchuk_one.z  = buf[6];
 
207
          }
 
208
 
 
209
        std::cout << "Wiimote Calibration: "
 
210
                  << (int)wiimote_zero.x << ", "
 
211
                  << (int)wiimote_zero.x << ", "
 
212
                  << (int)wiimote_zero.x << " - "
 
213
                  << (int)wiimote_one.x << ", "
 
214
                  << (int)wiimote_one.x << ", "
 
215
                  << (int)wiimote_one.x << std::endl;
 
216
 
 
217
        std::cout << "Nunchuk Calibration: "
 
218
                  << (int)nunchuk_zero.x << ", "
 
219
                  << (int)nunchuk_zero.x << ", "
 
220
                  << (int)nunchuk_zero.x << " - "
 
221
                  << (int)nunchuk_one.x << ", "
 
222
                  << (int)nunchuk_one.x << ", "
 
223
                  << (int)nunchuk_one.x << std::endl;
 
224
          
 
225
      }
 
226
    }
 
227
}
 
228
 
 
229
void
 
230
Wiimote::disconnect()
 
231
{
 
232
  if (m_wiimote)
 
233
    {
 
234
      cwiid_disconnect(m_wiimote);
 
235
      m_wiimote = 0;
 
236
    }
 
237
}
 
238
 
 
239
void
 
240
Wiimote::set_led(unsigned char led_state)
 
241
{
 
242
  if (m_led_state != led_state)
 
243
    {
 
244
      //std::cout << "Wiimote: " << (int)m_led_state << std::endl;
 
245
      m_led_state = led_state;
 
246
 
 
247
      if (cwiid_command(m_wiimote, CWIID_CMD_LED, m_led_state)) {
 
248
        fprintf(stderr, "Error setting LEDs \n");
 
249
      }
 
250
    }
 
251
}
 
252
 
 
253
void
 
254
Wiimote::set_led(int num, bool state)
 
255
{
 
256
  assert(num >= 1 && num <= 4);
 
257
 
 
258
  int new_led_state = m_led_state;
 
259
  if (state)
 
260
    new_led_state |= (1 << (num-1));
 
261
  else // (!state)
 
262
    new_led_state &= ~(1 << (num-1));
 
263
 
 
264
  set_led(new_led_state);
 
265
}
 
266
 
 
267
void
 
268
Wiimote::set_rumble(bool r)
 
269
{
 
270
  if (r != m_rumble)
 
271
    {
 
272
      m_rumble = r;
 
273
 
 
274
      if (cwiid_command(m_wiimote, CWIID_CMD_RUMBLE, m_rumble)) {
 
275
        std::cerr << "Error setting rumble" << std::endl;
 
276
      }
 
277
    }
 
278
}
 
279
 
 
280
void
 
281
Wiimote::add_button_event(int device, int button, bool down)
 
282
{
 
283
  // std::cout << "Wiimote::add_button_event: " << device << " " << button << " " << down << std::endl;
 
284
  WiimoteEvent event;
 
285
 
 
286
  event.type = WiimoteEvent::WIIMOTE_BUTTON_EVENT;
 
287
  event.button.device = 0;
 
288
  event.button.button = button;
 
289
  event.button.down   = down;
 
290
 
 
291
  events.push_back(event);
 
292
}
 
293
 
 
294
void
 
295
Wiimote::add_axis_event(int device, int axis, float pos)
 
296
{
 
297
  //std::cout << "Wiimote::add_axis_event: " << device << " " << axis << " " << pos << std::endl;
 
298
 
 
299
  WiimoteEvent event;
 
300
 
 
301
  event.type = WiimoteEvent::WIIMOTE_AXIS_EVENT;
 
302
  event.axis.device = 0;
 
303
  event.axis.axis = axis;
 
304
  event.axis.pos  = pos;
 
305
 
 
306
  events.push_back(event); 
 
307
}
 
308
 
 
309
void
 
310
Wiimote::add_acc_event(int device, int accelerometer, float x, float y, float z)
 
311
{
 
312
  WiimoteEvent event;
 
313
 
 
314
  event.type = WiimoteEvent::WIIMOTE_ACC_EVENT;
 
315
  event.acc.device = 0;
 
316
  event.acc.accelerometer = accelerometer;
 
317
  event.acc.x = x;
 
318
  event.acc.y = y;
 
319
  event.acc.z = z;
 
320
 
 
321
  events.push_back(event);  
 
322
}
 
323
 
 
324
 
 
325
void
 
326
Wiimote::on_status(const cwiid_status_mesg& msg)
 
327
{
 
328
  printf("Status Report: battery=%d extension=", msg.battery);
 
329
  switch (msg.ext_type)
 
330
    {
 
331
    case CWIID_EXT_NONE:
 
332
      printf("none");
 
333
      break;
 
334
 
 
335
    case CWIID_EXT_NUNCHUK:
 
336
      printf("Nunchuk");
 
337
      break;
 
338
 
 
339
    case CWIID_EXT_CLASSIC:
 
340
      printf("Classic Controller");
 
341
      break;
 
342
 
 
343
    default:
 
344
      printf("Unknown Extension");
 
345
      break;
 
346
    }
 
347
  printf("\n");
 
348
}
 
349
 
 
350
void
 
351
Wiimote::on_error(const cwiid_error_mesg& msg)
 
352
{
 
353
  std::cout << "On Error" << std::endl;
 
354
 
 
355
  if (m_wiimote)
 
356
    {
 
357
      if (cwiid_disconnect(m_wiimote)) 
 
358
        {
 
359
          fprintf(stderr, "Error on wiimote disconnect\n");
 
360
          m_wiimote = 0;
 
361
        }
 
362
    }
 
363
}
 
364
 
 
365
void
 
366
Wiimote::on_button(const cwiid_btn_mesg& msg)
 
367
{
 
368
#define CHECK_BTN(btn, num) if (changes & btn) add_button_event(0, num, m_buttons & btn)
 
369
 
 
370
  uint16_t changes = m_buttons ^ msg.buttons;
 
371
  m_buttons = msg.buttons;
 
372
 
 
373
  CHECK_BTN(CWIID_BTN_A, WIIMOTE_A);
 
374
  CHECK_BTN(CWIID_BTN_B, WIIMOTE_B);
 
375
 
 
376
  CHECK_BTN(CWIID_BTN_LEFT,  WIIMOTE_LEFT);
 
377
  CHECK_BTN(CWIID_BTN_RIGHT, WIIMOTE_RIGHT);
 
378
  CHECK_BTN(CWIID_BTN_UP,    WIIMOTE_UP);
 
379
  CHECK_BTN(CWIID_BTN_DOWN,  WIIMOTE_DOWN);
 
380
 
 
381
  CHECK_BTN(CWIID_BTN_PLUS,  WIIMOTE_PLUS);
 
382
  CHECK_BTN(CWIID_BTN_HOME,  WIIMOTE_HOME);
 
383
  CHECK_BTN(CWIID_BTN_MINUS, WIIMOTE_MINUS);
 
384
 
 
385
  CHECK_BTN(CWIID_BTN_1,  WIIMOTE_1);
 
386
  CHECK_BTN(CWIID_BTN_2,  WIIMOTE_2);
 
387
}
 
388
 
 
389
void
 
390
Wiimote::on_acc(const cwiid_acc_mesg& msg)
 
391
{
 
392
  //printf("Acc Report: x=%d, y=%d, z=%d\n", msg.acc[0], msg.acc[1], msg.acc[2]);
 
393
 
 
394
  add_acc_event(0, 0, 
 
395
                (msg.acc[0] - wiimote_zero.x) / float(wiimote_one.x - wiimote_zero.x),
 
396
                (msg.acc[1] - wiimote_zero.y) / float(wiimote_one.y - wiimote_zero.y),
 
397
                (msg.acc[2] - wiimote_zero.z) / float(wiimote_one.z - wiimote_zero.z));
 
398
}
 
399
 
 
400
void
 
401
Wiimote::on_ir(const cwiid_ir_mesg& msg)
 
402
{
 
403
  bool is_valid = false;
 
404
  for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
 
405
    is_valid = is_valid || msg.src[i].valid;
 
406
 
 
407
  if (is_valid)
 
408
    {
 
409
      std::cout << "IR Report: ";
 
410
      for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
 
411
        {
 
412
          if (msg.src[i].valid) {
 
413
            std::cout << "(" <<  msg.src[i].pos[0] << ", " <<  msg.src[i].pos[1] << ") ";
 
414
          }
 
415
        }
 
416
      std::cout << std::endl;
 
417
    }
 
418
}
 
419
 
 
420
/** Convert value to float while taking calibration data, left/center/right into account */
 
421
inline float to_float(uint8_t min, 
 
422
                      uint8_t center, 
 
423
                      uint8_t max, 
 
424
                      uint8_t value)
 
425
{
 
426
  if (value < center)
 
427
    {
 
428
      return Math::clamp(-1.0f, -(center - value) / float(center - min), 1.0f);
 
429
    }
 
430
  else if (value > center)
 
431
    {
 
432
      return Math::clamp(-1.0f, (value - center) / float(max - center), 1.0f);
 
433
    }
 
434
  else 
 
435
    {
 
436
      return 0.0f;
 
437
    }
 
438
}
 
439
 
 
440
void
 
441
Wiimote::on_nunchuk(const cwiid_nunchuk_mesg& msg)
 
442
{
 
443
  uint8_t changes = m_nunchuk_btns ^ msg.buttons;
 
444
  m_nunchuk_btns  = msg.buttons;
 
445
 
 
446
#define CHECK_NCK_BTN(btn, num) if (changes & btn) add_button_event(0, num, m_nunchuk_btns & btn)
 
447
      
 
448
  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_Z, NUNCHUK_Z);
 
449
  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_C, NUNCHUK_C);
 
450
  
 
451
  // FIXME: Read real calibration data, instead of hardcoded one
 
452
  float nunchuk_stick_x =  to_float(37, 129, 231, msg.stick[0]);
 
453
  float nunchuk_stick_y = -to_float(22, 119, 213, msg.stick[1]);
 
454
 
 
455
  if (m_nunchuk_stick_x != nunchuk_stick_x)
 
456
    {
 
457
      m_nunchuk_stick_x = nunchuk_stick_x;
 
458
      add_axis_event(0, 0, m_nunchuk_stick_x);
 
459
    } 
 
460
 
 
461
  if (m_nunchuk_stick_y != nunchuk_stick_y)
 
462
    {
 
463
      m_nunchuk_stick_y = nunchuk_stick_y;
 
464
      add_axis_event(0, 1, m_nunchuk_stick_y);
 
465
    }
 
466
 
 
467
  add_acc_event(0, 1, 
 
468
                (msg.acc[0] - nunchuk_zero.x) / float(nunchuk_one.x - nunchuk_zero.x),
 
469
                (msg.acc[1] - nunchuk_zero.y) / float(nunchuk_one.y - nunchuk_zero.y),
 
470
                (msg.acc[2] - nunchuk_zero.z) / float(nunchuk_one.z - nunchuk_zero.z));
 
471
  if (0)
 
472
    printf("Nunchuk Report: btns=%.2X stick=(%3d,%3d) (%5.2f, %5.2f) acc.x=%d acc.y=%d acc.z=%d\n", 
 
473
           msg.buttons,
 
474
           msg.stick[0], msg.stick[1], 
 
475
           m_nunchuk_stick_x,
 
476
           m_nunchuk_stick_y,
 
477
           msg.acc[0], msg.acc[1], msg.acc[2]);
 
478
}
 
479
 
 
480
void
 
481
Wiimote::on_classic(const cwiid_classic_mesg& msg)
 
482
{
 
483
  printf("Classic Report: btns=%.4X l_stick=(%d,%d) r_stick=(%d,%d) "
 
484
         "l=%d r=%d\n", msg.buttons,
 
485
         msg.l_stick[0], msg.l_stick[1],
 
486
         msg.r_stick[0], msg.r_stick[1],
 
487
         msg.l, msg.r);
 
488
}
 
489
 
 
490
std::vector<WiimoteEvent>
 
491
Wiimote::pop_events()
 
492
{
 
493
  pthread_mutex_lock(&mutex);
 
494
  std::vector<WiimoteEvent> ret = events;
 
495
  events.clear();
 
496
  pthread_mutex_unlock(&mutex);
 
497
  return ret;
 
498
}
 
499
 
 
500
// Callback function that get called by the Wiimote thread
 
501
void
 
502
Wiimote::err(cwiid_wiimote_t* w, const char *s, va_list ap)
 
503
{
 
504
  pthread_mutex_lock(&mutex);
 
505
 
 
506
  if (w) 
 
507
    printf("%d:", cwiid_get_id(w));
 
508
  else 
 
509
    printf("-1:");
 
510
 
 
511
  vprintf(s, ap);
 
512
  printf("\n");  
 
513
 
 
514
  pthread_mutex_unlock(&mutex);
 
515
}
 
516
 
 
517
void
 
518
Wiimote::mesg(cwiid_wiimote_t* w, int mesg_count, union cwiid_mesg mesg[])
 
519
{
 
520
  pthread_mutex_lock(&mutex);
 
521
 
 
522
  //std::cout << "StatusCallback: " << w << " " << mesg_count << std::endl;
 
523
  for (int i=0; i < mesg_count; i++)
 
524
    {
 
525
      switch (mesg[i].type) 
 
526
        {
 
527
        case CWIID_MESG_STATUS:
 
528
          wiimote->on_status(mesg[i].status_mesg);
 
529
          break;
 
530
 
 
531
        case CWIID_MESG_BTN:
 
532
          wiimote->on_button(mesg[i].btn_mesg);
 
533
          break;
 
534
 
 
535
        case CWIID_MESG_ACC:
 
536
          wiimote->on_acc(mesg[i].acc_mesg);
 
537
          break;
 
538
 
 
539
        case CWIID_MESG_IR:
 
540
          wiimote->on_ir(mesg[i].ir_mesg);
 
541
          break;
 
542
 
 
543
        case CWIID_MESG_NUNCHUK:
 
544
          wiimote->on_nunchuk(mesg[i].nunchuk_mesg);
 
545
          break;
 
546
 
 
547
        case CWIID_MESG_CLASSIC:
 
548
          wiimote->on_classic(mesg[i].classic_mesg);
 
549
          break;
 
550
 
 
551
        case CWIID_MESG_ERROR:
 
552
          wiimote->on_error(mesg[i].error_mesg);
 
553
          break;
 
554
 
 
555
        default:
 
556
          printf("Wiimote: Unknown Report");
 
557
          break;
 
558
        }
 
559
    }
 
560
 
 
561
  pthread_mutex_unlock(&mutex);
 
562
}
 
563
 
 
564
// static callback functions
 
565
  
 
566
void
 
567
Wiimote::err_callback(cwiid_wiimote_t* w, const char *s, va_list ap)
 
568
{
 
569
  wiimote->err(w, s, ap);
 
570
}
 
571
 
 
572
void
 
573
Wiimote::mesg_callback(cwiid_wiimote_t* w, int mesg_count, union cwiid_mesg mesg[], timespec*)
 
574
{
 
575
  wiimote->mesg(w, mesg_count, mesg);
 
576
}
 
577
 
 
578
/* EOF */