Hey All,
I've had this finished for some time now, and been meaning to post my experience with it.
I had fallen in love with the idea of the
ALPS RKJXT Rotary Encoder/Joystick as a solution for input on my CarPC. So, I started looking into it further.
I tried to build a board, that used various hardware means to decode the quadrature signal from the encoder, including the
usdigital ls chips but eventually was unsuccessful.
My solution always depended upon a game controller interface called the
GPWiz, which turned a low going switch input into an HID signal, and the
Girder software to intercept that HID signal, and turn it into something useful for the front-end I was using.
Eventually, I gave up on decoding the Quadrature signal in hardware and built a LUA method to be used in Girder under the HID "OnRead" method, and shorted a couple pins on the board I'd built to hold the decoding chip.
Over all, it works quite well, and I'm happy with it. I haven't actually installed it in a car, since I'm still in the process of designing/building my setup, and haven't actually installed anything yet. However, the device seemed to work well, and felt good, and was VERY compact.
I've included below, the code for Girder, as well as a couple screenshots of the EaglePCB drawings of the two boards I used. I'll get some photos of the whole thing later today, and post those as well.
Code:
function HidRead( data )
-- This uses the bitwise shortcut method of decoding a quadrature signal found at;
-- http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv8.pdf
-- Set some variables we'll use later
envTable = _G
envTable = getfenv(1)
if envTable.prev == nil then envTable.prev = "" end
if envTable.prevBits == nil then envTable.prevBits = 0 end
local s=""
local index=0
local curBits = envTable.prevBits
if data then
-- Check each byte in the string. This comes in the format XX XX XX XX XX XX
for b in string.gfind(data, ".") do
-- For the GPWiz 32, the first two bytes are always 77 77. The third byte contains info we're interested in
-- namely 01 == Quadrature A and 02 == Quadrature B
if index == 2 then
curBits = math.band(string.byte(b),3)
end
-- Concatenate this bit back onto the data string
s =s .. string.format("%02X ", string.byte(b))
index = index+1
end
end
-- Check to see if our current data string is the same as the last, we don't want to do anything if it is.
if s ~= envTable.prev then
-- Bitshift our current byte one to the right so we can compare previous B with current A
shifted = math.bshiftr(curBits,1)
result = math.bxor(envTable.prevBits, shifted)
-- Now we need to filter our result to only the second bit
andResult = math.band(result, 1)
if andResult == 0 and curBits ~= envTable.prevBits then
gir.TriggerEvent("Quadrature Increased", 18, 0)
elseif andResult == 1 and curBits ~= envTable.prevBits then
gir.TriggerEvent("Quadrature Decreased", 18, 0)
end
gir.TriggerEvent(s, 239)
end
envTable.prevBits = curBits
envTable.prev = s
end