Skip to content

Commit

Permalink
Add wireless EU support
Browse files Browse the repository at this point in the history
  • Loading branch information
S4mpsa committed Oct 12, 2022
1 parent 6dae62c commit 1d6c0eb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
62 changes: 46 additions & 16 deletions hud/powerdisplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local updateInterval = 100

local energyData = {
intervalCounter = 1,
animationCounter = 1,
readings = {},
startTime = 0,
endTime = 0,
Expand All @@ -41,7 +42,8 @@ local energyData = {
energyIn = getNewTable(updateInterval, 0),
energyOut = getNewTable(updateInterval, 0),
input = 0,
output = 0
output = 0,
wirelessMode = false
}

local energyUnit = "EU"
Expand Down Expand Up @@ -78,6 +80,7 @@ end
function powerDisplay.widget(glasses, data)
if data ~= nil then
if data.state ~= states.MISSING then

local currentEU = math.abs(math.floor(data.storedEU))
local maxEU = math.abs(math.floor(data.EUCapacity))

Expand Down Expand Up @@ -124,6 +127,23 @@ function powerDisplay.widget(glasses, data)
else
energyData.offset = energyData.offset + 10*(energyData.energyPerTick / energyData.highestOutput)
end
--Wireless EU addition
if data.wirelessEU > 0 then
currentEU = data.wirelessEU
maxEU = 2^1023
data.wirelessMode = true
percentage = energyData.animationCounter / 500
if energyData.energyPerTick > 0 then
energyData.animationCounter = energyData.animationCounter + 1
else
energyData.animationCounter = energyData.animationCounter - 1
end
if energyData.animationCounter > 500 then
energyData.animationCounter = 1
elseif energyData.animationCounter < 0 then
energyData.animationCounter = 500
end
end

if #hudObjects < #glasses then
for i = 1, #glasses do
Expand Down Expand Up @@ -197,6 +217,7 @@ function powerDisplay.widget(glasses, data)
else
hudObjects[i].dynamic.currentEU.setText(parser.splitNumber(currentEU).." "..energyUnit)
end

if maxEU > 9000000000000000000 then
hudObjects[i].dynamic.maxEU.setText(""..energyUnit)
hudObjects[i].dynamic.maxEU.setPosition(x+w-25, y-9)
Expand Down Expand Up @@ -230,22 +251,27 @@ function powerDisplay.widget(glasses, data)

local fillTimeString = ""
local fillTime = 0
if energyData.energyPerTick > 0 then
fillTime = math.floor((maxEU-currentEU)/(energyData.energyPerTick*20))
fillTimeString = "Full: " .. time.format(math.abs(fillTime))
elseif energyData.energyPerTick < 0 then
fillTime = math.floor((currentEU)/(energyData.energyPerTick*20))
fillTimeString = "Empty: " .. time.format(math.abs(fillTime))
else
fillTimeString = ""
end
if math.abs(fillTime) > 500000 or percentage < 0.05 then
hudObjects[i].dynamic.percentage.setPosition(x+w/2-20, y-9)
hudObjects[i].dynamic.percentage.setText(tostring(math.floor(percentage*10000000)/100000).."%")
if data.wirelessMode then
hudObjects[i].dynamic.percentage.setText("")
else
hudObjects[i].dynamic.percentage.setPosition(x+w/2-5, y-9)
hudObjects[i].dynamic.percentage.setText(parser.percentage(percentage))
if energyData.energyPerTick > 0 then
fillTime = math.floor((maxEU-currentEU)/(energyData.energyPerTick*20))
fillTimeString = "Full: " .. time.format(math.abs(fillTime))
elseif energyData.energyPerTick < 0 then
fillTime = math.floor((currentEU)/(energyData.energyPerTick*20))
fillTimeString = "Empty: " .. time.format(math.abs(fillTime))
else
fillTimeString = ""
end
if math.abs(fillTime) > 500000 or percentage < 0.05 then
hudObjects[i].dynamic.percentage.setPosition(x+w/2-20, y-9)
hudObjects[i].dynamic.percentage.setText(tostring(math.floor(percentage*10000000)/100000).."%")
else
hudObjects[i].dynamic.percentage.setPosition(x+w/2-5, y-9)
hudObjects[i].dynamic.percentage.setText(parser.percentage(percentage))
end
end

if data.state == states.OFF then
hudObjects[i].dynamic.state.setText("Disabled")
else
Expand All @@ -255,7 +281,11 @@ function powerDisplay.widget(glasses, data)
hudObjects[i].dynamic.state.setText("")
end
end
hudObjects[i].dynamic.filltime.setText(fillTimeString)
if data.wirelessMode then
hudObjects[i].dynamic.filltime.setText("")
else
hudObjects[i].dynamic.filltime.setText(fillTimeString)
end
local function moveForward(quad)
if energyData.energyPerTick > 0 then
local remaining = math.min((x+w-hIO-6) - (x+3+energyBarLength*percentage), ((x+w-hIO-6 - x+3) / 8))
Expand Down
2 changes: 1 addition & 1 deletion nidas_version.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return "1.33"
return "1.34"
7 changes: 4 additions & 3 deletions server/usecases/get-lsc-status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ local function exec(address, name, location)
storedEU = parser.getInteger(sensorInformation[2]),
EUCapacity = parser.getInteger(sensorInformation[3]),
problems = problems,
passiveLoss = parser.getInteger(sensorInformation[4]),
passiveLoss = parser.getInteger(sensorInformation[4] or 0),
location = location,
EUIn = parser.getInteger(sensorInformation[5]),
EUOut = parser.getInteger(sensorInformation[6])
EUIn = parser.getInteger(sensorInformation[5] or 0),
EUOut = parser.getInteger(sensorInformation[6] or 0),
wirelessEU = parser.getInteger(sensorInformation[12] or 0)
}
return status
end
Expand Down

0 comments on commit 1d6c0eb

Please sign in to comment.