I am making steering wheel using encoder and MegaJoy library with Arduino Uno R3. MegaJoy supports 10 bit axis but since I am using encoder I want to use full 16 bit for my steering wheel. I am using following code for the steering wheel.
steerpos = steer.read(); //read the encoder value
steerpos = map(steerpos, sl, sr, 0, 1023); //map encoder value between 0 and 1023
if(steerpos > 1023)
steerpos = 1023;
else if(steerpos < 0)
steerpos = 0;
controllerData.analogAxisArray[4] = steerpos;
As you can see in above code snippet I am taking encoder reading and mapping the leftmost and rightmost steering wheel position between 0 and 1023 which is 10 bit value. But I want to map them between 0 to 65535 which is 16 bit value. Since MegaJoy only supports 10 bit value, I tried to do some changes in HID descriptor but it did not work. How do I get 16 bit value using MegaJoy?
The problem is that Megajoy only shows value between 0 to 1023 on PC. I want to change that so that it will show value between 0 to 65553 or -32768 to 32768. In HID descriptor of the MegaJoy LOGICAL MAXIMUM is defined as 1024 so if send any value greater than 1024 it will only show 1024 in PC.
I changed values in HID descriptor and replaced all int16_t to uint16_t and it is working now. Megajoy has two controllers with 6 axis and 32 buttons each. The problem is that it is working only on 2nd controller even though I made same changes for both the controllers. I am still trying to find why it is behaving like that.
Anyway I have some problem with map function.
consider the following example
val = map(991, 510, 980, 0, 1023);
the above code gives value of 1046. observe that 991 is greater than max range i.e. 980 hence output is greater than 1023
now look at the following code
val = map(991, 510, 980, 0, 65535);
in above code, it gives output of 1532. Since 991 is out of max range i.e. 980 it should give output greater than 65535 like in case of 1046 but it is giving 1532. Can someone explain what is happening here?