mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
USBHost library to new format
This commit is contained in:
@ -0,0 +1,70 @@
|
||||
/*
|
||||
|
||||
ADK Terminal Test
|
||||
|
||||
This demonstrates USB Host connectivity between an
|
||||
Android phone and an Arduino Due.
|
||||
|
||||
The ADK for the Arduino Due is a work in progress
|
||||
For additional information on the Arduino ADK visit
|
||||
http://labs.arduino.cc/ADK/Index
|
||||
|
||||
created 27 June 2012
|
||||
by Cristian Maglie
|
||||
|
||||
*/
|
||||
|
||||
#include "variant.h"
|
||||
#include <stdio.h>
|
||||
#include <adk.h>
|
||||
|
||||
// Accessory descriptor. It's how Arduino identifies itself to Android.
|
||||
char applicationName[] = "Arduino_Terminal"; // the app on your phone
|
||||
char accessoryName[] = "Arduino Due"; // your Arduino board
|
||||
char companyName[] = "Arduino SA";
|
||||
|
||||
// Make up anything you want for these
|
||||
char versionNumber[] = "1.0";
|
||||
char serialNumber[] = "1";
|
||||
char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk";
|
||||
|
||||
USBHost Usb;
|
||||
ADK adk(&Usb, companyName, applicationName, accessoryName,versionNumber,url,serialNumber);
|
||||
|
||||
void setup()
|
||||
{
|
||||
cpu_irq_enable();
|
||||
printf("\r\nADK demo start\r\n");
|
||||
delay(200);
|
||||
}
|
||||
|
||||
#define RCVSIZE 128
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint8_t buf[RCVSIZE];
|
||||
uint32_t nbread = 0;
|
||||
char helloworld[] = "Hello World!\r\n";
|
||||
|
||||
Usb.Task();
|
||||
|
||||
if (adk.isReady())
|
||||
{
|
||||
/* Write hello string to ADK */
|
||||
adk.write(strlen(helloworld), (uint8_t *)helloworld);
|
||||
|
||||
delay(1000);
|
||||
|
||||
/* Read data from ADK and print to UART */
|
||||
adk.read(&nbread, RCVSIZE, buf);
|
||||
if (nbread > 0)
|
||||
{
|
||||
printf("RCV: ");
|
||||
for (uint32_t i = 0; i < nbread; ++i)
|
||||
{
|
||||
printf("%c", (char)buf[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
Keyboard Controller Example
|
||||
|
||||
Shows the output of a USB Keyboard connected to
|
||||
the Native USB port on an Arduino Due Board.
|
||||
|
||||
created 8 Oct 2012
|
||||
by Cristian Maglie
|
||||
|
||||
http://arduino.cc/en/Tutorial/KeyboardController
|
||||
|
||||
This sample code is part of the public domain.
|
||||
*/
|
||||
|
||||
|
||||
// Require keyboard control library
|
||||
#include <KeyboardController.h>
|
||||
|
||||
// Initialize USB Controller
|
||||
USBHost usb;
|
||||
|
||||
// Attach keyboard controller to USB
|
||||
KeyboardController keyboard(usb);
|
||||
|
||||
// This function intercepts key press
|
||||
void keyPressed() {
|
||||
Serial.print("Pressed: ");
|
||||
printKey();
|
||||
}
|
||||
|
||||
// This function intercepts key release
|
||||
void keyReleased() {
|
||||
Serial.print("Released: ");
|
||||
printKey();
|
||||
}
|
||||
|
||||
void printKey() {
|
||||
// getOemKey() returns the OEM-code associated with the key
|
||||
Serial.print(" key:");
|
||||
Serial.print(keyboard.getOemKey());
|
||||
|
||||
// getModifiers() returns a bits field with the modifiers-keys
|
||||
int mod = keyboard.getModifiers();
|
||||
Serial.print(" mod:");
|
||||
Serial.print(mod);
|
||||
|
||||
Serial.print(" => ");
|
||||
|
||||
if (mod & LeftCtrl)
|
||||
Serial.print("L-Ctrl ");
|
||||
if (mod & LeftShift)
|
||||
Serial.print("L-Shift ");
|
||||
if (mod & Alt)
|
||||
Serial.print("Alt ");
|
||||
if (mod & LeftCmd)
|
||||
Serial.print("L-Cmd ");
|
||||
if (mod & RightCtrl)
|
||||
Serial.print("R-Ctrl ");
|
||||
if (mod & RightShift)
|
||||
Serial.print("R-Shift ");
|
||||
if (mod & AltGr)
|
||||
Serial.print("AltGr ");
|
||||
if (mod & RightCmd)
|
||||
Serial.print("R-Cmd ");
|
||||
|
||||
// getKey() returns the ASCII translation of OEM key
|
||||
// combined with modifiers.
|
||||
Serial.write(keyboard.getKey());
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Program started");
|
||||
delay(200);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Process USB tasks
|
||||
usb.Task();
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
Mouse Controller Example
|
||||
|
||||
Shows the output of a USB Mouse connected to
|
||||
the Native USB port on an Arduino Due Board.
|
||||
|
||||
created 8 Oct 2012
|
||||
by Cristian Maglie
|
||||
|
||||
http://arduino.cc/en/Tutorial/MouseController
|
||||
|
||||
This sample code is part of the public domain.
|
||||
*/
|
||||
|
||||
// Require mouse control library
|
||||
#include <MouseController.h>
|
||||
|
||||
// Initialize USB Controller
|
||||
USBHost usb;
|
||||
|
||||
// Attach mouse controller to USB
|
||||
MouseController mouse(usb);
|
||||
|
||||
// variables for mouse button states
|
||||
boolean leftButton = false;
|
||||
boolean middleButton = false;
|
||||
boolean rightButton = false;
|
||||
|
||||
// This function intercepts mouse movements
|
||||
void mouseMoved() {
|
||||
Serial.print("Move: ");
|
||||
Serial.print(mouse.getXChange());
|
||||
Serial.print(", ");
|
||||
Serial.println(mouse.getYChange());
|
||||
}
|
||||
|
||||
// This function intercepts mouse movements while a button is pressed
|
||||
void mouseDragged() {
|
||||
Serial.print("DRAG: ");
|
||||
Serial.print(mouse.getXChange());
|
||||
Serial.print(", ");
|
||||
Serial.println(mouse.getYChange());
|
||||
}
|
||||
|
||||
// This function intercepts mouse button press
|
||||
void mousePressed() {
|
||||
Serial.print("Pressed: ");
|
||||
if (mouse.getButton(LEFT_BUTTON)){
|
||||
Serial.print("L");
|
||||
leftButton = true;
|
||||
}
|
||||
if (mouse.getButton(MIDDLE_BUTTON)){
|
||||
Serial.print("M");
|
||||
middleButton = true;
|
||||
}
|
||||
if (mouse.getButton(RIGHT_BUTTON)){
|
||||
Serial.print("R");
|
||||
Serial.println();
|
||||
rightButton = true;
|
||||
}
|
||||
}
|
||||
|
||||
// This function intercepts mouse button release
|
||||
void mouseReleased() {
|
||||
Serial.print("Released: ");
|
||||
if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) {
|
||||
Serial.print("L");
|
||||
leftButton = false;
|
||||
}
|
||||
if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) {
|
||||
Serial.print("M");
|
||||
middleButton = false;
|
||||
}
|
||||
if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) {
|
||||
Serial.print("R");
|
||||
rightButton = false;
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Program started");
|
||||
delay(200);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Process USB tasks
|
||||
usb.Task();
|
||||
}
|
||||
|
Reference in New Issue
Block a user