fix terminate thing for good hopefully and add the throttles table to the config so it persists on restart
This commit is contained in:
70
main.lua
70
main.lua
@@ -160,25 +160,14 @@ Config.Autopilot = {
|
|||||||
AutopilotDesiredHeading = nil
|
AutopilotDesiredHeading = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
Throttles = {
|
Config.Throttles = nil
|
||||||
fore = {
|
|
||||||
name = nil,
|
|
||||||
side = nil
|
|
||||||
},
|
|
||||||
aft = {
|
|
||||||
name = nil,
|
|
||||||
side = nil
|
|
||||||
},
|
|
||||||
down = {
|
|
||||||
name = nil,
|
|
||||||
side = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ThrottleInit()
|
function ThrottleInit()
|
||||||
|
|
||||||
|
if Config.Throttles ~= nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local sides = {
|
local sides = {
|
||||||
"top",
|
"top",
|
||||||
"bottom",
|
"bottom",
|
||||||
@@ -227,8 +216,8 @@ function ThrottleInit()
|
|||||||
local initialState = initialStates[pname]
|
local initialState = initialStates[pname]
|
||||||
for k, v in pairs(currentState) do
|
for k, v in pairs(currentState) do
|
||||||
if initialState[k] ~= v then
|
if initialState[k] ~= v then
|
||||||
Throttles[throttleType].name = pname
|
Config.Throttles[throttleType].name = pname
|
||||||
Throttles[throttleType].side = k
|
Config.Throttles[throttleType].side = k
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -443,7 +432,7 @@ function UpdateStabilization()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function PollThrottle()
|
function PollThrottle()
|
||||||
for _, v in pairs(Throttles) do
|
for _, v in pairs(Config.Throttles) do
|
||||||
if v.name and v.side then
|
if v.name and v.side then
|
||||||
v.input = peripheral.wrap(v.name).getAnalogInput(v.side)
|
v.input = peripheral.wrap(v.name).getAnalogInput(v.side)
|
||||||
end
|
end
|
||||||
@@ -614,6 +603,15 @@ end
|
|||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
|
|
||||||
|
local configFile = io.open(Config.ConfigPath, "r")
|
||||||
|
if configFile then
|
||||||
|
local configContent = configFile:read("*all")
|
||||||
|
Config = stringToTable(configContent)
|
||||||
|
configFile:close()
|
||||||
|
else
|
||||||
|
print("Could not open the config file")
|
||||||
|
end
|
||||||
|
|
||||||
-- Initialize monitors - identify which monitor is for which type
|
-- Initialize monitors - identify which monitor is for which type
|
||||||
if Config.Monitors.InstrumentPanelMonitor == nil then
|
if Config.Monitors.InstrumentPanelMonitor == nil then
|
||||||
print("Identifying instrument panel monitor...")
|
print("Identifying instrument panel monitor...")
|
||||||
@@ -630,15 +628,6 @@ function Init()
|
|||||||
|
|
||||||
Thrusters = {}
|
Thrusters = {}
|
||||||
|
|
||||||
local configFile = io.open(Config.ConfigPath, "r")
|
|
||||||
if configFile then
|
|
||||||
local configContent = configFile:read("*all")
|
|
||||||
Config = stringToTable(configContent)
|
|
||||||
configFile:close()
|
|
||||||
else
|
|
||||||
print("Could not open the config file")
|
|
||||||
end
|
|
||||||
|
|
||||||
if Config.thrusterConfigPath ~= nil then
|
if Config.thrusterConfigPath ~= nil then
|
||||||
local thrusterConfigFile = io.open(Config.thrusterConfigPath, "r")
|
local thrusterConfigFile = io.open(Config.thrusterConfigPath, "r")
|
||||||
if thrusterConfigFile then
|
if thrusterConfigFile then
|
||||||
@@ -750,6 +739,18 @@ function collectSensorData()
|
|||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function WriteConfigFiles()
|
||||||
|
print("Writing to thruster config file.")
|
||||||
|
local thrusterConfigFile = fs.open(Config.thrusterConfigPath, "w+")
|
||||||
|
thrusterConfigFile.write(tableToString(Thrusters))
|
||||||
|
thrusterConfigFile.close()
|
||||||
|
|
||||||
|
print("Writing to config file")
|
||||||
|
local configFile = fs.open(Config.ConfigPath, "w+")
|
||||||
|
configFile.write(tableToString(Config))
|
||||||
|
configFile.close()
|
||||||
|
end
|
||||||
|
|
||||||
function Main()
|
function Main()
|
||||||
Init()
|
Init()
|
||||||
|
|
||||||
@@ -778,24 +779,13 @@ function Main()
|
|||||||
local event = nil
|
local event = nil
|
||||||
local function getTerminateEvent()
|
local function getTerminateEvent()
|
||||||
event = os.pullEventRaw("terminate")
|
event = os.pullEventRaw("terminate")
|
||||||
|
if event == "terminate" then print("Terminate Event Received") WriteConfigFiles() end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_sleep() os.sleep(0.1) end
|
local function do_sleep() os.sleep(0.1) end
|
||||||
|
|
||||||
parallel.waitForAny(do_sleep, getTerminateEvent)
|
parallel.waitForAny(do_sleep, getTerminateEvent)
|
||||||
if event == "terminate" then print("Terminate Event Received") break end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Writing to thruster config file.")
|
|
||||||
local thrusterConfigFile = fs.open(Config.thrusterConfigPath, "w+")
|
|
||||||
thrusterConfigFile.write(tableToString(Thrusters))
|
|
||||||
thrusterConfigFile.close()
|
|
||||||
|
|
||||||
print("Writing to config file")
|
|
||||||
local configFile = fs.open(Config.ConfigPath, "w+")
|
|
||||||
configFile.write(tableToString(Config))
|
|
||||||
configFile.close()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run the main function when the script starts
|
-- Run the main function when the script starts
|
||||||
|
|||||||
Reference in New Issue
Block a user