Compare commits
10 Commits
7bab5e6be0
...
4e491790ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e491790ad | |||
| 00375ebb3a | |||
| 9b06e72f8b | |||
| aa3673bd1b | |||
| 6d33f3eb85 | |||
| 9253f00eef | |||
| 9c75bfb89c | |||
| 6165808cc4 | |||
| cc0aef4434 | |||
| b84450a360 |
171
PowerManager.lua
171
PowerManager.lua
@@ -1,171 +0,0 @@
|
|||||||
--Programm um an den PC angeschlossene TE und RF Speicherzellen grafisch darzustellen
|
|
||||||
|
|
||||||
local component = require( "component" )
|
|
||||||
local gpu = component.gpu
|
|
||||||
local event = require( "event" )
|
|
||||||
|
|
||||||
local splashText = "Stromanzeige - Ultimate ROG RGB LED Edition"
|
|
||||||
local frameTitle = "Power Monitor - Klicken zum Beenden"
|
|
||||||
|
|
||||||
local oldW, oldH = gpu.getResolution()
|
|
||||||
local newW = 160
|
|
||||||
local newH = 50
|
|
||||||
local numberOfPanels = 2
|
|
||||||
local panelWidth = (newW / numberOfPanels)
|
|
||||||
gpu.setResolution(newW, newH)
|
|
||||||
|
|
||||||
function clearScreen()
|
|
||||||
local w,h = gpu.getResolution()
|
|
||||||
drawLine(1, 1, w, h, 0x000000)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function drawLine(startX, startY, stopX, stopY, colorOfLine)
|
|
||||||
local oldColor = gpu.getBackground(false)
|
|
||||||
gpu.setBackground(colorOfLine, false)
|
|
||||||
gpu.fill(startX, startY, stopX, stopY, " ")
|
|
||||||
gpu.setBackground(oldColor, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
function powerBar( label, y, x, value, maxVal, colorOfBar, show, unit, border)
|
|
||||||
local oldColor = gpu.getBackground(false)
|
|
||||||
local borderSymbol = " "
|
|
||||||
local barSymbol = " "
|
|
||||||
local percentage = (value * 100 / maxVal)
|
|
||||||
local redGraphValue = 20
|
|
||||||
|
|
||||||
if percentage <= redGraphValue then
|
|
||||||
colorOfBar = 0xf00000
|
|
||||||
end
|
|
||||||
drawLine(border, y, x, 2, 0x000000)
|
|
||||||
w = math.floor( value * (x / maxVal) )
|
|
||||||
p = math.floor( (w / x) * 100 )
|
|
||||||
gpu.set( border, y, label .. ": " .. tostring( p ) .. "%" )
|
|
||||||
drawLine(border, y+1, x, 1, 0x222222)
|
|
||||||
drawLine(border, y+1, w, 1, colorOfBar)
|
|
||||||
gpu.setBackground( oldColor, false )
|
|
||||||
if show then
|
|
||||||
local valStr = formatBig( value ) .. unit
|
|
||||||
local n = string.len( valStr )
|
|
||||||
gpu.set( (x+3) - n, y, valStr )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function formatBig( value )
|
|
||||||
local output = ""
|
|
||||||
local valRem = 0
|
|
||||||
local valPart = 0
|
|
||||||
while value > 0 do
|
|
||||||
valRem = math.floor( value / 1000 )
|
|
||||||
valPart = value - (valRem * 1000)
|
|
||||||
if output == "" then
|
|
||||||
output = string.format( "%03d", valPart )
|
|
||||||
elseif valRem == 0 then
|
|
||||||
output = valPart .. "," .. output
|
|
||||||
else
|
|
||||||
output = string.format( "%03d", valPart ) .. "," .. output
|
|
||||||
end
|
|
||||||
value = valRem
|
|
||||||
end
|
|
||||||
return output
|
|
||||||
end
|
|
||||||
|
|
||||||
function getCells()
|
|
||||||
local countDcOrb = 0
|
|
||||||
local countTEcell = 0
|
|
||||||
local countRfTCell = 0
|
|
||||||
|
|
||||||
local TEcell = component.list( "energy_device" )
|
|
||||||
local RfTCell = component.list("rftools_powercell")
|
|
||||||
|
|
||||||
local cellsID = {}
|
|
||||||
|
|
||||||
for address, name in pairs(TEcell) do
|
|
||||||
countTEcell = countTEcell + 1
|
|
||||||
if countTEcell > 1 then
|
|
||||||
cellsID[address] = "TE Zelle".." "..countTEcell
|
|
||||||
else
|
|
||||||
cellsID[address] = "TE Zelle"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for address, name in pairs(RfTCell) do
|
|
||||||
countRfTCell = countRfTCell + 1
|
|
||||||
if countRfTCell > 1 then
|
|
||||||
cellsID[address] = "RfT Zelle".." "..countRfTCell
|
|
||||||
else
|
|
||||||
cellsID[address] = "RfT Zelle"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return cellsID
|
|
||||||
end
|
|
||||||
|
|
||||||
function getTotal()
|
|
||||||
local totalPower = 0
|
|
||||||
local totalMaxPower = 0
|
|
||||||
local cellid = getCells()
|
|
||||||
for address, name in pairs(cellid) do
|
|
||||||
local cell = component.proxy( address )
|
|
||||||
totalPower = totalPower + cell.getEnergyStored()
|
|
||||||
totalMaxPower = totalMaxPower + cell.getMaxEnergyStored()
|
|
||||||
end
|
|
||||||
return totalPower, totalMaxPower
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawPanel(x, y, width, height, color)
|
|
||||||
drawLine(x, y, width, height, color)
|
|
||||||
drawLine(x + 1, y + 1, width -1, height - 1, 0x000000)
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawDesktop()
|
|
||||||
--Title
|
|
||||||
local titleHeight = 3
|
|
||||||
drawPanel(1, 1, newW, titleHeight, 0xffffff)
|
|
||||||
gpu.set((newW - #frameTitle) / 2, 2, frameTitle)
|
|
||||||
local cellsID = getCells()
|
|
||||||
local count = 0
|
|
||||||
local t = titleHeight
|
|
||||||
|
|
||||||
for i = numberOfPanels - 1, 0, -1
|
|
||||||
do
|
|
||||||
drawPanel(panelWidth*i+1, titleHeight + 1, panelWidth, newH - titleHeight, 0xffffff)
|
|
||||||
if i == 0 then
|
|
||||||
for address, name in pairs(cellsID) do
|
|
||||||
local cell = component.proxy( address )
|
|
||||||
count = count + 1
|
|
||||||
t = t + 3
|
|
||||||
powerBar( name, t , panelWidth - 6, cell.getEnergyStored(), cell.getMaxEnergyStored() , 0x00bb00, true, "RF", panelWidth*i+2)
|
|
||||||
end
|
|
||||||
elseif i == 1 then
|
|
||||||
local totalPower, totalMaxPower = getTotal()
|
|
||||||
powerBar( "Gesamt", titleHeight + 3, panelWidth - 6, totalPower, totalMaxPower, 0x00bb00, true, "RF", panelWidth*i+2)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
clearScreen()
|
|
||||||
drawLine(1, 1, newW, 1, 0xbbbbbb)
|
|
||||||
gpu.set((newW - #splashText) / 2, 24, splashText)
|
|
||||||
os.sleep(1)
|
|
||||||
clearScreen()
|
|
||||||
|
|
||||||
while true do
|
|
||||||
drawDesktop()
|
|
||||||
local id, _, x, y = event.pullMultiple("touch", "interrupted")
|
|
||||||
if id == "interrupted" then
|
|
||||||
print("soft interrupt, closing")
|
|
||||||
goto quit
|
|
||||||
elseif id == "touch" then
|
|
||||||
goto quit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
::quit::
|
|
||||||
gpu.setResolution( oldW, oldH )
|
|
||||||
clearScreen()
|
|
||||||
print("Programm beendet.")
|
|
||||||
19
README.md
Normal file
19
README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Repo Template for git-tool compatible layout
|
||||||
|
|
||||||
|
unfinished
|
||||||
|
|
||||||
|
## Shortcut
|
||||||
|
FIXME: Explain shortcuts generically and remove logic from actual program, instead replace with generic configurable shortcut
|
||||||
|
|
||||||
|
Of course this project will be installed with a shell shortcut. To run the application with GUI just type `powerman`.
|
||||||
|
If you want to know what arguments can be used put an `-h` behind it.
|
||||||
|
For example:
|
||||||
|
`powerman -h` displays the help text for the application it starts.
|
||||||
|
`powerman update -h` displays the help text for the git-tool. (May change in the future)
|
||||||
|
The shortcut is installed in /usr/bin. If this folder does not exist yet it will be created.
|
||||||
|
|
||||||
|
## Application
|
||||||
|
FIXME: Explain layout of repo for generic Application here
|
||||||
|
|
||||||
|
This is where the fun begins. On startup you will be greeted with a desktop.
|
||||||
|
These features are yet to be implemented, but you can expect things like Powermanagement (Hey, the original idea behind this Project), AE2 interfaces (including Autocrafting and stuff), redstone control, chat application for communicating with friends on a server and many more! Just wait till we are done (which will be never because there are many ideas)
|
||||||
@@ -5,8 +5,6 @@ local helpText = "This is a tool for displaying and managing your Power cells an
|
|||||||
" '' -h - this help text\n" ..
|
" '' -h - this help text\n" ..
|
||||||
" '' update <update argument>"
|
" '' update <update argument>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if #args<1 then
|
if #args<1 then
|
||||||
dofile("/usr/PowerManager/main.lua")
|
dofile("/usr/PowerManager/main.lua")
|
||||||
return
|
return
|
||||||
|
|||||||
253
updater.lua
253
updater.lua
@@ -1,253 +0,0 @@
|
|||||||
local args = {...}
|
|
||||||
local internet=require("internet")
|
|
||||||
local filesystem=require("filesystem")
|
|
||||||
local unicode=require("unicode")
|
|
||||||
|
|
||||||
YES = {"y","yes","Y","Yes","YES"}
|
|
||||||
NO = {"n","no","N","No","NO"}
|
|
||||||
|
|
||||||
SupportedRemotes = {
|
|
||||||
Github = {
|
|
||||||
BaseUrl = "https://github.com/",
|
|
||||||
Implemented = true
|
|
||||||
},
|
|
||||||
Gitea = {
|
|
||||||
BaseUrl = "https://git.realrobin.io",
|
|
||||||
Implemented = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Repository = {}
|
|
||||||
|
|
||||||
---default repo to update
|
|
||||||
DefaultRepository = {
|
|
||||||
Owner = "seesberger",
|
|
||||||
Name = "PowerManager",
|
|
||||||
ShortName = "powerman",
|
|
||||||
RepoIdentifier = "seesberger/PowerManager",
|
|
||||||
Remote = SupportedRemotes.Github,
|
|
||||||
CurrentBranch = "master",
|
|
||||||
CurrentLocalPath = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultTemporaryDownloadPath = "/home/.tmp/git/"
|
|
||||||
DefaultInstallationPath = "/usr/"
|
|
||||||
|
|
||||||
local function askYesOrNoQuestion(question, expectedTrue, expectedFalse, defaultYesOnEnter)
|
|
||||||
local function checkContains(array,value)
|
|
||||||
for idx, val in array do
|
|
||||||
if value == val then return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if defaultYesOnEnter==true then print(question.." [Y/n]") else print(question.." [y/N]") end
|
|
||||||
while true do
|
|
||||||
local userInput = io.read("l")
|
|
||||||
if checkContains({""}, userInput) then return defaultYesOnEnter end
|
|
||||||
if checkContains(expectedTrue, userInput) then return true end
|
|
||||||
if checkContains(expectedFalse, userInput) then return false end
|
|
||||||
print("Please answer with yes or no. You can also press ENTER to choose the default option.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function askTextQuestion(question, defaultAnswerOnEnter, allowOnly)
|
|
||||||
local allowedInputsString = ""
|
|
||||||
for idx, entry in allowOnly do allowedInputsString = allowedInputsString..entry end
|
|
||||||
if allowOnly then print(question.." ["..allowedInputsString.."]")
|
|
||||||
else print(question) end
|
|
||||||
local userInput = nil
|
|
||||||
local found = false
|
|
||||||
repeat
|
|
||||||
userInput = io.read("l")
|
|
||||||
if allowOnly then
|
|
||||||
for idx, entry in allowOnly do if entry == userInput then found = true end end
|
|
||||||
else break end
|
|
||||||
until found
|
|
||||||
if userInput == "" then return defaultAnswerOnEnter else return userInput end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- todo: pcall and catch errors
|
|
||||||
local function downloadRepo(repository, autoOverride)
|
|
||||||
|
|
||||||
local function validateRepositoryIdentifier(repository)
|
|
||||||
if not repository.RepoIdentifier:match("^[%w-.]*/[%w-.]*$") then
|
|
||||||
print('"'..repository.RepoIdentifier..'" does not look like a valid repo identifier.\nShould be <owner>/<reponame>')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
validateRepositoryIdentifier(repository)
|
|
||||||
|
|
||||||
local function makeDirIfNotExists(target)
|
|
||||||
if filesystem.exists(target) then
|
|
||||||
if not filesystem.isDirectory(target) then error("target directory already exists and is not a directory.") end
|
|
||||||
if filesystem.get(target).isReadOnly() then error("target directory is read-only.") end
|
|
||||||
else
|
|
||||||
if not filesystem.makeDirectory(target) then error("directory creation failed") end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- FIXME: If download only mode is enabled, set this to /home. still todo
|
|
||||||
local targetDownloadPath = DefaultTemporaryDownloadPath..repository.RepoIdentifier
|
|
||||||
repository.CurrentLocalPath = targetDownloadPath
|
|
||||||
local success, err = pcall(makeDirIfNotExists, targetDownloadPath)
|
|
||||||
if not success then error("the download failed because of filesystem errors.") end
|
|
||||||
|
|
||||||
local function fetchFilesAndSubdirs(repository, remoteType, dir)
|
|
||||||
dir = dir or "" -- default value, start at root dir
|
|
||||||
if remoteType == SupportedRemotes.Github then
|
|
||||||
print("fetching contents for "..repository.RepoIdentifier..dir)
|
|
||||||
local githubApiUrl="https://api.github.com/repos/"..repository.RepoIdentifier.."/contents"..dir
|
|
||||||
local success,chunks=pcall(internet.request,githubApiUrl)
|
|
||||||
local raw=""
|
|
||||||
local files={}
|
|
||||||
local directories={}
|
|
||||||
|
|
||||||
if success then for chunk in chunks do raw=raw..chunk end
|
|
||||||
else error("you've been cut off. Serves you right.") end
|
|
||||||
|
|
||||||
--- do not question the magic of the outer gods
|
|
||||||
--- turns raw response into t, which has usable fields.
|
|
||||||
raw=raw:gsub("%[","{"):gsub("%]","}"):gsub("(\".-\"):(.-[,{}])",function(a,b) return "["..a.."]="..b end)
|
|
||||||
local t=load("return "..raw)()
|
|
||||||
|
|
||||||
for i=1,#t do
|
|
||||||
if t[i].type=="dir" then
|
|
||||||
table.insert(directories,dir.."/"..t[i].name)
|
|
||||||
|
|
||||||
local subfiles,subdirs=fetchFilesAndSubdirs(repository.RepoIdentifier,dir.."/"..t[i].name)
|
|
||||||
for i=1,#subfiles do
|
|
||||||
table.insert(files,subfiles[i])
|
|
||||||
end
|
|
||||||
for i=1,#subdirs do
|
|
||||||
table.insert(directories,subdirs[i])
|
|
||||||
end
|
|
||||||
else
|
|
||||||
files[#files+1]=dir.."/"..t[i].name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return files, directories
|
|
||||||
else error("not Implemented") end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- fetch and make dirs in the target download path recursively
|
|
||||||
local files,dirs=fetchFilesAndSubdirs(repository.RepoIdentifier, "", SupportedRemotes.Github)
|
|
||||||
for i=1,#dirs do
|
|
||||||
local success, err = pcall(makeDirIfNotExists, targetDownloadPath..dirs[i])
|
|
||||||
if not success then error(("the download failed because of filesystem errors. %x"):format(err)) end
|
|
||||||
end
|
|
||||||
|
|
||||||
local replaceMode="ask"
|
|
||||||
if autoOverride == true then replaceMode = "always" end
|
|
||||||
|
|
||||||
local function downloadFiles(files, targetDownloadPath, replaceMode)
|
|
||||||
for i=1,#files do
|
|
||||||
local replace=nil
|
|
||||||
if filesystem.exists(targetDownloadPath..files[i]) then
|
|
||||||
--- FIXME dir löschen statt error
|
|
||||||
if filesystem.isDirectory(targetDownloadPath..files[i]) then error("file "..targetDownloadPath..files[i].." blocked by directory with same name!") end
|
|
||||||
if not replaceMode == "ask" then
|
|
||||||
replace = (replaceMode=="always")
|
|
||||||
replace = not (replaceMode=="never")
|
|
||||||
end
|
|
||||||
else print("\nFile "..targetDownloadPath..files[i].." already exists.\nReplace with new version?") end
|
|
||||||
local response=""
|
|
||||||
if replace == nil then
|
|
||||||
--- FIXME: ggf falsch und buggy
|
|
||||||
local userInput = askTextQuestion("\nFile "..targetDownloadPath..files[i].." already exists.\nReplace with new version?","n",{"y","n","A","S"})
|
|
||||||
|
|
||||||
if userInput=="A" then
|
|
||||||
replaceMode="always"
|
|
||||||
userInput="y"
|
|
||||||
elseif userInput=="S" then
|
|
||||||
replaceMode="never"
|
|
||||||
userInput="n"
|
|
||||||
elseif userInput == "y" then replace=true
|
|
||||||
elseif userInput == "n" then replace=false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if replace then filesystem.remove(targetDownloadPath..files[i]) end
|
|
||||||
if replace or replace == nil then
|
|
||||||
--- TODO @Freddy: Coole Animation hinzufügen
|
|
||||||
print("downloading file "..files[i])
|
|
||||||
local url=repository.Remote.BaseUrl..repository.Name.."/"..repository.CurrentBranch..files[i]
|
|
||||||
local success,response=pcall(internet.request,url)
|
|
||||||
if success then
|
|
||||||
local raw=""
|
|
||||||
for chunk in response do
|
|
||||||
raw=raw..chunk
|
|
||||||
end
|
|
||||||
print("writing to "..targetDownloadPath..files[i])
|
|
||||||
local file=io.open(targetDownloadPath..files[i],"w")
|
|
||||||
if file then -- might be nil under wierd circumstances
|
|
||||||
file:write(raw)
|
|
||||||
file:close()
|
|
||||||
end
|
|
||||||
else error("a file did not download correctly. aborting") end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
success, err = pcall(downloadFiles, files, targetDownloadPath, replaceMode)
|
|
||||||
if success then print("All files downloaded successfully.") else error(err) end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function installShortcut(currentRepoPath, shortcutName)
|
|
||||||
print("installing shortcut...")
|
|
||||||
os.execute("mv "..currentRepoPath.."shortcut.lua /usr/bin/"..shortcutName..".lua")
|
|
||||||
end
|
|
||||||
|
|
||||||
--- todo: automatic read of dependency list (txt file containing lines with <link> <dst> or somethink like it)
|
|
||||||
--- removeme
|
|
||||||
local function legacyInstallDependencies(enabled)
|
|
||||||
if enabled==true then
|
|
||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/shapes_default.lua /lib/shapes_default.lua")
|
|
||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/GUI.lua /lib/GUI.lua")
|
|
||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/term_mod.lua /lib/term_mod.lua")
|
|
||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/tech_demo.lua /home/GUI_tech_demo.lua")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- fix legacy shit
|
|
||||||
local function runFullInstallTask(repository)
|
|
||||||
--- first, download the actual repo.
|
|
||||||
--- then, find dependencies - if then exist, download and install them
|
|
||||||
--- then, install the actual program
|
|
||||||
legacyInstallDependencies(true) --only for testing while new version not implemented yet
|
|
||||||
print("downloading "..repository.RepoIdentifier)
|
|
||||||
downloadRepo(repository, false) --enable autooverwrite in other situations still todo
|
|
||||||
installShortcut(repository.CurrentLocalPath)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function printHelpText()
|
|
||||||
local helpText = "This updater pulls the git files for installation and application updates.\n"..
|
|
||||||
"Usage:\n" ..
|
|
||||||
"updater <option> - no args: manual update and install\n"..
|
|
||||||
" '' -h or --help - this help text"
|
|
||||||
print(helpText)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function run(cliArgs)
|
|
||||||
if #cliArgs<1 then
|
|
||||||
print("No Arguments given. For help, please check -h or --help")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if cliArgs[1] == ("-h" or "--help") then
|
|
||||||
printHelpText()
|
|
||||||
return
|
|
||||||
elseif cliArgs[1] == ("--setup-default") then
|
|
||||||
--- ask user about repo
|
|
||||||
Repository = DefaultRepository
|
|
||||||
if askYesOrNoQuestion("Use default config? (github::seesberger/PowerManager)?",YES,NO,true) then runFullInstallTask(Repository) end
|
|
||||||
return
|
|
||||||
else
|
|
||||||
print('"'..cliArgs[1]..'" - Bad argument. Try --help')
|
|
||||||
return
|
|
||||||
print("Program exited.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
run(args)
|
|
||||||
Reference in New Issue
Block a user