2021-08-10 22:29:20 +00:00
|
|
|
// Functions for reading from on-board sensors and performing other ship-local
|
|
|
|
// monitoring tasks.
|
2021-08-06 08:57:07 +00:00
|
|
|
|
|
|
|
// we rebuild the sensor list with every invocation, because things change
|
|
|
|
function buildSensorList {
|
|
|
|
local sList is Lexicon().
|
|
|
|
list SENSORS in SensorList.
|
|
|
|
for s in SensorList {
|
2021-08-08 01:33:51 +00:00
|
|
|
if not sList:HasKey(s:type) {
|
|
|
|
sList:add(s:type, s).
|
|
|
|
}
|
2021-08-06 08:57:07 +00:00
|
|
|
}
|
|
|
|
return sList.
|
|
|
|
}
|
|
|
|
|
|
|
|
function HasSensor {
|
|
|
|
parameter s.
|
|
|
|
local sList is buildSensorList().
|
|
|
|
return sList:HasKey(s).
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReadSensor {
|
|
|
|
parameter s.
|
|
|
|
|
|
|
|
local sList is buildSensorList().
|
|
|
|
if not sList:HasKey(s) {
|
|
|
|
return -1. // TODO: is -1 an impossible result for all sensors? I suspect not...
|
|
|
|
}
|
2021-08-09 17:51:24 +00:00
|
|
|
|
|
|
|
if not sList[s]:ACTIVE {
|
|
|
|
sList[s]:Toggle().
|
|
|
|
}
|
|
|
|
|
|
|
|
// UGH, this appears to be the only way to do this.
|
|
|
|
local ret is -1.
|
|
|
|
if s = "PRES" {
|
|
|
|
set ret to SHIP:SENSORS:PRES.
|
|
|
|
}
|
|
|
|
if s = "TEMP" {
|
|
|
|
set ret to SHIP:SENSORS:TEMP.
|
|
|
|
}
|
|
|
|
if s = "ACC" {
|
|
|
|
set ret to SHIP:SENSORS:ACC:MAG.
|
|
|
|
}
|
|
|
|
if s = "GRAV" {
|
|
|
|
set ret to SHIP:SENSORS:GRAV.
|
|
|
|
}
|
|
|
|
if s = "LIGHT" {
|
|
|
|
set ret to SHIP:SENSORS:LIGHT.
|
|
|
|
}
|
|
|
|
|
|
|
|
// turn off the sensor when we're done with it
|
|
|
|
sList[s]:Toggle().
|
|
|
|
|
|
|
|
return ret.
|
2021-08-06 08:57:07 +00:00
|
|
|
}
|
2021-08-10 22:29:20 +00:00
|
|
|
|