im pretty new on the STM32 and i encountered a problem.
With a Qt App i'm sending stuff over the USB with the following code:
if (m_hidDevice->isOpen())
{
QByteArray buffer(m_hidDevice->readOutputBufferSize(), 0);
buffer[0] = 16;
buffer[1] = 18;
uint16_t number = 4096;
uint16_t randomValue = qrand() % number;
buffer[2] = (char)((randomValue >> 8) & 0x00ff);
buffer[3] = (char)(randomValue & 0x00ff);
buffer[4] = (char)((2556 >> 8) & 0x00ff);
buffer[5] = (char)(2556 & 0x00ff);
qDebug() << "------------" << randomValue;
qDebug() << "//" << (uint8_t)buffer[2] << "//" << (uint8_t)buffer[3];
qDebug() << "//" << (uint8_t)buffer[4] << "//" << (uint8_t)buffer[5];
m_hidDevice->write(buffer);
and on the STM32F4 im using
switch (buffer[1])
{
case 18:
x = ((uint16_t)buffer[2] << 8) + buffer[3];
y = ((uint16_t)buffer[4] << 8) + buffer[5];
sr.m_value1[0] = x;
sr.m_value1[1] = y;
do(M);
m_value has size 4 and it is uint16_t;
The output on the Qt App is
------------ 2083
// 8 // 35
// 9 // 252
while on the STM32F4 x and y have values
x = 2083 (as expected)
y = 0
Now the size of the buffer should be 64 bytes while my data is 8*5 = 40 bytes. My question then is why i can't retrieve correctly the values in the buffer?
Regards,
0x09, 0x01, // USAGE (Vendor Usage x) --> x = 1,2,3
0x75, 0x08, // REPORT_SIZE (8) --> 2^8 = 255
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x85, 0x02, // REPORT_ID (n) --> n must be the report id
0x95, 0x3f, // REPORT_COUNT (63) --> size
0x91, 0x02 // OUTPUT (Data,Var,Abs)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.