Update drone.lua

This commit is contained in:
Innovation Inc 2021-01-06 04:07:38 -06:00 committed by GitHub
parent 6eef9c5584
commit 7ab1d91ce9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,27 +4,28 @@
local fwv = "0.01" local fwv = "0.01"
local d = component.proxy(component.list("drone")()) local d = component.proxy(component.list("drone")())
local t = component.proxy(component.list("tunnel")()) local t = component.proxy(component.list("modem")())
local eeprom = part "eeprom" local eeprom = part "eeprom"
local interweb = part "internet" local interweb = part "internet"
local fwaddress = "https://raw.githubusercontent.com/DremOSDeveloperTeam/opencomputers-drone/master/drone.lua" local fwaddress = "https://raw.githubusercontent.com/DremOSDeveloperTeam/opencomputers-drone/master/drone.lua"
local commport = 6500
while true do while true do
local evt,_,sender,_,_,name,cmd,a,b,c = computer.pullSignal() local evt,_,sender,port,_,name,cmd,a,b,c = computer.pullSignal()
if evt == "modem_message" and name == d.name() then if evt == "modem_message" and name == d.name() then
if cmd == "gfw" then -- Get Firmware Version if cmd == "gfw" then -- Get Firmware Version
t.send(fwv) t.broadcast(commport, fwv)
end end
if cmd == "ufw" then -- Update Firmware. Essentially stolen from https://github.com/osmarks/oc-drone/ if cmd == "ufw" then -- Update Firmware. Essentially stolen from https://github.com/osmarks/oc-drone/
local web_request = interweb.request(fwaddress) local web_request = interweb.request(fwaddress)
t.send("Updating firmware...") t.broadcast(commport, "Updating firmware...")
t.send(" Connecting...") t.broadcast(commport, " Connecting...")
web_request.finishConnect() web_request.finishConnect()
t.send(" Connected!") t.broadcast(commport, " Connected!")
t.send(" Downloading new firmware...") t.broadcast(commport, " Downloading new firmware...")
local full_response = "" local full_response = ""
while true do while true do
status "Processing" --status "Processing"
local chunk = web_request.read() local chunk = web_request.read()
if chunk then if chunk then
str.gsub(chunk, "\r\n", "\n") str.gsub(chunk, "\r\n", "\n")
@ -33,69 +34,69 @@ while true do
break break
end end
end end
t.send(" Firmware file downloaded!") t.broadcast(commport, " Firmware file downloaded!")
t.send(" Flashing new firmware...") t.broadcast(commport, " Flashing new firmware...")
eeprom.set(full_response) eeprom.set(full_response)
t.send(" Done flashing firmware!") t.broadcast(commport, " Done flashing firmware!")
t.send("Update process done! Please reboot the drone for changes to take effect.") t.broadcast(commport, "Update process done! Please reboot the drone for changes to take effect.")
end end
if cmd == "gst" then -- Get Status Text if cmd == "gst" then -- Get Status Text
t.send(d.name(),"gst",d.getStatusText()) t.broadcast(commport, d.name(),"gst",d.getStatusText())
end end
if cmd == "sst" then -- Set Status Text if cmd == "sst" then -- Set Status Text
t.send(d.name(),"sst",d.setStatusText(a)) t.broadcast(commport, d.name(),"sst",d.setStatusText(a))
end end
if cmd == "mov" then -- MOVe if cmd == "mov" then -- MOVe
d.move(a,b,c) d.move(a,b,c)
end end
if cmd == "gos" then -- Get OffSet if cmd == "gos" then -- Get OffSet
t.send(d.name(),"gos",d.getOffset()) t.broadcast(commport, d.name(),"gos",d.getOffset())
end end
if cmd == "gve" then -- Get VElocity if cmd == "gve" then -- Get VElocity
t.send(d.name(),"gv",d.getVelocity()) t.broadcast(commport, d.name(),"gv",d.getVelocity())
end end
if cmd == "gmv" then -- Get Max Velocity if cmd == "gmv" then -- Get Max Velocity
t.send(d.name(),"gmv",d.getMaxVelocity()) t.send(commport, d.name(),"gmv",d.getMaxVelocity())
end end
if cmd == "gac" then -- Get ACceleration if cmd == "gac" then -- Get ACceleration
t.send(d.name(),"ga",d.getAcceleration()) t.broadcast(commport, d.name(),"ga",d.getAcceleration())
end end
if cmd == "sac" then -- Set ACceleration if cmd == "sac" then -- Set ACceleration
d.setAcceleration(a) d.setAcceleration(a)
end end
if cmd == "glc" then -- Get Light Color if cmd == "glc" then -- Get Light Color
t.send(d.name(),"glc",d.getLightColor()) t.broadcast(commport, d.name(),"glc",d.getLightColor())
end end
if cmd == "slc" then -- Set Light Color (RGB is important!) if cmd == "slc" then -- Set Light Color (RGB is important!)
d.setLightColor(a) d.setLightColor(a)
end end
if cmd == "eif" then -- External Inventory Find (Instead of detect) if cmd == "eif" then -- External Inventory Find (Instead of detect)
local b, s = d.detect(a) local b, s = d.detect(a)
t.send(d.name(),"dct",b,s) t.broadcast(commport, d.name(),"dct",b,s)
end end
if cmd == "eco" then -- External inventory COmpare if cmd == "eco" then -- External inventory COmpare
t.send(d.name(),"c",d.compare(a)) t.broadcast(commport, d.name(),"c",d.compare(a))
end end
if cmd == "esu" then -- External inventory SUck if cmd == "esu" then -- External inventory SUck
o = d.suck(a, b) o = d.suck(a, b)
t.send(o) t.broadcast(commport, o)
end end
if cmd == "edr" then -- External inventory DRop if cmd == "edr" then -- External inventory DRop
o = d.drop(a, b) o = d.drop(a, b)
t.send(o) t.broadcast(commport, o)
end end
if cmd == "igs" then -- Internal inventory Get Slot if cmd == "igs" then -- Internal inventory Get Slot
t.send(d.select()) t.broadcast(commport, d.select())
end end
if cmd == "iss" then -- Internal inventory Set Slot if cmd == "iss" then -- Internal inventory Set Slot
o = d.select(a) o = d.select(a)
t.send(o) t.broadcast(commport, o)
end end
if cmd == "gis" then -- Get Inventory Size if cmd == "gis" then -- Get Inventory Size
t.send(d.inventorySize()) t.broadcast(commport, d.inventorySize())
end end
if cmd == "gsr" then -- Get Slot space Remaining if cmd == "gsr" then -- Get Slot space Remaining
t.send(d.space(a)) t.broadcast(commport, d.space(a))
end end
end end
end end