Master SIAME | Université Toulouse 3

Internet of things and System on Chip

Master SIAME | Université Toulouse 3

Internet of things and System on Chip

User Tools


Commande à distance

Notre quadcopter ne possède pas encore de système de communication ou de commande à distance. Pour l'instant, la mise en oeuvre d'un tel système a été retardé par le choix d'une technologie (wifi, BlueTooth, etc) et la complexité de mise en oeuvre associée (en plus, le kernel installé sur les BeagleBone ne contient pas le driver wifi bien qu'on puisse le compiler sans problème).

Cependant, l'un d'entre vous m'a soumis l'idée d'utiliser un clavier sans fil RF. Il reste alors seulement à connecter le Dongle sur le port USB du BeagleBone et on se retrouve avec une télécommande peu chère (15 euros le clavier) avec une portée de 10m. Il reste encore à coder la captation des touches du clavier (qui ne devrait pas être disponible puisque le programme de pilotage doit se lancer sans console).

Ci-dessous un exemple de code permettant de lire directement les touches du clavier (Read-device-file-for-linux-keyboard-and-). Il faut bien sûr sélectionner le fichier d'entrée /dev/input/eventX. On peut aussi passer par /dev/input/by-path qui fournit des chemins plus explicites.

/*Modified version of this question: http://stackoverflow.com/questions/11519759/how-to-read-low-level-mouse-click-position-in-linux
Reads the keyboard device file. You probably will have to change the name/location of the file depending on your hardware setup.
I only tested this on one machine (IBM Thinkpad 2366 running Linux Mint).
*/
 
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<unistd.h>
 
#include<fcntl.h>
#include<linux/input.h>
// Keyboard file. Probably a different for you.
#define KEYBOARDFILE "/dev/input/event3"
char convertCodeToKey(int k){
	// returns '#' for modifier keys/backspace/capslock/enter
	if(k==1 || k==29 || k==28 || k==42 || k==56 || k==100 || k==97 || k==54 || k==14 || k==15 || k==58)
		return '#';
	if(k==2)
		return '1';
	if(k==3)
		return '2';
	if(k==4)
		return '3';
	if(k==5)
		return '4';
	if(k==6)
		return '5';
	if(k==7)
		return '6';
	if(k==8)
		return '7';
	if(k==9)
		return '8';
	if(k==10)
		return '9';
	if(k==11)
		return '0';
	if(k==12)
		return '-';
	if(k==13)
		return '=';
	//14 and 15 are modifier keys
	if(k==16)
		return 'q';
	if(k==17)
		return 'w';
	if(k==18)
		return 'e';
	if(k==19)
		return 'r';
	if(k==20)
		return 't';
	if(k==21)
		return 'y';
	if(k==22)
		return 'u';
	if(k==23)
		return 'i';
	if(k==24)
		return 'o';
	if(k==25)
		return 'p';
	if(k==30)
		return 'a';
	if(k==31)
		return 's';
	if(k==32)
		return 'd';
	if(k==33)
		return 'f';
	if(k==34)
		return 'g';
	if(k==35)
		return 'h';
	if(k==36)
		return 'j';
	if(k==37)
		return 'k';
	if(k==38)
		return 'l';
	if(k==39)
		return ';';
	if(k==40)
		return '\'';
	//41 and 42 are modifier keys
	if(k==44)
		return 'z';
	if(k==45)
		return 'x';
	if(k==46)
		return 'c';
	if(k==47)
		return 'v';
	if(k==48)
		return 'b';
	if(k==49)
		return 'n';
	if(k==50)
		return 'm';
	if(k==51)
		return ',';
	if(k==52)
		return '.';
	if(k==53)
		return '/';
	if(k==57)
		return '_';//return underscore for spacebar
	else
		return ' ';
}
 
main(){
	int fd;
	struct input_event ie;
	// To read keyboard
	if((fd = open(KEYBOARDFILE, O_RDONLY))== -1){
		perror("opening device");
		exit(EXIT_FAILURE);
	}
	while(read(fd, &ie, sizeof(struct input_event))) {
		if(ie.value==1)
			printf("%c \t %d \n", convertCodeToKey(ie.code), ie.code);
		//printf("c %d\tv %d\n", ie.code, ie.value);
	}
	return 0;
}