微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

16 位 HID 轴操作

如何解决16 位 HID 轴操作

我无法让我的 Arduino HID Axis 控制器在 Windows 中正确读取。我正在使用此代码的旧版本 (https://github.com/MHeironimus/ArduinoJoystickLibrary),我正在修改代码删除除轴之外的所有内容

#include "Joystick.h"

#if defined(_USING_HID)

#define JOYSTICK_REPORT_ID 0x03
#define JOYSTICK_STATE_SIZE 8

static const uint8_t _hidReportDescriptor[] PROGMEM = {

    // Joystick
    0x05,0x01,// USAGE_PAGE (Generic Desktop)
    0x09,0x04,// USAGE (Joystick)
    0xa1,// COLLECTION (Application)
    0x85,JOYSTICK_REPORT_ID,//   REPORT_ID (3)

    // 16 bit Throttle and Steering
    0x05,0x02,//   USAGE_PAGE (Simulation Controls)
    0x15,0x00,//   LOGICAL_MINIMUM (0)
    0x27,0xff,//   LOGICAL_MAXIMUM (65535)
    0xA1,//   COLLECTION (Physical)
    0x09,0xBB,//     USAGE (Throttle)
    0x09,0xBA,//     USAGE (Rudder)
    0x75,0x10,//     REPORT_SIZE (16)
    0x95,//     REPORT_COUNT (2)
    0x81,//     INPUT (Data,Var,Abs)
    0xc0,//   END_COLLECTION



    // rx,ry,Axis
    0x05,// Usage Page (Generic Desktop)
    //0x09,// Usage (Pointer)
    0x15,0x33,//     USAGE (rx)
    0x09,0x34,//     USAGE (ry)
    0x75,//        REPORT_SIZE (16)
    0x95,//   END_COLLECTION

    0xc0                      // END_COLLECTION
};

Joystick_::Joystick_()
{
    // Setup HID report structure
    static HIDSubDescriptor node(_hidReportDescriptor,sizeof(_hidReportDescriptor));
    HID().AppendDescriptor(&node);

    // Initalize State
    xAxisRotation = 0;
    yAxisRotation = 0;
    throttle = 0;
    rudder = 0;

}

void Joystick_::begin(bool initAutoSendState)
{
    autoSendState = initAutoSendState;
    sendState();
}

void Joystick_::end()
{
}


void Joystick_::setThrottle(uint16_t value)
{
    throttle = value;
    if (autoSendState) sendState();
}
void Joystick_::setRudder(uint16_t value)
{
    rudder = value;
    if (autoSendState) sendState();
}

void Joystick_::setXAxisRotation(uint16_t value)
{
    xAxisRotation = value;
    if (autoSendState) sendState();
}
void Joystick_::setYAxisRotation(uint16_t value)
{
    yAxisRotation = value;
    if (autoSendState) sendState();
}



void Joystick_::sendState()
{
    uint8_t data[JOYSTICK_STATE_SIZE];


  data[0] = throttle; //lsb
  data[1] = throttle >> 8; //msb
  data[2] = rudder;
  data[3] = rudder >> 8;
    data[4] = xAxisRotation;
    data[5] = xAxisRotation >> 8;
    data[6] = yAxisRotation;
    data[7] = yAxisRotation >> 8;

    // HID().SendReport(Report number,array of values in same order as HID descriptor,length)
    HID().SendReport(JOYSTICK_REPORT_ID,data,JOYSTICK_STATE_SIZE);
}

Joystick_ Joystick;

#endif

这是我的cpp文件

我的 16 位油门和方向舵工作正常,但我的 rx 和 ry 旋转没有。我也无法摆脱帽子开关,如果我移除帽子开关并将报告大小设置为 7,所有 AXIS 都会停止工作。

我觉得我没有正确执行位移或掩码,或者我缺少一些命令来让它正确地组合在一起。 每次我尝试从 .h 文件删除按钮或轴时,它都会完全破坏控制器并且 Windows 无法检测到它。但是,如果我可以将 cpp 文件以 16 位的速度传输到 4 AXIS,我可以不理会它。

我正在使用 BEETLE LEONARDO USB ATMEGA32U4 开发板和 I2C 上的 ADS1115。设置起来很有趣,这是我的第一个 Arduino 项目,所以我对此非常陌生。

编辑:我想出了如何摆脱帽子开关(更新我的代码)。当我查看 x 和 y 旋转的原始数据时,在 Windows 的校准设置中,数字从 0 到 65000 就像我的油门和方向舵一样,但蓝色条形图从 1900-2000 开始,而不是百分比值就像油门和方向舵一样。我是否必须更改这些轴的最大值?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。