Ragazzi scusate il ritardo, sono in fase di esame all'università e sto studiando molto. :~
Comunque, alla fine ho optato per usare un programma (scritto in python, mi andava bene perchè su ubuntu è presente di default, se ne può scrivere anche una versione in java comunque) che simula la pressione di un tasto della tastiera quando riceve via seriale un particolare comando dall'arduino.
Il programma funziona così: quando viene premuto un tasto, arduino invia un codice (un numero) via seriale, ed invia lo stesso numero quando viene rilasciato il tasto.
L'ho usato come esercizio sugli array quindi non uccidetemi se ce ne sono 3 di inutili
#include <Psx.h> // Includes the Psx Library
#undef round //remove Whprogram.h problem
#define dataPin 12
#define cmndPin 11
#define attPin 10
#define clockPin 13
Psx Psx; // Initializes the library
unsigned int data = 0; // data stores the controller response
unsigned int ControllerButtons[] = {psxLeft, psxDown, psxRight, psxUp, psxStrt, psxSlct, psxSqu, psxX, psxO, psxTri, psxR1, psxR2, psxL1, psxL2};
unsigned int flags[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned int buttons[14][2];
int index;
void setup()
{
Psx.setupPins(dataPin, cmndPin, attPin, clockPin, 10); // Defines what each pin is used
// (Data Pin #, Cmnd Pin #, Att Pin #, Clk Pin #, Delay)
Serial.begin(57600); // Delay measures how long the clock remains at each state,
// measured in microseconds.
for (int i = 0; i < 14; i++)
{
buttons[i][0] = ControllerButtons[i];
buttons[i][1] = flags[i];
}
}
void loop()
{
data = Psx.read(); // Psx.read() initiates the PSX controller and returns
// the button data
for (index = 0; index < 14; index++)
{
if ((buttons[index][1] == 0) && (data & buttons[index][0]))
{
Serial.println(buttons[index][0]);
buttons[index][1] = 1;
continue;
}
if ((buttons[index][1] == 1) && !(data & buttons[index][0]))
{
Serial.println(buttons[index][0]);
buttons[index][1] = 0;
continue;
}
}
}
il codice python funziona così:
quando riceve un numero, se non è mai stato inviato, simula la pressione di un tasto, se è già premuto, rilascia il tasto:
import serial
import pyatspi
def pressKey(keycode):
"""Takes an integer keycode. You can find these with xev."""
pyatspi.Registry.generateKeyboardEvent(keycode, None,pyatspi.KEY_PRESS)
def releaseKey(keycode):
pyatspi.Registry.generateKeyboardEvent(keycode, None,pyatspi.KEY_RELEASE)