00001 /* 00002 * BaseJoystick.cpp 00003 * 00004 * Created on: Oct 25, 2011 00005 * Author: mriedel 00006 */ 00007 00008 #include <telekyb_joystick/BaseJoystick.hpp> 00009 00010 #include <fcntl.h> 00011 #include <ros/console.h> 00012 00013 namespace TELEKYB_NAMESPACE 00014 { 00015 00016 BaseJoystick::BaseJoystick(const std::string& devPath_, bool autoOpen_) 00017 : joystick_fd(-1), devPath(devPath_) 00018 { 00019 if (autoOpen_) { 00020 openJoystick(); 00021 } 00022 00023 } 00024 00025 BaseJoystick::~BaseJoystick() 00026 { 00027 // does not make Sense. Element not copyable. 00028 //closeJoystick(); 00029 } 00030 00031 00032 bool BaseJoystick::openJoystick() 00033 { 00034 if ((joystick_fd = open(devPath.c_str(), O_RDONLY)) != -1) { 00035 ROS_INFO("Opened joystick: %s", devPath.c_str()); 00036 return true; 00037 } else { 00038 ROS_ERROR("Unable to open joystick: %s", devPath.c_str()); 00039 return false; 00040 } 00041 } 00042 bool BaseJoystick::isOpen() 00043 { 00044 return (joystick_fd != -1); 00045 } 00046 void BaseJoystick::closeJoystick() 00047 { 00048 if (isOpen()) { 00049 close(joystick_fd); 00050 } 00051 } 00052 00053 }