eufon

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c426bf7893420a6a1528fb59821eb60db49cba72
parent 89d629bdda60b43e0720d110f6d344231ad7663d
Author: Daniel Barlow <dan@telent.net>
Date:   Tue,  5 Apr 2022 20:57:44 +0000

add indicator for modem status

Diffstat:
Mblinkenlicht/bl.fnl | 15+++++++++++++++
Mblinkenlicht/default.nix | 2++
Ablinkenlicht/modem.fnl | 48++++++++++++++++++++++++++++++++++++++++++++++++
Mblinkenlicht/shell.nix | 4+++-
4 files changed, 68 insertions(+), 1 deletion(-)

diff --git 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 @@ -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 @@ -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 @@ -1,2 +1,4 @@ -with import <nixpkgs> {} ; +with import <nixpkgs> { + overlays = [ (import ../slab/overlay.nix) ]; +} ; callPackage ./. {}