vputz wrote:
...which is basically taken from the linux magellan.c driver in magellan_process_packet:
Code: Select all
case 'k': /* Button data */
103 if (magellan->idx != 4) return;
104 if (magellan_crunch_nibbles(data, 3)) return;
Sorry...back on this after being tied up a bit on another project.
Why did you rewrite crunch_magellan_nibbles so it doesn't take a buffer ptr + count? Just wanted to make sure this is ok. Looks like you're just stripping nibbles for the bytes you read in automatically from this so it seems ok:
Code: Select all
for ( unsigned short i = 1; i < (cursor-1); ++i )
if (buffer[i] == nibbles[buffer[i] & 0xf])
I decided to look at the packet data via the serial dump to COM6.
buttons 1-9 return
107 65 48 48 13 107 48 48 48 13
107 66 48 48 13 107 48 48 48 13
107 68 48 48 13 107 48 48 48 13
107 72 48 48 13 107 48 48 48 13
107 48 65 48 13 107 48 48 48 13
107 48 66 48 13 107 48 48 48 13
107 48 68 48 13 107 48 48 48 13
107 48 72 48 13 107 48 48 48 13
107 48 48 65 13 107 48 48 48 13
buttons A-C return
107 48 48 66 13 107 48 48 48 13
107 48 48 68 13 107 48 48 48 13
107 48 48 72 13 107 48 48 48 13
So each byte goes through 65, 66, 68, 72 before going to the next one.
This translates to 0x41, 0x42, 0x44, 0x48. The crunch nibbles function seems to just strip off the top 4 bits (the 0x40 part) so this becomes 0x1, 0x2, 0x4, 0x8.
The 107 is a button change so it's a 5 byte packet (the 2nd 107 packet is me releasing the button).
Given the byte pattern above, I don't get how process_magellan_buttondata would work because of the weird left shifting increments that aren't a multiple of 4
Code: Select all
physical_buttons = (buffer[1] << 1)
| (buffer[2] << 5)
| buffer[3];
So I re-did the code to merge the nibbles and it seems to work ok.
Also added a chording option for button C, but ran into some weird Arduino weirdness w/ unsigned shorts. If you hit the C button to chord w/ buttons 4/5, they get translated to buttons 15&16 so there's obviously some sign/unsigned issue. I tried casting to a 32-bit unsigned long before the left shift but that didn't make a difference and it would have in a real C compiler :p
Sent you a pull request via github w/ the changes.
p.s., I managed to re-solder the adapter's popped off microusb port over the weekend. It was as bloody annoying as you mentioned. Shorted internally after I soldered the pins on and ended up shoving a piece of solderwick underneath and sitting a pencil iron tip on it until it sucked off most of the solder. Whoever decided to put the pins underneath the microusb shield should be tied to an ant farm and covered w/ honey
While I was handling it, capacitor C11 fell off too...you might want to jiggle test all the chips to make sure the reflow worked well enough...