Last active
June 22, 2017 20:10
-
-
Save brentpicasso/76de936acc1ca7ee26efa1cb4373a28d to your computer and use it in GitHub Desktop.
Cycles ShiftX2 through all colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sxCan = 0 | |
sxId=0 | |
tickRate=30 | |
sxBright=0 | |
r = 0 | |
g = 0 | |
b = 0 | |
step = 10 | |
function sxOnUpdate() | |
if r < 255 then | |
r = r + step | |
else | |
r = 255 | |
if g < 255 then | |
g = g + step | |
else | |
g = 255 | |
if b < 255 then | |
b = b + step | |
else | |
r = 0 | |
g = 0 | |
b = 0 | |
end | |
end | |
end | |
sxSetLed(i, 9, r, g, b, 0) | |
end | |
function sxOnBut(d) | |
println('button: ' ..d[1]) | |
end | |
function sxOnInit() | |
println('sx onInit') | |
end | |
--ShiftX2 library functions-- | |
function sxSetLed(id,l,r,g,b,f) | |
sxTx(10,{id,l,r,g,b,f}) | |
end | |
function sxSetLinearThresh(id,s,th,r,g,b,f) | |
sxTx(41,{id,s,spl(th),sph(th),r,g,b,f}) | |
end | |
function sxSetAlertThresh(id,tid,th,r,g,b,f) | |
sxTx(21,{id,tid,spl(th),sph(th),r,g,b,f}) | |
end | |
function setBaseConfig(bright) | |
sxTx(3,{bright}) | |
end | |
function setAlert(id,r,g,b,f) | |
sxTx(20,{id,r,g,b,f}) | |
end | |
function updateAlert(id,v) | |
if v~=nil then sxTx(22,{id,spl(v),sph(v)}) end | |
end | |
function sxCfgLinearGraph(rs,ls,lr,hr) | |
sxTx(40,{rs,ls,spl(lr),sph(lr),spl(hr),sph(hr)}) | |
end | |
function updateLinearGraph(v) | |
sxTx(42,{spl(v),sph(v)}) | |
end | |
function sxInit() | |
println('config shiftX2') | |
setBaseConfig(sxBright) | |
if sxOnInit~=nil then sxOnInit() end | |
end | |
function sxChkCan() | |
id,ext,data=rxCAN(sxCan,0) | |
if id==sxCanId then sxInit() end | |
if id==sxCanId+60 and sxOnBut~=nil then sxOnBut(data) end | |
end | |
function sxProcess() | |
sxChkCan() | |
if sxOnUpdate~=nil then sxOnUpdate() end | |
end | |
function sxTx(offset, data) | |
txCAN(sxCan, sxCanId + offset, 1, data) | |
sleep(10) | |
end | |
function spl(v) return bit.band(v,0xFF) end | |
function sph(v) return bit.rshift(bit.band(v,0xFF00),8) end | |
function onTick() | |
sxProcess() | |
end | |
sxCanId = 0xE3600 + (256 * sxId) | |
println('shiftx2 base id ' ..sxCanId) | |
setTickRate(tickRate) | |
sxInit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment