-
Notifications
You must be signed in to change notification settings - Fork 20
DisplayScripting
Josh Wardell edited this page Sep 22, 2020
·
12 revisions
CANserver uses a simplified version of Lua scripting to process CAN data and send it to the microDisplays. This document contains documentation to write your own display scrips and several examples that can be copy/pasted into the Server web page. The Analysis signals (CAN messages) needed for each display script can also be copy and pasted into the Server Analysis page.
ToDo - document Lua scripting here.
Refer to official Lua documentation
Script:
if (CANServer_getAnalysisVar("DisplayOn") < 1) then
return "1m t0b1000r"
end
local battPowerKW = (CANServer_getAnalysisVar("BattVolts") * CANServer_getAnalysisVar("BattAmps") / 1000.0)
local graphBattPower = math.floor(math.min(math.max((24) * (battPowerKW) / (300), -24), 24))
return "65535c" .. math.floor(battPowerKW * 10) .. "vWK Bu" .. graphBattPower .. "b0m100r"
Analysis signals:
{
"n": "BattVolts",
"fid": 306,
"sb": 0,
"bl": 16,
"f": 0.01,
"so": 0,
"s": false,
"bo": true,
"v": 1
}
{
"n": "BattAmps",
"fid": 306,
"sb": 16,
"bl": 16,
"f": -0.1,
"so": 0,
"s": true,
"bo": true,
"v": 1
}
Rear Script:
if (CANServer_getAnalysisVar("DisplayOn") < 1) then
return "1m t0b1000r"
end
local rearTorque = CANServer_getAnalysisVar("RearTorque")
local graphRearTorque = math.floor(math.min(math.max((24) * (rearTorque) / (400), -24), 24))
return "65535c" .. math.floor(rearTorque * 10) .. "vMNu" .. graphRearTorque .. "b0m100r"
Front Script:
if (CANServer_getAnalysisVar("DisplayOn") < 1) then
return "1m t0b1000r"
end
local frontTorque = CANServer_getAnalysisVar("FrontTorque")
local graphFrontTorque = math.floor(math.min(math.max((24) * (frontTorque) / (400), -24), 24))
return "65535c" .. math.floor(frontTorque * 10) .. "vMNu" .. graphFrontTorque .. "b0m100r"
Analysis signals:
{
"n": "RearTorque",
"fid": 472,
"sb": 24,
"bl": 13,
"f": 0.25,
"so": 0,
"s": true,
"bo": true,
"v": 1
}
{
"n": "FrontTorque",
"fid": 469,
"sb": 24,
"bl": 13,
"f": 0.25,
"so": 0,
"s": true,
"bo": true,
"v": 1
}
Script:
if (CANServer_getAnalysisVar("DisplayOn") < 1) then
return "1m t0b1000r"
end
local battPowerKW = (CANServer_getAnalysisVar("BattVolts") * CANServer_getAnalysisVar("BattAmps") / 1000.0)
local graphBattPower = math.floor(math.min(math.max((24) * (battPowerKW) / (300), -24), 24))
local bsr = CANServer_getAnalysisVar("BSR");
local bsl = CANServer_getAnalysisVar("BSL");
local bsd = 0;
if (bsl == 1 or bsl == 2) then
bsd = 1;
end
if (bsr == 1 or bsr == 2) then
bsd = bsd + 2;
end
if (bsd > 0) then
return bsd .. "v63488c6m1000r";
else
local speedUnitText = "HMK"
local displaySpeed = CANServer_getAnalysisVar("VehSpeed")
if (CANServer_getAnalysisVar("DistanceUnitMiles") == 1) then
speedUnitText = "HPM"
displaySpeed = displaySpeed * 0.6213712;
end
return "65535c" .. math.floor(displaySpeed * 10) .. "v" .. speedUnitText .. "u"
.. graphBattPower .. "b0m100r"
end
Analysis signals:
Script:
if (CANServer_getAnalysisVar("DisplayOn") < 1) then
return "1m4s t0b1000r"
end
local rearTorque = CANServer_getAnalysisVar("RearTorque")
local graphRearTorque = math.floor(math.min(math.max((24) * (rearTorque) / (400), -24), 24))
return "65535c1s -BATTERY STATUS- " .. CANServer_getAnalysisVar("Range") .. "MI " .. CANServer_getAnalysisVar("uSOE") .. "%SOC " .. CANServer_getAnalysisVar("MinBattTemp")*1.8+32 .. "F " .. CANServer_getAnalysisVar("battTempPct") .. "% " .. CANServer_getAnalysisVar("EnergyRemaining") .. " OF ".. CANServer_getAnalysisVar("FullPackEnergy") .. "KWHt" .. graphRearTorque .. "b1m1o100r"
Analysis signals:
{
"n": "EnergyRemaining",
"fid": 850,
"sb": 11,
"bl": 11,
"f": 0.1,
"so": 0,
"s": false,
"bo": true,
"v": 1
}
{
"n": "FullPackEnergy",
"fid": 850,
"sb": 0,
"bl": 11,
"f": 0.1,
"so": 0,
"s": false,
"bo": true,
"v": 1
}
{
"n": "FullPackEnergy",
"fid": 850,
"sb": 0,
"bl": 11,
"f": 0.1,
"so": 0,
"s": false,
"bo": true,
"v": 1
}
{
"n": "Range",
"fid": 826,
"sb": 0,
"bl": 10,
"f": 1,
"so": 0,
"s": false,
"bo": true,
"v": 1
}
{
"n": "battTempPct",
"fid": 658,
"sb": 50,
"bl": 8,
"f": 0.4,
"so": 0,
"s": false,
"bo": true,
"v": 1
}
{
"n": "uSOE",
"fid": 826,
"sb": 56,
"bl": 7,
"f": 1,
"so": 0,
"s": false,
"bo": true,
"v": 1
}