Hi,
i want to use several rotary encoders as an HID-device (joystick). they work quite fine if i use them as an analog axis which sends an 8bit value. but now i want them to act like a joystick-button, lets say button 1 for left- and button 2 for right turn. the problem is, that the "button is pressed"-conditions last only very shortly, so that no pc-program take notice of it. does anyone have an idea what i could do to make it work? my software is based on the redkontrol-project.
thanks in advice, best regards
HID Device -> Rotary Encoder Problem
-
- Rank 2
- Posts: 43
- Joined: Fri Jun 19, 2009 4:43 pm
Re: HID Device -> Rotary Encoder Problem
two solutions:
make your host application event driven (I can't help much with this)
or
elongate the period which your button appears pressed, using a hardware timer or loop counter
make your host application event driven (I can't help much with this)
or
elongate the period which your button appears pressed, using a hardware timer or loop counter
Code: Select all
int pressedFor; // counter
while (1)
{
usbPoll();
if (buttonIsPressed())
{
pressedFor = 0; // reset counter
}
if (pressedFor < 10) // hold down button for 10 loops
{
report.button = 1;
pressedFor++; // delay button release
}
else
{
report.button = 0; // 10 loops passed, release button
}
if (usbInterruptIsReady())
{
usbSetInterrupt(report, sizeof(report));
}
}
Re: HID Device -> Rotary Encoder Problem
Thank you very much for your answer, i'll try it using a timer.
I also tried another approach, but i had a problem there too. i used the rotary encoder as an analog axis with 8 bit for values from 0-255. works fine. but now i want to have an range from 0-359 (9 bit). i tried many varants for the device descriptor, but none of them worked properly. i set REPORT_SIZE to 9, LOGICAL_MINIMUM to 0 and LOGICAL_MAXIMUM to 359, but it won't work, the windows-joystick calibration reads only values until 255. is there any other part in the descriptor i have to change?
thanks in advice!
I also tried another approach, but i had a problem there too. i used the rotary encoder as an analog axis with 8 bit for values from 0-255. works fine. but now i want to have an range from 0-359 (9 bit). i tried many varants for the device descriptor, but none of them worked properly. i set REPORT_SIZE to 9, LOGICAL_MINIMUM to 0 and LOGICAL_MAXIMUM to 359, but it won't work, the windows-joystick calibration reads only values until 255. is there any other part in the descriptor i have to change?
thanks in advice!
-
- Rank 2
- Posts: 43
- Joined: Fri Jun 19, 2009 4:43 pm
Re: HID Device -> Rotary Encoder Problem
359? uh, i'd suggest you avoid that, stick to 0-255 and use software to multiply the number by 1.40784314
Re: HID Device -> Rotary Encoder Problem
i need exactly 360 possible values, its gonna be a flight simulation device, and a circle has 360 degrees
-
- Rank 2
- Posts: 43
- Joined: Fri Jun 19, 2009 4:43 pm
Re: HID Device -> Rotary Encoder Problem
ElGreco wrote:i need exactly 360 possible values, its gonna be a flight simulation device, and a circle has 360 degrees
does the encoder have exactly 360 discrete values? if not, then i suggest you either use the number of discrete values per full rotation of the encoder, or stick with 256, or maybe 65536, and then process the number using host-side software
what about declaring a report main item size as 16 bit but still reporting 0-359?