From 2da2fc26e785590eb0bf2e699d276184cb31ddc6 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 6 May 2024 15:00:19 +0200 Subject: [PATCH] Improved example plugins --- docs/example_plugins/basic.py | 4 +++ docs/example_plugins/comic.py | 4 +++ docs/example_plugins/gpsd_location.py | 43 +++++++++++++++++---------- docs/example_plugins/service.py | 4 +++ docs/example_plugins/telemetry.py | 4 +++ docs/example_plugins/view.py | 4 ++- 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/docs/example_plugins/basic.py b/docs/example_plugins/basic.py index 03f0fc9..b80af0c 100644 --- a/docs/example_plugins/basic.py +++ b/docs/example_plugins/basic.py @@ -1,3 +1,7 @@ +# This is a bare-minimum command plugin +# example that you can build upon to +# implement your own command plugins. + import RNS class BasicCommandPlugin(SidebandCommandPlugin): diff --git a/docs/example_plugins/comic.py b/docs/example_plugins/comic.py index f475ffa..3e5a3f4 100644 --- a/docs/example_plugins/comic.py +++ b/docs/example_plugins/comic.py @@ -1,3 +1,7 @@ +# This plugin example fetches an XKCD comic +# from an external URL and returns it as an +# embedded image in an LXMF message. + import io import RNS import requests diff --git a/docs/example_plugins/gpsd_location.py b/docs/example_plugins/gpsd_location.py index 33bb60d..2c3e713 100644 --- a/docs/example_plugins/gpsd_location.py +++ b/docs/example_plugins/gpsd_location.py @@ -1,10 +1,14 @@ -import RNS -import time -import threading +# This plugin allows using GPSd as a location +# telemetry provider on Linux systems. # This plugin requires the "gpsdclient" pip # package to be installed on your system. # Install it with: pip install gpsdclient + +import RNS +import time +import threading + from gpsdclient import GPSDClient class GpsdLocationPlugin(SidebandTelemetryPlugin): @@ -50,19 +54,28 @@ class GpsdLocationPlugin(SidebandTelemetryPlugin): RNS.log("Connected, streaming GPSd data", RNS.LOG_DEBUG) self.client_connected = True - self.last_update = time.time() - self.latitude = result.get("lat", None) - self.longitude = result.get("lon", None) - self.altitude = result.get("altHAE", None) - self.speed = result.get("speed", None) - self.bearing = result.get("track", None) - epx = result.get("epx", None); epy = result.get("epy", None) - epv = result.get("epv", None) - if epx != None and epy != None and epv != None: - self.accuracy = max(epx, epy, epv) - else: - self.accuracy = None + gpsd_latitude = result.get("lat", None) + gpsd_longitude = result.get("lon", None) + gpsd_altitude = result.get("altHAE", None) + gpsd_speed = result.get("speed", None) + gpsd_bearing = result.get("track", None) + gpsd_required = [gpsd_latitude, gpsd_longitude, gpsd_altitude, gpsd_speed, gpsd_bearing] + + if not None in gpsd_required: + self.last_update = time.time() + self.latitude = gpsd_latitude + self.longitude = gpsd_longitude + self.altitude = gpsd_altitude + self.speed = gpsd_speed + self.bearing = gpsd_bearing + + epx = result.get("epx", None); epy = result.get("epy", None) + epv = result.get("epv", None) + if epx != None and epy != None and epv != None: + self.accuracy = max(epx, epy, epv) + else: + self.accuracy = None except Exception as e: RNS.log("Could not connect to local GPSd, retrying later", RNS.LOG_ERROR) diff --git a/docs/example_plugins/service.py b/docs/example_plugins/service.py index e9c4250..085c265 100644 --- a/docs/example_plugins/service.py +++ b/docs/example_plugins/service.py @@ -1,3 +1,7 @@ +# This is a bare-minimum service plugin +# example that you can build upon to +# implement your own service plugins. + import RNS import time import threading diff --git a/docs/example_plugins/telemetry.py b/docs/example_plugins/telemetry.py index 97f90db..b436a06 100644 --- a/docs/example_plugins/telemetry.py +++ b/docs/example_plugins/telemetry.py @@ -1,3 +1,7 @@ +# This is a bare-minimum telemetry plugin +# example that you can build upon to +# implement your own telemetry plugins. + import RNS class BasicTelemetryPlugin(SidebandTelemetryPlugin): diff --git a/docs/example_plugins/view.py b/docs/example_plugins/view.py index f8e357c..a30f9d1 100644 --- a/docs/example_plugins/view.py +++ b/docs/example_plugins/view.py @@ -1,5 +1,7 @@ # This plugin lets you remotely query and view a -# number of different image sources in Sideband. +# number of different image sources in Sideband, +# including remote or local webcams, video sources +# or images stored in a filesystem. # # This plugin requires the "pillow" pip package. #