summaryrefslogtreecommitdiffstats
path: root/matchblox/common/wiimote_utils.h
blob: edb59cea9246b44faf5d5ef0b7780714d8efeff1 (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
#ifndef WIIMOTE_UTILS_H

#define WIIMOTE_UTILS_H

#include "message_input.h"
#include "typedefs.h"
#include "C_Smoother.h"

#define _USE_MATH_DEFINES
#include <math.h>

static double g_dWiimoteXCamResolution = 1016.0;
static double g_dWiimoteYCamResolution =  760.0;
static double g_dWiimoteRadPerPixel    = (41.0 * (M_PI/180.0))/g_dWiimoteXCamResolution;

//abstract wiimote needs to be inherited and the virtual functions implemented to communicate
//with a wiimote lib
class AbstractWiimote
{
public:
  AbstractWiimote();
  ~AbstractWiimote();

  virtual bool Connect() = 0;
  virtual void StartRumble() = 0;
  virtual void StopRumble() = 0;
  virtual void SetLeds(unsigned char bitmask) = 0;
  virtual bool IsConnected() = 0;

  void FillWiimoteMsgPayload(input_payload_wiimote &f_payload, double f_dSensBarLedDist);

protected:
  virtual void ParseWiimote(input_payload_wiimote &f_payload) = 0;

  bool   FindSensorBarDots(rawdot *f_rd, int f_iNumdots, Vect3D_t f_Dots[2]);
  bool   CalcWiimoteRelativeCursorPos(input_payload_wiimote &f_pWiimoteMsg, double f_dSensBarLedDist);
  double CalcZDistInMM(Vect3D_t f_Dots[2], double f_dSensBarLedDist);

  C_Smoother<Vect3D_t> *m_pSensBarDotSmoother[2];
};

#ifdef USE_WIIYOURSELF

#include <wiimote.h>

//implementation of an abstract wiimote using the wiiyourself! lib
class WiiYourselfWiimote : public AbstractWiimote
{
public:
  WiiYourselfWiimote();
  ~WiiYourselfWiimote();

  bool Connect();
  void StartRumble();
  void StopRumble();
  void SetLeds(unsigned char bitmask);
  bool IsConnected();

  void ParseWiimote(input_payload_wiimote &f_payload);

private:
  wiimote *m_pWm;
};

#endif //USE_WIIYOURSELF


#endif //WIIMOTE_UTILS_H