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
wlan.open(9999)
wlan.open(9998)
local respondedTurtles = {}
local keyStates = {}
@ -17,19 +17,19 @@ function()
elseif ev == "key_up" then keyStates[keycode] = false
end
if not repeating then
if ev == "key" and not repeating 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
wlan.transmit(9999, 9999, { _ = "move", dir = "bck" })
wlan.transmit(9999, 9998, { _ = "move", dir = "bck" })
elseif keycode == keys.left then
wlan.transmit(9999, 9999, { _ = "move", dir = "rotl" })
wlan.transmit(9999, 9998, { _ = "move", dir = "rotl" })
elseif keycode == keys.right then
wlan.transmit(9999, 9999, { _ = "move", dir = "rotr" })
wlan.transmit(9999, 9998, { _ = "move", dir = "rotr" })
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
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
@ -38,7 +38,7 @@ end,
function()
while true do
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
respondedTurtles[data.from] = { true, "Hello!" }
elseif data._ == "Ack" then

View File

@ -8,7 +8,7 @@ wlan.open(9999)
local ID = os.getComputerID()
wlan.transmit(9999, 9999, {
wlan.transmit(9998, 9999, {
["_"] = "WakeUp",
["from"] = ID
})
@ -16,7 +16,7 @@ wlan.transmit(9999, 9999, {
parallel.waitForAll(function()
while true do
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
wlan.transmit(rchan, chan, { ["_"] = "Ack", ["from"] = ID })
if data.tgt == nil or data.tgt == ID then

View File

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

View File

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