FF3DDeviceSenderAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "stdafx.h"
00024 #include "FF3DDeviceSenderAgent.h"
00025 #include "ReachinMicoleApplication.h"
00026 #include "MicoleAgentThread.h"
00027 #include "MicoleStringStream.h"
00028 
00029 
00030 FF3DDeviceSenderAgent::FF3DDeviceSenderAgent(const int &pDelay)
00031 : MicoleAgentThread("FF3DDeviceSenderAgent","SenderAgent"), _FF3DCoord(new FF3DCoord), _buttonPress(new ButtonPress), _delay(pDelay)
00032 {
00033         Display * dis = ReachinMicoleApplication::getInstance()->getDisplay();
00034         
00035         dis->tracker_pos->route( _FF3DCoord );
00036         dis->button->route( _buttonPress );
00037 
00038         start(); //Start thread*/
00039 }
00040 
00041 FF3DDeviceSenderAgent::~FF3DDeviceSenderAgent()
00042 {}
00043 
00044 void FF3DDeviceSenderAgent::run ()
00045 {
00046         Vec3f p = Vec3f(0,0,0);
00047         MicoleStringStream s;
00048         while(getState()==ACTIVE)
00049         {
00050                 p = _FF3DCoord->get();
00051 
00052                 if (p.x < 100 && p.x > -100) 
00053                 { //if reachin doesn't start
00054                         //value can be really big
00055                         //bus packet example: "IN PHANTOM : (pos=(4.5, 5.6, 2.3));"
00056                         s<< "IN FF3D : pos=(" << p.x << ", "<< p.y << ", " << p.z<<");";
00057 
00058                         if (_buttonPress->eventPressed())
00059                                 s << " evt=PRESSED;";
00060 
00061 
00062                         if (_buttonPress->eventReleased())
00063                                 s << " evt=RELEASED;";
00064 
00065 
00066                         sendMessage(s.str());
00067                 }
00068                 ::Sleep(_delay);
00069                 //Sleep(_delay);
00070                 s.flush();
00071         }
00072 }
00073 
00074 void FF3DDeviceSenderAgent::ButtonPress::evaluate( SFBool _pressed )
00075 {
00076         //we skip if the time difference between the last click event is too small
00077         pressed = !pressed;
00078         skip = !((Time(last_event + BUTTON_LAG)).inPast());
00079         last_event.setToNow();
00080         value = (!skip && pressed);
00081 }
00082 
00083 bool FF3DDeviceSenderAgent::ButtonPress::eventPressed()
00084 {
00085         return (pressed && !skip);
00086 }
00087 
00088 bool FF3DDeviceSenderAgent::ButtonPress::eventReleased()
00089 {
00090         return (!pressed && !skip);
00091 }
00092 
00093 void FF3DDeviceSenderAgent::prepareToStop(int argc, const char **argv)
00094 {
00095 }
00096 
00097 void FF3DDeviceSenderAgent::prepareToSuspend(int argc, const char **argv)
00098 {
00099 }

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7