...
|
...
|
@@ -8,15 +8,15 @@ |
|
|
enum{NORMAL_KEY=0, QUIT_KEY, NEUTRAL_KEY, INDEX_KEY, ARROW_CHANGE_INDEX, WRONG_KEY, DECREMENT_KEY, INCREMENT_KEY, FAST_DECREMENT_KEY, FAST_INCREMENT_KEY};
|
|
|
enum { LEFT_ARROW='D', RIGHT_ARROW='C', UP_ARROW='A', DOWN_ARROW='B'};
|
|
|
|
|
|
blc_channel channel;
|
|
|
blc_mem table;
|
|
|
char *key_list;
|
|
|
char const *display;
|
|
|
int keys_nb;
|
|
|
uchar min, max;
|
|
|
uchar quitting_key, neutral_key;
|
|
|
float neutral_value, max_value, min_value, float_step_size=0.004;
|
|
|
uchar uchar_step_size=1;
|
|
|
static blc_channel channel;
|
|
|
static blc_mem table;
|
|
|
static char *key_list;
|
|
|
static char const *display;
|
|
|
static int keys_nb;
|
|
|
static uchar min, max;
|
|
|
static uchar quitting_key=0, neutral_key;
|
|
|
static float neutral_value, max_value, min_value, float_step_size=0.004;
|
|
|
static uchar uchar_step_size=1;
|
|
|
|
|
|
//quitting key return -1, neutral return -2;
|
|
|
static int update_index(int *index){
|
...
|
...
|
@@ -37,28 +37,28 @@ static int update_index(int *index){ |
|
|
} if (ret==2){
|
|
|
switch (answer[1]){
|
|
|
default:fprintf(stderr, "\nImpossible key of '%ld' bytes. Byte 0 '%c','%d', byte 1, '%c','%d'\n", ret, answer[0], answer[0], answer[1], answer[1]);
|
|
|
break;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
else if (ret==3){
|
|
|
if ((answer[0]==27 && answer[1]=='[') || (answer[0]==239 && answer[1]==156)) {
|
|
|
switch (answer[2]){
|
|
|
case LEFT_ARROW: case 130: *index=MAX(0, *index-1);
|
|
|
return ARROW_CHANGE_INDEX;
|
|
|
break;
|
|
|
return ARROW_CHANGE_INDEX;
|
|
|
break;
|
|
|
case RIGHT_ARROW: case 131: *index=MIN(keys_nb-1, *index+1);
|
|
|
return ARROW_CHANGE_INDEX;
|
|
|
break;
|
|
|
return ARROW_CHANGE_INDEX;
|
|
|
break;
|
|
|
case UP_ARROW:case 128: return INCREMENT_KEY;
|
|
|
break;
|
|
|
break;
|
|
|
case DOWN_ARROW:case 129: return DECREMENT_KEY;
|
|
|
break;
|
|
|
/* case PAGE_UP:case 172: return FAST_INCREMENT_KEY;
|
|
|
break;
|
|
|
case PAGE_DOWN:case 173: return FAST_DECREMENT_KEY;
|
|
|
break;*/
|
|
|
break;
|
|
|
/* case PAGE_UP:case 172: return FAST_INCREMENT_KEY;
|
|
|
break;
|
|
|
case PAGE_DOWN:case 173: return FAST_DECREMENT_KEY;
|
|
|
break;*/
|
|
|
default: fprintf(stderr, "This key does not have effect\n");
|
|
|
break;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
printf("Answer 0 '%c','%d', answer 1, '%c','%d', 2: '%c','%d'\n" , answer[0], answer[0] , answer[1], answer[1], answer[2], answer[2]);
|
...
|
...
|
@@ -105,18 +105,18 @@ static void loop_toggle_uchar(){ |
|
|
ret=update_index(&index);
|
|
|
switch (ret){
|
|
|
case INCREMENT_KEY:
|
|
|
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(max_value);
|
|
|
break;
|
|
|
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(max_value);
|
|
|
break;
|
|
|
case DECREMENT_KEY: channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(min_value);
|
|
|
break;
|
|
|
break;
|
|
|
case NEUTRAL_KEY:
|
|
|
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
|
|
|
break;
|
|
|
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
|
|
|
break;
|
|
|
case INDEX_KEY:
|
|
|
if (channel.uchars[index] > BLC_NORMED_FLOAT_TO_UCHAR(neutral_value)) channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(min_value);
|
|
|
else channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(max_value);
|
|
|
if (channel.uchars[index] > BLC_NORMED_FLOAT_TO_UCHAR(neutral_value)) channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(min_value);
|
|
|
else channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(max_value);
|
|
|
case ARROW_CHANGE_INDEX:case QUIT_KEY:
|
|
|
break;
|
|
|
break;
|
|
|
default:color_eprintf(BLC_YELLOW, "Unknownd ret '%d'", ret);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -139,22 +139,22 @@ static void loop_uchar(){ |
|
|
ret=update_index(&index);
|
|
|
switch (ret){
|
|
|
case INCREMENT_KEY:
|
|
|
channel.uchars[index]=MIN(channel.uchars[index]+uchar_step_size, BLC_NORMED_FLOAT_TO_UCHAR(max_value));
|
|
|
break;
|
|
|
channel.uchars[index]=MIN(channel.uchars[index]+uchar_step_size, BLC_NORMED_FLOAT_TO_UCHAR(max_value));
|
|
|
break;
|
|
|
case DECREMENT_KEY: channel.uchars[index]=MAX(channel.uchars[index]-uchar_step_size, BLC_NORMED_FLOAT_TO_UCHAR(min_value));
|
|
|
break;
|
|
|
/* case FAST_INCREMENT_KEY:
|
|
|
channel.uchars[index]=MIN(channel.uchars[index]+10*uchar_step_size, UINT8_MAX);
|
|
|
previous_index=index;
|
|
|
break;
|
|
|
case FAST_DECREMENT_KEY:
|
|
|
channel.uchars[index]=MAX(channel.uchars[index]-10*uchar_step_size, 0);
|
|
|
break;*/
|
|
|
break;
|
|
|
/* case FAST_INCREMENT_KEY:
|
|
|
channel.uchars[index]=MIN(channel.uchars[index]+10*uchar_step_size, UINT8_MAX);
|
|
|
previous_index=index;
|
|
|
break;
|
|
|
case FAST_DECREMENT_KEY:
|
|
|
channel.uchars[index]=MAX(channel.uchars[index]-10*uchar_step_size, 0);
|
|
|
break;*/
|
|
|
case NEUTRAL_KEY:
|
|
|
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
|
|
|
break;
|
|
|
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
|
|
|
break;
|
|
|
case INDEX_KEY:case QUIT_KEY:case ARROW_CHANGE_INDEX:
|
|
|
break;
|
|
|
break;
|
|
|
default:EXIT_ON_ERROR("Unknownd ret '%d'", ret);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -172,18 +172,18 @@ static void loop_toggle_float(){ |
|
|
ret=update_index(&index);
|
|
|
switch (ret){
|
|
|
case INCREMENT_KEY:
|
|
|
channel.floats[index]=max_value;
|
|
|
break;
|
|
|
channel.floats[index]=max_value;
|
|
|
break;
|
|
|
case DECREMENT_KEY: channel.floats[index]=min_value;
|
|
|
break;
|
|
|
break;
|
|
|
case NEUTRAL_KEY:
|
|
|
channel.floats[index]=neutral_value;
|
|
|
break;
|
|
|
channel.floats[index]=neutral_value;
|
|
|
break;
|
|
|
case INDEX_KEY:
|
|
|
if (channel.floats[index] > neutral_value) channel.floats[index]=min_value;
|
|
|
else channel.floats[index]=max_value;
|
|
|
if (channel.floats[index] > neutral_value) channel.floats[index]=min_value;
|
|
|
else channel.floats[index]=max_value;
|
|
|
case ARROW_CHANGE_INDEX:case QUIT_KEY:
|
|
|
break;
|
|
|
break;
|
|
|
default:color_eprintf(BLC_YELLOW, "Unknownd ret '%d'", ret);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -201,17 +201,17 @@ static void loop_float(){ |
|
|
ret=update_index(&index);
|
|
|
switch (ret){
|
|
|
case INCREMENT_KEY: channel.floats[index]=MIN(channel.floats[index]+float_step_size, max_value);
|
|
|
break;
|
|
|
break;
|
|
|
case DECREMENT_KEY: channel.floats[index]=MAX(channel.floats[index]-float_step_size, min_value);
|
|
|
break;
|
|
|
/* case FAST_INCREMENT_KEY: channel.floats[index]+=float_step_size*10;
|
|
|
break;
|
|
|
case FAST_DECREMENT_KEY:channel.floats[index]-=float_step_size*10;
|
|
|
break;*/
|
|
|
break;
|
|
|
/* case FAST_INCREMENT_KEY: channel.floats[index]+=float_step_size*10;
|
|
|
break;
|
|
|
case FAST_DECREMENT_KEY:channel.floats[index]-=float_step_size*10;
|
|
|
break;*/
|
|
|
case NEUTRAL_KEY:channel.floats[index]=neutral_value;
|
|
|
break;
|
|
|
break;
|
|
|
case INDEX_KEY: case ARROW_CHANGE_INDEX:
|
|
|
previous_index=index;
|
|
|
previous_index=index;
|
|
|
case QUIT_KEY:break;
|
|
|
default:EXIT_ON_ERROR("Unknownd ret '%d'", ret);
|
|
|
}
|
...
|
...
|
@@ -233,15 +233,15 @@ int main(int argc, char** argv){ |
|
|
|
|
|
asprintf(&default_output, "/%s%d", basename(argv[0]), getpid()); //This will not be free but it is only allocate once
|
|
|
blc_program_set_description("Get keyboard inputs");
|
|
|
blc_program_add_option(&display, 'd', "display", NULL, "Display a text graph (UIN8 only)", NULL);
|
|
|
blc_program_add_option(&display, 'd', "display", NULL, "Display a text graph", NULL);
|
|
|
blc_program_add_option(&filename, 'f', "file", "filename", "Initialize the values with a tsv file", NULL);
|
|
|
blc_program_add_option((char const**)&key_list, 'k', "key_list", "string", "Define all the keys that can be stroke", NULL);
|
|
|
blc_program_add_option(&min_str, 'm', "min", "real", "Define the normed minimum value", "0.0");
|
|
|
blc_program_add_option(&str_neutral_key, 'n', "neutral_key", "string", "Define the neutral key", "escape");
|
|
|
blc_program_add_option(&channel_name, 'o', "output", "blc_channel", "Define where the result will be put", default_output);
|
|
|
blc_program_add_option(&str_quitting_key, 'q', "quitting_key", "string", "Define the key used to quit", "q");
|
|
|
blc_program_add_option(&str_quitting_key, 'q', "quitting_key", "string", "Define the key used to quit", "return");
|
|
|
blc_program_add_option(&key_nb_str, 's', "size", "integer", "Size of key vector", NULL);
|
|
|
blc_program_add_option(&type_str, 't', "type", "UIN8|FL32", "Define the type of the result", NULL);
|
|
|
blc_program_add_option(&type_str, 't', "type", "UIN8|FL32", "Define the type of the result (default 'UIN8')", NULL);
|
|
|
blc_program_add_option(&file_select_name, 'F', "select", "filename", "File among which values will be selected", NULL);
|
|
|
blc_program_add_option(&max_str, 'M', "max", "real", "Define the normed max value", "1.0");
|
|
|
blc_program_add_option(&str_neutral_value, 'N', "neutral_value", "real", "Define the normed neutral value", "0.5");
|
...
|
...
|
@@ -251,55 +251,61 @@ int main(int argc, char** argv){ |
|
|
blc_program_init(&argc, &argv, blc_quit);
|
|
|
blc_command_forward_blc_channels();
|
|
|
|
|
|
//This get back normal keyboard behavior after quitting
|
|
|
//This get back normal keyboard behavior (blocking mode) after quitting
|
|
|
atexit(blc_set_back_stdin_mode);
|
|
|
|
|
|
if (strlen(str_quitting_key)!=1) EXIT_ON_ERROR("You can only have one quitting key. You propose %s", str_quitting_key);
|
|
|
|
|
|
if (strcmp(str_neutral_key, "escape")==0) neutral_key=27; //Escape
|
|
|
else if (strlen(str_neutral_key)!=1) EXIT_ON_ERROR("You can only have one neutral key. You propose %s", str_neutral_key);
|
|
|
else if (strlen(str_neutral_key)!=1) EXIT_ON_ERROR("You can only have one neutral key. You propose '%s'", str_neutral_key);
|
|
|
else neutral_key=str_neutral_key[0];
|
|
|
|
|
|
if (strcmp(str_quitting_key, "return")==0) quitting_key=10; //Escape
|
|
|
else if (strlen(str_quitting_key)!=1) EXIT_ON_ERROR("You can only have one quitting key. You propose '%s'", str_quitting_key);
|
|
|
else quitting_key=str_quitting_key[0];
|
|
|
|
|
|
neutral_value=strtof(str_neutral_value, NULL);
|
|
|
max_value=strtof(max_str, NULL);
|
|
|
min_value=strtof(min_str, NULL);
|
|
|
|
|
|
quitting_key=str_quitting_key[0];
|
|
|
|
|
|
if (key_nb_str) keys_nb=strtod(key_nb_str, NULL);
|
|
|
else if (key_list) keys_nb=strlen(key_list);
|
|
|
if (key_nb_str && key_list) EXIT_ON_ERROR("You cannot precise size (-s) '%s' and key_list (-k) '%s' at the same time", key_nb_str, key_list);
|
|
|
else if (key_nb_str) keys_nb=strtod(key_nb_str, NULL);
|
|
|
else if (key_list) keys_nb=strlen(key_list);
|
|
|
else keys_nb=-1;
|
|
|
|
|
|
if (type_str) type=STRING_TO_UINT32(type_str);
|
|
|
|
|
|
if ( blc_channel_get_info_with_name(&channel_info, channel_name)==-1){
|
|
|
if (key_list==NULL) {
|
|
|
key_list=(char *)"0123456789abcdef";
|
|
|
keys_nb=strlen(key_list);
|
|
|
if (type_str==NULL) type='UIN8'; //Default
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
// if the channel exist, we use it as porpeties
|
|
|
if (blc_channel_get_info_with_name(&channel_info, channel_name)!=-1){
|
|
|
if (type_str==NULL) type=channel_info.type;
|
|
|
else if (STRING_TO_UINT32(type_str)!=channel_info.type) EXIT_ON_CHANNEL_ERROR(&channel_info, "The requested type '%s' differ from the exisiting channel", type_str);
|
|
|
if (keys_nb==-1) keys_nb=channel_info.total_length;
|
|
|
else if (keys_nb!=channel_info.total_length) EXIT_ON_CHANNEL_ERROR(&channel_info, "number of keys(%d) differ from channel length (%d)", keys_nb, channel.total_length);
|
|
|
}
|
|
|
|
|
|
if (key_list==NULL){
|
|
|
key_list=MANY_ALLOCATIONS(keys_nb, char);
|
|
|
FOR(i, keys_nb){
|
|
|
if (i<10) key_list[i]=48+i; //01234567890
|
|
|
else if (i<36) key_list[i]=97+i-10; //abc...xyz
|
|
|
else if (i<62) key_list[i]=65+i-36; //ABC...XYZ
|
|
|
else if (i==62) key_list[i]='[';
|
|
|
else if (i==63) key_list[i]=']';
|
|
|
else EXIT_ON_ERROR("Too many keys. You have '%d' max is 64", keys_nb);
|
|
|
if (key_list==NULL) {
|
|
|
if (keys_nb==-1){
|
|
|
key_list=(char *)"0123456789abcdef";
|
|
|
keys_nb=strlen(key_list);
|
|
|
}
|
|
|
else {
|
|
|
key_list=MANY_ALLOCATIONS(keys_nb, char);
|
|
|
FOR(i, keys_nb){
|
|
|
if (i<10) key_list[i]=48+i; //01234567890
|
|
|
else if (i<36) key_list[i]=97+i-10; //abc...xyz
|
|
|
else if (i<62) key_list[i]=65+i-36; //ABC...XYZ
|
|
|
else if (i==62) key_list[i]='[';
|
|
|
else if (i==63) key_list[i]=']';
|
|
|
else EXIT_ON_ERROR("Too many keys. You have '%d' max is 64", keys_nb);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (memchr(key_list, quitting_key, keys_nb)) EXIT_ON_ERROR("The quitting key '%c' is in your key list %*s, you need to select an other one with --quitting_key=...", quitting_key, keys_nb, quitting_key);
|
|
|
if (memchr(key_list, neutral_key, keys_nb)) EXIT_ON_ERROR("The neutral key '%c' is in your key list %*s, you need to select an other one with --neutral_key=...", quitting_key, keys_nb, neutral_key);
|
|
|
if (type_str) type=STRING_TO_UINT32(type_str);
|
|
|
else type='UIN8'; //default type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (memchr(key_list, quitting_key, keys_nb)) EXIT_ON_ERROR("The quitting key '%c' is in your key list %.*s, you need to select an other one with --quitting_key=...", quitting_key, keys_nb, key_list);
|
|
|
if (memchr(key_list, neutral_key, keys_nb)) EXIT_ON_ERROR("The neutral key '%c' is in your key list %.*s, you need to select an other one with --neutral_key=...", neutral_key, keys_nb, key_list);
|
|
|
|
|
|
channel.create_or_open(channel_name, BLC_CHANNEL_WRITE, type, 'NDEF', 1, keys_nb);
|
|
|
|
...
|
...
|
@@ -312,13 +318,13 @@ int main(int argc, char** argv){ |
|
|
else {
|
|
|
switch (type){
|
|
|
case 'UIN8':
|
|
|
FOR(i, keys_nb) channel.uchars[i]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
|
|
|
break;
|
|
|
FOR(i, keys_nb) channel.uchars[i]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
|
|
|
break;
|
|
|
case 'FL32':
|
|
|
FOR(i, keys_nb) channel.floats[i]=neutral_value;
|
|
|
break;
|
|
|
FOR(i, keys_nb) channel.floats[i]=neutral_value;
|
|
|
break;
|
|
|
default:EXIT_ON_ARRAY_ERROR(&channel, "Type not managed");
|
|
|
break;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -332,7 +338,7 @@ int main(int argc, char** argv){ |
|
|
}
|
|
|
blc_set_stdin_non_blocking_mode();
|
|
|
|
|
|
fprintf(stderr, "Waiting for one key in '%s'. Quitting with '%c'\n", key_list, quitting_key);
|
|
|
fprintf(stderr, "Waiting for one key in '%.*s'. Quitting with '%s'\n", keys_nb, key_list, str_quitting_key);
|
|
|
|
|
|
//We pre calculate the answers
|
|
|
max=min=key_list[0];
|
...
|
...
|
@@ -352,18 +358,18 @@ int main(int argc, char** argv){ |
|
|
channel.publish();
|
|
|
switch (channel.type){
|
|
|
case 'UIN8':
|
|
|
if (step_size_str) uchar_step_size=strtod(step_size_str, NULL);
|
|
|
if (toggle_mode) loop_toggle_uchar();
|
|
|
else loop_uchar();
|
|
|
break;
|
|
|
if (step_size_str) uchar_step_size=strtod(step_size_str, NULL);
|
|
|
if (toggle_mode) loop_toggle_uchar();
|
|
|
else loop_uchar();
|
|
|
break;
|
|
|
case 'FL32':
|
|
|
if (step_size_str) float_step_size=strtof(step_size_str, NULL);
|
|
|
if (toggle_mode) loop_toggle_float();
|
|
|
else loop_float();
|
|
|
break;
|
|
|
if (step_size_str) float_step_size=strtof(step_size_str, NULL);
|
|
|
if (toggle_mode) loop_toggle_float();
|
|
|
else loop_float();
|
|
|
break;
|
|
|
default:
|
|
|
EXIT_ON_ARRAY_ERROR(&channel, "The type is not managed.");
|
|
|
break;
|
|
|
EXIT_ON_ARRAY_ERROR(&channel, "The type is not managed.");
|
|
|
break;
|
|
|
}
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|
...
|
...
|
|