forked from mirrors/qmk_userspace
Move USB Host Shield and Arduino core to lib/
(#13973)
This commit is contained in:
parent
cf5e40c251
commit
b16091659c
182 changed files with 6 additions and 6 deletions
|
@ -0,0 +1,129 @@
|
|||
#include <hidboot.h>
|
||||
#include <usbhub.h>
|
||||
|
||||
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
class KbdRptParser : public KeyboardReportParser
|
||||
{
|
||||
void PrintKey(uint8_t mod, uint8_t key);
|
||||
|
||||
protected:
|
||||
void OnControlKeysChanged(uint8_t before, uint8_t after);
|
||||
|
||||
void OnKeyDown (uint8_t mod, uint8_t key);
|
||||
void OnKeyUp (uint8_t mod, uint8_t key);
|
||||
void OnKeyPressed(uint8_t key);
|
||||
};
|
||||
|
||||
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
|
||||
{
|
||||
MODIFIERKEYS mod;
|
||||
*((uint8_t*)&mod) = m;
|
||||
Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
|
||||
Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
|
||||
Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
|
||||
Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");
|
||||
|
||||
Serial.print(" >");
|
||||
PrintHex<uint8_t>(key, 0x80);
|
||||
Serial.print("< ");
|
||||
|
||||
Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
|
||||
Serial.print((mod.bmRightShift == 1) ? "S" : " ");
|
||||
Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
|
||||
Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
|
||||
};
|
||||
|
||||
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
|
||||
{
|
||||
Serial.print("DN ");
|
||||
PrintKey(mod, key);
|
||||
uint8_t c = OemToAscii(mod, key);
|
||||
|
||||
if (c)
|
||||
OnKeyPressed(c);
|
||||
}
|
||||
|
||||
void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
|
||||
|
||||
MODIFIERKEYS beforeMod;
|
||||
*((uint8_t*)&beforeMod) = before;
|
||||
|
||||
MODIFIERKEYS afterMod;
|
||||
*((uint8_t*)&afterMod) = after;
|
||||
|
||||
if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
|
||||
Serial.println("LeftCtrl changed");
|
||||
}
|
||||
if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
|
||||
Serial.println("LeftShift changed");
|
||||
}
|
||||
if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
|
||||
Serial.println("LeftAlt changed");
|
||||
}
|
||||
if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
|
||||
Serial.println("LeftGUI changed");
|
||||
}
|
||||
|
||||
if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
|
||||
Serial.println("RightCtrl changed");
|
||||
}
|
||||
if (beforeMod.bmRightShift != afterMod.bmRightShift) {
|
||||
Serial.println("RightShift changed");
|
||||
}
|
||||
if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
|
||||
Serial.println("RightAlt changed");
|
||||
}
|
||||
if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
|
||||
Serial.println("RightGUI changed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
|
||||
{
|
||||
Serial.print("UP ");
|
||||
PrintKey(mod, key);
|
||||
}
|
||||
|
||||
void KbdRptParser::OnKeyPressed(uint8_t key)
|
||||
{
|
||||
Serial.print("ASCII: ");
|
||||
Serial.println((char)key);
|
||||
};
|
||||
|
||||
USB Usb;
|
||||
//USBHub Hub(&Usb);
|
||||
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
|
||||
|
||||
uint32_t next_time;
|
||||
|
||||
KbdRptParser Prs;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin( 115200 );
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
delay( 200 );
|
||||
|
||||
next_time = millis() + 5000;
|
||||
|
||||
HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
#include <hidboot.h>
|
||||
#include <usbhub.h>
|
||||
|
||||
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
class MouseRptParser : public MouseReportParser
|
||||
{
|
||||
protected:
|
||||
void OnMouseMove(MOUSEINFO *mi);
|
||||
void OnLeftButtonUp(MOUSEINFO *mi);
|
||||
void OnLeftButtonDown(MOUSEINFO *mi);
|
||||
void OnRightButtonUp(MOUSEINFO *mi);
|
||||
void OnRightButtonDown(MOUSEINFO *mi);
|
||||
void OnMiddleButtonUp(MOUSEINFO *mi);
|
||||
void OnMiddleButtonDown(MOUSEINFO *mi);
|
||||
};
|
||||
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
|
||||
{
|
||||
Serial.print("dx=");
|
||||
Serial.print(mi->dX, DEC);
|
||||
Serial.print(" dy=");
|
||||
Serial.println(mi->dY, DEC);
|
||||
};
|
||||
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("L Butt Up");
|
||||
};
|
||||
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("L Butt Dn");
|
||||
};
|
||||
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("R Butt Up");
|
||||
};
|
||||
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("R Butt Dn");
|
||||
};
|
||||
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("M Butt Up");
|
||||
};
|
||||
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("M Butt Dn");
|
||||
};
|
||||
|
||||
class KbdRptParser : public KeyboardReportParser
|
||||
{
|
||||
void PrintKey(uint8_t mod, uint8_t key);
|
||||
|
||||
protected:
|
||||
void OnControlKeysChanged(uint8_t before, uint8_t after);
|
||||
void OnKeyDown (uint8_t mod, uint8_t key);
|
||||
void OnKeyUp (uint8_t mod, uint8_t key);
|
||||
void OnKeyPressed(uint8_t key);
|
||||
};
|
||||
|
||||
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
|
||||
{
|
||||
MODIFIERKEYS mod;
|
||||
*((uint8_t*)&mod) = m;
|
||||
Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
|
||||
Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
|
||||
Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
|
||||
Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");
|
||||
|
||||
Serial.print(" >");
|
||||
PrintHex<uint8_t>(key, 0x80);
|
||||
Serial.print("< ");
|
||||
|
||||
Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
|
||||
Serial.print((mod.bmRightShift == 1) ? "S" : " ");
|
||||
Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
|
||||
Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
|
||||
};
|
||||
|
||||
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
|
||||
{
|
||||
Serial.print("DN ");
|
||||
PrintKey(mod, key);
|
||||
uint8_t c = OemToAscii(mod, key);
|
||||
|
||||
if (c)
|
||||
OnKeyPressed(c);
|
||||
}
|
||||
|
||||
void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
|
||||
|
||||
MODIFIERKEYS beforeMod;
|
||||
*((uint8_t*)&beforeMod) = before;
|
||||
|
||||
MODIFIERKEYS afterMod;
|
||||
*((uint8_t*)&afterMod) = after;
|
||||
|
||||
if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
|
||||
Serial.println("LeftCtrl changed");
|
||||
}
|
||||
if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
|
||||
Serial.println("LeftShift changed");
|
||||
}
|
||||
if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
|
||||
Serial.println("LeftAlt changed");
|
||||
}
|
||||
if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
|
||||
Serial.println("LeftGUI changed");
|
||||
}
|
||||
|
||||
if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
|
||||
Serial.println("RightCtrl changed");
|
||||
}
|
||||
if (beforeMod.bmRightShift != afterMod.bmRightShift) {
|
||||
Serial.println("RightShift changed");
|
||||
}
|
||||
if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
|
||||
Serial.println("RightAlt changed");
|
||||
}
|
||||
if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
|
||||
Serial.println("RightGUI changed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
|
||||
{
|
||||
Serial.print("UP ");
|
||||
PrintKey(mod, key);
|
||||
}
|
||||
|
||||
void KbdRptParser::OnKeyPressed(uint8_t key)
|
||||
{
|
||||
Serial.print("ASCII: ");
|
||||
Serial.println((char)key);
|
||||
};
|
||||
|
||||
USB Usb;
|
||||
USBHub Hub(&Usb);
|
||||
|
||||
HIDBoot < HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE > HidComposite(&Usb);
|
||||
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
|
||||
HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb);
|
||||
|
||||
//uint32_t next_time;
|
||||
|
||||
KbdRptParser KbdPrs;
|
||||
MouseRptParser MousePrs;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin( 115200 );
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
delay( 200 );
|
||||
|
||||
//next_time = millis() + 5000;
|
||||
|
||||
HidComposite.SetReportParser(0, (HIDReportParser*)&KbdPrs);
|
||||
HidComposite.SetReportParser(1, (HIDReportParser*)&MousePrs);
|
||||
HidKeyboard.SetReportParser(0, (HIDReportParser*)&KbdPrs);
|
||||
HidMouse.SetReportParser(0, (HIDReportParser*)&MousePrs);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
#include <hidboot.h>
|
||||
#include <usbhub.h>
|
||||
|
||||
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
class MouseRptParser : public MouseReportParser
|
||||
{
|
||||
protected:
|
||||
void OnMouseMove (MOUSEINFO *mi);
|
||||
void OnLeftButtonUp (MOUSEINFO *mi);
|
||||
void OnLeftButtonDown (MOUSEINFO *mi);
|
||||
void OnRightButtonUp (MOUSEINFO *mi);
|
||||
void OnRightButtonDown (MOUSEINFO *mi);
|
||||
void OnMiddleButtonUp (MOUSEINFO *mi);
|
||||
void OnMiddleButtonDown (MOUSEINFO *mi);
|
||||
};
|
||||
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
|
||||
{
|
||||
Serial.print("dx=");
|
||||
Serial.print(mi->dX, DEC);
|
||||
Serial.print(" dy=");
|
||||
Serial.println(mi->dY, DEC);
|
||||
};
|
||||
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("L Butt Up");
|
||||
};
|
||||
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("L Butt Dn");
|
||||
};
|
||||
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("R Butt Up");
|
||||
};
|
||||
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("R Butt Dn");
|
||||
};
|
||||
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("M Butt Up");
|
||||
};
|
||||
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
|
||||
{
|
||||
Serial.println("M Butt Dn");
|
||||
};
|
||||
|
||||
USB Usb;
|
||||
USBHub Hub(&Usb);
|
||||
HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb);
|
||||
|
||||
uint32_t next_time;
|
||||
|
||||
MouseRptParser Prs;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin( 115200 );
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
delay( 200 );
|
||||
|
||||
next_time = millis() + 5000;
|
||||
|
||||
HidMouse.SetReportParser(0,(HIDReportParser*)&Prs);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#include <hid.h>
|
||||
#include <hiduniversal.h>
|
||||
#include <usbhub.h>
|
||||
|
||||
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
#include "hidjoystickrptparser.h"
|
||||
|
||||
USB Usb;
|
||||
USBHub Hub(&Usb);
|
||||
HIDUniversal Hid(&Usb);
|
||||
JoystickEvents JoyEvents;
|
||||
JoystickReportParser Joy(&JoyEvents);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
delay(200);
|
||||
|
||||
if (!Hid.SetReportParser(0, &Joy))
|
||||
ErrorMessage<uint8_t > (PSTR("SetReportParser"), 1);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
#include "hidjoystickrptparser.h"
|
||||
|
||||
JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
|
||||
joyEvents(evt),
|
||||
oldHat(0xDE),
|
||||
oldButtons(0) {
|
||||
for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++)
|
||||
oldPad[i] = 0xD;
|
||||
}
|
||||
|
||||
void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
|
||||
bool match = true;
|
||||
|
||||
// Checking if there are changes in report since the method was last called
|
||||
for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++)
|
||||
if (buf[i] != oldPad[i]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Calling Game Pad event handler
|
||||
if (!match && joyEvents) {
|
||||
joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
|
||||
|
||||
for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i];
|
||||
}
|
||||
|
||||
uint8_t hat = (buf[5] & 0xF);
|
||||
|
||||
// Calling Hat Switch event handler
|
||||
if (hat != oldHat && joyEvents) {
|
||||
joyEvents->OnHatSwitch(hat);
|
||||
oldHat = hat;
|
||||
}
|
||||
|
||||
uint16_t buttons = (0x0000 | buf[6]);
|
||||
buttons <<= 4;
|
||||
buttons |= (buf[5] >> 4);
|
||||
uint16_t changes = (buttons ^ oldButtons);
|
||||
|
||||
// Calling Button Event Handler for every button changed
|
||||
if (changes) {
|
||||
for (uint8_t i = 0; i < 0x0C; i++) {
|
||||
uint16_t mask = (0x0001 << i);
|
||||
|
||||
if (((mask & changes) > 0) && joyEvents)
|
||||
if ((buttons & mask) > 0)
|
||||
joyEvents->OnButtonDn(i + 1);
|
||||
else
|
||||
joyEvents->OnButtonUp(i + 1);
|
||||
}
|
||||
oldButtons = buttons;
|
||||
}
|
||||
}
|
||||
|
||||
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) {
|
||||
Serial.print("X1: ");
|
||||
PrintHex<uint8_t > (evt->X, 0x80);
|
||||
Serial.print("\tY1: ");
|
||||
PrintHex<uint8_t > (evt->Y, 0x80);
|
||||
Serial.print("\tX2: ");
|
||||
PrintHex<uint8_t > (evt->Z1, 0x80);
|
||||
Serial.print("\tY2: ");
|
||||
PrintHex<uint8_t > (evt->Z2, 0x80);
|
||||
Serial.print("\tRz: ");
|
||||
PrintHex<uint8_t > (evt->Rz, 0x80);
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
void JoystickEvents::OnHatSwitch(uint8_t hat) {
|
||||
Serial.print("Hat Switch: ");
|
||||
PrintHex<uint8_t > (hat, 0x80);
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
void JoystickEvents::OnButtonUp(uint8_t but_id) {
|
||||
Serial.print("Up: ");
|
||||
Serial.println(but_id, DEC);
|
||||
}
|
||||
|
||||
void JoystickEvents::OnButtonDn(uint8_t but_id) {
|
||||
Serial.print("Dn: ");
|
||||
Serial.println(but_id, DEC);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
|
||||
#define __HIDJOYSTICKRPTPARSER_H__
|
||||
|
||||
#include <hid.h>
|
||||
|
||||
struct GamePadEventData {
|
||||
uint8_t X, Y, Z1, Z2, Rz;
|
||||
};
|
||||
|
||||
class JoystickEvents {
|
||||
public:
|
||||
virtual void OnGamePadChanged(const GamePadEventData *evt);
|
||||
virtual void OnHatSwitch(uint8_t hat);
|
||||
virtual void OnButtonUp(uint8_t but_id);
|
||||
virtual void OnButtonDn(uint8_t but_id);
|
||||
};
|
||||
|
||||
#define RPT_GEMEPAD_LEN 5
|
||||
|
||||
class JoystickReportParser : public HIDReportParser {
|
||||
JoystickEvents *joyEvents;
|
||||
|
||||
uint8_t oldPad[RPT_GEMEPAD_LEN];
|
||||
uint8_t oldHat;
|
||||
uint16_t oldButtons;
|
||||
|
||||
public:
|
||||
JoystickReportParser(JoystickEvents *evt);
|
||||
|
||||
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
|
||||
};
|
||||
|
||||
#endif // __HIDJOYSTICKRPTPARSER_H__
|
|
@ -0,0 +1,77 @@
|
|||
#include <hid.h>
|
||||
#include <hiduniversal.h>
|
||||
#include <hidescriptorparser.h>
|
||||
#include <usbhub.h>
|
||||
#include "pgmstrings.h"
|
||||
|
||||
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
class HIDUniversal2 : public HIDUniversal
|
||||
{
|
||||
public:
|
||||
HIDUniversal2(USB *usb) : HIDUniversal(usb) {};
|
||||
|
||||
protected:
|
||||
uint8_t OnInitSuccessful();
|
||||
};
|
||||
|
||||
uint8_t HIDUniversal2::OnInitSuccessful()
|
||||
{
|
||||
uint8_t rcode;
|
||||
|
||||
HexDumper<USBReadParser, uint16_t, uint16_t> Hex;
|
||||
ReportDescParser Rpt;
|
||||
|
||||
if ((rcode = GetReportDescr(0, &Hex)))
|
||||
goto FailGetReportDescr1;
|
||||
|
||||
if ((rcode = GetReportDescr(0, &Rpt)))
|
||||
goto FailGetReportDescr2;
|
||||
|
||||
return 0;
|
||||
|
||||
FailGetReportDescr1:
|
||||
USBTRACE("GetReportDescr1:");
|
||||
goto Fail;
|
||||
|
||||
FailGetReportDescr2:
|
||||
USBTRACE("GetReportDescr2:");
|
||||
goto Fail;
|
||||
|
||||
Fail:
|
||||
Serial.println(rcode, HEX);
|
||||
Release();
|
||||
return rcode;
|
||||
}
|
||||
|
||||
USB Usb;
|
||||
//USBHub Hub(&Usb);
|
||||
HIDUniversal2 Hid(&Usb);
|
||||
UniversalReportParser Uni;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin( 115200 );
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
delay( 200 );
|
||||
|
||||
if (!Hid.SetReportParser(0, &Uni))
|
||||
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#if !defined(__PGMSTRINGS_H__)
|
||||
#define __PGMSTRINGS_H__
|
||||
|
||||
#define LOBYTE(x) ((char*)(&(x)))[0]
|
||||
#define HIBYTE(x) ((char*)(&(x)))[1]
|
||||
#define BUFSIZE 256 //buffer size
|
||||
|
||||
|
||||
/* Print strings in Program Memory */
|
||||
const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t";
|
||||
const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: ";
|
||||
const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t";
|
||||
const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t";
|
||||
const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t";
|
||||
const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t";
|
||||
const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t";
|
||||
const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t";
|
||||
const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t";
|
||||
const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t";
|
||||
const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t";
|
||||
const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t";
|
||||
const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t";
|
||||
const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t";
|
||||
const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t";
|
||||
const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t";
|
||||
const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes";
|
||||
const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:";
|
||||
const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t";
|
||||
const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t";
|
||||
const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t";
|
||||
const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t";
|
||||
const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t";
|
||||
const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t";
|
||||
const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:";
|
||||
const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t";
|
||||
const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t";
|
||||
const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t";
|
||||
const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t";
|
||||
const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t";
|
||||
const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t";
|
||||
const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t";
|
||||
const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:";
|
||||
const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t";
|
||||
const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t";
|
||||
const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t";
|
||||
const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t";
|
||||
const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:";
|
||||
const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t";
|
||||
const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t";
|
||||
const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t";
|
||||
|
||||
#endif // __PGMSTRINGS_H__
|
42
lib/usbhost/USB_Host_Shield_2.0/examples/HID/le3dp/le3dp.ino
Normal file
42
lib/usbhost/USB_Host_Shield_2.0/examples/HID/le3dp/le3dp.ino
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */
|
||||
|
||||
#include <hid.h>
|
||||
#include <hiduniversal.h>
|
||||
#include <usbhub.h>
|
||||
|
||||
#include "le3dp_rptparser.h"
|
||||
|
||||
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
USB Usb;
|
||||
USBHub Hub(&Usb);
|
||||
HIDUniversal Hid(&Usb);
|
||||
JoystickEvents JoyEvents;
|
||||
JoystickReportParser Joy(&JoyEvents);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin( 115200 );
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
delay( 200 );
|
||||
|
||||
if (!Hid.SetReportParser(0, &Joy))
|
||||
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#include "le3dp_rptparser.h"
|
||||
|
||||
JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
|
||||
joyEvents(evt)
|
||||
{}
|
||||
|
||||
void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
|
||||
{
|
||||
bool match = true;
|
||||
|
||||
// Checking if there are changes in report since the method was last called
|
||||
for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) {
|
||||
if( buf[i] != oldPad[i] ) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Calling Game Pad event handler
|
||||
if (!match && joyEvents) {
|
||||
joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
|
||||
|
||||
for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) oldPad[i] = buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
|
||||
{
|
||||
Serial.print("X: ");
|
||||
PrintHex<uint16_t>(evt->x, 0x80);
|
||||
Serial.print(" Y: ");
|
||||
PrintHex<uint16_t>(evt->y, 0x80);
|
||||
Serial.print(" Hat Switch: ");
|
||||
PrintHex<uint8_t>(evt->hat, 0x80);
|
||||
Serial.print(" Twist: ");
|
||||
PrintHex<uint8_t>(evt->twist, 0x80);
|
||||
Serial.print(" Slider: ");
|
||||
PrintHex<uint8_t>(evt->slider, 0x80);
|
||||
Serial.print(" Buttons A: ");
|
||||
PrintHex<uint8_t>(evt->buttons_a, 0x80);
|
||||
Serial.print(" Buttons B: ");
|
||||
PrintHex<uint8_t>(evt->buttons_b, 0x80);
|
||||
Serial.println("");
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
|
||||
#define __HIDJOYSTICKRPTPARSER_H__
|
||||
|
||||
#include <hid.h>
|
||||
|
||||
struct GamePadEventData
|
||||
{
|
||||
union { //axes and hut switch
|
||||
uint32_t axes;
|
||||
struct {
|
||||
uint32_t x : 10;
|
||||
uint32_t y : 10;
|
||||
uint32_t hat : 4;
|
||||
uint32_t twist : 8;
|
||||
};
|
||||
};
|
||||
uint8_t buttons_a;
|
||||
uint8_t slider;
|
||||
uint8_t buttons_b;
|
||||
};
|
||||
|
||||
class JoystickEvents
|
||||
{
|
||||
public:
|
||||
virtual void OnGamePadChanged(const GamePadEventData *evt);
|
||||
};
|
||||
|
||||
#define RPT_GAMEPAD_LEN sizeof(GamePadEventData)/sizeof(uint8_t)
|
||||
|
||||
class JoystickReportParser : public HIDReportParser
|
||||
{
|
||||
JoystickEvents *joyEvents;
|
||||
|
||||
uint8_t oldPad[RPT_GAMEPAD_LEN];
|
||||
|
||||
public:
|
||||
JoystickReportParser(JoystickEvents *evt);
|
||||
|
||||
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
|
||||
};
|
||||
|
||||
#endif // __HIDJOYSTICKRPTPARSER_H__
|
51
lib/usbhost/USB_Host_Shield_2.0/examples/HID/scale/scale.ino
Normal file
51
lib/usbhost/USB_Host_Shield_2.0/examples/HID/scale/scale.ino
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* Digital Scale Output. Written for Stamps.com Model 510 */
|
||||
/* 5lb Digital Scale; any HID scale with Usage page 0x8d should work */
|
||||
|
||||
#include <hid.h>
|
||||
#include <hiduniversal.h>
|
||||
#include <usbhub.h>
|
||||
|
||||
#include "scale_rptparser.h"
|
||||
|
||||
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
||||
#ifdef dobogusinclude
|
||||
#include <spi4teensy3.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
USB Usb;
|
||||
USBHub Hub(&Usb);
|
||||
HIDUniversal Hid(&Usb);
|
||||
Max_LCD LCD(&Usb);
|
||||
ScaleEvents ScaleEvents(&LCD);
|
||||
ScaleReportParser Scale(&ScaleEvents);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin( 115200 );
|
||||
#if !defined(__MIPSEL__)
|
||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||
#endif
|
||||
Serial.println("Start");
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
Serial.println("OSC did not start.");
|
||||
|
||||
// set up the LCD's number of rows and columns:
|
||||
LCD.begin(16, 2);
|
||||
LCD.clear();
|
||||
LCD.home();
|
||||
LCD.setCursor(0,0);
|
||||
LCD.write('R');
|
||||
|
||||
delay( 200 );
|
||||
|
||||
if (!Hid.SetReportParser(0, &Scale))
|
||||
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
}
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
/* Parser for standard HID scale (usage page 0x8d) data input report (ID 3) */
|
||||
#include "scale_rptparser.h"
|
||||
|
||||
const char* UNITS[13] = {
|
||||
"units", // unknown unit
|
||||
"mg", // milligram
|
||||
"g", // gram
|
||||
"kg", // kilogram
|
||||
"cd", // carat
|
||||
"taels", // lian
|
||||
"gr", // grain
|
||||
"dwt", // pennyweight
|
||||
"tonnes", // metric tons
|
||||
"tons", // avoir ton
|
||||
"ozt", // troy ounce
|
||||
"oz", // ounce
|
||||
"lbs" // pound
|
||||
};
|
||||
|
||||
ScaleReportParser::ScaleReportParser(ScaleEvents *evt) :
|
||||
scaleEvents(evt)
|
||||
{}
|
||||
|
||||
void ScaleReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
|
||||
{
|
||||
bool match = true;
|
||||
|
||||
// Checking if there are changes in report since the method was last called
|
||||
for (uint8_t i=0; i<RPT_SCALE_LEN; i++) {
|
||||
if( buf[i] != oldScale[i] ) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Calling Game Pad event handler
|
||||
if (!match && scaleEvents) {
|
||||
scaleEvents->OnScaleChanged((const ScaleEventData*)buf);
|
||||
|
||||
for (uint8_t i=0; i<RPT_SCALE_LEN; i++) oldScale[i] = buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
ScaleEvents::ScaleEvents( Max_LCD* pLCD ) :
|
||||
|
||||
pLcd( pLCD )
|
||||
|
||||
{}
|
||||
|
||||
void ScaleEvents::LcdPrint( const char* str )
|
||||
{
|
||||
|
||||
while( *str ) {
|
||||
|
||||
pLcd->write( *str++ );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ScaleEvents::OnScaleChanged(const ScaleEventData *evt)
|
||||
{
|
||||
|
||||
pLcd->clear();
|
||||
pLcd->home();
|
||||
pLcd->setCursor(0,0);
|
||||
|
||||
if( evt->reportID != 3 ) {
|
||||
|
||||
const char inv_report[]="Invalid report!";
|
||||
|
||||
Serial.println(inv_report);
|
||||
LcdPrint(inv_report);
|
||||
|
||||
return;
|
||||
|
||||
}//if( evt->reportID != 3...
|
||||
|
||||
switch( evt->status ) {
|
||||
|
||||
case REPORT_FAULT:
|
||||
Serial.println(F("Report fault"));
|
||||
break;
|
||||
|
||||
case ZEROED:
|
||||
Serial.println(F("Scale zero set"));
|
||||
break;
|
||||
|
||||
case WEIGHING: {
|
||||
|
||||
const char progress[] = "Weighing...";
|
||||
Serial.println(progress);
|
||||
LcdPrint(progress);
|
||||
break;
|
||||
}
|
||||
|
||||
case WEIGHT_VALID: {
|
||||
|
||||
char buf[10];
|
||||
double weight = evt->weight * pow( 10, evt->exp );
|
||||
|
||||
|
||||
|
||||
Serial.print(F("Weight: "));
|
||||
Serial.print( weight );
|
||||
Serial.print(F(" "));
|
||||
Serial.println( UNITS[ evt->unit ]);
|
||||
|
||||
LcdPrint("Weight: ");
|
||||
dtostrf( weight, 4, 2, buf );
|
||||
LcdPrint( buf );
|
||||
LcdPrint( UNITS[ evt->unit ]);
|
||||
|
||||
break;
|
||||
|
||||
}//case WEIGHT_VALID...
|
||||
|
||||
case WEIGHT_NEGATIVE: {
|
||||
|
||||
const char negweight[] = "Negative weight";
|
||||
Serial.println(negweight);
|
||||
LcdPrint(negweight);
|
||||
break;
|
||||
}
|
||||
|
||||
case OVERWEIGHT: {
|
||||
|
||||
const char overweight[] = "Max.weight reached";
|
||||
Serial.println(overweight);
|
||||
LcdPrint( overweight );
|
||||
break;
|
||||
}
|
||||
|
||||
case CALIBRATE_ME:
|
||||
|
||||
Serial.println(F("Scale calibration required"));
|
||||
break;
|
||||
|
||||
case ZERO_ME:
|
||||
|
||||
Serial.println(F("Scale zeroing required"));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Serial.print(F("Undefined status code: "));
|
||||
Serial.println( evt->status );
|
||||
break;
|
||||
|
||||
}//switch( evt->status...
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
#if !defined(__SCALERPTPARSER_H__)
|
||||
#define __SCALERPTPARSER_H__
|
||||
|
||||
#include <max_LCD.h>
|
||||
#include <hid.h>
|
||||
|
||||
/* Scale status constants */
|
||||
#define REPORT_FAULT 0x01
|
||||
#define ZEROED 0x02
|
||||
#define WEIGHING 0x03
|
||||
#define WEIGHT_VALID 0x04
|
||||
#define WEIGHT_NEGATIVE 0x05
|
||||
#define OVERWEIGHT 0x06
|
||||
#define CALIBRATE_ME 0x07
|
||||
#define ZERO_ME 0x08
|
||||
|
||||
/* input data report */
|
||||
struct ScaleEventData
|
||||
{
|
||||
uint8_t reportID; //must be 3
|
||||
uint8_t status;
|
||||
uint8_t unit;
|
||||
int8_t exp; //scale factor for the weight
|
||||
uint16_t weight; //
|
||||
};
|
||||
|
||||
class ScaleEvents
|
||||
{
|
||||
|
||||
Max_LCD* pLcd;
|
||||
|
||||
void LcdPrint( const char* str );
|
||||
|
||||
public:
|
||||
|
||||
ScaleEvents( Max_LCD* pLCD );
|
||||
|
||||
virtual void OnScaleChanged(const ScaleEventData *evt);
|
||||
};
|
||||
|
||||
#define RPT_SCALE_LEN sizeof(ScaleEventData)/sizeof(uint8_t)
|
||||
|
||||
class ScaleReportParser : public HIDReportParser
|
||||
{
|
||||
ScaleEvents *scaleEvents;
|
||||
|
||||
uint8_t oldScale[RPT_SCALE_LEN];
|
||||
|
||||
public:
|
||||
ScaleReportParser(ScaleEvents *evt);
|
||||
|
||||
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
|
||||
};
|
||||
|
||||
#endif // __SCALERPTPARSER_H__
|
Loading…
Add table
Add a link
Reference in a new issue