From 56d2fd68c9ddd5abecee09747e6d2e5f246232a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= Date: Wed, 18 May 2011 16:31:28 +0200 Subject: [PATCH] Added a formula to calculate DFP wheel range --- wheels.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 37 insertions(+), 9 deletions(-) diff --git a/wheels.c b/wheels.c index 0b67d65..022bf92 100644 --- a/wheels.c +++ b/wheels.c @@ -70,6 +70,27 @@ int get_range_cmd(cmdstruct *c, int range) /* used by DFP */ 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; + /* According to MadCatXs investigation this additional * cmd is needed to enable rotation range > 200 degrees. */ @@ -82,17 +103,24 @@ int get_range_cmd2(cmdstruct *c, int range) c->cmds[0][6] = 0x00; c->cmds[0][7] = 0x00; - // FIXME - This is not working, need to find out the correct formula... - c->cmds[1][0] = 0xf8; - c->cmds[1][1] = 0x81; - c->cmds[1][2] = range & 0x00ff; - c->cmds[1][3] = (range & 0xff00)>>8; - c->cmds[1][4] = 0x00; - c->cmds[1][5] = 0x00; - c->cmds[1][6] = 0x00; - c->cmds[1][7] = 0x00; + 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; + + /*DEBUG + int i; + printf("%d %d\n", segment, byte6_idx); + for(i = 0; i < 7; i++) { + printf("%x\n", c->cmds[1][i]); + }*/ + return 0; } -- 1.7.5.1