Ciao a tutti,
per lavoro mi hanno affidato un progetto, del quale però non riesco a venire a capo.
Ho bisogno di collegare una seconda tastiera al pc, alla quale devo rimappare i tasti. Ad esempio il tasto "A" deve diventare "C".
Cercando online ho trovato dei progetti simili a ciò che devo realizzare ma implicano l'uso della tastiera PS/2.
Ho acquistato quindi un Arduino Leonardo e una USB Host Shield ed ho caricato il codice in allegato.
// USB host keyboard from USB Host Shield Library. Install using Library Manager
#include <hidboot.h>
// USB device keyboard library included with Arduino IDE 1.8.5
#include "Keyboard.h"
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
class KbdRptParser : public KeyboardReportParser
{
protected:
void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};
void KbdRptParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
// Run parent class method so keyboard LEDs are updated.
KeyboardReportParser::Parse(hid, is_rpt_id, len, buf);
Serial.print("KbdRptParser::Parse");
// Show USB HID keyboard report
for (uint8_t i = 0; i < len ; i++) {
Serial.print(' '); Serial.print(buf[i], HEX);
}
Serial.println();
// On error - return
if (buf[2] == 1)
return;
if (len == 8) {
//Keyboard.sendReport((KeyReport *)buf);
HID().SendReport(2, buf, sizeof(KeyReport));
}
}
USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
KbdRptParser Prs;
void setup()
{
Serial.begin( 115200 );
uint8_t attempts = 30;
while (!Serial && attempts--) {
delay(100); // Wait for serial port to connect for up to 3 seconds
}
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("USB host shield did not start.");
delay( 200 );
HidKeyboard.SetReportParser(0, &Prs);
Keyboard.begin();
}
void loop()
{
Usb.Task();
}
La tastiera collegata all'arduino viene vista correttamente ma non trovo il modo per poter rimappare i tasti. Ho provato con alcuni software ma Windows purtroppo riceve i comandi in anticipo e quindi i software per il remapping non funzionano correttamente.
Spero di aver espresso nel migliore dei modi ciò che devo fare.
Grazie mille anticipatamente