PaulStoffregen 7 years ago
parent
commit
75ac4d21e6
3 changed files with 93 additions and 0 deletions
  1. +33
    -0
      USBHost_t36.h
  2. +55
    -0
      examples/Mouse/Mouse.ino
  3. +5
    -0
      keywords.txt

+ 33
- 0
USBHost_t36.h View File

Transfer_t mytransfers[7] __attribute__ ((aligned(32))); Transfer_t mytransfers[7] __attribute__ ((aligned(32)));
}; };


class MouseController : public USBDriver {
public:
MouseController(USBHost &host) { init(); }
MouseController(USBHost *host) { init(); }
bool available() { return mouseEvent; }
void mouseDataClear();
uint8_t getButtons() { return buttons; }
int8_t getMouseX() { return mouseX; }
int8_t getMouseY() { return mouseY; }
int8_t getWheel() { return wheel; }
protected:
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len);
virtual void control(const Transfer_t *transfer);
virtual void disconnect();
static void callback(const Transfer_t *transfer);
void new_data(const Transfer_t *transfer);
void init();
private:
void update();
Pipe_t *datapipe;
setup_t setup;
uint32_t packetSize;
uint8_t buttons;
int8_t mouseX;
int8_t mouseY;
int8_t wheel;
bool mouseEvent = false;
uint8_t report[20]; // Set to largest packet size 20 bytes
uint8_t prev_report[20]; // Same as above
Pipe_t mypipes[2] __attribute__ ((aligned(32)));
Transfer_t mytransfers[4] __attribute__ ((aligned(32)));
};

#endif #endif

+ 55
- 0
examples/Mouse/Mouse.ino View File

// Simple test of USB Host Mouse/Keyboard
//
// This example is in the public domain

#include "USBHost_t36.h"

USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
KeyboardController keyboard1(myusb);
KeyboardController keyboard2(myusb);
MouseController mouse1(myusb);

void setup()
{
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("USB Host Testing");
myusb.begin();
keyboard1.attachPress(OnPress);
keyboard2.attachPress(OnPress);
}


void loop()
{
myusb.Task();
if(mouse1.available()) {
Serial.print("buttons = ");
Serial.print(mouse1.getButtons(),DEC);
Serial.print(", wheel = ");
Serial.print(mouse1.getWheel(),DEC);
Serial.print(", mouseX = ");
Serial.print(mouse1.getMouseX(),DEC);
Serial.print(", mouseY = ");
Serial.println(mouse1.getMouseY(),DEC);
mouse1.mouseDataClear();
}
delay(50);
}


void OnPress(int key)
{
Serial.print("key '");
Serial.print((char)key);
Serial.print("' ");
Serial.println(key);
//Serial.print("key ");
//Serial.print((char)keyboard1.getKey());
//Serial.print(" ");
//Serial.print((char)keyboard2.getKey());
//Serial.println();
}


+ 5
- 0
keywords.txt View File

USBHost KEYWORD1 USBHost KEYWORD1
USBHub KEYWORD1 USBHub KEYWORD1
KeyboardController KEYWORD1 KeyboardController KEYWORD1
MouseController KEYWORD1
MIDIDevice KEYWORD1 MIDIDevice KEYWORD1
Task KEYWORD2 Task KEYWORD2
getKey KEYWORD2 getKey KEYWORD2
getOemKey KEYWORD2 getOemKey KEYWORD2
attachPress KEYWORD2 attachPress KEYWORD2
attachRelease KEYWORD2 attachRelease KEYWORD2
getButtons KEYWORD2
getWheel KEYWORD2
getMouseX KEYWORD2
getMouseY KEYWORD2

Loading…
Cancel
Save