mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-22 13:30:36 +01:00
Implemented available sensors
This commit is contained in:
parent
10a1f32057
commit
3025ea7a5b
@ -1,4 +1,4 @@
|
||||
__debug_build__ = False
|
||||
__debug_build__ = True
|
||||
__disable_shaders__ = False
|
||||
__version__ = "0.6.3"
|
||||
__variant__ = "beta"
|
||||
@ -2868,13 +2868,10 @@ class SidebandApp(MDApp):
|
||||
self.root.ids.telemetry_s_location.active = self.sideband.config["telemetry_s_location"]
|
||||
self.root.ids.telemetry_s_location.bind(active=self.telemetry_location_toggle)
|
||||
|
||||
self.root.ids.telemetry_s_orientation.active = self.sideband.config["telemetry_s_orientation"]
|
||||
self.root.ids.telemetry_s_orientation.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_battery.active = self.sideband.config["telemetry_s_battery"]
|
||||
self.root.ids.telemetry_s_battery.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_barometer.active = self.sideband.config["telemetry_s_barometer"]
|
||||
self.root.ids.telemetry_s_barometer.active = self.sideband.config["telemetry_s_pressure"]
|
||||
self.root.ids.telemetry_s_barometer.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_temperature.active = self.sideband.config["telemetry_s_temperature"]
|
||||
@ -2883,19 +2880,19 @@ class SidebandApp(MDApp):
|
||||
self.root.ids.telemetry_s_humidity.active = self.sideband.config["telemetry_s_humidity"]
|
||||
self.root.ids.telemetry_s_humidity.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_compass.active = self.sideband.config["telemetry_s_compass"]
|
||||
self.root.ids.telemetry_s_compass.active = self.sideband.config["telemetry_s_magnetic_field"]
|
||||
self.root.ids.telemetry_s_compass.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_light.active = self.sideband.config["telemetry_s_light"]
|
||||
self.root.ids.telemetry_s_light.active = self.sideband.config["telemetry_s_ambient_light"]
|
||||
self.root.ids.telemetry_s_light.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_gravity.active = self.sideband.config["telemetry_s_gravity"]
|
||||
self.root.ids.telemetry_s_gravity.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_gyroscope.active = self.sideband.config["telemetry_s_gyroscope"]
|
||||
self.root.ids.telemetry_s_gyroscope.active = self.sideband.config["telemetry_s_angular_velocity"]
|
||||
self.root.ids.telemetry_s_gyroscope.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_accelerometer.active = self.sideband.config["telemetry_s_accelerometer"]
|
||||
self.root.ids.telemetry_s_accelerometer.active = self.sideband.config["telemetry_s_acceleration"]
|
||||
self.root.ids.telemetry_s_accelerometer.bind(active=self.telemetry_save)
|
||||
|
||||
self.root.ids.telemetry_s_proximity.active = self.sideband.config["telemetry_s_proximity"]
|
||||
@ -2947,16 +2944,15 @@ class SidebandApp(MDApp):
|
||||
self.sideband.config["telemetry_send_appearance"] = self.root.ids.telemetry_send_appearance.active
|
||||
|
||||
self.sideband.config["telemetry_s_location"] = self.root.ids.telemetry_s_location.active
|
||||
self.sideband.config["telemetry_s_orientation"] = self.root.ids.telemetry_s_orientation.active
|
||||
self.sideband.config["telemetry_s_battery"] = self.root.ids.telemetry_s_battery.active
|
||||
self.sideband.config["telemetry_s_barometer"] = self.root.ids.telemetry_s_barometer.active
|
||||
self.sideband.config["telemetry_s_pressure"] = self.root.ids.telemetry_s_barometer.active
|
||||
self.sideband.config["telemetry_s_temperature"] = self.root.ids.telemetry_s_temperature.active
|
||||
self.sideband.config["telemetry_s_humidity"] = self.root.ids.telemetry_s_humidity.active
|
||||
self.sideband.config["telemetry_s_compass"] = self.root.ids.telemetry_s_compass.active
|
||||
self.sideband.config["telemetry_s_light"] = self.root.ids.telemetry_s_light.active
|
||||
self.sideband.config["telemetry_s_magnetic_field"] = self.root.ids.telemetry_s_compass.active
|
||||
self.sideband.config["telemetry_s_ambient_light"] = self.root.ids.telemetry_s_light.active
|
||||
self.sideband.config["telemetry_s_gravity"] = self.root.ids.telemetry_s_gravity.active
|
||||
self.sideband.config["telemetry_s_gyroscope"] = self.root.ids.telemetry_s_gyroscope.active
|
||||
self.sideband.config["telemetry_s_accelerometer"] = self.root.ids.telemetry_s_accelerometer.active
|
||||
self.sideband.config["telemetry_s_angular_velocity"] = self.root.ids.telemetry_s_gyroscope.active
|
||||
self.sideband.config["telemetry_s_acceleration"] = self.root.ids.telemetry_s_accelerometer.active
|
||||
self.sideband.config["telemetry_s_proximity"] = self.root.ids.telemetry_s_proximity.active
|
||||
|
||||
self.sideband.save_configuration()
|
||||
@ -2981,6 +2977,7 @@ class SidebandApp(MDApp):
|
||||
|
||||
def telemetry_copy(self, sender=None):
|
||||
Clipboard.copy(str(self.sideband.get_telemetry()))
|
||||
self.sideband.update_telemetry()
|
||||
|
||||
def telemetry_send_update(self, sender=None):
|
||||
# TODO: Implement
|
||||
|
@ -467,26 +467,24 @@ class SidebandCore():
|
||||
|
||||
if not "telemetry_s_location" in self.config:
|
||||
self.config["telemetry_s_location"] = False
|
||||
if not "telemetry_s_orientation" in self.config:
|
||||
self.config["telemetry_s_orientation"] = False
|
||||
if not "telemetry_s_battery" in self.config:
|
||||
self.config["telemetry_s_battery"] = False
|
||||
if not "telemetry_s_barometer" in self.config:
|
||||
self.config["telemetry_s_barometer"] = False
|
||||
if not "telemetry_s_pressure" in self.config:
|
||||
self.config["telemetry_s_pressure"] = False
|
||||
if not "telemetry_s_temperature" in self.config:
|
||||
self.config["telemetry_s_temperature"] = False
|
||||
if not "telemetry_s_humidity" in self.config:
|
||||
self.config["telemetry_s_humidity"] = False
|
||||
if not "telemetry_s_compass" in self.config:
|
||||
self.config["telemetry_s_compass"] = False
|
||||
if not "telemetry_s_light" in self.config:
|
||||
self.config["telemetry_s_light"] = False
|
||||
if not "telemetry_s_magnetic_field" in self.config:
|
||||
self.config["telemetry_s_magnetic_field"] = False
|
||||
if not "telemetry_s_ambient_light" in self.config:
|
||||
self.config["telemetry_s_ambient_light"] = False
|
||||
if not "telemetry_s_gravity" in self.config:
|
||||
self.config["telemetry_s_gravity"] = False
|
||||
if not "telemetry_s_gyroscope" in self.config:
|
||||
self.config["telemetry_s_gyroscope"] = False
|
||||
if not "telemetry_s_accelerometer" in self.config:
|
||||
self.config["telemetry_s_accelerometer"] = False
|
||||
if not "telemetry_s_angular_velocity" in self.config:
|
||||
self.config["telemetry_s_angular_velocity"] = False
|
||||
if not "telemetry_s_acceleration" in self.config:
|
||||
self.config["telemetry_s_acceleration"] = False
|
||||
if not "telemetry_s_proximity" in self.config:
|
||||
self.config["telemetry_s_proximity"] = False
|
||||
|
||||
@ -606,9 +604,13 @@ class SidebandCore():
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_trusted(self, context_dest):
|
||||
def is_trusted(self, context_dest, conv_data = None):
|
||||
try:
|
||||
if conv_data == None:
|
||||
existing_conv = self._db_conversation(context_dest)
|
||||
else:
|
||||
existing_conv = conv_data
|
||||
|
||||
if existing_conv != None:
|
||||
if existing_conv["trust"] == 1:
|
||||
return True
|
||||
@ -628,6 +630,9 @@ class SidebandCore():
|
||||
cd = existing_conv["data"]
|
||||
if cd != None and "telemetry" in cd and cd["telemetry"] == True:
|
||||
return True
|
||||
else:
|
||||
if self.is_trusted(context_dest, conv_data=existing_conv) and self.config["telemetry_send_to_trusted"]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
@ -1633,6 +1638,7 @@ class SidebandCore():
|
||||
self.telemeter.stop_all()
|
||||
|
||||
def update_telemetry(self):
|
||||
try:
|
||||
telemetry = self.get_telemetry()
|
||||
packed_telemetry = self.get_packed_telemetry()
|
||||
telemetry_changed = False
|
||||
@ -1656,13 +1662,15 @@ class SidebandCore():
|
||||
self.telemetry_changes += 1
|
||||
self.latest_telemetry = telemetry
|
||||
self.latest_packed_telemetry = packed_telemetry
|
||||
except Exception as e:
|
||||
RNS.log("Error while updating telemetry: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
def update_telemeter_config(self):
|
||||
if self.config["telemetry_enabled"] == True:
|
||||
if self.telemeter == None:
|
||||
self.telemeter = Telemeter()
|
||||
|
||||
sensors = ["location", "orientation", "battery", "barometer", "temperature", "humidity", "compass", "light", "gravity", "gyroscope", "accelerometer", "proximity"]
|
||||
sensors = ["location", "battery", "pressure", "temperature", "humidity", "magnetic_field", "ambient_light", "gravity", "angular_velocity", "acceleration", "proximity"]
|
||||
for sensor in sensors:
|
||||
if self.config["telemetry_s_"+sensor]:
|
||||
self.telemeter.enable(sensor)
|
||||
@ -2357,7 +2365,7 @@ class SidebandCore():
|
||||
|
||||
if send_telemetry:
|
||||
# TODO: REMOVE
|
||||
RNS.log("Sending telemetry", RNS.LOG_WARNING)
|
||||
RNS.log("Sending telemetry: "+str(self.latest_packed_telemetry), RNS.LOG_WARNING)
|
||||
fields[LXMF.FIELD_TELEMETRY] = self.latest_packed_telemetry
|
||||
|
||||
return fields
|
||||
|
@ -17,7 +17,7 @@ class Telemeter():
|
||||
name = None
|
||||
s = t.sids[sid]()
|
||||
for n in t.available:
|
||||
if t.available[n] == type(s):
|
||||
if t.sids[t.available[n]] == type(s):
|
||||
name = n
|
||||
|
||||
if name != None:
|
||||
@ -35,16 +35,32 @@ class Telemeter():
|
||||
self.sids = {
|
||||
Sensor.SID_TIME: Time,
|
||||
Sensor.SID_BATTERY: Battery,
|
||||
Sensor.SID_BAROMETER: Barometer,
|
||||
Sensor.SID_PRESSURE: Pressure,
|
||||
Sensor.SID_LOCATION: Location,
|
||||
Sensor.SID_PHYSICAL_LINK: PhysicalLink
|
||||
Sensor.SID_PHYSICAL_LINK: PhysicalLink,
|
||||
Sensor.SID_TEMPERATURE: Temperature,
|
||||
Sensor.SID_HUMIDITY: Humidity,
|
||||
Sensor.SID_MAGNETIC_FIELD: MagneticField,
|
||||
Sensor.SID_AMBIENT_LIGHT: AmbientLight,
|
||||
Sensor.SID_GRAVITY: Gravity,
|
||||
Sensor.SID_ANGULAR_VELOCITY: AngularVelocity,
|
||||
Sensor.SID_ACCELERATION: Acceleration,
|
||||
Sensor.SID_PROXIMITY: Proximity,
|
||||
}
|
||||
self.available = {
|
||||
"time": Time,
|
||||
"battery": Battery,
|
||||
"barometer": Barometer,
|
||||
"location": Location,
|
||||
"physical_link": PhysicalLink,
|
||||
"time": Sensor.SID_TIME,
|
||||
"battery": Sensor.SID_BATTERY,
|
||||
"pressure": Sensor.SID_PRESSURE,
|
||||
"location": Sensor.SID_LOCATION,
|
||||
"physical_link": Sensor.SID_PHYSICAL_LINK,
|
||||
"temperature": Sensor.SID_TEMPERATURE,
|
||||
"humidity": Sensor.SID_HUMIDITY,
|
||||
"magnetic_field": Sensor.SID_MAGNETIC_FIELD,
|
||||
"ambient_light": Sensor.SID_AMBIENT_LIGHT,
|
||||
"gravity": Sensor.SID_GRAVITY,
|
||||
"angular_velocity": Sensor.SID_ANGULAR_VELOCITY,
|
||||
"acceleration": Sensor.SID_ACCELERATION,
|
||||
"proximity": Sensor.SID_PROXIMITY,
|
||||
}
|
||||
self.from_packed = from_packed
|
||||
self.sensors = {}
|
||||
@ -61,7 +77,7 @@ class Telemeter():
|
||||
if not self.from_packed:
|
||||
if sensor in self.available:
|
||||
if not sensor in self.sensors:
|
||||
self.sensors[sensor] = self.available[sensor]()
|
||||
self.sensors[sensor] = self.sids[self.available[sensor]]()
|
||||
if not self.sensors[sensor].active:
|
||||
self.sensors[sensor].start()
|
||||
|
||||
@ -111,9 +127,17 @@ class Sensor():
|
||||
SID_NONE = 0x00
|
||||
SID_TIME = 0x01
|
||||
SID_LOCATION = 0x02
|
||||
SID_BAROMETER = 0x03
|
||||
SID_PRESSURE = 0x03
|
||||
SID_BATTERY = 0x04
|
||||
SID_PHYSICAL_LINK = 0x05
|
||||
SID_ACCELERATION = 0x06
|
||||
SID_TEMPERATURE = 0x07
|
||||
SID_HUMIDITY = 0x08
|
||||
SID_MAGNETIC_FIELD = 0x09
|
||||
SID_AMBIENT_LIGHT = 0x0A
|
||||
SID_GRAVITY = 0x0B
|
||||
SID_ANGULAR_VELOCITY = 0x0C
|
||||
SID_PROXIMITY = 0x0E
|
||||
|
||||
def __init__(self, sid = None, stale_time = None):
|
||||
self._sid = sid or Sensor.SID_NONE
|
||||
@ -280,8 +304,8 @@ class Battery(Sensor):
|
||||
except:
|
||||
return None
|
||||
|
||||
class Barometer(Sensor):
|
||||
SID = Sensor.SID_BAROMETER
|
||||
class Pressure(Sensor):
|
||||
SID = Sensor.SID_PRESSURE
|
||||
STALE_TIME = 5
|
||||
|
||||
def __init__(self):
|
||||
@ -289,22 +313,22 @@ class Barometer(Sensor):
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import barometer
|
||||
self.android_barometer = barometer
|
||||
self.android_sensor = barometer
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_barometer.enable()
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_barometer.disable()
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.data = {"mbar": self.android_barometer.pressure}
|
||||
self.data = {"mbar": self.android_sensor.pressure}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
@ -495,3 +519,367 @@ class PhysicalLink(Sensor):
|
||||
return {"rssi": packed[0], "snr": packed[1], "q": packed[2]}
|
||||
except:
|
||||
return None
|
||||
|
||||
class Temperature(Sensor):
|
||||
SID = Sensor.SID_TEMPERATURE
|
||||
STALE_TIME = 5
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import temperature
|
||||
self.android_sensor = temperature
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.data = {"c": round(self.android_sensor.temperature, 2)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return d["percent_relative"]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"percent_relative": packed}
|
||||
except:
|
||||
return None
|
||||
|
||||
class Humidity(Sensor):
|
||||
SID = Sensor.SID_HUMIDITY
|
||||
STALE_TIME = 5
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import humidity
|
||||
self.android_sensor = humidity
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.data = {"percent_relative": round(self.android_sensor.tell, 2)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return d["percent_relative"]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"percent_relative": packed}
|
||||
except:
|
||||
return None
|
||||
|
||||
class MagneticField(Sensor):
|
||||
SID = Sensor.SID_MAGNETIC_FIELD
|
||||
STALE_TIME = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import compass
|
||||
self.android_sensor = compass
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
vectors = self.android_sensor.field
|
||||
self.data = {"x": round(vectors[0], 6), "y": round(vectors[1], 6), "z": round(vectors[2], 6)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return [d["x"], d["y"], d["z"]]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"x": packed[0], "y": packed[1], "z": packed[2]}
|
||||
except:
|
||||
return None
|
||||
|
||||
class AmbientLight(Sensor):
|
||||
SID = Sensor.SID_AMBIENT_LIGHT
|
||||
STALE_TIME = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import light
|
||||
self.android_sensor = light
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.data = {"lux": round(self.android_sensor.illumination, 2)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return d["lux"]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"lux": packed}
|
||||
except:
|
||||
return None
|
||||
|
||||
class Gravity(Sensor):
|
||||
SID = Sensor.SID_GRAVITY
|
||||
STALE_TIME = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import gravity
|
||||
self.android_sensor = gravity
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
vectors = self.android_sensor.gravity
|
||||
self.data = {"x": round(vectors[0], 6), "y": round(vectors[1], 6), "z": round(vectors[2], 6)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return [d["x"], d["y"], d["z"]]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"x": packed[0], "y": packed[1], "z": packed[2]}
|
||||
except:
|
||||
return None
|
||||
|
||||
class AngularVelocity(Sensor):
|
||||
SID = Sensor.SID_ANGULAR_VELOCITY
|
||||
STALE_TIME = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import gyroscope
|
||||
self.android_sensor = gyroscope
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
vectors = self.android_sensor.rotation
|
||||
self.data = {"x": round(vectors[0], 6), "y": round(vectors[1], 6), "z": round(vectors[2], 6)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return [d["x"], d["y"], d["z"]]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"x": packed[0], "y": packed[1], "z": packed[2]}
|
||||
except:
|
||||
return None
|
||||
|
||||
class Acceleration(Sensor):
|
||||
SID = Sensor.SID_ACCELERATION
|
||||
STALE_TIME = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import accelerometer
|
||||
self.android_sensor = accelerometer
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
vectors = self.android_sensor.acceleration
|
||||
self.data = {"x": round(vectors[0], 6), "y": round(vectors[1], 6), "z": round(vectors[2], 6)}
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return [d["x"], d["y"], d["z"]]
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return {"x": packed[0], "y": packed[1], "z": packed[2]}
|
||||
except:
|
||||
return None
|
||||
|
||||
class Proximity(Sensor):
|
||||
SID = Sensor.SID_PROXIMITY
|
||||
STALE_TIME = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
from plyer import proximity
|
||||
self.android_sensor = proximity
|
||||
|
||||
def setup_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.enable()
|
||||
self.update_data()
|
||||
|
||||
def teardown_sensor(self):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.android_sensor.disable()
|
||||
self.data = None
|
||||
|
||||
def update_data(self):
|
||||
try:
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.data = self.android_sensor.proximity
|
||||
|
||||
except:
|
||||
self.data = None
|
||||
|
||||
def pack(self):
|
||||
d = self.data
|
||||
if d == None:
|
||||
return None
|
||||
else:
|
||||
return d
|
||||
|
||||
def unpack(self, packed):
|
||||
try:
|
||||
if packed == None:
|
||||
return None
|
||||
else:
|
||||
return packed
|
||||
except:
|
||||
return None
|
@ -1102,21 +1102,6 @@ MDNavigationLayout:
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Orientation"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: telemetry_s_orientation
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
@ -1139,7 +1124,7 @@ MDNavigationLayout:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Barometer"
|
||||
text: "Pressure"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
@ -1184,7 +1169,7 @@ MDNavigationLayout:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Compass"
|
||||
text: "Magnetic Field"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
@ -1229,7 +1214,7 @@ MDNavigationLayout:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Gyroscope"
|
||||
text: "Angular Velocity"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
@ -1244,7 +1229,7 @@ MDNavigationLayout:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Accelerometer"
|
||||
text: "Acceleration"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
|
@ -173,7 +173,6 @@ class Messages():
|
||||
extra_telemetry = {}
|
||||
|
||||
phy_stats_str = ""
|
||||
RNS.log(str(m["lxm"].fields), RNS.LOG_WARNING)
|
||||
if "extras" in m and m["extras"] != None:
|
||||
phy_stats = m["extras"]
|
||||
if "q" in phy_stats:
|
||||
|
Loading…
Reference in New Issue
Block a user