···3434By rightclicking on the board, advanced, edit lua parameters, you can customize these options:
35353636- `fontSize`: the size of the text for each line on the screen
3737-- `calibration_red_level`: The percent calibration below gauge will be red
3838-- `calibration_yellow_level`: The percent calibration below gauge will be red
3737+- `calibrationRedLevel`: The percent calibration below gauge will be red
3838+- `calibrationYellowLevel`: The percent calibration below gauge will be red
3939+- `calibrationSecondsRedLevel`: The time in seconds from last calibration above the time will be displayed in red. Default to 259200 (3 days / 72h)
4040+- `calibrationSecondsYellowLevel`: The time in seconds from last calibration above the time will be displayed in yellow. Default to 86400 (1 day / 24h)
+1-1
config.json
···11-{"events":[],"handlers":[{"code":"if coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend","filter":{"args":[],"signature":"update()","slotKey":"-2"},"key":"1"},{"code":"system.print(\"-----------------------------------\")\nsystem.print(\"DU-Mining-Units-Monitoring version 1.0.0\")\nsystem.print(\"-----------------------------------\")\n\nfont_size = 25 --export: font size for each line on the screen\ncalibration_red_level = 50 --export: The percent calibration below gauge will be red\ncalibration_yellow_level = 90 --export: The percent calibration below gauge will be yellow\n\nlocal renderScript = [[\nlocal json = require('dkjson')\nlogMessage(getInput())\nlocal screen_data = json.decode(getInput()) or {}\nlocal options = screen_data[1]\nlocal data = screen_data[2]\nimages = {}\nfor index,mu in ipairs(data) do\n images[index] = loadImage(mu[3][2])\nend\n\nlocal rx,ry = getResolution()\n\nlocal back=createLayer()\nlocal front=createLayer()\n\nfont_size = options[1]\ncalibration_red_level = options[2]\ncalibration_yellow_level = options[3]\n\nlocal mini=loadFont('Play',12)\nlocal small=loadFont('Play',14)\nlocal smallBold=loadFont('Play-Bold',18)\nlocal itemName=loadFont('Play-Bold',font_size)\nlocal itemNameSmall=loadFont('Play-Bold',font_size*0.75)\nlocal medV=loadFont('Play-Bold', 25)\nlocal bigV=loadFont('Play-Bold', 30)\nlocal big=loadFont('Play',38)\n\nsetBackgroundColor( 15/255,24/255,29/255)\n\nsetDefaultStrokeColor( back,Shape_Line,0,0,0,0.5)\nsetDefaultShadow( back,Shape_Line,6,0,0,0,0.5)\n\nsetDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1)\nsetDefaultFillColor( front,Shape_Text,0,0,0,1)\nsetDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1)\n\nfunction format_number(value)\n local formatted = value\n while true do\n formatted, k = string.gsub(formatted, \"^(-?%d+)(%d%d%d)\", '%1 %2')\n if (k==0) then\n break\n end\n end\n return formatted\nend\n\nfunction SecondsToClockString(seconds)\n local seconds = tonumber(seconds)\n\n if seconds == nil or seconds <= 0 then\n return \"-\";\n else\n days = string.format(\"%2.f\", math.floor(seconds/(3600*24)));\n hours = string.format(\"%2.f\", math.floor(seconds/3600 - (days*24)));\n mins = string.format(\"%2.f\", math.floor(seconds/60 - (hours*60) - (days*24*60)));\n secs = string.format(\"%2.f\", math.floor(seconds - hours*3600 - (days*24*60*60) - mins *60));\n str = \"\"\n if tonumber(days) > 0 then str = str .. days..\"d \" end\n if tonumber(hours) > 0 then str = str .. hours..\"h \" end\n if tonumber(mins) > 0 then str = str .. mins..\"m \" end\n if tonumber(secs) > 0 then str = str .. secs ..\"s\" end\n return str\n end\nend\n\nfunction round(value, precision)\n if precision then return utils.round(value / precision) * precision end\n return value >= 0 and math.floor(value+0.5) or math.ceil(value-0.5)\nend\n\nfunction renderHeader(title)\n local h_factor = 12\n local h = 35\n if subtitle ~= nil and subtitle ~= \"\" then\n h = 50\n end\n addLine( back,0,h+12,rx,h+12)\n addBox(front,0,12,rx,h)\n addText(front,smallBold,title,44,35)\nend\n\nlocal storageBar = createLayer()\nsetDefaultFillColor(storageBar,Shape_Text,110/255,166/255,181/255,1)\nsetDefaultFillColor(storageBar,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor(storageBar,Shape_Line,1,1,1,1)\n\nlocal storageYellow = createLayer()\nsetDefaultFillColor(storageYellow,Shape_Text,249/255,212/255,123/255,1)\nsetDefaultFillColor(storageYellow,Shape_Box,249/255,212/255,123/255,1)\n\nlocal storageDark = createLayer()\nsetDefaultFillColor(storageDark,Shape_Text,63/255,92/255,102/255,1)\nsetDefaultFillColor(storageDark,Shape_Box,13/255,24/255,28/255,1)\n\nlocal storageRed = createLayer()\nsetDefaultFillColor(storageRed,Shape_Text,177/255,42/255,42/255,1)\nsetDefaultFillColor(storageRed,Shape_Box,177/255,42/255,42/255,1)\n\nlocal storageGreen = createLayer()\nsetDefaultFillColor(storageGreen,Shape_Text,34/255,177/255,76/255,1)\nsetDefaultFillColor(storageGreen,Shape_Box,34/255,177/255,76/255,1)\n\nlocal imagesLayer = createLayer()\n\nfunction renderResistanceBar(title, index, status, time, prod_rate, calibration, efficiency, x, y, w, h, withTitle)\n local quantity_x_pos = font_size * 6.7\n local percent_x_pos = font_size * 2\n\n local colorLayer = storageGreen\n if status == \"STALLED\" then colorLayer = storageYellow end\n if status == \"STOPPED\" then colorLayer = storageRed end\n\n local gaugeColorLayer = storageGreen\n if calibration < calibration_yellow_level then gaugeColorLayer = storageYellow end\n if calibration < calibration_red_level then gaugeColorLayer = storageRed end\n\n addBox(storageBar,x,y,w,h)\n\n\n if withTitle then\n addText(storageBar, small, \"ORE\", x, y-5)\n addText(storageBar, small, \"STATUS\", x+w-60, y-5)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"TIME\", x+(w*0.3), y-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"RATE\", x+(w*0.45), y-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"CALIBRATION\", x+(w*0.6), y-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"EFFICIENCY\", x+(w*0.75), y-3)\n end\n\n addText(storageBar, itemName, title, x+15+font_size, y+h-font_size/2)\n addBox(gaugeColorLayer,x,y+h-3,w*calibration/100,3)\n\n if isImageLoaded(images[index]) then\n addImage(imagesLayer, images[index], x+10, y+5, font_size, font_size)\n end\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, SecondsToClockString(time), x+(w*0.3), y+(h/2)-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, format_number(prod_rate) .. 'L', x+(w*0.45), y+(h/2)-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, format_number(calibration) .. '%', x+(w*0.6), y+(h/2)-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, format_number(efficiency) .. '%', x+(w*0.75), y+(h/2)-3)\n\n setNextTextAlign(colorLayer, AlignH_Right, AlignV_Middle)\n addText(colorLayer, itemName, status, x+w-10, y+(h/2)-3)\n\n --addBox(storageDark,x+w-400,y+5,390,20)\nend\n\nrenderHeader('MINING UNITS MONITORING')\n\nstart_h = 75\n\nlocal h = font_size + font_size / 2\nfor i,mu in ipairs(data) do\n renderResistanceBar(mu[3][1], i, mu[1], mu[2], mu[4], mu[5], mu[6], 44, start_h, rx-88, h, i==1)\n start_h = start_h+h+10\nend\nrequestAnimationFrame(10)\n]]\n\nscreens = {}\nmining_units = {}\nfor slot_name, slot in pairs(unit) do\n if type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getElementClass\n then\n slot.slotname = slot_name\n if slot.getElementClass():lower() == 'screenunit' then\n table.insert(screens,slot)\n slot.setRenderScript(renderScript)\n elseif slot.getElementClass():lower() == 'miningunit' then\n table.insert(mining_units,slot)\n end\n end\nend\nif #screens == 0 then\n system.print(\"No screen detected\")\nelse\n table.sort(screens, function(a,b) return a.slotname < b.slotname end)\n local plural = \"\"\n if #screens > 1 then plural = \"s\" end\n system.print(#screens .. \" screen\" .. plural .. \" connected\")\nend\nif #mining_units == 0 then\n system.print(\"No mining unit detected\")\nelse\n table.sort(mining_units, function(a,b) return a.slotname < b.slotname end)\n local plural = \"\"\n if #mining_units > 1 then plural = \"s\" end\n system.print(#mining_units .. \" mining unit\" .. plural .. \" connected\")\nend\n\nfunction round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end\n\nores = {}\n\n--Nested Coroutines by Jericho\ncoroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n screen_data = {}\n for index, mu in pairs(mining_units) do\n local ore_id = mu.getActiveOre()\n if ores[ore_id] == nil then\n local item_data = system.getItem(ore_id)\n ores[ore_id] = {\n item_data.displayName,\n item_data.iconPath\n }\n end\n local mu_data = {\n mu.getStatus(),\n round(mu.getRemainingTime()),\n ores[ore_id],\n round(mu.getProductionRate()*100)/100,\n round(mu.getCalibrationRate()*100),\n round(mu.getEfficiency()*100),\n }\n table.insert(screen_data, mu_data)\n coroutine.yield(coroutinesTable[1])\n end\n for index, screen in pairs(screens) do\n local options = {font_size, calibration_red_level, calibration_yellow_level}\n local data_to_send = {options, screen_data}\n screen.setScriptInput(json.encode(data_to_send))\n end\n end\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"0"}],"methods":[],"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}}}}
11+{"events":[],"handlers":[{"code":"if coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend","filter":{"args":[],"signature":"update()","slotKey":"-2"},"key":"1"},{"code":"system.print(\"----------------------------------------\")\nsystem.print(\"DU-Mining-Units-Monitoring version 1.2.0\")\nsystem.print(\"----------------------------------------\")\n\nfontSize = 25 --export: font size for each line on the screen\ncalibrationRedLevel = 50 --export: The percent calibration below gauge will be red\ncalibrationYellowLevel = 90 --export: The percent calibration below gauge will be yellow\ncalibrationSecondsRedLevel = 259200 --export: The time in seconds from last calibration above the time will be displayed in red. Default to 259200 (3 days / 72h)\ncalibrationSecondsYellowLevel = 86400 --export: The time in seconds from last calibration above the time will be displayed in yellow. Default to 86400 (1 day / 24h)\n\nlocal renderScript = [[\nlocal json = require('dkjson')\nlocal data = json.decode(getInput()) or {}\nimages = {}\nfor index,mu in ipairs(data) do\n images[index] = loadImage(\"resources_generated/env/\" .. mu[3][2])\nend\n\nlocal rx,ry = getResolution()\n\nlocal back=createLayer()\nlocal front=createLayer()\n\nfont_size = ]] .. fontSize .. [[\n\n\nlocal mini=loadFont('Play',12)\nlocal small=loadFont('Play',14)\nlocal smallBold=loadFont('Play-Bold',18)\nlocal itemName=loadFont('Play-Bold',font_size)\nlocal itemNameSmall=loadFont('Play-Bold',font_size*0.75)\nlocal itemNameXs=loadFont('Play-Bold',font_size*0.65)\n\nsetBackgroundColor( 15/255,24/255,29/255)\n\nsetDefaultStrokeColor( back,Shape_Line,0,0,0,0.5)\nsetDefaultShadow( back,Shape_Line,6,0,0,0,0.5)\n\nsetDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1)\nsetDefaultFillColor( front,Shape_Text,0,0,0,1)\nsetDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1)\n\nfunction format_number(value)\n local formatted = value\n while true do\n formatted, k = string.gsub(formatted, \"^(-?%d+)(%d%d%d)\", '%1 %2')\n if (k==0) then\n break\n end\n end\n return formatted\nend\n\nfunction SecondsToClockString(a)local a=tonumber(a)if a==nil or a<=0 then return\"-\"else days=string.format(\"%2.f\",math.floor(a/(3600*24)))hours=string.format(\"%2.f\",math.floor(a/3600-days*24))mins=string.format(\"%2.f\",math.floor(a/60-hours*60-days*24*60))secs=string.format(\"%2.f\",math.floor(a-hours*3600-days*24*60*60-mins*60))str=\"\"if tonumber(days)>0 then str=str..days..\"d \"end;if tonumber(hours)>0 then str=str..hours..\"h \"end;if tonumber(mins)>0 then str=str..mins..\"m \"end;if tonumber(secs)>0 then str=str..secs..\"s\"end;return str end end\n\nfunction round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end\n\nfunction renderHeader(title)\n local h_factor = 12\n local h = 35\n addLine( back,0,h+12,rx,h+12)\n addBox(front,0,12,rx,h)\n addText(front,smallBold,title,44,35)\nend\n\nlocal storageBar = createLayer()\nsetDefaultFillColor(storageBar,Shape_Text,110/255,166/255,181/255,1)\nsetDefaultFillColor(storageBar,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor(storageBar,Shape_Line,1,1,1,1)\n\nlocal storageYellow = createLayer()\nsetDefaultFillColor(storageYellow,Shape_Text,249/255,212/255,123/255,1)\nsetDefaultFillColor(storageYellow,Shape_Box,249/255,212/255,123/255,1)\n\nlocal storageDark = createLayer()\nsetDefaultFillColor(storageDark,Shape_Text,63/255,92/255,102/255,1)\nsetDefaultFillColor(storageDark,Shape_Box,13/255,24/255,28/255,1)\n\nlocal storageRed = createLayer()\nsetDefaultFillColor(storageRed,Shape_Text,177/255,42/255,42/255,1)\nsetDefaultFillColor(storageRed,Shape_Box,177/255,42/255,42/255,1)\n\nlocal storageGreen = createLayer()\nsetDefaultFillColor(storageGreen,Shape_Text,34/255,177/255,76/255,1)\nsetDefaultFillColor(storageGreen,Shape_Box,34/255,177/255,76/255,1)\n\nlocal imagesLayer = createLayer()\n\nfunction renderResistanceBar(title, index, status, time, prod_rate, calibration, efficiency, cal_time, x, y, w, h, withTitle)\n local quantity_x_pos = font_size * 6.7\n local percent_x_pos = font_size * 2\n\n local colorLayer = storageGreen\n if status == \"STALLED\" then colorLayer = storageYellow end\n if status == \"STOPPED\" then colorLayer = storageRed end\n\n local gaugeColorLayer = storageGreen\n if calibration < ]] .. calibrationRedLevel .. [[ then gaugeColorLayer = storageYellow end\n if calibration < ]] .. calibrationYellowLevel .. [[ then gaugeColorLayer = storageRed end\n\n local CalibrationTimeColorLayer = storageGreen\n if cal_time > ]] .. calibrationSecondsYellowLevel .. [[ then CalibrationTimeColorLayer = storageYellow end\n if cal_time > ]] .. calibrationSecondsRedLevel .. [[ then CalibrationTimeColorLayer = storageRed end\n\n addBox(storageBar,x,y,w,h)\n\n\n if withTitle then\n addText(storageBar, small, \"ORE\", x, y-5)\n addText(storageBar, small, \"STATUS\", x+w-60, y-5)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"TIME\", x+(w*0.3), y-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"RATE\", x+(w*0.45), y-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"LAST CALIBRATION\", x+(w*0.6), y-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)\n addText(storageBar, small, \"EFFICIENCY\", x+(w*0.75), y-3)\n end\n\n addText(storageBar, itemName, title, x+15+font_size, y+h-font_size/2)\n addBox(gaugeColorLayer,x,y+h-3,w*calibration/100,3)\n\n if isImageLoaded(images[index]) then\n addImage(imagesLayer, images[index], x+10, y+5, font_size, font_size)\n end\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, SecondsToClockString(time), x+(w*0.3), y+(h/2)-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, format_number(prod_rate) .. 'L', x+(w*0.45), y+(h/2)-3)\n setNextTextAlign(CalibrationTimeColorLayer, AlignH_Center, AlignV_Middle)\n addText(CalibrationTimeColorLayer, itemNameXs, SecondsToClockString(cal_time), x+(w*0.6), y+(h/4)-3)\n setNextTextAlign(gaugeColorLayer, AlignH_Center, AlignV_Middle)\n addText(gaugeColorLayer, itemNameXs, format_number(calibration) .. '%', x+(w*0.6), y+(h/4)+(h/4)+(h/4)-3)\n setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)\n addText(storageBar, itemNameSmall, format_number(efficiency) .. '%', x+(w*0.75), y+(h/2)-3)\n\n setNextTextAlign(colorLayer, AlignH_Right, AlignV_Middle)\n addText(colorLayer, itemName, status, x+w-10, y+(h/2)-3)\n\n --addBox(storageDark,x+w-400,y+5,390,20)\nend\n\nrenderHeader('MINING UNITS MONITORING')\n\nstart_h = 75\n\nlocal h = font_size + font_size / 2\nfor i,mu in ipairs(data) do\n renderResistanceBar(mu[3][1], i, mu[1], mu[2], mu[4], mu[5], mu[6], mu[7], 44, start_h, rx-88, h, i==1)\n start_h = start_h+h+15\nend\nrequestAnimationFrame(10)\n]]\n\nscreens = {}\nmining_units = {}\nfor slot_name, slot in pairs(unit) do\n if type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getElementClass\n then\n slot.slotname = slot_name\n if slot.getElementClass():lower() == 'screenunit' then\n table.insert(screens,slot)\n slot.setRenderScript(renderScript)\n elseif slot.getElementClass():lower() == 'miningunit' then\n table.insert(mining_units,slot)\n end\n end\nend\nif #screens == 0 then\n system.print(\"No screen detected\")\nelse\n table.sort(screens, function(a,b) return a.slotname < b.slotname end)\n local plural = \"\"\n if #screens > 1 then plural = \"s\" end\n system.print(#screens .. \" screen\" .. plural .. \" connected\")\nend\nif #mining_units == 0 then\n system.print(\"No mining unit detected\")\nelse\n table.sort(mining_units, function(a,b) return a.slotname < b.slotname end)\n local plural = \"\"\n if #mining_units > 1 then plural = \"s\" end\n system.print(#mining_units .. \" mining unit\" .. plural .. \" connected\")\nend\n\nfunction round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end\n\nores = {}\n\n--Nested Coroutines by Jericho\ncoroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n screen_data = {}\n for index, mu in pairs(mining_units) do\n local ore_id = mu.getActiveOre()\n if ores[ore_id] == nil then\n local item_data = system.getItem(ore_id)\n ores[ore_id] = {\n item_data.displayName,\n item_data.iconPath:gsub(\"resources_generated/env/\",\"\")\n }\n end\n local mu_data = {\n mu.getStatus(),\n round(mu.getRemainingTime()),\n ores[ore_id],\n round(mu.getProductionRate()*100)/100,\n round(mu.getCalibrationRate()*100),\n round(mu.getEfficiency()*100),\n round(mu.getLastExtractionTime()),\n }\n table.insert(screen_data, mu_data)\n coroutine.yield(coroutinesTable[1])\n end\n for index, screen in pairs(screens) do\n screen.setScriptInput(json.encode(screen_data))\n end\n end\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"0"}],"methods":[],"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}}}}
+33-58
source/unit/start.lua
···11-system.print("-----------------------------------")
22-system.print("DU-Mining-Units-Monitoring version 1.0.0")
33-system.print("-----------------------------------")
11+system.print("----------------------------------------")
22+system.print("DU-Mining-Units-Monitoring version 1.2.0")
33+system.print("----------------------------------------")
4455-font_size = 25 --export: font size for each line on the screen
66-calibration_red_level = 50 --export: The percent calibration below gauge will be red
77-calibration_yellow_level = 90 --export: The percent calibration below gauge will be yellow
55+fontSize = 25 --export: font size for each line on the screen
66+calibrationRedLevel = 50 --export: The percent calibration below gauge will be red
77+calibrationYellowLevel = 90 --export: The percent calibration below gauge will be yellow
88+calibrationSecondsRedLevel = 259200 --export: The time in seconds from last calibration above the time will be displayed in red. Default to 259200 (3 days / 72h)
99+calibrationSecondsYellowLevel = 86400 --export: The time in seconds from last calibration above the time will be displayed in yellow. Default to 86400 (1 day / 24h)
810911local renderScript = [[
1012local json = require('dkjson')
1111-logMessage(getInput())
1212-local screen_data = json.decode(getInput()) or {}
1313-local options = screen_data[1]
1414-local data = screen_data[2]
1313+local data = json.decode(getInput()) or {}
1514images = {}
1615for index,mu in ipairs(data) do
1717- images[index] = loadImage(mu[3][2])
1616+ images[index] = loadImage("resources_generated/env/" .. mu[3][2])
1817end
19182019local rx,ry = getResolution()
···2221local back=createLayer()
2322local front=createLayer()
24232525-font_size = options[1]
2626-calibration_red_level = options[2]
2727-calibration_yellow_level = options[3]
2424+font_size = ]] .. fontSize .. [[
2525+28262927local mini=loadFont('Play',12)
3028local small=loadFont('Play',14)
3129local smallBold=loadFont('Play-Bold',18)
3230local itemName=loadFont('Play-Bold',font_size)
3331local itemNameSmall=loadFont('Play-Bold',font_size*0.75)
3434-local medV=loadFont('Play-Bold', 25)
3535-local bigV=loadFont('Play-Bold', 30)
3636-local big=loadFont('Play',38)
3232+local itemNameXs=loadFont('Play-Bold',font_size*0.65)
37333834setBackgroundColor( 15/255,24/255,29/255)
3935···5652 return formatted
5753end
58545959-function SecondsToClockString(seconds)
6060- local seconds = tonumber(seconds)
5555+function SecondsToClockString(a)local a=tonumber(a)if a==nil or a<=0 then return"-"else days=string.format("%2.f",math.floor(a/(3600*24)))hours=string.format("%2.f",math.floor(a/3600-days*24))mins=string.format("%2.f",math.floor(a/60-hours*60-days*24*60))secs=string.format("%2.f",math.floor(a-hours*3600-days*24*60*60-mins*60))str=""if tonumber(days)>0 then str=str..days.."d "end;if tonumber(hours)>0 then str=str..hours.."h "end;if tonumber(mins)>0 then str=str..mins.."m "end;if tonumber(secs)>0 then str=str..secs.."s"end;return str end end
61566262- if seconds == nil or seconds <= 0 then
6363- return "-";
6464- else
6565- days = string.format("%2.f", math.floor(seconds/(3600*24)));
6666- hours = string.format("%2.f", math.floor(seconds/3600 - (days*24)));
6767- mins = string.format("%2.f", math.floor(seconds/60 - (hours*60) - (days*24*60)));
6868- secs = string.format("%2.f", math.floor(seconds - hours*3600 - (days*24*60*60) - mins *60));
6969- str = ""
7070- if tonumber(days) > 0 then str = str .. days.."d " end
7171- if tonumber(hours) > 0 then str = str .. hours.."h " end
7272- if tonumber(mins) > 0 then str = str .. mins.."m " end
7373- if tonumber(secs) > 0 then str = str .. secs .."s" end
7474- return str
7575- end
7676-end
7777-7878-function round(value, precision)
7979- if precision then return utils.round(value / precision) * precision end
8080- return value >= 0 and math.floor(value+0.5) or math.ceil(value-0.5)
8181-end
5757+function round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end
82588359function renderHeader(title)
8460 local h_factor = 12
8561 local h = 35
8686- if subtitle ~= nil and subtitle ~= "" then
8787- h = 50
8888- end
8962 addLine( back,0,h+12,rx,h+12)
9063 addBox(front,0,12,rx,h)
9164 addText(front,smallBold,title,44,35)
···1148711588local imagesLayer = createLayer()
11689117117-function renderResistanceBar(title, index, status, time, prod_rate, calibration, efficiency, x, y, w, h, withTitle)
9090+function renderResistanceBar(title, index, status, time, prod_rate, calibration, efficiency, cal_time, x, y, w, h, withTitle)
11891 local quantity_x_pos = font_size * 6.7
11992 local percent_x_pos = font_size * 2
12093···12396 if status == "STOPPED" then colorLayer = storageRed end
1249712598 local gaugeColorLayer = storageGreen
126126- if calibration < calibration_yellow_level then gaugeColorLayer = storageYellow end
127127- if calibration < calibration_red_level then gaugeColorLayer = storageRed end
9999+ if calibration < ]] .. calibrationRedLevel .. [[ then gaugeColorLayer = storageYellow end
100100+ if calibration < ]] .. calibrationYellowLevel .. [[ then gaugeColorLayer = storageRed end
101101+102102+ local CalibrationTimeColorLayer = storageGreen
103103+ if cal_time > ]] .. calibrationSecondsYellowLevel .. [[ then CalibrationTimeColorLayer = storageYellow end
104104+ if cal_time > ]] .. calibrationSecondsRedLevel .. [[ then CalibrationTimeColorLayer = storageRed end
128105129106 addBox(storageBar,x,y,w,h)
130107···137114 setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)
138115 addText(storageBar, small, "RATE", x+(w*0.45), y-3)
139116 setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)
140140- addText(storageBar, small, "CALIBRATION", x+(w*0.6), y-3)
117117+ addText(storageBar, small, "LAST CALIBRATION", x+(w*0.6), y-3)
141118 setNextTextAlign(storageBar, AlignH_Center, AlignV_Bottom)
142119 addText(storageBar, small, "EFFICIENCY", x+(w*0.75), y-3)
143120 end
···152129 addText(storageBar, itemNameSmall, SecondsToClockString(time), x+(w*0.3), y+(h/2)-3)
153130 setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)
154131 addText(storageBar, itemNameSmall, format_number(prod_rate) .. 'L', x+(w*0.45), y+(h/2)-3)
155155- setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)
156156- addText(storageBar, itemNameSmall, format_number(calibration) .. '%', x+(w*0.6), y+(h/2)-3)
132132+ setNextTextAlign(CalibrationTimeColorLayer, AlignH_Center, AlignV_Middle)
133133+ addText(CalibrationTimeColorLayer, itemNameXs, SecondsToClockString(cal_time), x+(w*0.6), y+(h/4)-3)
134134+ setNextTextAlign(gaugeColorLayer, AlignH_Center, AlignV_Middle)
135135+ addText(gaugeColorLayer, itemNameXs, format_number(calibration) .. '%', x+(w*0.6), y+(h/4)+(h/4)+(h/4)-3)
157136 setNextTextAlign(storageBar, AlignH_Center, AlignV_Middle)
158137 addText(storageBar, itemNameSmall, format_number(efficiency) .. '%', x+(w*0.75), y+(h/2)-3)
159138···169148170149local h = font_size + font_size / 2
171150for i,mu in ipairs(data) do
172172- renderResistanceBar(mu[3][1], i, mu[1], mu[2], mu[4], mu[5], mu[6], 44, start_h, rx-88, h, i==1)
173173- start_h = start_h+h+10
151151+ renderResistanceBar(mu[3][1], i, mu[1], mu[2], mu[4], mu[5], mu[6], mu[7], 44, start_h, rx-88, h, i==1)
152152+ start_h = start_h+h+15
174153end
175154requestAnimationFrame(10)
176155]]
···208187 system.print(#mining_units .. " mining unit" .. plural .. " connected")
209188end
210189211211-function round(value, precision)
212212- if precision then return utils.round(value / precision) * precision end
213213- return value >= 0 and math.floor(value+0.5) or math.ceil(value-0.5)
214214-end
190190+function round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end
215191216192ores = {}
217193···227203 local item_data = system.getItem(ore_id)
228204 ores[ore_id] = {
229205 item_data.displayName,
230230- item_data.iconPath
206206+ item_data.iconPath:gsub("resources_generated/env/","")
231207 }
232208 end
233209 local mu_data = {
···237213 round(mu.getProductionRate()*100)/100,
238214 round(mu.getCalibrationRate()*100),
239215 round(mu.getEfficiency()*100),
216216+ round(mu.getLastExtractionTime()),
240217 }
241218 table.insert(screen_data, mu_data)
242219 coroutine.yield(coroutinesTable[1])
243220 end
244221 for index, screen in pairs(screens) do
245245- local options = {font_size, calibration_red_level, calibration_yellow_level}
246246- local data_to_send = {options, screen_data}
247247- screen.setScriptInput(json.encode(data_to_send))
222222+ screen.setScriptInput(json.encode(screen_data))
248223 end
249224 end
250225}