6 # [WISH-OPTIONS... [-- TRAY-EMBED-OPTIONS... [-- XBATMON-SIMPLE-OPTIONS...]]]
12 proc cmdline {id orientation} {
14 return [concat [list xacpi-simple -into $id] $argv]
17 #----- tooltip generation -----
19 proc tt-invisible {} {
21 applet::tooltip-set {}
26 catch { after cancel $ttafter }
27 catch { unset ttafter }
33 set ttafter [after 500 tt-show]
34 applet::tooltip-set [tt-string]
37 proc append-energies {av energy power eunit punit fmt} {
40 append o [format " ${fmt}%s / ${fmt}%s / ${fmt}%s ${fmt}%s" \
41 [expr { $a(${energy}_NOW) * 1e-6 }] $eunit \
42 [expr { $a(${energy}_FULL) * 1e-6 }] $eunit \
43 [expr { $a(${energy}_FULL_DESIGN) * 1e-6 }] $eunit \
44 [expr { $a(${power}_NOW) * 1e-6 }] $punit]
47 proc append-percents {qv} {
50 append o [format " %.0f%% (%.0f%%/%.0f%%)" \
51 [expr { $q(energy_NOW) * 100.0 / $q(energy_FULL_DESIGN) }] \
52 [expr { $q(energy_NOW) * 100.0 / $q(energy_FULL) }] \
53 [expr { $q(energy_FULL) * 100.0 / $q(energy_FULL_DESIGN) }]]
54 if {$q(power_NOW) < -1} {
56 } elseif {$q(power_NOW) > -1} {
57 set endpoint $q(energy_FULL)
59 if {[info exists endpoint]} {
60 set until [expr {($endpoint - $q(energy_NOW)) * 60.0/ $q(power_NOW)}]
62 append o [format " %.fmins" $until]
71 set dir /sys/class/power_supply
72 foreach f [glob -nocomplain -tails -directory $dir *] {
73 debug::debug "TT-INFO $f"
75 set chan [open $dir/$f/uevent]
78 set info "error: $info"
79 debug::debug "$f $errorInfo"
81 lappend lines "$f: $info"
86 lappend lines "error scanning: $emsg"
87 debug::debug "scanning $errorInfo"
90 set o "Total: $nbatts present "
91 append o [join [lsort [array names states]] /]
92 append-energies tot energy power Wh W %.1f
96 if {![llength $lines]} {
97 lappend lines "no power information"
99 return [join $lines "\n"]
102 proc compute {power energy factor punit eunit sign fmt} {
107 debug::debug "COMPUTE $power $energy $factor"
110 set entl {{energy NOW} {energy FULL} {energy FULL_DESIGN} {power NOW}}
114 set kv "[set $pe]_$k"
115 if {![info exists a($kv)]} { return 0 }
116 set a($kv) [expr {$a($kv) * [set "${pe}_sign"]}]
117 set q($kq) [expr {$a($kv) * $factor}]
119 debug::debug "COMPUTE OK [array names q]"
123 if {![info exists tot($kq)]} { set tot($kq) 0 }
124 set tot($kq) [expr {$tot($kq) + $q($kq)}]
126 append-energies a $energy $power $eunit $punit $fmt
131 proc tt-info {chan} {
133 upvar 1 nbatts nbatts
134 upvar 1 states states
135 while {[gets $chan l] >= 0} {
136 if {[regexp {^POWER_SUPPLY_([A-Z0-9_]+)=(.*)$} $l dummy k v]} {
137 debug::debug " uevent ok $l"
140 debug::debug " uevent unk $l"
143 debug::debug "GOT [array names a]"
146 switch -exact -- $a(TYPE) {
148 switch -exact -- $a(ONLINE) {
149 0 { append o " Offline" }
150 1 { append o " Online" }
151 default { append o " ?$o" }
155 switch -exact -- $a(PRESENT) {
156 0 { append o " Absent"; return $o }
157 1 { append o " Present" }
158 default { apend o " ?$o" }
162 switch -exact -- $a(STATUS) {
164 Discharging { set sign -1 }
165 default { append o "Status=" }
167 set states($a(STATUS)) 1
169 foreach power {POWER CURRENT} energy {ENERGY CHARGE} \
170 punit {W A} eunit {Wh Ah} fmt {%.1f %.2f} {
171 switch -exact $power {
172 POWER { set factor 1.0 }
173 CURRENT { set factor [expr {$a(VOLTAGE_NOW) * 1e-6}] }
175 if {![compute $power $energy $factor \
176 $punit $eunit $sign $fmt]} continue
186 proc mode/normal {} {
187 uplevel #0 source applet.tcl
188 applet::setup-subproc cmdline
189 applet::setup-tooltip tt-show tt-invisible
192 proc mode/-tooltip-string {} {
197 #----- command line parsing -----
201 while {[args::next_special arg]} {
202 switch -exact -- $arg {
204 -tooltip-string { set mode $arg }
205 default { args::badoption }