Implemented available sensors

This commit is contained in:
Mark Qvist 2023-10-22 13:16:43 +02:00
parent 10a1f32057
commit 3025ea7a5b
5 changed files with 468 additions and 91 deletions

View File

@ -1,4 +1,4 @@
__debug_build__ = False __debug_build__ = True
__disable_shaders__ = False __disable_shaders__ = False
__version__ = "0.6.3" __version__ = "0.6.3"
__variant__ = "beta" __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.active = self.sideband.config["telemetry_s_location"]
self.root.ids.telemetry_s_location.bind(active=self.telemetry_location_toggle) 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.active = self.sideband.config["telemetry_s_battery"]
self.root.ids.telemetry_s_battery.bind(active=self.telemetry_save) 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_barometer.bind(active=self.telemetry_save)
self.root.ids.telemetry_s_temperature.active = self.sideband.config["telemetry_s_temperature"] 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.active = self.sideband.config["telemetry_s_humidity"]
self.root.ids.telemetry_s_humidity.bind(active=self.telemetry_save) 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_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_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.active = self.sideband.config["telemetry_s_gravity"]
self.root.ids.telemetry_s_gravity.bind(active=self.telemetry_save) 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_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_accelerometer.bind(active=self.telemetry_save)
self.root.ids.telemetry_s_proximity.active = self.sideband.config["telemetry_s_proximity"] 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_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_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_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_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_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_magnetic_field"] = 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_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_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_angular_velocity"] = 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_acceleration"] = self.root.ids.telemetry_s_accelerometer.active
self.sideband.config["telemetry_s_proximity"] = self.root.ids.telemetry_s_proximity.active self.sideband.config["telemetry_s_proximity"] = self.root.ids.telemetry_s_proximity.active
self.sideband.save_configuration() self.sideband.save_configuration()
@ -2981,6 +2977,7 @@ class SidebandApp(MDApp):
def telemetry_copy(self, sender=None): def telemetry_copy(self, sender=None):
Clipboard.copy(str(self.sideband.get_telemetry())) Clipboard.copy(str(self.sideband.get_telemetry()))
self.sideband.update_telemetry()
def telemetry_send_update(self, sender=None): def telemetry_send_update(self, sender=None):
# TODO: Implement # TODO: Implement

View File

@ -467,26 +467,24 @@ class SidebandCore():
if not "telemetry_s_location" in self.config: if not "telemetry_s_location" in self.config:
self.config["telemetry_s_location"] = False 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: if not "telemetry_s_battery" in self.config:
self.config["telemetry_s_battery"] = False self.config["telemetry_s_battery"] = False
if not "telemetry_s_barometer" in self.config: if not "telemetry_s_pressure" in self.config:
self.config["telemetry_s_barometer"] = False self.config["telemetry_s_pressure"] = False
if not "telemetry_s_temperature" in self.config: if not "telemetry_s_temperature" in self.config:
self.config["telemetry_s_temperature"] = False self.config["telemetry_s_temperature"] = False
if not "telemetry_s_humidity" in self.config: if not "telemetry_s_humidity" in self.config:
self.config["telemetry_s_humidity"] = False self.config["telemetry_s_humidity"] = False
if not "telemetry_s_compass" in self.config: if not "telemetry_s_magnetic_field" in self.config:
self.config["telemetry_s_compass"] = False self.config["telemetry_s_magnetic_field"] = False
if not "telemetry_s_light" in self.config: if not "telemetry_s_ambient_light" in self.config:
self.config["telemetry_s_light"] = False self.config["telemetry_s_ambient_light"] = False
if not "telemetry_s_gravity" in self.config: if not "telemetry_s_gravity" in self.config:
self.config["telemetry_s_gravity"] = False self.config["telemetry_s_gravity"] = False
if not "telemetry_s_gyroscope" in self.config: if not "telemetry_s_angular_velocity" in self.config:
self.config["telemetry_s_gyroscope"] = False self.config["telemetry_s_angular_velocity"] = False
if not "telemetry_s_accelerometer" in self.config: if not "telemetry_s_acceleration" in self.config:
self.config["telemetry_s_accelerometer"] = False self.config["telemetry_s_acceleration"] = False
if not "telemetry_s_proximity" in self.config: if not "telemetry_s_proximity" in self.config:
self.config["telemetry_s_proximity"] = False self.config["telemetry_s_proximity"] = False
@ -606,9 +604,13 @@ class SidebandCore():
else: else:
return False return False
def is_trusted(self, context_dest): def is_trusted(self, context_dest, conv_data = None):
try: try:
existing_conv = self._db_conversation(context_dest) if conv_data == None:
existing_conv = self._db_conversation(context_dest)
else:
existing_conv = conv_data
if existing_conv != None: if existing_conv != None:
if existing_conv["trust"] == 1: if existing_conv["trust"] == 1:
return True return True
@ -629,7 +631,10 @@ class SidebandCore():
if cd != None and "telemetry" in cd and cd["telemetry"] == True: if cd != None and "telemetry" in cd and cd["telemetry"] == True:
return True return True
else: else:
return False if self.is_trusted(context_dest, conv_data=existing_conv) and self.config["telemetry_send_to_trusted"]:
return True
else:
return False
else: else:
return False return False
@ -1633,36 +1638,39 @@ class SidebandCore():
self.telemeter.stop_all() self.telemeter.stop_all()
def update_telemetry(self): def update_telemetry(self):
telemetry = self.get_telemetry() try:
packed_telemetry = self.get_packed_telemetry() telemetry = self.get_telemetry()
telemetry_changed = False packed_telemetry = self.get_packed_telemetry()
telemetry_changed = False
if telemetry != None and packed_telemetry != None: if telemetry != None and packed_telemetry != None:
if self.latest_telemetry == None or len(telemetry) != len(self.latest_telemetry): if self.latest_telemetry == None or len(telemetry) != len(self.latest_telemetry):
telemetry_changed = True telemetry_changed = True
for sn in telemetry: for sn in telemetry:
if telemetry_changed: if telemetry_changed:
break break
if sn != "time": if sn != "time":
if sn in self.latest_telemetry: if sn in self.latest_telemetry:
if telemetry[sn] != self.latest_telemetry[sn]: if telemetry[sn] != self.latest_telemetry[sn]:
telemetry_changed = True
else:
telemetry_changed = True telemetry_changed = True
else:
telemetry_changed = True
if telemetry_changed: if telemetry_changed:
self.telemetry_changes += 1 self.telemetry_changes += 1
self.latest_telemetry = telemetry self.latest_telemetry = telemetry
self.latest_packed_telemetry = packed_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): def update_telemeter_config(self):
if self.config["telemetry_enabled"] == True: if self.config["telemetry_enabled"] == True:
if self.telemeter == None: if self.telemeter == None:
self.telemeter = Telemeter() 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: for sensor in sensors:
if self.config["telemetry_s_"+sensor]: if self.config["telemetry_s_"+sensor]:
self.telemeter.enable(sensor) self.telemeter.enable(sensor)
@ -2357,7 +2365,7 @@ class SidebandCore():
if send_telemetry: if send_telemetry:
# TODO: REMOVE # 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 fields[LXMF.FIELD_TELEMETRY] = self.latest_packed_telemetry
return fields return fields

View File

@ -17,7 +17,7 @@ class Telemeter():
name = None name = None
s = t.sids[sid]() s = t.sids[sid]()
for n in t.available: for n in t.available:
if t.available[n] == type(s): if t.sids[t.available[n]] == type(s):
name = n name = n
if name != None: if name != None:
@ -35,16 +35,32 @@ class Telemeter():
self.sids = { self.sids = {
Sensor.SID_TIME: Time, Sensor.SID_TIME: Time,
Sensor.SID_BATTERY: Battery, Sensor.SID_BATTERY: Battery,
Sensor.SID_BAROMETER: Barometer, Sensor.SID_PRESSURE: Pressure,
Sensor.SID_LOCATION: Location, 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 = { self.available = {
"time": Time, "time": Sensor.SID_TIME,
"battery": Battery, "battery": Sensor.SID_BATTERY,
"barometer": Barometer, "pressure": Sensor.SID_PRESSURE,
"location": Location, "location": Sensor.SID_LOCATION,
"physical_link": PhysicalLink, "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.from_packed = from_packed
self.sensors = {} self.sensors = {}
@ -61,7 +77,7 @@ class Telemeter():
if not self.from_packed: if not self.from_packed:
if sensor in self.available: if sensor in self.available:
if not sensor in self.sensors: 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: if not self.sensors[sensor].active:
self.sensors[sensor].start() self.sensors[sensor].start()
@ -108,12 +124,20 @@ class Telemeter():
return umsgpack.packb(packed) return umsgpack.packb(packed)
class Sensor(): class Sensor():
SID_NONE = 0x00 SID_NONE = 0x00
SID_TIME = 0x01 SID_TIME = 0x01
SID_LOCATION = 0x02 SID_LOCATION = 0x02
SID_BAROMETER = 0x03 SID_PRESSURE = 0x03
SID_BATTERY = 0x04 SID_BATTERY = 0x04
SID_PHYSICAL_LINK = 0x05 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): def __init__(self, sid = None, stale_time = None):
self._sid = sid or Sensor.SID_NONE self._sid = sid or Sensor.SID_NONE
@ -280,8 +304,8 @@ class Battery(Sensor):
except: except:
return None return None
class Barometer(Sensor): class Pressure(Sensor):
SID = Sensor.SID_BAROMETER SID = Sensor.SID_PRESSURE
STALE_TIME = 5 STALE_TIME = 5
def __init__(self): def __init__(self):
@ -289,22 +313,22 @@ class Barometer(Sensor):
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
from plyer import barometer from plyer import barometer
self.android_barometer = barometer self.android_sensor = barometer
def setup_sensor(self): def setup_sensor(self):
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
self.android_barometer.enable() self.android_sensor.enable()
self.update_data() self.update_data()
def teardown_sensor(self): def teardown_sensor(self):
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
self.android_barometer.disable() self.android_sensor.disable()
self.data = None self.data = None
def update_data(self): def update_data(self):
try: try:
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
self.data = {"mbar": self.android_barometer.pressure} self.data = {"mbar": self.android_sensor.pressure}
except: except:
self.data = None self.data = None
@ -495,3 +519,367 @@ class PhysicalLink(Sensor):
return {"rssi": packed[0], "snr": packed[1], "q": packed[2]} return {"rssi": packed[0], "snr": packed[1], "q": packed[2]}
except: except:
return None 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

View File

@ -1102,21 +1102,6 @@ MDNavigationLayout:
pos_hint: {"center_y": 0.3} pos_hint: {"center_y": 0.3}
active: False 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: MDBoxLayout:
orientation: "horizontal" orientation: "horizontal"
size_hint_y: None size_hint_y: None
@ -1139,7 +1124,7 @@ MDNavigationLayout:
height: dp(48) height: dp(48)
MDLabel: MDLabel:
text: "Barometer" text: "Pressure"
font_style: "H6" font_style: "H6"
MDSwitch: MDSwitch:
@ -1184,7 +1169,7 @@ MDNavigationLayout:
height: dp(48) height: dp(48)
MDLabel: MDLabel:
text: "Compass" text: "Magnetic Field"
font_style: "H6" font_style: "H6"
MDSwitch: MDSwitch:
@ -1229,7 +1214,7 @@ MDNavigationLayout:
height: dp(48) height: dp(48)
MDLabel: MDLabel:
text: "Gyroscope" text: "Angular Velocity"
font_style: "H6" font_style: "H6"
MDSwitch: MDSwitch:
@ -1244,7 +1229,7 @@ MDNavigationLayout:
height: dp(48) height: dp(48)
MDLabel: MDLabel:
text: "Accelerometer" text: "Acceleration"
font_style: "H6" font_style: "H6"
MDSwitch: MDSwitch:

View File

@ -173,7 +173,6 @@ class Messages():
extra_telemetry = {} extra_telemetry = {}
phy_stats_str = "" phy_stats_str = ""
RNS.log(str(m["lxm"].fields), RNS.LOG_WARNING)
if "extras" in m and m["extras"] != None: if "extras" in m and m["extras"] != None:
phy_stats = m["extras"] phy_stats = m["extras"]
if "q" in phy_stats: if "q" in phy_stats: