diff --git a/blinkenlicht/bl.fnl b/blinkenlicht/bl.fnl index cb8f2b6..246a2e0 100644 --- a/blinkenlicht/bl.fnl +++ b/blinkenlicht/bl.fnl @@ -4,6 +4,7 @@ (local iostream (require :iostream)) (local metric (require :metric)) (local uplink (require :uplink)) +(local modem (require :modem)) (stylesheet "licht.css") @@ -41,6 +42,20 @@ {:text v}) })) + (let [modem (modem.new)] + (indicator { + :wait-for { + :interval (* 4 1000) + } + :refresh + #(let [{:m3gpp-operator-name operator + :signal-quality quality} (modem:value)] + {:text (.. operator + ;" " (. quality 1) "dBm" + ) + }) + })) + (let [uplink (uplink.new) input (iostream.from-descriptor uplink.fd)] (indicator { diff --git a/blinkenlicht/default.nix b/blinkenlicht/default.nix index 60fd7c4..1a39a2a 100644 --- a/blinkenlicht/default.nix +++ b/blinkenlicht/default.nix @@ -9,6 +9,7 @@ , librsvg , lua53Packages , lua5_3 +, luaDbusProxy , makeWrapper , writeText }: @@ -24,6 +25,7 @@ let lua = lua5_3.withPackages (ps: with ps; [ lgi + luaDbusProxy luafilesystem luaposix readline diff --git a/blinkenlicht/modem.fnl b/blinkenlicht/modem.fnl new file mode 100644 index 0000000..e930a54 --- /dev/null +++ b/blinkenlicht/modem.fnl @@ -0,0 +1,48 @@ +(local { : GLib } (require :lgi)) +(local dbus (require :dbus_proxy)) +(local { : view } (require :fennel)) +(local GV GLib.Variant) +(local variant dbus.variant) + +;; https://www.freedesktop.org/software/ModemManager/api/latest/ref-dbus.html +(var the-modem-manager nil) +(fn modem-manager [] + (when (not the-modem-manager) + (set the-modem-manager + (dbus.Proxy:new + { + :bus dbus.Bus.SYSTEM + :name "org.freedesktop.ModemManager1" + :interface "org.freedesktop.DBus.ObjectManager" + :path "/org/freedesktop/ModemManager1" + }))) + the-modem-manager) + +;; this is a function because the path to the modem may change +;; (e.g. due to suspend/resume cycles causing services to be stopped +;; and started) + +(fn modem-interface [] + (let [modem-path (next (: (assert (modem-manager)) :GetManagedObjects))] + (dbus.Proxy:new + { + :bus dbus.Bus.SYSTEM + :name "org.freedesktop.ModemManager1" + :interface "org.freedesktop.ModemManager1.Modem.Simple" + :path modem-path + }))) + +(fn new-modem-status [] + { + :value #(let [m (modem-interface)] + (variant.strip (m:GetStatus))) + }) + +(comment +(let [ctx (: (GLib.MainLoop) :get_context) + s (new-modem-status)] + (while true + (ctx:iteration) + (print (view (s:value) ))))) + +{ :new new-modem-status } diff --git a/blinkenlicht/shell.nix b/blinkenlicht/shell.nix index e404c8c..0e1e05b 100644 --- a/blinkenlicht/shell.nix +++ b/blinkenlicht/shell.nix @@ -1,2 +1,4 @@ -with import {} ; +with import { + overlays = [ (import ../slab/overlay.nix) ]; +} ; callPackage ./. {}