Commit 48119736ff66d3b9b4c6f25d6bfc053b9f947ac8

Authored by Arnaud Blanchard
1 parent 19e96d2c

Add application to read the mouse's movements. (Linux only)

# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cmake_minimum_required(VERSION 2.6)
#The name of the project is the basename of the directory
project(i_mouse)
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
add_definitions(${BL_DEFINTIIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(i_mouse i_mouse.cpp)
target_link_libraries(i_mouse ${BL_LIBRARIES})
... ...
Load a tsv file and put it in a blc_channel.
It between can be done line by line --with=period value in ms separating the time two lines.
... ...
#include "blc_core.h"
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <termios.h>
#include <libgen.h> //basename
int main(int argc, char** argv){
char const *period_str, *text, *gain_str;
char const *channel_name, *filename, *time_str;
char const *number_str;
char *default_output;
int number, ret;
uint64_t executing_time, previous_executing_time;
size_t linecap=0;
ssize_t line_size;
blc_channel channel;
float gain;
int fd;
int period, read_chars_nb;
signed char data[3];
asprintf(&default_output, "/%s%d", basename(argv[0]), getpid());
blc_program_set_description("Read the movements of the mouse");
blc_program_add_option(&gain_str, 'g', "gain", "real", "Gain to multiply the values between [-128, 127]", "1");
blc_program_add_option(&channel_name, 'o', "output_channel", "string", "Name of the channel to output the data", default_output);
blc_program_add_option(&period_str, 'p', "period", "integer", "Period in µs to read the mouse", "0");
blc_program_init(&argc, &argv, blc_quit);
blc_command_forward_blc_channels();
SSCANF(1, gain_str, "%f", &gain);
SSCANF(1, period_str, "%d", &period);
SYSTEM_ERROR_CHECK(fd=open("/dev/input/mice", O_RDONLY | O_NONBLOCK), -1, "Opening mouse file");
channel.create_or_open(channel_name, BLC_CHANNEL_WRITE, 'FL32', 'NDEF', 1, 2);
blc_loop_try_add_posting_semaphore(channel.sem_new_data);
blc_loop_try_add_waiting_semaphore(channel.sem_ack_data);
channel.publish();
BLC_COMMAND_LOOP(period){
read_chars_nb=read(fd, data, sizeof(data));
if (read_chars_nb==-1){
CLEAR(data);
}
channel.floats[0]=data[1]*gain;
channel.floats[1]=data[2]*gain;
}
SYSTEM_ERROR_CHECK(close(fd), -1, "Closing ");
FREE(default_output);
return EXIT_SUCCESS;
}
... ...