From e4962dbfa2d145e4ad40d1b754ed454e57fb81f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= Date: Wed, 1 Jun 2011 19:57:09 +0200 Subject: [PATCH] Improved get_range_cmd2 function. Setting range from 200 to 900 deg including is now possible. --- wheels.c | 95 +++++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 58 insertions(+), 37 deletions(-) diff --git a/wheels.c b/wheels.c index 39f2a04..afa376b 100644 --- a/wheels.c +++ b/wheels.c @@ -69,55 +69,76 @@ int get_range_cmd(cmdstruct *c, int range) /* used by DFP * - * Credits go to MadCatX for finding out correct formula + * Credits go to MadCatX and slim.one 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 */ int get_range_cmd2(cmdstruct *c, int range) { - //Table of valid values for 6th byte - char valid_byte6[] = { - 0xe0, - 0xa4, - 0x86, - 0x68, - 0x4a, - 0x2c, - 0x0e, - }; - - //Which segment to use - int segment = (900 - range) / 7; //Yes, integer division is what we need - - //Values for 3rd and 4th byte - char byte4 = 255 - segment; - char byte3 = 255 - byte4; - - //Set value of 6th byte - int byte6_idx = 899 - (segment * 7) - range; - + //Prepare command A c->cmds[0][0] = 0xf8; - if (range > 200) - c->cmds[0][1] = 0x03; - else - c->cmds[0][1] = 0x02; + 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->cmds[1][0] = 0x81; - c->cmds[1][1] = 0x0b; - c->cmds[1][2] = byte3; - c->cmds[1][3] = byte4; - c->cmds[1][4] = 0xff; - c->cmds[1][5] = valid_byte6[byte6_idx]; - c->cmds[1][6] = 0xff; - c->cmds[1][7] = 0x00; //Logitech driver does not send the 8th byte. - - c->numCmds = 2; + c->numCmds = 2; + return 0; } -- 1.7.5.2