1
0
Fork 0

Move ports and update from internet

This commit is contained in:
Casey 2024-01-12 22:04:57 +03:00
parent 6dcd1cd1b2
commit 637827c6af
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
4 changed files with 35 additions and 18 deletions

View File

@ -4,7 +4,7 @@ end)
if not wlan then error("no wireless interface") end if not wlan then error("no wireless interface") end
wlan.open(9999) wlan.open(9998)
local respondedTurtles = {} local respondedTurtles = {}
local keyStates = {} local keyStates = {}
@ -17,19 +17,19 @@ function()
elseif ev == "key_up" then keyStates[keycode] = false elseif ev == "key_up" then keyStates[keycode] = false
end end
if not repeating then if ev == "key" and not repeating then
if keycode == keys.up then if keycode == keys.up then
wlan.transmit(9999, 9999, { _ = "move", dir = "fwd", dig = keyStates[keys.leftShift] }) wlan.transmit(9999, 9998, { _ = "move", dir = "fwd", dig = keyStates[keys.leftShift] })
elseif keycode == keys.down then elseif keycode == keys.down then
wlan.transmit(9999, 9999, { _ = "move", dir = "bck" }) wlan.transmit(9999, 9998, { _ = "move", dir = "bck" })
elseif keycode == keys.left then elseif keycode == keys.left then
wlan.transmit(9999, 9999, { _ = "move", dir = "rotl" }) wlan.transmit(9999, 9998, { _ = "move", dir = "rotl" })
elseif keycode == keys.right then elseif keycode == keys.right then
wlan.transmit(9999, 9999, { _ = "move", dir = "rotr" }) wlan.transmit(9999, 9998, { _ = "move", dir = "rotr" })
elseif keycode == keys.pageUp then elseif keycode == keys.pageUp then
wlan.transmit(9999, 9999, { _ = "move", dir = "up", dig = keyStates[keys.leftShift] }) wlan.transmit(9999, 9998, { _ = "move", dir = "up", dig = keyStates[keys.leftShift] })
elseif keycode == keys.pageDown then elseif keycode == keys.pageDown then
wlan.transmit(9999, 9999, { _ = "move", dir = "down", dig = keyStates[keys.leftShift] }) wlan.transmit(9999, 9998, { _ = "move", dir = "down", dig = keyStates[keys.leftShift] })
end end
end end
end end
@ -38,7 +38,7 @@ end,
function() function()
while true do while true do
local _, side, chan, rchan, data, dist = os.pullEvent("modem_message") local _, side, chan, rchan, data, dist = os.pullEvent("modem_message")
if chan == 9999 and rchan == chan then if chan == 9998 and rchan == 9999 then
if data._ == "WakeUp" then if data._ == "WakeUp" then
respondedTurtles[data.from] = { true, "Hello!" } respondedTurtles[data.from] = { true, "Hello!" }
elseif data._ == "Ack" then elseif data._ == "Ack" then

View File

@ -8,7 +8,7 @@ wlan.open(9999)
local ID = os.getComputerID() local ID = os.getComputerID()
wlan.transmit(9999, 9999, { wlan.transmit(9998, 9999, {
["_"] = "WakeUp", ["_"] = "WakeUp",
["from"] = ID ["from"] = ID
}) })
@ -16,7 +16,7 @@ wlan.transmit(9999, 9999, {
parallel.waitForAll(function() parallel.waitForAll(function()
while true do while true do
local _, side, chan, rchan, data, dist = os.pullEvent("modem_message") local _, side, chan, rchan, data, dist = os.pullEvent("modem_message")
if chan == 9999 and chan == rchan then if chan == 9999 and rchan == 9998 then
if data._ == "move" then if data._ == "move" then
wlan.transmit(rchan, chan, { ["_"] = "Ack", ["from"] = ID }) wlan.transmit(rchan, chan, { ["_"] = "Ack", ["from"] = ID })
if data.tgt == nil or data.tgt == ID then if data.tgt == nil or data.tgt == ID then

View File

@ -3,6 +3,8 @@ if not turtle then
return return
end end
local base_path = "https://git.salushnes.solutions/hkc/cc-stuff/raw/branch/master/turtos"
_G._TOS_VER = "N/A" _G._TOS_VER = "N/A"
local tos_ver_fp = io.open("/.tos-ver", "r") local tos_ver_fp = io.open("/.tos-ver", "r")
if tos_ver_fp then if tos_ver_fp then
@ -10,12 +12,28 @@ if tos_ver_fp then
tos_ver_fp:close() tos_ver_fp:close()
end end
if fs.exists("/disk/update.json") then local function getFile(url, path)
local info_fp = io.open("/disk/update.json", "r") local r, err = http.get(url)
local info = textutils.unserializeJSON(info_fp:read("a")) io.write("GET " .. path .. " ... ")
info_fp:close() if not r then
print("FAIL: " .. err)
return false, err
end
io.open(path, "w"):write(r.readAll()):close()
io.write("OK\n")
end
local req, err = http.get(base_path .. "/update.json")
if not req then
printError("Failed to get update info:", err)
else
local info = textutils.unserializeJSON(req.readAll())
req.close()
print("OTP version: " .. info.ver) print("OTP version: " .. info.ver)
print("H/W version: " .. _TOS_VER) print("H/W version: " .. _TOS_VER)
if info.ver == _TOS_VER then if info.ver == _TOS_VER then
print("Running on latest firmware") print("Running on latest firmware")
else else
@ -27,8 +45,7 @@ if fs.exists("/disk/update.json") then
term.write(" [DEL] ...") term.write(" [DEL] ...")
fs.delete(file.dst) fs.delete(file.dst)
end end
fs.copy("/disk" .. file.src, file.dst) getFile(base_path .. file.src, file.dst)
print(" OK, copied from", file.src)
end end
print("Writing new version info") print("Writing new version info")
io.open("/.tos-ver", "w"):write(info.ver):close() io.open("/.tos-ver", "w"):write(info.ver):close()

View File

@ -1,5 +1,5 @@
{ {
"ver": "0.0.2", "ver": "0.0.3",
"files": [ "files": [
{ "src": "/startup.lua", "dst": "/startup.lua" }, { "src": "/startup.lua", "dst": "/startup.lua" },
{ "src": "/main.lua", "dst": "/main.lua" } { "src": "/main.lua", "dst": "/main.lua" }