kOS/lib/sensors.ks
2021-08-07 21:33:51 -04:00

29 lines
598 B
Plaintext

// 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 {
if not sList:HasKey(s:type) {
sList:add(s:type, s).
}
}
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...
}
return s:DISPLAY:TOSCALAR.
}