Parcourir la source

Example: USBHost_viewer.ino also work with ST7735/ST7789_t3 displays

Some of the display may not have enough room on them to show everything, but they can work to show at least some of it.

Also got rid of comments and settings for like Beta1 T4 boards as real real boards exist now.
main
Kurt Eckhardt il y a 4 ans
Parent
révision
f915271f3a
1 fichiers modifiés avec 166 ajouts et 145 suppressions
  1. +166
    -145
      examples/USBHost_viewer/USBHost_viewer.ino

+ 166
- 145
examples/USBHost_viewer/USBHost_viewer.ino Voir le fichier

//============================================================================= //=============================================================================
// Simple test viewer app for several of the USB devices on ili9341 display
// Simple test viewer app for several of the USB devices on a display
// This sketch as well as all others in this library will only work with the
// Teensy 3.6 and the T4.x boards.
// //
// Currently requires the libraries
// The default display is the ILI9341, which uses the ILI9341_t3n library,
// which is located at:
// ili9341_t3n that can be located: https://github.com/KurtE/ILI9341_t3n // ili9341_t3n that can be located: https://github.com/KurtE/ILI9341_t3n
// spin: https://github.com/KurtE/SPIN
// //
// Teensy 3.6 Pins
// Alternate display ST7735 or ST7789 using the ST7735_t3 library which comes
// with Teensyduino.
//
// Default pins
// 8 = RST // 8 = RST
// 9 = D/C // 9 = D/C
// 10 = CS // 10 = CS
// //
// Teensy 4.0 Beta Pins
// 23 = RST (Marked MCLK on T4 beta breakout)
// 10 = CS (Marked CS)
// 9 = DC (Marked MEMCS)
//
// This example is in the public domain // This example is in the public domain
//============================================================================= //=============================================================================
#define USE_ST77XX // define this if you wish to use one of these displays.


#include "USBHost_t36.h" #include "USBHost_t36.h"

#ifdef USE_ST77XX
#include <ST7735_t3.h>
#include <st7735_t3_font_Arial.h>
#include <ST7789_t3.h>
#define BLACK ST77XX_BLACK
#define WHITE ST77XX_WHITE
#define YELLOW ST77XX_YELLOW
#define GREEN ST77XX_GREEN
#define RED ST77XX_RED
#else
#include <ILI9341_t3n.h>
#include <ili9341_t3n_font_Arial.h> #include <ili9341_t3n_font_Arial.h>
#define TEENSY64
#define BLACK ILI9341_BLACK
#define WHITE ILI9341_WHITE
#define YELLOW ILI9341_YELLOW
#define GREEN ILI9341_GREEN
#define RED ILI9341_RED
#endif


//============================================================================= //=============================================================================
// Connection configuration of ILI9341 LCD TFT // Connection configuration of ILI9341 LCD TFT
//============================================================================= //=============================================================================
DMAMEM uint16_t frame_buffer[ILI9341_TFTWIDTH * ILI9341_TFTHEIGHT];
#if defined(__MK66FX1M0__) && !defined(TEENSY64)
#define TFT_RST 255
#define TFT_DC 20
#define TFT_CS 21
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
// On Teensy 4 beta with Paul's breakout out:
// Using pins (MOSI, MISO, SCK which are labeled on Audio board breakout location
// which are not in the Normal processor positions
// Also DC=10(CS), CS=9(BCLK) and RST 23(MCLK)
#define TFT_RST 23
#define TFT_RST 8
#define TFT_DC 9 #define TFT_DC 9
#define TFT_CS 10 #define TFT_CS 10
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
#elif defined(TEENSY64)
#define TFT_RST 255
#define TFT_DC 20
#define TFT_CS 21
#define TFT_SCK 14
#define TFT_MISO 39
#define TFT_MOSI 28
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);

#ifdef USE_ST77XX
// define which one you are using
//DMAMEM uint16_t frame_buffer[ILI9341_TFTWIDTH * ILI9341_TFTHEIGHT];
// Note there are other options, like defining MOSI, SCK...
//ST7735_t3 tft = ST7735_t3(cs, dc, rst);
// For 1.54" TFT with ST7789
ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_RST);
#else #else
#error "This example App will only work with Teensy 3.6 or Teensy 4."
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
#endif #endif

//============================================================================= //=============================================================================
// USB Host Ojbects // USB Host Ojbects
//============================================================================= //=============================================================================
MouseController mouse(myusb); MouseController mouse(myusb);
DigitizerController tablet(myusb); DigitizerController tablet(myusb);
JoystickController joystick(myusb); JoystickController joystick(myusb);
BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device
//BluetoothController bluet(myusb); // version assumes it already was paired
//BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device
BluetoothController bluet(myusb); // version assumes it already was paired
RawHIDController rawhid2(myusb); RawHIDController rawhid2(myusb);


// Lets only include in the lists The most top level type devices we wish to show information for. // Lets only include in the lists The most top level type devices we wish to show information for.
//============================================================================= //=============================================================================


// Save away values for buttons, x, y, wheel, wheelh // Save away values for buttons, x, y, wheel, wheelh
int buttons_cur = 0;
uint32_t buttons_cur = 0;
int x_cur = 0, int x_cur = 0,
y_cur = 0, y_cur = 0,
z_cur = 0; z_cur = 0;
// device like wireless mouse and keyboard this can cause mouse problems. // device like wireless mouse and keyboard this can cause mouse problems.
//keyboard1.forceBootProtocol(); //keyboard1.forceBootProtocol();


#ifdef USE_ST77XX
// Only uncomment one of these init options.
// ST7735 - More options mentioned in examples for st7735_t3 library
//tft.initR(INITR_BLACKTAB); // if you're using a 1.8" TFT 128x160 displays
//tft.initR(INITR_144GREENTAB); // if you're using a 1.44" TFT (128x128)
//tft.initR(INITR_MINI160x80); //if you're using a .96" TFT(160x80)

// ST7789
tft.init(240, 240); // initialize a ST7789 chip, 240x240 pixels
//tft.init(240, 320); // Init ST7789 2.0" 320x240
//tft.init(135, 240); // Init ST7789 1.4" 135x240
//tft.init(240, 240, SPI_MODE2); // clones Init ST7789 240x240 no CS
#else
tft.begin(); tft.begin();
#endif
// explicitly set the frame buffer // explicitly set the frame buffer
tft.setFrameBuffer(frame_buffer);
// tft.setFrameBuffer(frame_buffer);
delay(100); delay(100);
tft.setRotation(3); // 180 tft.setRotation(3); // 180
delay(100); delay(100);


tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);
tft.setTextSize(2); tft.setTextSize(2);
tft.println("Waiting for Device..."); tft.println("Waiting for Device...");
tft.useFrameBuffer(true); tft.useFrameBuffer(true);
new_device_detected = true; new_device_detected = true;
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct()); Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true; driver_active[i] = true;
tft.fillScreen(ILI9341_BLACK); // clear the screen.
tft.fillScreen(BLACK); // clear the screen.
tft.setCursor(0, 0); tft.setCursor(0, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(YELLOW);
tft.setFont(Arial_12); tft.setFont(Arial_12);
tft.printf("Device %s %x:%x\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct()); tft.printf("Device %s %x:%x\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());


new_device_detected = true; new_device_detected = true;
Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct()); Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
hid_driver_active[i] = true; hid_driver_active[i] = true;
tft.fillScreen(ILI9341_BLACK); // clear the screen.
tft.fillScreen(BLACK); // clear the screen.
tft.setCursor(0, 0); tft.setCursor(0, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(YELLOW);
tft.setFont(Arial_12); tft.setFont(Arial_12);
tft.printf("HID Device %s %x:%x\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct()); tft.printf("HID Device %s %x:%x\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());


new_device_detected = true; new_device_detected = true;
Serial.printf("*** BTHID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct()); Serial.printf("*** BTHID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
bthid_driver_active[i] = true; bthid_driver_active[i] = true;
tft.fillScreen(ILI9341_BLACK); // clear the screen.
tft.fillScreen(BLACK); // clear the screen.
tft.setCursor(0, 0); tft.setCursor(0, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(YELLOW);
tft.setFont(Arial_12); tft.setFont(Arial_12);
tft.printf("Bluetooth Device %s %x:%x\n", bthid_driver_names[i], bthiddrivers[i]->idVendor(), bthiddrivers[i]->idProduct()); tft.printf("Bluetooth Device %s %x:%x\n", bthid_driver_names[i], bthiddrivers[i]->idVendor(), bthiddrivers[i]->idProduct());


// Lets display the titles. // Lets display the titles.
int16_t x; int16_t x;
tft.getCursor(&x, &y_position_after_device_info); tft.getCursor(&x, &y_position_after_device_info);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(YELLOW);
tft.printf("Buttons:\nX:\nY:\nWheel:\nWheel H:\nAxis:"); tft.printf("Buttons:\nX:\nY:\nWheel:\nWheel H:\nAxis:");
new_device_detected = false; new_device_detected = false;
} }
#define TABLET_DATA_X 100 #define TABLET_DATA_X 100
int16_t x, y2; int16_t x, y2;
unsigned char line_space = Arial_12.line_space; unsigned char line_space = Arial_12.line_space;
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextColor(WHITE, BLACK);
//tft.setTextDatum(BR_DATUM); //tft.setTextDatum(BR_DATUM);
int16_t y = y_position_after_device_info; int16_t y = y_position_after_device_info;
tft.setCursor(TABLET_DATA_X, y); tft.setCursor(TABLET_DATA_X, y);
tft.printf("%d(%x)", buttons_cur, buttons_cur); tft.printf("%d(%x)", buttons_cur, buttons_cur);
tft.getCursor(&x, &y2); tft.getCursor(&x, &y2);
tft.fillRect(x, y, 320, line_space, ILI9341_BLACK);
tft.fillRect(x, y, 320, line_space, BLACK);


y += line_space; OutputNumberField(TABLET_DATA_X, y, x_cur, 320); y += line_space; OutputNumberField(TABLET_DATA_X, y, x_cur, 320);
y += line_space; OutputNumberField(TABLET_DATA_X, y, y_cur, 320); y += line_space; OutputNumberField(TABLET_DATA_X, y, y_cur, 320);
int16_t x2, y2; int16_t x2, y2;
tft.setCursor(x, y); tft.setCursor(x, y);
tft.print(val, DEC); tft.getCursor(&x2, &y2); tft.print(val, DEC); tft.getCursor(&x2, &y2);
tft.fillRect(x2, y, field_width - (x2 - x), Arial_12.line_space, ILI9341_BLACK);
tft.fillRect(x2, y, field_width - (x2 - x), Arial_12.line_space, BLACK);
} }


//============================================================================= //=============================================================================
// Lets display the titles. // Lets display the titles.
int16_t x; int16_t x;
tft.getCursor(&x, &y_position_after_device_info); tft.getCursor(&x, &y_position_after_device_info);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(YELLOW);
tft.printf("Buttons:\nX:\nY:\nWheel:\nWheel H:"); tft.printf("Buttons:\nX:\nY:\nWheel:\nWheel H:");
new_device_detected = false; new_device_detected = false;
} }
#define MOUSE_DATA_X 100 #define MOUSE_DATA_X 100
int16_t x, y2; int16_t x, y2;
unsigned char line_space = Arial_12.line_space; unsigned char line_space = Arial_12.line_space;
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextColor(WHITE, BLACK);
//tft.setTextDatum(BR_DATUM); //tft.setTextDatum(BR_DATUM);
int16_t y = y_position_after_device_info; int16_t y = y_position_after_device_info;
tft.setCursor(TABLET_DATA_X, y); tft.setCursor(TABLET_DATA_X, y);
tft.printf("%d(%x)", buttons_cur, buttons_cur); tft.printf("%d(%x)", buttons_cur, buttons_cur);
tft.getCursor(&x, &y2); tft.getCursor(&x, &y2);
tft.fillRect(x, y, 320, line_space, ILI9341_BLACK);
tft.fillRect(x, y, 320, line_space, BLACK);


y += line_space; OutputNumberField(MOUSE_DATA_X, y, x_cur, 320); y += line_space; OutputNumberField(MOUSE_DATA_X, y, x_cur, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, y_cur, 320); y += line_space; OutputNumberField(MOUSE_DATA_X, y, y_cur, 320);
// TFT_joystick // TFT_joystick
//============================================================================= //=============================================================================
void tft_JoystickData() { void tft_JoystickData() {
if (new_device_detected) {
// Lets display the titles.
int16_t x;
tft.getCursor(&x, &y_position_after_device_info);
tft.setTextColor(ILI9341_YELLOW);
tft.printf("Buttons:\nX:\nY:\nX2\nY2(Z):\nL1:\nR1:\nHAT:");
new_device_detected = false;
}
if (new_device_detected) {
// Lets display the titles.
int16_t x;
tft.getCursor(&x, &y_position_after_device_info);
tft.setTextColor(YELLOW);
tft.printf("Buttons:\nX:\nY:\nX2\nY2(Z):\nL1:\nR1:\nHAT:");
new_device_detected = false;
}


bool something_changed = false;
if (buttons != buttons_prev) { //buttons
something_changed = true;
}
if (user_axis[0] != x_cur) { //xL
x_cur = user_axis[0];
something_changed = true;
}
if (user_axis[1] != y_cur) { //yL
y_cur = user_axis[1];
something_changed = true;
}
if (user_axis[9] != wheel_cur) { //Hat
wheel_cur = user_axis[9];
something_changed = true;
}
bool something_changed = false;
if (buttons != buttons_prev) { //buttons
something_changed = true;
}
if (user_axis[0] != x_cur) { //xL
x_cur = user_axis[0];
something_changed = true;
}
if (user_axis[1] != y_cur) { //yL
y_cur = user_axis[1];
something_changed = true;
}
if (user_axis[9] != wheel_cur) { //Hat
wheel_cur = user_axis[9];
something_changed = true;
}
//Second Axis //Second Axis
if (user_axis[2] != x2_cur) { //xR
x2_cur = user_axis[2];
something_changed = true;
}
if (user_axis[5] != y2_cur) { //yR or z-axis
y2_cur = user_axis[5];
something_changed = true;
}
//Rumble Axis
switch (joystick.joystickType()) {
case JoystickController::XBOXONE:
case JoystickController::XBOX360:
case JoystickController::PS4:
if (user_axis[3] != L1_cur) { //xR
L1_cur = user_axis[3];
something_changed = true;
}
if (user_axis[4] != R1_cur) { //yR or z-axis
R1_cur = user_axis[4];
something_changed = true;
}
break;
case JoystickController::PS3:
if (user_axis[18] != L1_cur) { //xR
L1_cur = user_axis[18];
something_changed = true;
}
if (user_axis[19] != R1_cur) { //yR or z-axis
R1_cur = user_axis[19];
something_changed = true;
}
break;
}
if (something_changed) {
#define MOUSE_DATA_X 100
int16_t x, y2;
unsigned char line_space = Arial_12.line_space;
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
//tft.setTextDatum(BR_DATUM);
int16_t y = y_position_after_device_info;
tft.setCursor(TABLET_DATA_X, y);
tft.printf("%d(%x)", buttons, buttons);
tft.getCursor(&x, &y2);
tft.fillRect(x, y, 320, line_space, ILI9341_BLACK);

y += line_space; OutputNumberField(MOUSE_DATA_X, y, x_cur, 320); //x
y += line_space; OutputNumberField(MOUSE_DATA_X, y, y_cur, 320); //y
y += line_space; OutputNumberField(MOUSE_DATA_X, y, x2_cur, 320); //x2(z)
y += line_space; OutputNumberField(MOUSE_DATA_X, y, y2_cur, 320); //y2
switch (joystick.joystickType()) {
case JoystickController::PS4:
case JoystickController::PS3:
case JoystickController::XBOXONE:
case JoystickController::XBOX360:
y += line_space; OutputNumberField(MOUSE_DATA_X, y, L1_cur, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, R1_cur, 320);
break;
default:
y += line_space; OutputNumberField(MOUSE_DATA_X, y, 0, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, 0, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, wheel_cur, 320); //hat
break;
if (user_axis[2] != x2_cur) { //xR
x2_cur = user_axis[2];
something_changed = true;
}
if (user_axis[5] != y2_cur) { //yR or z-axis
y2_cur = user_axis[5];
something_changed = true;
}
//Rumble Axis
switch (joystick.joystickType()) {
case JoystickController::XBOXONE:
case JoystickController::XBOX360:
case JoystickController::PS4:
if (user_axis[3] != L1_cur) { //xR
L1_cur = user_axis[3];
something_changed = true;
} }
tft.updateScreen(); // update the screen now
if (user_axis[4] != R1_cur) { //yR or z-axis
R1_cur = user_axis[4];
something_changed = true;
}
break;
case JoystickController::PS3:
if (user_axis[18] != L1_cur) { //xR
L1_cur = user_axis[18];
something_changed = true;
}
if (user_axis[19] != R1_cur) { //yR or z-axis
R1_cur = user_axis[19];
something_changed = true;
}
break;
default: // All others
break;
}
if (something_changed) {
#define MOUSE_DATA_X 100
int16_t x, y2;
unsigned char line_space = Arial_12.line_space;
tft.setTextColor(WHITE, BLACK);
//tft.setTextDatum(BR_DATUM);
int16_t y = y_position_after_device_info;
tft.setCursor(TABLET_DATA_X, y);
tft.printf("%d(%x)", buttons, buttons);
tft.getCursor(&x, &y2);
tft.fillRect(x, y, 320, line_space, BLACK);

y += line_space; OutputNumberField(MOUSE_DATA_X, y, x_cur, 320); //x
y += line_space; OutputNumberField(MOUSE_DATA_X, y, y_cur, 320); //y
y += line_space; OutputNumberField(MOUSE_DATA_X, y, x2_cur, 320); //x2(z)
y += line_space; OutputNumberField(MOUSE_DATA_X, y, y2_cur, 320); //y2
switch (joystick.joystickType()) {
case JoystickController::PS4:
case JoystickController::PS3:
case JoystickController::XBOXONE:
case JoystickController::XBOX360:
y += line_space; OutputNumberField(MOUSE_DATA_X, y, L1_cur, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, R1_cur, 320);
break;
default:
y += line_space; OutputNumberField(MOUSE_DATA_X, y, 0, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, 0, 320);
y += line_space; OutputNumberField(MOUSE_DATA_X, y, wheel_cur, 320); //hat
break;
} }
tft.updateScreen(); // update the screen now
}
} }


//============================================================================= //=============================================================================
} }


bool something_changed = false; bool something_changed = false;
if (user_axis[3] != buttons_cur) {
buttons_cur = user_axis[3];
if ((uint32_t)user_axis[3] != buttons_cur) {
buttons_cur = (uint32_t)user_axis[3];
something_changed = true; something_changed = true;
} }
if (user_axis[4] != x_cur) { if (user_axis[4] != x_cur) {
something_changed = true; something_changed = true;
} }
if (something_changed) { if (something_changed) {
tft.fillRect(45, 197, 240, 20, ILI9341_RED);
tft.fillRect(45, 197, 240, 20, RED);
tft.drawNumber(buttons_cur, 50, 200); tft.drawNumber(buttons_cur, 50, 200);
tft.drawNumber(x_cur, 100, 200); tft.drawNumber(x_cur, 100, 200);
tft.drawNumber(y_cur, 150, 200); tft.drawNumber(y_cur, 150, 200);
if (BT == 0) { if (BT == 0) {
tft.enableScroll(); tft.enableScroll();
tft.setScrollTextArea(20, 70, 280, 140); tft.setScrollTextArea(20, 70, 280, 140);
tft.setScrollBackgroundColor(ILI9341_GREEN);
tft.setScrollBackgroundColor(GREEN);
tft.setFont(Arial_11); tft.setFont(Arial_11);
tft.setTextColor(ILI9341_BLACK);
tft.setTextColor(BLACK);
tft.setCursor(20, 70); tft.setCursor(20, 70);
BT = 1; BT = 1;
} }
tft.print(top, HEX); tft.print(top, HEX);
tft.print(") key release:"); tft.print(") key release:");
tft.println(key, HEX); tft.println(key, HEX);
}
}

Chargement…
Annuler
Enregistrer