Untitled

 avatar
unknown
plain_text
5 hours ago
1.7 kB
15
Indexable
#include <Arduino.h>
#include "Adafruit_TinyUSB.h"

// HID tanımı (1 byte buton, 2 byte eksen)
uint8_t const desc_hid_report[] = {
  0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
  0x09, 0x04, // Usage (Joystick)
  0xA1, 0x01, // Collection (Application)
    0x05, 0x09, // Usage Page (Button)
    0x19, 0x01, // Usage Minimum (1)
    0x29, 0x08, // Usage Maximum (8)
    0x15, 0x00, // Logical Minimum (0)
    0x25, 0x01, // Logical Maximum (1)
    0x95, 0x08, // Report Count (8)
    0x75, 0x01, // Report Size (1)
    0x81, 0x02, // Input (Data,Var,Abs)

    0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
    0x09, 0x30, // Usage (X)
    0x09, 0x31, // Usage (Y)
    0x15, 0x81, // Logical Minimum (-127)
    0x25, 0x7F, // Logical Maximum (127)
    0x75, 0x08, // Report Size (8)
    0x95, 0x02, // Report Count (2)
    0x81, 0x02, // Input (Data,Var,Abs)
  0xC0        // End Collection
};

Adafruit_USBD_HID usb_hid;

typedef struct {
  uint8_t buttons; // 8 buttons
  int8_t x;        // -127 ~ 127
  int8_t y;        // -127 ~ 127
} __attribute__((packed)) JoyReport;

JoyReport report = {0, 0, 0};

void setup() {
  Serial.begin(115200);
  delay(1000);

  // HID tanımını ata
  usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
  usb_hid.begin();

  // TinyUSB mount olana kadar bekle
  while (!TinyUSBDevice.mounted()) {
    delay(10);
  }

  Serial.println("Joystick ready");
}

void loop() {
  // Düğme 1 basılı, eksenler X=50, Y=-50
  report.buttons = 0b00000001;
  report.x = 50;
  report.y = -50;

  usb_hid.sendReport(0, &report, sizeof(report));
  delay(100);
}
Editor is loading...
Leave a Comment