Last active
June 20, 2017 19:35
-
-
Save brentpicasso/bf870aab94d6809e8db761ae923e27de to your computer and use it in GitHub Desktop.
ShiftX2 random 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 | |
function rndc() | |
return math.random(0,255) | |
end | |
function sxOnUpdate() | |
for i=0,9,1 do | |
r = rndc() | |
g = rndc() | |
b = rndc() | |
sxSetLed(i,1,r,g,b,0) | |
end | |
end | |
function sxOnBut(d) | |
println('button: ' ..d[1]) | |
end | |
function sxOnInit() | |
print('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