From 48bff52deca8af7e476e5bb6d7ce56c644ed43f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= Date: Sun, 26 Jun 2011 22:05:15 +0200 Subject: [PATCH 1/2] Improved range setting command for DFP. All ranges from 40 to 900 degrees should work now. --- wheels.c | 105 +++++++++++++++++++++++++++---------------------------------- 1 files changed, 47 insertions(+), 58 deletions(-) diff --git a/wheels.c b/wheels.c index f1ae226..b44f6d3 100644 --- a/wheels.c +++ b/wheels.c @@ -1,4 +1,5 @@ #include "wheels.h" +#include int get_nativemode_cmd_DFP(cmdstruct *c) { @@ -69,75 +70,62 @@ int get_range_cmd(cmdstruct *c, int range) /* used by DFP * - * Credits go to MadCatX and slim.one for finding out correct formula + * Credits go to MadCatX, slim.one and lbondar for finding out correct formula * See http://www.lfsforum.net/showthread.php?p=1593389#post1593389 - * and http://www.lfsforum.net/showthread.php?p=1595604#post1595604 + * http://www.lfsforum.net/showthread.php?p=1595604#post1595604 + * http://www.lfsforum.net/showthread.php?p=1603971#post1603971 */ int get_range_cmd2(cmdstruct *c, int range) { - //Prepare command A + /* Prepare command A */ c->cmds[0][0] = 0xf8; - c->cmds[0][1] = 0x00; //Set later + c->cmds[0][1] = 0x00; /* Set later */ c->cmds[0][2] = 0x00; c->cmds[0][3] = 0x00; c->cmds[0][4] = 0x00; c->cmds[0][5] = 0x00; c->cmds[0][6] = 0x00; c->cmds[0][7] = 0x00; - - if (range == 900) { - //Finish command A - c->cmds[0][1] = 0x03; - - //Set command B - c->cmds[1][0] = 0x83; - c->cmds[1][1] = 0x00; - c->cmds[1][2] = 0x00; - c->cmds[1][3] = 0x00; - c->cmds[1][4] = 0x00; - c->cmds[1][5] = 0x00; - c->cmds[1][6] = 0x00; - c->cmds[1][7] = 0x00; - } else if (range < 900 && range > 200) { - //Finish command A - c->cmds[0][1] = 0x03; - - unsigned char byte3, byte6; - byte3 = 127 - (unsigned char)((range - 5) / 7); - - //Set 6th byte - int rem = (range - 5) % 7; - if (rem == 6) - byte6 = 0xe0; - else - byte6 = rem * 30 + 14; - - //Set command B - c->cmds[1][0] = 0x81; - c->cmds[1][1] = 0x0b; - c->cmds[1][2] = byte3; - c->cmds[1][3] = 255 - byte3; - c->cmds[1][4] = 0xff; - c->cmds[1][5] = byte6; - c->cmds[1][6] = 0xff; - c->cmds[1][7] = 0x00; //Official Logitech Windows driver does not send the 8th byte. - } else if (range == 200) { - //Finish command A - c->cmds[0][1] = 0x02; - - //Set command B - c->cmds[1][0] = 0x83; - c->cmds[1][1] = 0x00; - c->cmds[1][2] = 0x00; - c->cmds[1][3] = 0x00; - c->cmds[1][4] = 0x00; - c->cmds[1][5] = 0x00; - c->cmds[1][6] = 0x00; - c->cmds[1][7] = 0x00; - } else - return -1; - - c->numCmds = 2; + + /* Prepare command B */ + c->cmds[1][0] = 0x81; + c->cmds[1][1] = 0x0b; + c->cmds[1][2] = 0x00; + c->cmds[1][3] = 0x00; + c->cmds[1][4] = 0x00; + c->cmds[1][5] = 0x00; + c->cmds[1][6] = 0x00; + c->cmds[1][7] = 0x00; + + c->numCmds = 2; + + int rampLeft, rampRight, fullRange; + + if(range > 200) { + c->cmds[0][1] = 0x03; + + if(range == 900) /* Do not limit the range */ + return 0; + else + fullRange = 900; + } else { + c->cmds[0][1] = 0x02; + + if(range == 200) /* Do not limit the range */ + return 0; + else + fullRange = 200; + } + + /* Construct range limiting command */ + rampLeft = (((fullRange - range + 1) * 2047) / fullRange); + rampRight = 0xfff - rampLeft; + + c->cmds[1][2] = rampLeft >> 4; + c->cmds[1][3] = rampRight >> 4; + c->cmds[1][4] = 0xff; + c->cmds[1][5] = (rampRight & 0xe) << 4 | (rampLeft & 0xe); + c->cmds[1][6] = 0xff; return 0; } @@ -153,6 +141,7 @@ int get_autocenter_cmd(cmdstruct *c, int centerforce, int rampspeed) c->cmds[0][5] = 0x00; c->cmds[0][6] = 0x00; c->cmds[0][7] = 0x00; + c->numCmds = 1; return 0; } -- 1.7.5.4