AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
input/keyboard/demo_keyboard.c

Scrute le clavier et affiche les touches sur la liaison série.

#include <ctype.h>
#include <avrio/tc.h>
#include <avrio/keyb.h>
/* constants ================================================================ */
#define BAUDRATE 115200
#define PORT "tty0"
/* main ===================================================================== */
int
main (void) {
// Configuration du port série par défaut (8N1, sans RTS/CTS)
xSerialIos settings = SERIAL_SETTINGS (BAUDRATE);
// Ouverture du port série en sortie
FILE * serial_port = xFileOpen (PORT, O_WRONLY, &settings);
stdout = serial_port; // le port série est la sortie standard
puts ("Press key...");
/* Initialisation Clavier */
for (;;) {
// Test si une touche est appuyée
if (usKeybHit () != 0) {
char c;
// lecture de la touche
c = cKeybGetChar ();
if (isprint (c)) {
// Si la touche est affichable, on l'affiche
putchar (c);
}
else {
// sinon, on affiche son code hexa
printf ("0x%02X", c);
}
}
}
return 0;
}
/* ========================================================================== */