Explorar o código

Show the AC adapter state in the top bar

Draw `AC on`/`AC off` immediately left of the battery percentage, green while the adapter is online and amber while running from the battery.  The battery colour still follows the charging/AC state.

Use the ThinkPad EC as the laptop marker: read the AC state and look for a battery only when tpec reports the EC present, so desktop machines show neither indicator.  Keep the existing 1 Hz poll and redraw the bar only when the state changes.

Update the WM, sensor and CPU documentation.  Verified with make ucmd_wm.elf, make ucmd_powerinfo.elf and make cmds.pack.
Johannes Zellner hai 1 semana
pai
achega
53529d5b8c
Modificáronse 6 ficheiros con 63 adicións e 17 borrados
  1. 5 4
      AGENTS.md
  2. 1 1
      docs/cpu.html
  3. 3 2
      docs/drivers.html
  4. 2 1
      docs/graphics.html
  5. 2 1
      ucmd_powerinfo.c
  6. 50 8
      ucmd_wm.c

+ 5 - 4
AGENTS.md

@@ -575,9 +575,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   Bonnell = 90, otherwise 100).  The 330's 125 °C is Linux coretemp's
   empirical value; Intel only specifies TJ = 90 °C and Tcase-max = 85.2 °C,
   so `sensors` prints the raw delta and the 90/100/125 °C scales as well as
-  the top bar's `CPU 43C` before the clock (with `BAT 87%` to its left on
-  ThinkPads) and `cpuinfo`'s value plus EIST state.  Platforms without DTS
-  (QEMU, Pentium) hide it.
+  the top bar's `CPU 43C` before the clock (with `AC on`/`AC off` and
+  `BAT 87%` to its left on ThinkPads) and `cpuinfo`'s value plus EIST state.
+  Platforms without DTS (QEMU, Pentium) hide it.
 - **Board sensors**: `it87.c/h` — read-only probe of the IT87xx Super I/O
   (the AT3IONT-I exposes three temperatures and three fan tachometers), used
   by `SYS_SENSORS` and the ring-3 `sensors` command to cross-check the DTS
@@ -598,7 +598,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   page selector, restored when it changed.  `sensors` labels the EC
   registers and decodes the fan mode (auto / full speed / level); the ring-3
   `powerinfo` command prints AC/battery details and the WM top bar shows the
-  first present battery with a valid percentage.
+  AC adapter state plus the first present battery with a valid percentage.
+  Machines without the EC show neither.
 - **Ring-3 address space**: the ELF image and 8 KB stack live in the 2 MB
   `USER_BASE` (`0x40000000`)..`USER_STACK_TOP` (`0x40200000`) window, which is
   too small for a full-frame image.  `SYS_MEM_ALLOC`/`SYS_MEM_GROW`/`SYS_MEM_FREE`

+ 1 - 1
docs/cpu.html

@@ -346,7 +346,7 @@
 		<ul>
 			<li><strong>P-states.</strong> On the allowlisted Nehalem/Westmere models, <code>power_init</code> enables SpeedStep, raises the package C-state limit to C6 when unlocked, reads min/max ratios and starts at the maximum non-turbo ratio.</li>
 			<li><strong>Governor.</strong> A 100 ms window picks min/max/linear target ratios; short busy streaks jump to max immediately. Each CPU writes its own <code>IA32_PERF_CTL</code>.</li>
-			<li><strong>Telemetry.</strong> <code>power</code> prints effective MHz from APERF/MPERF, ratios and C3/C6 residency; <code>sensors</code> prints DTS, board sensors and ThinkPad EC temperatures/fan; <code>powerinfo</code> prints the AC adapter and battery state, and the WM top bar shows the battery percentage.</li>
+			<li><strong>Telemetry.</strong> <code>power</code> prints effective MHz from APERF/MPERF, ratios and C3/C6 residency; <code>sensors</code> prints DTS, board sensors and ThinkPad EC temperatures/fan; <code>powerinfo</code> prints the AC adapter and battery state, and the WM top bar shows the AC adapter state and battery percentage on ThinkPads.</li>
 			<li><strong>Thermal.</strong> Each CPU samples its DTS once a second from its scheduler tick; the hottest core is exposed to ring 3.</li>
 		</ul>
 	</section>

+ 3 - 2
docs/drivers.html

@@ -326,8 +326,9 @@
 			board sensors and EC registers; <code>powerinfo</code> prints the
 			AC adapter and battery state from <code>SYS_POWER_INFO</code>;
 			<code>power</code> prints ratios, effective MHz and C-state
-			residency. The WM top bar shows the first present battery
-			with a valid percentage next to the CPU temperature.
+			residency. The WM top bar shows the AC adapter state and the first
+			present battery with a valid percentage next to the CPU
+			temperature; machines without the EC show neither.
 		</p>
 	</section>
 

+ 2 - 1
docs/graphics.html

@@ -139,7 +139,8 @@
 		<p>
 			The WM is a process that owns the desktop and a fixed array of eight
 			windows. It draws a system bar with the banner, launcher buttons,
-			clock and the CPU temperature/battery percentage, plus draggable
+			clock, the CPU temperature and, on ThinkPads, the AC adapter state
+			and battery percentage, plus draggable
 			terminal and canvas windows with a title bar and close button.
 			Click-to-focus, drag-by-title-bar and close are routed through the
 			same pointer path. The right-aligned date/time text is also a

+ 2 - 1
ucmd_powerinfo.c

@@ -1,7 +1,8 @@
 /* powerinfo: AC adapter and battery state from the ThinkPad H8 EC.
  *
  * The EC access lives in the kernel (SYS_POWER_INFO); this command only
- * formats the snapshot.  The same syscall feeds the WM's top-bar percentage.
+ * formats the snapshot.  The same syscall feeds the WM's top-bar AC and
+ * battery indicators.
  */
 #include "ucmd_lib.h"
 

+ 50 - 8
ucmd_wm.c

@@ -36,7 +36,7 @@ static unsigned int bar_kexec_busy, bar_kexec_progress, bar_kexec_total;
 static int bar_temp_c = -1;
 static int bar_batt_pct = -1;
 static int bar_batt_charging;
-static int bar_batt_ac;
+static int bar_ac_online = -1;
 static char bar_msg[24];
 static unsigned int bar_msg_until;
 static int bar_msg_dirty;
@@ -171,11 +171,36 @@ static unsigned int batt_color(int pct, int charging, int ac)
 		return 0xFF5050u;
 	if (pct <= 20)
 		return 0xFFD250u;
-	if (charging || ac)
+	if (charging || ac > 0)
 		return 0x55FF55u;
 	return 0x55D2FFu;
 }
 
+/* "AC on" / "AC off" (no libc printf here).  Only drawn on machines whose
+ * ThinkPad EC reported the adapter state. */
+static unsigned int ac_text(char *b, int online)
+{
+	unsigned int n = 0;
+
+	b[n++] = 'A';
+	b[n++] = 'C';
+	b[n++] = ' ';
+	b[n++] = 'o';
+	if (online) {
+		b[n++] = 'n';
+	} else {
+		b[n++] = 'f';
+		b[n++] = 'f';
+	}
+	b[n] = '\0';
+	return n;
+}
+
+static unsigned int ac_color(int online)
+{
+	return online ? 0x55FF55u : 0xFFD250u;
+}
+
 static void draw_bar(void)
 {
 	char dt[48];
@@ -277,12 +302,26 @@ static void draw_bar(void)
 			(void)batt_text(bb, bar_batt_pct);
 			bx = right - (int)usurf_text_width(&screen, bb);
 
-			if (bx >= min_x)
+			if (bx >= min_x) {
 				usurf_text(&screen, bx, 5, bb,
 					   batt_color(bar_batt_pct,
 						      bar_batt_charging,
-						      bar_batt_ac),
+						      bar_ac_online),
 					   0, 0, fbw, WM_BAR_H);
+				right = bx - 8;
+			}
+		}
+		if (bar_ac_online >= 0) {
+			char ab[8];
+			int ax;
+
+			(void)ac_text(ab, bar_ac_online);
+			ax = right - (int)usurf_text_width(&screen, ab);
+
+			if (ax >= min_x)
+				usurf_text(&screen, ax, 5, ab,
+					   ac_color(bar_ac_online), 0, 0,
+					   fbw, WM_BAR_H);
 		}
 	}
 }
@@ -721,12 +760,15 @@ static void do_update(struct wm_status *st)
 			}
 			{
 				struct sys_powerinfo pi;
-				int pct = -1, charging = 0, ac = 0;
+				int pct = -1, charging = 0, ac = -1;
 				unsigned int bi;
 
 				if (u_power_info(&pi, 0) == 0) {
-					ac = pi.ac_online > 0;
+					/* The ThinkPad EC is the laptop marker:
+					 * desktops have no EC, so neither the
+					 * AC state nor a battery is shown. */
 					if (pi.present) {
+						ac = pi.ac_online;
 						for (bi = 0; bi < SYS_POWER_BATT_MAX;
 						     bi++) {
 							struct sys_battery *b =
@@ -742,10 +784,10 @@ static void do_update(struct wm_status *st)
 					}
 					if (pct != bar_batt_pct ||
 					    charging != bar_batt_charging ||
-					    ac != bar_batt_ac) {
+					    ac != bar_ac_online) {
 						bar_batt_pct = pct;
 						bar_batt_charging = charging;
-						bar_batt_ac = ac;
+						bar_ac_online = ac;
 						bar_dirty = 1;
 					}
 				}