Commit 48119736ff66d3b9b4c6f25d6bfc053b9f947ac8

Authored by Arnaud Blanchard
1 parent 19e96d2c

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

  1 +# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS
  2 +# Author: Arnaud Blanchard (November 2016)
  3 +# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
  4 +# 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".
  5 +# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
  6 +# 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.
  7 +# 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,
  8 +# 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.
  9 +# 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.
  10 +# 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.
  11 +
  12 +cmake_minimum_required(VERSION 2.6)
  13 +
  14 +#The name of the project is the basename of the directory
  15 +project(i_mouse)
  16 +
  17 +find_package(blc_channel REQUIRED)
  18 +find_package(blc_program REQUIRED)
  19 +
  20 +add_definitions(${BL_DEFINTIIONS})
  21 +include_directories(${BL_INCLUDE_DIRS})
  22 +add_executable(i_mouse i_mouse.cpp)
  23 +target_link_libraries(i_mouse ${BL_LIBRARIES})
  24 +
  25 +
  26 +
  27 +
  1 +
  2 +
  3 +Load a tsv file and put it in a blc_channel.
  4 +
  5 +It between can be done line by line --with=period value in ms separating the time two lines.
  1 +#include "blc_core.h"
  2 +#include "blc_channel.h"
  3 +#include "blc_program.h"
  4 +#include <unistd.h>
  5 +#include <termios.h>
  6 +#include <libgen.h> //basename
  7 +
  8 +int main(int argc, char** argv){
  9 + char const *period_str, *text, *gain_str;
  10 + char const *channel_name, *filename, *time_str;
  11 + char const *number_str;
  12 + char *default_output;
  13 + int number, ret;
  14 + uint64_t executing_time, previous_executing_time;
  15 + size_t linecap=0;
  16 + ssize_t line_size;
  17 + blc_channel channel;
  18 + float gain;
  19 + int fd;
  20 + int period, read_chars_nb;
  21 + signed char data[3];
  22 +
  23 +
  24 + asprintf(&default_output, "/%s%d", basename(argv[0]), getpid());
  25 + blc_program_set_description("Read the movements of the mouse");
  26 + blc_program_add_option(&gain_str, 'g', "gain", "real", "Gain to multiply the values between [-128, 127]", "1");
  27 + blc_program_add_option(&channel_name, 'o', "output_channel", "string", "Name of the channel to output the data", default_output);
  28 + blc_program_add_option(&period_str, 'p', "period", "integer", "Period in µs to read the mouse", "0");
  29 + blc_program_init(&argc, &argv, blc_quit);
  30 + blc_command_forward_blc_channels();
  31 +
  32 + SSCANF(1, gain_str, "%f", &gain);
  33 +
  34 + SSCANF(1, period_str, "%d", &period);
  35 +
  36 + SYSTEM_ERROR_CHECK(fd=open("/dev/input/mice", O_RDONLY | O_NONBLOCK), -1, "Opening mouse file");
  37 + channel.create_or_open(channel_name, BLC_CHANNEL_WRITE, 'FL32', 'NDEF', 1, 2);
  38 + blc_loop_try_add_posting_semaphore(channel.sem_new_data);
  39 + blc_loop_try_add_waiting_semaphore(channel.sem_ack_data);
  40 + channel.publish();
  41 + BLC_COMMAND_LOOP(period){
  42 + read_chars_nb=read(fd, data, sizeof(data));
  43 + if (read_chars_nb==-1){
  44 + CLEAR(data);
  45 + }
  46 + channel.floats[0]=data[1]*gain;
  47 + channel.floats[1]=data[2]*gain;
  48 + }
  49 + SYSTEM_ERROR_CHECK(close(fd), -1, "Closing ");
  50 + FREE(default_output);
  51 + return EXIT_SUCCESS;
  52 +}