Skip to content

Commit

Permalink
two-hand touchless no finger tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
larrylisky committed May 14, 2016
1 parent f0dd824 commit 9477164
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 413 deletions.
2 changes: 1 addition & 1 deletion TinTin/touchless_tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_definitions(-msse2 -pthread -std=c++11 -fPIC -ffast-math)
set(VOXEL_INCLUDE_DIRS . /usr/include/voxel /usr/include/voxel/pcl /usr/include/voxel/ti3dtof /usr/include/voxel/Filter )
set(VOXEL_LIBRARIES /usr/lib/libti3dtof.so /usr/lib/libvoxel.so /usr/lib/libvoxelpcl.so)

add_executable(touchless touchless.cpp Jive.cpp TOFApp.cpp)
add_executable(touchless touchless.cpp Jive.cpp TOFApp.cpp FakeMouse.cpp)
target_include_directories(touchless PUBLIC ${VOXEL_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS})
target_link_libraries(touchless voxelpcl X11 ${OpenCV_LIBS} ${VOXEL_LIBRARIES} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} ${PCL_VISUALIZATION_LIBRARIES})

Expand Down
236 changes: 236 additions & 0 deletions TinTin/touchless_tracking/FakeMouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
/*!
* ==========================================================================================
*
* @addtogroup FakeMouse
* @{
*
* @file FakeMouse.cpp
* @version 1.0
* @date 1/7/2016
*
* @note FakeMouse class
*
* Copyright(c) 20015-2016 Texas Instruments Corporation, All Rights Reserved.q
* TI makes NO WARRANTY as to software products, which are supplied "AS-IS"
*
* ==========================================================================================
*/
#define __FAKEMOUSE_CPP__
#include "FakeMouse.h"


/*!
*===========================================================================================
* @brief Constructors
*===========================================================================================
*/
FakeMouse::FakeMouse()
{
setDisplay(XOpenDisplay(0));
}

FakeMouse::FakeMouse(Display *disp)
{
setDisplay(disp);
}

/*!
*===========================================================================================
* @brief Initialize X display info
*===========================================================================================
*/
void FakeMouse::setDisplay(Display *disp)
{
display = disp;
root = DefaultRootWindow(display);
screen = DefaultScreenOfDisplay(display);
width = screen->width;
height = screen->height;
}


/*!
*===========================================================================================
* @brief Destructor
*===========================================================================================
*/
FakeMouse::~FakeMouse()
{
}


/*!
*===========================================================================================
* @brief Generate a button event
*===========================================================================================
*/
bool FakeMouse::buttonEvent(int button, int event_type)
{
XEvent event;

memset(&event, 0, sizeof(event));
event.type = event_type;
event.xbutton.button = button;
event.xbutton.same_screen = True;
XQueryPointer(display, RootWindow(display, DefaultScreen(display)),
&event.xbutton.root, &event.xbutton.window,
&event.xbutton.x_root, &event.xbutton.y_root,
&event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
event.xbutton.subwindow = event.xbutton.window;
while (event.xbutton.subwindow) {
event.xbutton.window = event.xbutton.subwindow;

XQueryPointer(display, event.xbutton.window,
&event.xbutton.root, &event.xbutton.subwindow,
&event.xbutton.x_root, &event.xbutton.y_root,
&event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
}
if (event_type == ButtonRelease)
event.xbutton.state = 1 << (button+7);

if (XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0)
return false;
XFlush(display);
return true;
}


/*!
*===========================================================================================
* @brief Generate a button down event
*===========================================================================================
*/
void FakeMouse::buttonDown(int button)
{
buttonEvent(button, ButtonPress);
}


/*!
*===========================================================================================
* @brief Generate a button up event
*===========================================================================================
*/
void FakeMouse::buttonUp(int button)
{
buttonEvent(button, ButtonRelease);
}


/*!
*===========================================================================================
* @brief Generate a click event
*===========================================================================================
*/
void FakeMouse::click(int button)
{
buttonDown(button);
usleep(100000);
buttonUp(button);
}


/*!
*===========================================================================================
* @brief Generate a double click event
*===========================================================================================
*/
void FakeMouse::doubleClick(int button)
{
click(button);
usleep(100000);
click(button);
}


/*!
*===========================================================================================
* @brief Move mouse to absolute position (x, y)
*===========================================================================================
*/
void FakeMouse::moveTo(int x, int y)
{
XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);
XFlush(display);
}


/*!
*===========================================================================================
* @brief Move mouse position incrementally by (dx, dy)
*===========================================================================================
*/
void FakeMouse::moveBy(int dx, int dy)
{
int x, y;

getPos(x, y);
XWarpPointer(display, None, root, 0, 0, 0, 0, x+dx, y+dy);
XFlush(display);
}


/*!
*===========================================================================================
* @brief Get current mouse absolute position
*===========================================================================================
*/
void FakeMouse::getPos(int &x, int &y)
{
XEvent event;
XQueryPointer(display, RootWindow(display, DefaultScreen(display)),
&event.xbutton.root, &event.xbutton.window,
&event.xbutton.x_root, &event.xbutton.y_root,
&event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
x = event.xbutton.x;
y = event.xbutton.y;
}


/*!
*===========================================================================================
* @brief Get display dimension
*===========================================================================================
*/
void FakeMouse::getDim(int &x, int &y)
{
x = width;
y = height;
}


/*!
*===========================================================================================
* @brief Unit Test
*===========================================================================================
*/
#ifdef __UNIT_TEST__
int main(int argc,char * argv[])
{
int i=0;
int x , y;
x=atoi(argv[1]);
y=atoi(argv[2]);
Display *display = XOpenDisplay(0);
FakeMouse mouse(display);
Screen *screen = DefaultScreenOfDisplay(display);
mouse.moveTo(x, y);
mouse.click(Button1);

mouse.moveTo(0,0);
for (int i=0; i < 200; i++) {
mouse.moveBy(screen->width/200, screen->height/200);
usleep(10000);
}

XCloseDisplay(display);
return 0;
}
#undef __UNIT_TEST__
#endif // UNIT_TEST

#undef __FAKEMOUSE_CPP__

38 changes: 38 additions & 0 deletions TinTin/touchless_tracking/FakeMouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* FakeMouse - simulated X windows mouse actions
*
* Copyright (c) 2015-2016 Texas Instruments Inc.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#ifndef __FAKEMOUSE_H__
#define __FAKEMOUSE_H__

class FakeMouse {
public:
FakeMouse();
FakeMouse(Display *disp);
~FakeMouse();
void setDisplay(Display *disp);
void buttonDown(int button);
void buttonUp(int button);
void click(int button);
void doubleClick(int button);
void moveTo(int x, int y);
void moveBy(int dx, int dy);
void getPos(int &x, int &y);
void getDim(int &xmax, int &ymax);

private:
bool buttonEvent(int btn, int e);
Display *display;
Window root;
Screen *screen;
int width, height;
};
#endif
Loading

0 comments on commit 9477164

Please sign in to comment.