One of the things I HOPED Innovation First woud do with the C controller was to use signed charaters types for joystick and PWM data.
Basically, this would allow for easy scaling, etc.
0 = off
-127 = full reverse
127 = full forward
It is beautiful and elegant for many reasons.
BUT…
I would rather not just waste the variable space to have 16 inputs from the OI and 16 PWM outputs more or less wasted just because I want to use an elegant solution.
I would like to use unions to allow these modified PWM outputs and Joystick values to be stored in the same location as the unsigned character variables that Innovation First defines.
To use this I would just do something like this just after the getdata statement:
p1_y.DrJoe = p1_y.InnovationFirst - (signed char) 127
The (signed char) is a cast that is required allow the math on the right side of the equation to be performed using signed math.
Also, just before the PWM output statements, I would have to do something like this:
pwm01.InnovationFirst = pwm01.DrJoe + (unsigned char) 127
Again, the cast is needed to get the math work out right (actually, now that I think about it, I may need to put in an (unsigned int)… …I have to go look it up or try it out)
Anyway, I have 2 questions for Union Geeks…
In order to do this, I will have to dig into the structure that Innovation First defines for the recieve data as well as the #define statement where they define p1_y. I will also have to redefine the transmit data structure and its associated macros.
#1 Will this screw up the library functions (which we don’t have access to) which access the same structure?
#2 Is there a better way to do this?
Do tell.
Joe J.