2024-08-18 16:09:14 +01:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< title > BatMon | Paul' s Site of Stuff< / title >
< meta http-equiv = "content-type" content = "text/html; charset=utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0, maximum-scale=1" >
< meta name = "robots" content = "noodp" / >
< link rel = "stylesheet" href = "https://paulwilde.uk/style.css" >
< link rel = "stylesheet" href = "https://paulwilde.uk/color/orange.css" >
< link rel = "stylesheet" href = "https://paulwilde.uk/color/background_blue.css" >
< link rel = "stylesheet" href = "https://paulwilde.uk/font-hack-subset.css" >
< meta name = "description" content = "" >
< meta property = "og:description" content = "" >
< meta property = "og:title" content = "BatMon | Paul's Site of Stuff" >
< meta property = "og:type" content = "article" >
< meta property = "og:url" content = "https://paulwilde.uk/ponderings/batmon/" >
< meta name = "twitter:card" content = "summary_large_image" >
< meta name = "twitter:description" content = "" >
< meta name = "twitter:title" content = "BatMon | Paul's Site of Stuff" >
< meta property = "twitter:domain" content = "paulwilde.uk" >
< meta property = "twitter:url" content = "https://paulwilde.uk/ponderings/batmon/" >
< link rel = "alternate" type = "application/atom+xml" title = "RSS" href = "https://paulwilde.uk/atom.xml" >
< link rel = "shortcut icon" type = "image/png" href = "/favicon.png" >
< script defer data-domain = "paulwilde.uk" src = "https://plausible.io/js/script.js" > < / script >
< / head >
< body class = "" >
< div class = "container" >
< header class = "header" >
< div class = "header__inner" >
< div class = "header__logo" >
< a href = "https://paulwilde.uk" style = "text-decoration: none;" >
< div class = "logo" >
Hello, I' m Paul
< / div >
< / a >
< / div >
< / div >
< nav class = "menu" >
< ul class = "menu__inner" >
< li > < a href = "/" > home< / a > < / li >
< li > < a href = "/aboutme" > about me< / a > < / li >
< li > < a href = "/ponderings" > ponderings< / a > < / li >
< li > < a href = "/iuse" > i use …< / a > < / li >
< li > < a href = "/tags" > tags< / a > < / li >
< li > < a href = "/atom.xml" > rss< / a > < / li >
< / ul >
< / nav >
< / header >
< div class = "post" >
< h1 class = "post-title" > < a href = "https://paulwilde.uk/ponderings/batmon/" > BatMon< / a > < / h1 >
< div class = "post-meta-inline" >
< span class = "post-date" >
2024-07-29
< / span >
< / div >
< span class = "post-tags-inline" >
:: tags:
< a class = "post-tag" href = "https://paulwilde.uk/tags/development/" > #development< / a >
< a class = "post-tag" href = "https://paulwilde.uk/tags/freebsd/" > #freebsd< / a >
< a class = "post-tag" href = "https://paulwilde.uk/tags/linux/" > #linux< / a >
< a class = "post-tag" href = "https://paulwilde.uk/tags/nim/" > #nim< / a >
< a class = "post-tag" href = "https://paulwilde.uk/tags/tools/" > #tools< / a > < / span >
< div class = "sourcecode" >
< a href = "https://codeberg.org/pswilde/batmon" target = "_blank" > source code< / a >
< / div >
< div class = "post-content" >
< p > A simple battery monitor tool that can notify you on battery status changes for FreeBSD.< br / >
Inspired by but in no way similar to < a href = "https://github.com/electrickite/batsignal" > batsignal< / a > - inspiring the basic function only.
Written in pure < a href = "https://paulwilde.uk/ponderings/batmon/https/nim-lang.org" > Nim< / a > .< / p >
< span id = "continue-reading" > < / span > < h2 id = "requirements" > Requirements< / h2 >
< h3 id = "run-requirements" > Run Requirements< / h3 >
< ul >
< li > < code > apm< / code > < / li >
< li > < code > notify-send< / code > < / li >
< / ul >
< h3 id = "build-requirements" > Build Requirements< / h3 >
< ul >
< li > < code > nim< / code > < / li >
< li > < code > nimble< / code > < / li >
< / ul >
< h2 id = "installation" > Installation< / h2 >
< p > To install into your < code > .nimble/bin< / code > directory< / p >
< pre data-lang = "sh" style = "background-color:#212121;color:#eeffff;" class = "language-sh " > < code class = "language-sh" data-lang = "sh" > < span style = "color:#82aaff;" > git clone https://codeberg.org/pswilde/batmon < / span > < span style = "color:#89ddff;" > & & < / span > < span style = "color:#82aaff;" > cd batmon
< / span > < span style = "color:#82aaff;" > nimble install
< / span > < / code > < / pre >
< h2 id = "running" > Running< / h2 >
< pre data-lang = "sh" style = "background-color:#212121;color:#eeffff;" class = "language-sh " > < code class = "language-sh" data-lang = "sh" > < span style = "font-style:italic;color:#4a4a4a;" > # To run the daemon server notifier, just run:
< / span > < span style = "color:#82aaff;" > batmon< / span > < span style = "color:#89ddff;" > -< / span > < span style = "color:#f78c6c;" > d
< / span > < span >
< / span > < span style = "font-style:italic;color:#4a4a4a;" > # To run once and just show battery level, run:
< / span > < span style = "color:#82aaff;" > batmon< / span > < span style = "color:#89ddff;" > -< / span > < span style = "color:#f78c6c;" > o
< / span > < / code > < / pre >
< h2 id = "using" > Using< / h2 >
< p > When importing Batmon as a module you have access to the < code > get_battery_status()< / code >
procedure which will return a < code > Battery< / code > object you can use elsewhere.< / p >
< h3 id = "battery-type" > Battery Type< / h3 >
< pre data-lang = "nim" style = "background-color:#212121;color:#eeffff;" class = "language-nim " > < code class = "language-nim" data-lang = "nim" > < span style = "color:#c792ea;" > type
< / span > < span > < / span > < span style = "color:#ffcb6b;" > Battery< / span > < span > * = < / span > < span style = "color:#c792ea;" > object
< / span > < span > status*: < / span > < span style = "color:#ffcb6b;" > Status
< / span > < span > charge*: < / span > < span style = "font-style:italic;color:#c792ea;" > float
< / span > < span > < / span > < span style = "color:#ffcb6b;" > Status< / span > < span > * = < / span > < span style = "color:#c792ea;" > enum
< / span > < span > < / span > < span style = "color:#ffcb6b;" > High< / span > < span > ,
< / span > < span > < / span > < span style = "color:#ffcb6b;" > Low< / span > < span > ,
< / span > < span > < / span > < span style = "color:#ffcb6b;" > Critical< / span > < span > ,
< / span > < span > < / span > < span style = "color:#ffcb6b;" > Charging< / span > < span > ,
< / span > < span > < / span > < span style = "color:#ffcb6b;" > Unknown
< / span > < / code > < / pre >
< p > Also, you have access to the notification handler module, where you can build
and send your own notifications:< / p >
< pre data-lang = "nim" style = "background-color:#212121;color:#eeffff;" class = "language-nim " > < code class = "language-nim" data-lang = "nim" > < span style = "color:#c792ea;" > var< / span > < span > n = < / span > < span style = "color:#82aaff;" > newNotification< / span > < span > (< / span > < span style = "color:#c3e88d;" > " Title" < / span > < span > , < / span > < span style = "color:#c3e88d;" > " Body" < / span > < span > , urgency = < / span > < span style = "color:#ffcb6b;" > Normal< / span > < span > , timeout = < / span > < span style = "color:#f78c6c;" > 5000< / span > < span > )
< / span > < span style = "color:#c792ea;" > discard< / span > < span > n.< / span > < span style = "color:#82aaff;" > send< / span > < span > ()
< / span > < / code > < / pre >
< / div >
< div class = "pagination" >
< div class = "pagination__title" >
< span class = "pagination__title-h" > Thanks for reading! Read other posts?< / span >
< hr / >
< / div >
< div class = "pagination__buttons" >
< span class = "button previous" >
< a href = "https://paulwilde.uk/ponderings/tootinstall-concept/" >
< span class = "button__icon" > ←< / span >
< span class = "button__text" > TootInstall< / span >
< / a >
< / span >
< span class = "button next" >
< a href = "https://paulwilde.uk/ponderings/norg/" >
< span class = "button__text" > Norg Backup Utility< / span >
< span class = "button__icon" > →< / span >
< / a >
< / span >
< / div >
< / div >
< / div >
< footer class = "footer" >
< div class = "footer__inner" >
< a href = "https://notnull.space/@paul" rel = "me" > fediverse (gts)< / a >
< a href = "https://snac.notnull.space/paul" rel = "me" > fediverse (snac)< / a >
< a href = "https://codeberg.org/pswilde" rel = "me" > codeberg< / a >
< a href = "https://keyoxide.org/85633E30514CC1932E4268460ED12CF710BC42CA" rel = "me" > keyoxide< / a >
< / div >
< div class = "footer__inner" >
< div class = "copyright" >
< span > ©
2025-01-13 11:04:16 +00:00
2025
2024-08-18 16:09:14 +01:00
Paul Wilde< / span >
< span class = "copyright-theme" >
< span class = "copyright-theme-sep" > :: < / span >
Theme: < a href = "https://github.com/pawroman/zola-theme-terminimal/" > Terminimal< / a >
< / span >
< / div >
< / div >
< / footer >
< / div >
< / body >
< / html >