Quote:
Originally Posted by jamie_1930
After thinking about this I think I have your code.
if(trig_sw==1)
x1==127
y1==127
x2==127
y2==127
This should be it. Although you still want to check the variables
x1,x2,y1,y2 are supposed to be the joystick direction.
|
Jamie, I don't think that's what he's talking about. If you did something like that at the beginning of you default routine, then you'd have your joysticks zeroed while you held down the trigger, but you'd never be able to move.
You could do this pretty simply with code along these lines:
Code:
//Definitions
signed char p1_x_off = 0;
signed char p1_y_off = 0;
//Code somewheres at the top of your default routine before you use p1_x, etc. for anything useful:
if (p1_top == 1)
{
p1_x_off = 127 - p1_x;
p1_y_off = 127 - p1_y;
}
p1_x = Limit_Mix(2000 + p1_x + p1_x_off);
p1_y = Limit_Mix(2000 + p1_y + p1_y_off);
And then you'd be able to virtually offset your joysticks back to center. Sort of. As QBranch has said, if you actually do this, then the effective range of your joystick is reduced by however wrong you were when you calibrated. for example:
Code:
Joystick center starts at:
p1_x = 147
You "calibrate" so:
p1_off = -20
Here, then are some typical joystick values
and how they'd come out in your code:
p1_x 147 127 0 20 254
p1_x + off 127 107 -20 0 234
Limit_Mix'd 127 107 0 0 234
Notice how actual values between 0 and 20 look like 0 to your code. Notice also how your code will now never see anything higher than 234. These sort of limits that come from this "calibration" are why you always see teams fiddling with trim dials as opposed to using code like this. It might be a little more time consuming and troublesome, but it just works better.