Commit cd0c932adf31175fedbeff3da9cc52e89f27eedc

Authored by Arnaud Blanchard
1 parent f42193dc

Minor fixes

@@ -2,21 +2,11 @@ cmake_minimum_required(VERSION 2.6) @@ -2,21 +2,11 @@ cmake_minimum_required(VERSION 2.6)
2 2
3 project(bapps) 3 project(bapps)
4 4
5 -subdirs(i_gaussian)  
6 -subdirs(i_read) 5 +subdirs(i_fread)
7 subdirs(i_oscillator) 6 subdirs(i_oscillator)
8 subdirs(i_keyboard) 7 subdirs(i_keyboard)
9 -subdirs(f_convolute)  
10 -subdirs(f_norm)  
11 subdirs(f_max) 8 subdirs(f_max)
12 -subdirs(f_point_of_interest)  
13 -subdirs(f_tee)  
14 -subdirs(f_arg_max)  
15 -#subdirs(serial) i_arduino deprecated  
16 -subdirs(i_fread)  
17 subdirs(o_fwrite) 9 subdirs(o_fwrite)
18 10
19 11
20 12
21 -  
22 -  
@@ -18,7 +18,7 @@ find_package(blc_program REQUIRED) @@ -18,7 +18,7 @@ find_package(blc_program REQUIRED)
18 18
19 add_definitions(${BL_DEFINITIONS}) 19 add_definitions(${BL_DEFINITIONS})
20 include_directories(${BL_INCLUDE_DIRS}) 20 include_directories(${BL_INCLUDE_DIRS})
21 -add_executable(i_keyboard src/i_keyboard.cpp) 21 +add_executable(i_keyboard src/main.cpp)
22 target_link_libraries(i_keyboard ${BL_LIBRARIES}) 22 target_link_libraries(i_keyboard ${BL_LIBRARIES})
23 23
24 24
@@ -62,8 +62,7 @@ int main(int argc, char **argv){ @@ -62,8 +62,7 @@ int main(int argc, char **argv){
62 blc_program_add_option(&refresh_rate_str, 'r', "refresh", "real ", "refresh rate in ms", "10"); 62 blc_program_add_option(&refresh_rate_str, 'r', "refresh", "real ", "refresh rate in ms", "10");
63 blc_program_add_option(&type_str, 't', "type", "FL32", "type of data", "FL32"); 63 blc_program_add_option(&type_str, 't', "type", "FL32", "type of data", "FL32");
64 blc_program_init(&argc, &argv, blc_quit); 64 blc_program_init(&argc, &argv, blc_quit);
65 - blc_command_forward_blc_channels();  
66 - 65 +
67 // period=strtol(period_str, NULL, 10); 66 // period=strtol(period_str, NULL, 10);
68 SSCANF(1, refresh_rate_str, "%f", &refresh_rate); 67 SSCANF(1, refresh_rate_str, "%f", &refresh_rate);
69 step=(double)refresh_rate/(double)period; 68 step=(double)refresh_rate/(double)period;
@@ -85,8 +85,7 @@ int main(int argc, char** argv){ @@ -85,8 +85,7 @@ int main(int argc, char** argv){
85 blc_program_add_option(&text, 't', "text", NULL, "Export the result as text instead of blc_channel", NULL); 85 blc_program_add_option(&text, 't', "text", NULL, "Export the result as text instead of blc_channel", NULL);
86 blc_program_add_parameter(&filename, "file name", 1, "file to load", NULL); 86 blc_program_add_parameter(&filename, "file name", 1, "file to load", NULL);
87 blc_program_init(&argc, &argv, blc_quit); 87 blc_program_init(&argc, &argv, blc_quit);
88 - blc_command_forward_blc_channels();  
89 - 88 +
90 period=strtod(period_str, NULL); 89 period=strtod(period_str, NULL);
91 90
92 if (text==NULL){ 91 if (text==NULL){
@@ -4,54 +4,102 @@ @@ -4,54 +4,102 @@
4 #include <unistd.h> 4 #include <unistd.h>
5 #include <termios.h> 5 #include <termios.h>
6 #include <libgen.h> //basename 6 #include <libgen.h> //basename
  7 +#include <pthread.h>
7 8
  9 +static int width_max, height_max;
  10 +static int current_pos=0, size_change=0;
  11 +static blc_channel channel;
  12 +static blc_mem history;
  13 +static int period, drawn=0;
8 14
9 -int fprint_spikes_uchars(blc_mem *mem, FILE *file, const char *title, int width){ 15 +static pthread_mutex_t resize_mutex;
  16 +
  17 +void resize_cb(int width, int height, void*){
  18 + width_max=width;
  19 + height_max=height;
  20 + size_change=1;
  21 +}
  22 +
  23 +int fprint_spikes_uchars(blc_mem *history, FILE *file, const char *title){
10 char c; 24 char c;
11 int i, j; 25 int i, j;
12 26
  27 + int last_col=current_pos;
  28 +
13 fprintf(file, "[%s]\n", title); 29 fprintf(file, "[%s]\n", title);
14 FOR(j, 8){ 30 FOR(j, 8){
15 - FOR(i, mem->size){  
16 - c=((1<<j) & mem->uchars[i])?'.':' '; 31 + FOR(i, last_col){
  32 + c=((1<<j) & history->uchars[i])? '.': ' ';
17 fputc(c, file); 33 fputc(c, file);
18 } 34 }
19 - fputc('\n', file);  
20 - 35 + eprintf_escape_command("K");
  36 + fprintf( file, "\n");
21 } 37 }
22 return 9; 38 return 9;
23 } 39 }
24 40
  41 +
  42 +void *record_thread(void*){
  43 + while(1){
  44 + if (size_change){ //Terminal resizing
  45 + pthread_mutex_lock(&resize_mutex);
  46 + history.reallocate(width_max);
  47 + if (current_pos >= history.size) current_pos=current_pos%history.size;
  48 + size_change=0;
  49 + pthread_mutex_unlock(&resize_mutex);
  50 +
  51 + }
  52 + history.uchars[current_pos]=channel.uchars[0];
  53 + current_pos++;
  54 + usleep(period/history.size);
  55 + if (current_pos==history.size || drawn) {
  56 + if (drawn==0) fprintf(stderr, "You do not draw fast enough\n");
  57 + else drawn=0;
  58 +
  59 + current_pos=0;
  60 + }
  61 + }
  62 + return NULL;
  63 +}
  64 +
25 int main(int argc, char** argv){ 65 int main(int argc, char** argv){
26 - blc_channel channel; 66 +
27 char const *period_str; 67 char const *period_str;
28 char const *channel_name, *filename, *time_str; 68 char const *channel_name, *filename, *time_str;
29 char const *number_str; 69 char const *number_str;
30 char const *ext; 70 char const *ext;
31 FILE *file; 71 FILE *file;
  72 + int height=0;
  73 + int width;
32 int number; 74 int number;
33 - int period;  
34 struct timeval timer; 75 struct timeval timer;
  76 + pthread_t thread;
35 77
36 blc_program_set_description("Display a text graph of blc_channel in the terminal"); 78 blc_program_set_description("Display a text graph of blc_channel in the terminal");
37 - blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to refresh the graph", "0"); 79 + blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to refresh the graph", "100");
38 blc_program_add_parameter(&channel_name, "blc_channel-in", 1, "channel to graph", NULL); 80 blc_program_add_parameter(&channel_name, "blc_channel-in", 1, "channel to graph", NULL);
39 blc_program_init(&argc, &argv, blc_quit); 81 blc_program_init(&argc, &argv, blc_quit);
40 blc_command_forward_blc_channels(); 82 blc_command_forward_blc_channels();
41 - 83 +
42 period=strtol(period_str, NULL,10)*1000; 84 period=strtol(period_str, NULL,10)*1000;
43 85
44 channel.open(channel_name, BLC_CHANNEL_READ); 86 channel.open(channel_name, BLC_CHANNEL_READ);
45 blc_loop_try_add_waiting_semaphore(channel.sem_new_data); 87 blc_loop_try_add_waiting_semaphore(channel.sem_new_data);
46 blc_loop_try_add_posting_semaphore(channel.sem_ack_data); 88 blc_loop_try_add_posting_semaphore(channel.sem_ack_data);
47 89
  90 + blc_terminal_get_size(&width_max, &height_max);
  91 + blc_terminal_set_resize_callback(resize_cb, NULL);
  92 +
  93 + history.allocate(width_max);
  94 + BLC_PTHREAD_CHECK(pthread_mutex_init(&resize_mutex, NULL), "");
  95 + BLC_PTHREAD_CHECK(pthread_create(&thread, NULL, record_thread, NULL), "Creating thread");
  96 +
48 BLC_COMMAND_LOOP(period){ 97 BLC_COMMAND_LOOP(period){
49 - //if (blc_loop_iteration!=0);  
50 - blc_eprint_cursor_up(8);  
51 - fprint_spikes_uchars(&channel, stderr, channel_name, 16);  
52 - blc_eprint_cursor_up(8);  
53 -  
54 - 98 + if (height) blc_eprint_cursor_up(height);
  99 + pthread_mutex_lock(&resize_mutex);
  100 + height=fprint_spikes_uchars(&history, stderr, channel_name);
  101 + pthread_mutex_unlock(&resize_mutex);
  102 + drawn=1;
55 } 103 }
56 return EXIT_SUCCESS; 104 return EXIT_SUCCESS;
57 } 105 }
1 -# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)  
2 -# Author: Arnaud Blanchard  
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 - 1 +# Set the minimum version of cmake required to build this project
12 cmake_minimum_required(VERSION 2.6) 2 cmake_minimum_required(VERSION 2.6)
13 -project(serial)  
14 3
15 -subdirs(serial_servos)  
16 -subdirs(o_serial_servos) 4 +# Set the name of the project as the directory basename
  5 +project(i_arduino)
  6 +
  7 +find_package(blc_channel)
  8 +find_package(blc_program)
  9 +
  10 +add_definitions(${BL_DEFINITIONS})
  11 +include_directories(${BL_INCLUDE_DIRS})
  12 +add_executable(i_arduino src/main.cpp)
  13 +target_link_libraries(i_arduino ${BL_LIBRARIES})
  14 +
  15 +
  16 +
  17 +
17 18
18 19
19 20
  1 +
  2 +#define END_LOOP 3000
  3 +
  4 +
  5 +
  6 +
  7 +int main(int argc, char **argv){
  8 + int i, sum=0;
  9 +
  10 + for (i=0; i<END_LOOP; i++){
  11 + sum+=2;
  12 + }
  13 +
  14 + i=0;
  15 + sum=0;
  16 +
  17 + while ( i<END_LOOP){
  18 + sum+=2;
  19 + i++;
  20 + }
  21 +
  22 +
  23 + return 0;
  24 +}
  1 +
  2 +#define END_LOOP 3000
  3 +
  4 +
  5 +
  6 +
  7 +int main(int argc, char **argv){
  8 + int i, sum=0;
  9 +
  10 + for (i=0; i<END_LOOP; i++){
  11 + sum+=2;
  12 + }
  13 +
  14 + i=0;
  15 + sum=0;
  16 +
  17 + while ( i<END_LOOP){
  18 + sum+=2;
  19 + i++;
  20 + }
  21 +
  22 +
  23 + return 0;
  24 +}