add indicator for modem status
This commit is contained in:
parent
89d629bdda
commit
c426bf7893
@ -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 {
|
||||
|
@ -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
|
||||
|
48
blinkenlicht/modem.fnl
Normal file
48
blinkenlicht/modem.fnl
Normal file
@ -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 }
|
@ -1,2 +1,4 @@
|
||||
with import <nixpkgs> {} ;
|
||||
with import <nixpkgs> {
|
||||
overlays = [ (import ../slab/overlay.nix) ];
|
||||
} ;
|
||||
callPackage ./. {}
|
||||
|
Loading…
Reference in New Issue
Block a user