Commit cd0c932adf31175fedbeff3da9cc52e89f27eedc

Authored by Arnaud Blanchard
1 parent f42193dc

Minor fixes

... ... @@ -2,21 +2,11 @@ cmake_minimum_required(VERSION 2.6)
project(bapps)
subdirs(i_gaussian)
subdirs(i_read)
subdirs(i_fread)
subdirs(i_oscillator)
subdirs(i_keyboard)
subdirs(f_convolute)
subdirs(f_norm)
subdirs(f_max)
subdirs(f_point_of_interest)
subdirs(f_tee)
subdirs(f_arg_max)
#subdirs(serial) i_arduino deprecated
subdirs(i_fread)
subdirs(o_fwrite)
... ...
... ... @@ -18,7 +18,7 @@ find_package(blc_program REQUIRED)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(i_keyboard src/i_keyboard.cpp)
add_executable(i_keyboard src/main.cpp)
target_link_libraries(i_keyboard ${BL_LIBRARIES})
... ...
... ... @@ -62,8 +62,7 @@ int main(int argc, char **argv){
blc_program_add_option(&refresh_rate_str, 'r', "refresh", "real ", "refresh rate in ms", "10");
blc_program_add_option(&type_str, 't', "type", "FL32", "type of data", "FL32");
blc_program_init(&argc, &argv, blc_quit);
blc_command_forward_blc_channels();
// period=strtol(period_str, NULL, 10);
SSCANF(1, refresh_rate_str, "%f", &refresh_rate);
step=(double)refresh_rate/(double)period;
... ...
... ... @@ -85,8 +85,7 @@ int main(int argc, char** argv){
blc_program_add_option(&text, 't', "text", NULL, "Export the result as text instead of blc_channel", NULL);
blc_program_add_parameter(&filename, "file name", 1, "file to load", NULL);
blc_program_init(&argc, &argv, blc_quit);
blc_command_forward_blc_channels();
period=strtod(period_str, NULL);
if (text==NULL){
... ...
... ... @@ -4,54 +4,102 @@
#include <unistd.h>
#include <termios.h>
#include <libgen.h> //basename
#include <pthread.h>
static int width_max, height_max;
static int current_pos=0, size_change=0;
static blc_channel channel;
static blc_mem history;
static int period, drawn=0;
int fprint_spikes_uchars(blc_mem *mem, FILE *file, const char *title, int width){
static pthread_mutex_t resize_mutex;
void resize_cb(int width, int height, void*){
width_max=width;
height_max=height;
size_change=1;
}
int fprint_spikes_uchars(blc_mem *history, FILE *file, const char *title){
char c;
int i, j;
int last_col=current_pos;
fprintf(file, "[%s]\n", title);
FOR(j, 8){
FOR(i, mem->size){
c=((1<<j) & mem->uchars[i])?'.':' ';
FOR(i, last_col){
c=((1<<j) & history->uchars[i])? '.': ' ';
fputc(c, file);
}
fputc('\n', file);
eprintf_escape_command("K");
fprintf( file, "\n");
}
return 9;
}
void *record_thread(void*){
while(1){
if (size_change){ //Terminal resizing
pthread_mutex_lock(&resize_mutex);
history.reallocate(width_max);
if (current_pos >= history.size) current_pos=current_pos%history.size;
size_change=0;
pthread_mutex_unlock(&resize_mutex);
}
history.uchars[current_pos]=channel.uchars[0];
current_pos++;
usleep(period/history.size);
if (current_pos==history.size || drawn) {
if (drawn==0) fprintf(stderr, "You do not draw fast enough\n");
else drawn=0;
current_pos=0;
}
}
return NULL;
}
int main(int argc, char** argv){
blc_channel channel;
char const *period_str;
char const *channel_name, *filename, *time_str;
char const *number_str;
char const *ext;
FILE *file;
int height=0;
int width;
int number;
int period;
struct timeval timer;
pthread_t thread;
blc_program_set_description("Display a text graph of blc_channel in the terminal");
blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to refresh the graph", "0");
blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to refresh the graph", "100");
blc_program_add_parameter(&channel_name, "blc_channel-in", 1, "channel to graph", NULL);
blc_program_init(&argc, &argv, blc_quit);
blc_command_forward_blc_channels();
period=strtol(period_str, NULL,10)*1000;
channel.open(channel_name, BLC_CHANNEL_READ);
blc_loop_try_add_waiting_semaphore(channel.sem_new_data);
blc_loop_try_add_posting_semaphore(channel.sem_ack_data);
blc_terminal_get_size(&width_max, &height_max);
blc_terminal_set_resize_callback(resize_cb, NULL);
history.allocate(width_max);
BLC_PTHREAD_CHECK(pthread_mutex_init(&resize_mutex, NULL), "");
BLC_PTHREAD_CHECK(pthread_create(&thread, NULL, record_thread, NULL), "Creating thread");
BLC_COMMAND_LOOP(period){
//if (blc_loop_iteration!=0);
blc_eprint_cursor_up(8);
fprint_spikes_uchars(&channel, stderr, channel_name, 16);
blc_eprint_cursor_up(8);
if (height) blc_eprint_cursor_up(height);
pthread_mutex_lock(&resize_mutex);
height=fprint_spikes_uchars(&history, stderr, channel_name);
pthread_mutex_unlock(&resize_mutex);
drawn=1;
}
return EXIT_SUCCESS;
}
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard
# 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.
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
project(serial)
subdirs(serial_servos)
subdirs(o_serial_servos)
# Set the name of the project as the directory basename
project(i_arduino)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(i_arduino src/main.cpp)
target_link_libraries(i_arduino ${BL_LIBRARIES})
... ...
#define END_LOOP 3000
int main(int argc, char **argv){
int i, sum=0;
for (i=0; i<END_LOOP; i++){
sum+=2;
}
i=0;
sum=0;
while ( i<END_LOOP){
sum+=2;
i++;
}
return 0;
}
... ...
#define END_LOOP 3000
int main(int argc, char **argv){
int i, sum=0;
for (i=0; i<END_LOOP; i++){
sum+=2;
}
i=0;
sum=0;
while ( i<END_LOOP){
sum+=2;
i++;
}
return 0;
}
... ...