gadget::SimAnalog Class Reference

Simulated analog device. More...

#include <gadget/Devices/Sim/SimAnalog.h>

Inheritance diagram for gadget::SimAnalog:

Inheritance graph
[legend]
Collaboration diagram for gadget::SimAnalog:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SimAnalog ()
 Default Constructor.
virtual ~SimAnalog ()
 Destructor.
virtual bool config (jccl::ConfigElementPtr element)
 Reads the minimum and maximum value configuration information for this analog device.
bool startSampling ()
 These functions don't do anything.
bool stopSampling ()
bool sample ()
virtual void updateData ()
 Updates the data.
virtual std::vector< KeyModPair > getUpKeys ()
virtual std::vector< KeyModPair > getDownKeys ()
void operator delete (void *p)
 Invokes the global scope delete operator.

Static Public Member Functions

static std::string getElementType ()

Protected Member Functions

virtual void destroy ()
 Deletes this object.

Detailed Description

Simulated analog device.

Simulates an analog device from a keyboard device. It allows any number of simulated analog devices to be created.

This class should not be used directly by the user.

Definition at line 59 of file SimAnalog.h.


Constructor & Destructor Documentation

gadget::SimAnalog::SimAnalog (  ) 

Default Constructor.

Definition at line 40 of file SimAnalog.cpp.

00041    : mAnaStep(0.0f)
00042    , mInitialValue(0.0f)
00043 {
00044    //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimAnalog::SimPinchGlove()\n"<< vprDEBUG_FLUSH;
00045 }

gadget::SimAnalog::~SimAnalog (  )  [virtual]

Destructor.

Definition at line 48 of file SimAnalog.cpp.

00049 {
00050    //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimAnalog::~SimPinchGlove()\n"<< vprDEBUG_FLUSH;
00051 }


Member Function Documentation

bool gadget::SimAnalog::config ( jccl::ConfigElementPtr  element  )  [virtual]

Reads the minimum and maximum value configuration information for this analog device.

Parameters:
element The config element for an analog device. It must derive from the base config element type 'analog'.

Definition at line 58 of file SimAnalog.cpp.

References gadget::SimInput::config(), gadget::Analog::config(), and gadget::Input::config().

00059 {
00060    //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimAnalog::config()\n"<< vprDEBUG_FLUSH;
00061    if (! (Input::config(element) && Analog::config(element) &&
00062           SimInput::config(element)) )
00063    {
00064       return false;
00065    }
00066 
00067    std::vector<jccl::ConfigElementPtr> key_inc_list, key_dec_list;
00068 
00069    int key_count = element->getNum("increment_keypress");
00070 
00071    for ( int i = 0; i < key_count; ++i )
00072    {
00073       key_inc_list.push_back(element->getProperty<jccl::ConfigElementPtr>("increment_keypress", i));
00074    }
00075 
00076    key_count = element->getNum("decrement_keypress");
00077 
00078    for ( int i = 0; i < key_count; ++i )
00079    {
00080       key_dec_list.push_back(element->getProperty<jccl::ConfigElementPtr>("decrement_keypress", i));
00081    }
00082 
00083    mSimKeysUp = readKeyList(key_inc_list);
00084    mSimKeysDown = readKeyList(key_dec_list);
00085 
00086    mAnaStep = element->getProperty<float>("delta");
00087    mInitialValue = element->getProperty<float>("initial_value");
00088 
00089    // Initialize all the data to the inital_value
00090    size_t num_pairs = mSimKeysUp.size();
00091    mAnaData = std::vector<AnalogData>(num_pairs);
00092    for (size_t i=0; i<num_pairs; ++i)
00093    {
00094       mAnaData[i].setAnalog(mInitialValue);
00095    }
00096 
00097    return true;
00098 }

bool gadget::SimAnalog::startSampling (  )  [inline]

These functions don't do anything.

Definition at line 76 of file SimAnalog.h.

00077    {
00078       return true;
00079    }

bool gadget::SimAnalog::stopSampling (  )  [inline]

Definition at line 81 of file SimAnalog.h.

00082    {
00083       return true;
00084    }

bool gadget::SimAnalog::sample (  )  [inline]

Definition at line 86 of file SimAnalog.h.

00087    {
00088       return true;
00089    }

void gadget::SimAnalog::updateData (  )  [virtual]

Updates the data.

Definition at line 100 of file SimAnalog.cpp.

00101 {
00102    //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimAnalog::updateData()\n"<< vprDEBUG_FLUSH;
00103 
00104    // Make an list of the data that will be normalized
00105    std::vector<AnalogData> norm_data(mAnaData.size());
00106 
00107    // -- Update analog data --- //
00108    for (unsigned int i = 0; i < mSimKeysUp.size(); ++i)
00109    {
00110       mAnaData[i].setTime();
00111       mAnaData[i].setAnalog(mAnaData[i].getAnalog()
00112                                 + (float)checkKeyPair(mSimKeysUp[i]) * mAnaStep);
00113       mAnaData[i].setAnalog(mAnaData[i].getAnalog()
00114                                 - (float)checkKeyPair(mSimKeysDown[i]) * mAnaStep);
00115 
00116       // Clamp to the min/max range
00117       mAnaData[i].setAnalog(gmtl::Math::clamp(mAnaData[i].getAnalog(),
00118                                               getMin(), getMax()));
00119 
00120       float normalized_value;
00121       normalizeMinToMax(mAnaData[i].getAnalog(), normalized_value);
00122 
00123       // Set the normalized data
00124       norm_data[i] = normalized_value;
00125       norm_data[i].setTime(mKeyboardMouse->getTimeStamp());
00126    }
00127 
00128    // Locks and then swaps the indices.
00129    addAnalogSample(norm_data);
00130    swapAnalogBuffers();
00131 }

std::string gadget::SimAnalog::getElementType (  )  [static]

Definition at line 53 of file SimAnalog.cpp.

00054 {
00055    return "simulated_analog_device";
00056 }

virtual std::vector<KeyModPair> gadget::SimAnalog::getUpKeys (  )  [inline, virtual]

Definition at line 96 of file SimAnalog.h.

00097    {
00098       return mSimKeysUp;
00099    }

virtual std::vector<KeyModPair> gadget::SimAnalog::getDownKeys (  )  [inline, virtual]

Definition at line 101 of file SimAnalog.h.

00102    {
00103       return mSimKeysDown;
00104    }

void gadget::SimAnalog::operator delete ( void *  p  )  [inline]

Invokes the global scope delete operator.

This is required for proper releasing of memory in DLLs on Win32.

Definition at line 110 of file SimAnalog.h.

00111    {
00112       ::operator delete(p);
00113    }

virtual void gadget::SimAnalog::destroy (  )  [inline, protected, virtual]

Deletes this object.

This is an implementation of the pure virtual gadget::Input::destroy() method.

Definition at line 120 of file SimAnalog.h.

00121    {
00122       delete this;
00123    }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:44:37 2007 for Gadgeteer by  doxygen 1.5.1