sensor_thread.cpp

00001 
00002 /***************************************************************************
00003  *  sensor_thread.cpp - Joystick thread that pushes data into the interface
00004  *
00005  *  Created: Sat Nov 22 18:05:55 2008
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include "sensor_thread.h"
00024 #include "acquisition_thread.h"
00025 
00026 #include <interfaces/JoystickInterface.h>
00027 
00028 using namespace fawkes;
00029 
00030 /** @class JoystickSensorThread "sensor_thread.h"
00031  * Joystick sensor thread.
00032  * This thread integrates into the Fawkes main loop at the sensor hook and
00033  * publishes new data when available from the JoystickAcquisitionThread.
00034  * @author Tim Niemueller
00035  */
00036 
00037 
00038 /** Constructor.
00039  * @param aqt JoystickAcquisitionThread to get data from
00040  */
00041 JoystickSensorThread::JoystickSensorThread(JoystickAcquisitionThread *aqt)
00042   : Thread("JoystickSensorThread", Thread::OPMODE_WAITFORWAKEUP),
00043     BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR)
00044 {
00045   __aqt    = aqt;
00046 }
00047 
00048 
00049 void
00050 JoystickSensorThread::init()
00051 {
00052   __joystick_if = blackboard->open_for_writing<JoystickInterface>("Joystick");
00053 }
00054 
00055 
00056 void
00057 JoystickSensorThread::finalize()
00058 {
00059   blackboard->close(__joystick_if);
00060 }
00061 
00062 
00063 void
00064 JoystickSensorThread::loop()
00065 {
00066   if ( __aqt->lock_if_new_data() ) {
00067     __joystick_if->set_num_axes( __aqt->num_axes() );
00068     __joystick_if->set_num_buttons( __aqt->num_buttons() );
00069     __joystick_if->set_pressed_buttons( __aqt->pressed_buttons() );
00070     __joystick_if->set_axis_x( __aqt->axis_x_values() );
00071     __joystick_if->set_axis_y( __aqt->axis_y_values() );
00072     __joystick_if->write();
00073     __aqt->unlock();
00074   }
00075 }

Generated on Tue Feb 22 13:32:29 2011 for Fawkes API by  doxygen 1.4.7