Commit 48119736 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

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

parent 19e96d2c
# 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 "".
# 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
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
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);
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);
read_chars_nb=read(fd, data, sizeof(data));
if (read_chars_nb==-1){
SYSTEM_ERROR_CHECK(close(fd), -1, "Closing ");
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment