00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <gadget/gadgetConfig.h>
00034
00035 #include <fstream>
00036 #include <vpr/Util/FileUtils.h>
00037 #include <jccl/Config/ConfigElement.h>
00038 #include <gadget/Util/Debug.h>
00039 #include <gadget/Devices/Sim/SimGloveGesture.h>
00040
00041
00042 namespace gadget
00043 {
00044
00045 std::string SimGloveGesture::getElementType()
00046 {
00047 return "simulated_glove_gesture";
00048 }
00049
00057 bool SimGloveGesture::config(jccl::ConfigElementPtr element)
00058 {
00059 if((!GloveGesture::config(element)) || (!SimInput::config(element)))
00060 {
00061 return false;
00062 }
00063
00064 mCurGesture = 0;
00065
00066 std::vector<jccl::ConfigElementPtr> key_list;
00067 int key_count = element->getNum("key_pair");
00068 for ( int i = 0; i < key_count; ++i )
00069 {
00070 key_list.push_back(element->getProperty<jccl::ConfigElementPtr>("key_pair", i));
00071 }
00072 mSimKeys = readKeyList(key_list);
00073
00074
00075 std::string sample_file = element->getProperty<std::string>("trained_filename");
00076 loadTrainedFile(vpr::replaceEnvVars(sample_file));
00077
00078
00079 unsigned int num_gestures = getNumGestures();
00080 while(num_gestures < mSimKeys.size())
00081 {
00082 mSimKeys.pop_back();
00083 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
00084 << "gadget::SimGloveGesture: Not enough gestures. Trimming"
00085 << std::endl << vprDEBUG_FLUSH;
00086 }
00087
00088
00089 std::string glove_pos_proxy = element->getProperty<std::string>("glove_position");
00090 if(glove_pos_proxy == std::string(""))
00091 {
00092 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
00093 << clrOutNORM(clrRED, "ERROR:") << " SimGloveGesture has no posProxy."
00094 << std::endl << vprDEBUG_FLUSH;
00095 return false;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 return true;
00113 }
00114
00123 const DigitalData SimGloveGesture::getDigitalData(int devNum)
00124 {
00125 int openLookupTable[] = { 0,0,0,0,0,-1,0,0,0,0,0 };
00126 int closedLookupTable[] = { 1,1,1,1,1,-1,1,1,1,1,1 };
00127 int pointingLookupTable[] = { 1,1,1,0,1,-1,1,1,1,0,1 };
00128 switch (mCurGesture)
00129 {
00130 case 0:
00131
00132 mDigitalData = openLookupTable[devNum];
00133 break;
00134 case 1:
00135
00136 mDigitalData = closedLookupTable[devNum];
00137 break;
00138 case 2:
00139
00140 mDigitalData = pointingLookupTable[devNum];
00141 break;
00142 default:
00143 mDigitalData = openLookupTable[devNum];
00144 break;
00145 }
00146 return mDigitalData;
00147 }
00148
00153 int SimGloveGesture::getGesture()
00154 { return mCurGesture; }
00155
00161 void SimGloveGesture::updateData()
00162 {
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 }
00182
00187 void SimGloveGesture::loadTrainedFile(std::string fileName)
00188 {
00189 std::ifstream inFile(fileName.c_str());
00190
00191 if(inFile)
00192 {
00193 this->loadFileHeader(inFile);
00194 inFile.close();
00195 }
00196 else
00197 {
00198 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
00199 << "gadget::SimGloveGesture:: Can't load trained file: "
00200 << fileName.c_str() << std::endl << vprDEBUG_FLUSH;
00201 }
00202 }
00203
00204 }