1
//-----------------------------------------------------------------------------------------
2
// Driver for the Bauhaus University Weimar "inertiamouse" device. The class for this
3
// device is found at the end of the file, after two helper classes.
5
#ifndef VRPN_INERTIAMOUSE_H
6
#define VRPN_INERTIAMOUSE_H
8
#include "vrpn_Analog.h"
9
#include "vrpn_Button.h"
12
class VRPN_API dcblocker {
13
public: // ctors, dtor
18
dcblocker (dcblocker const& o)
22
~dcblocker () throw () {}
24
void swap (dcblocker& o) throw ()
27
t = in_; in_ = o.in_; o.in_ = t;
28
t = out_; out_ = o.out_; o.out_ = t;
30
dcblocker& operator= (dcblocker const& o)
36
double filter (double s)
38
out_ = s - in_ + (0.95 * out_);
55
class VRPN_API lowpass {
56
public: // ctors, dtor
64
lowpass (lowpass const& o)
71
~lowpass () throw () {}
73
double filter (double s)
76
in_[1] = s / 6.242183581;
78
out_[1] = in_[0] + in_[1] + (0.6795992982 * out_[0]);
83
in_[0] = in_[1] = out_[0] = out_[1] = 0.0;
90
class VRPN_API vrpn_inertiamouse : public vrpn_Serial_Analog , public vrpn_Button {
96
Update_Interval_Hz = 7372800 / 64 / 13 / Channels,
98
static const double Vel_Decay;
100
public: // construction/destruction
102
vrpn_inertiamouse (const char* name,
108
static vrpn_inertiamouse* create (const char* name,
113
~vrpn_inertiamouse () { if (vel_) { delete [] vel_;} };
115
public: // virtual methods
117
/// Called once through each main loop iteration to handle updates.
118
virtual void mainloop ();
120
virtual int reset(void); //< Set device back to starting config
123
int status_; //< Used by mainloop() and get_report()
124
int numbuttons_; //< How many buttons to open
125
int numchannels_; //< How many analog channels to open
127
int expected_chars_; //< How many characters to expect in the report
128
unsigned char buffer_[512]; //< Buffer of characters in report
129
int bufcount_; //< How many characters we have so far
131
int null_radius_; //< The range over which no motion should be
134
struct timeval timestamp; //< Time of the last report from the device
136
double *vel_; // velocity update
138
dcblocker dcb_[Channels]; // dc blockers for all Channels
139
lowpass lp_[Channels]; // lowpass filters for all Channels
141
// Set all buttons, analogs and encoders back to 0
142
virtual void clear_values(void);
144
/// Try to read a report from the device. Returns 1 if complete report received,
145
/// 0 otherwise. Sets _status to match current status.
146
virtual int get_report(void);
148
/// send report iff changed
149
virtual void report_changes (vrpn_uint32 class_of_service
150
= vrpn_CONNECTION_LOW_LATENCY);
151
/// send report whether or not changed
152
virtual void report (vrpn_uint32 class_of_service
153
= vrpn_CONNECTION_LOW_LATENCY);
155
// NOTE: class_of_service is only applied to vrpn_Analog
156
// values, not vrpn_Button, which are always vrpn_RELIABLE