// SPDX-License-Identifier: GPL-2.0-or-later /* * tui.c ncurses text user interface for TMON program * * Copyright (C) 2013 Intel Corporation. All rights reserved. * * Author: Jacob Pan <jacob.jun.pan@linux.intel.com>
*/
void close_windows(void)
{ if (tui_disabled) return; /* must delete panels before their attached windows */ if (dialogue_window)
close_panel(dialogue_panel); if (cooling_device_window)
close_panel(data_panel);
cooling_device_window = subwin(stdscr, ptdata.nr_cooling_dev + 3, maxx,
y_begin, 0);
y_begin += ptdata.nr_cooling_dev + 3; /* 2 lines for border */ /* two lines to show borders, one line per tz show trip point position * and value. * dialogue window is a pop-up, when needed it lays on top of cdev win
*/
/* prepare panels for dialogue, if panel already created then we must * be doing resizing, so just replace windows with new ones, old ones * should have been deleted by close_window
*/
data_panel = new_panel(cooling_device_window); if (!data_panel)
syslog(LOG_DEBUG, "No data panel\n"); else { if (dialogue_window) {
dialogue_panel = new_panel(dialogue_window); if (!dialogue_panel)
syslog(LOG_DEBUG, "No dialogue panel\n"); else { /* Set up the user pointer to the next panel*/
set_panel_userptr(data_panel, dialogue_panel);
set_panel_userptr(dialogue_panel, data_panel);
top = data_panel;
}
} else
syslog(LOG_INFO, "no dialogue win, term too small\n");
}
doupdate();
werase(stdscr);
refresh();
}
void resize_handler(int sig)
{ /* start over when term gets resized, but first we clean up */
close_windows();
endwin();
refresh();
clear();
getmaxyx(stdscr, maxy, maxx); /* get the new screen size */
setup_windows(); /* rate limit */
sleep(1);
syslog(LOG_DEBUG, "SIG %d, term resized to %d x %d\n",
sig, maxy, maxx);
signal(SIGWINCH, resize_handler);
}
constchar cdev_title[] = " COOLING DEVICES "; void show_cooling_device(void)
{ int i, j, x, y = 0;
if (tui_disabled || !cooling_device_window) return;
werase(cooling_device_window);
wattron(cooling_device_window, A_BOLD);
mvwprintw(cooling_device_window, 1, 1, "ID Cooling Dev Cur Max Thermal Zone Binding");
wattroff(cooling_device_window, A_BOLD); for (j = 0; j < ptdata.nr_cooling_dev; j++) { /* draw cooling device list on the left in the order of * cooling device instances. skip unused idr.
*/
mvwprintw(cooling_device_window, j + 2, 1, "%02d %12.12s%6lu %6lu",
ptdata.cdi[j].instance,
ptdata.cdi[j].type,
ptdata.cdi[j].cur_state,
ptdata.cdi[j].max_state);
}
/* show cdev binding, y is the global cooling device instance */ for (i = 0; i < ptdata.nr_tz_sensor; i++) { int tz_inst = ptdata.tzi[i].instance; for (j = 0; j < ptdata.nr_cooling_dev; j++) { int cdev_inst;
y = j;
x = tz_inst * TZONE_RECORD_SIZE + TZ_LEFT_ALIGN;
/* draw a column of spaces to separate thermal zones */
mvwprintw(cooling_device_window, y+2, x-1, " "); if (ptdata.tzi[i].cdev_binding) {
cdev_inst = ptdata.cdi[j].instance; unsignedlong trip_binding =
ptdata.tzi[i].trip_binding[cdev_inst]; int k = 0; /* per zone trip point id that * binded to this cdev, one to * many possible based on the * binding bitmask.
*/
syslog(LOG_DEBUG, "bind tz%d cdev%d tp%lx %d cdev%lx\n",
i, j, trip_binding, y,
ptdata.tzi[i].cdev_binding); /* draw each trip binding for the cdev */ while (trip_binding >>= 1) {
k++; if (!(trip_binding & 1)) continue; /* draw '*' to show binding */
mvwprintw(cooling_device_window,
y + 2,
x + ptdata.tzi[i].nr_trip_pts -
k - 1, "*");
}
}
}
} /* draw border after data so that border will not be messed up * even there is not enough space for all the data to be shown
*/
wborder(cooling_device_window, 0, 0, 0, 0, 0, 0, 0, 0);
wattron(cooling_device_window, A_BOLD);
mvwprintw(cooling_device_window, 0, maxx/2 - sizeof(cdev_title),
cdev_title);
wattroff(cooling_device_window, A_BOLD);
wrefresh(cooling_device_window);
}
constchar DIAG_TITLE[] = "[ TUNABLES ]"; void show_dialogue(void)
{ int j, x = 0, y = 0; int rows, cols;
WINDOW *w = dialogue_window;
/* draw border last such that everything is within boundary */
wborder(control_window, 0, 0, 0, 0, 0, 0, 0, 0);
wattron(control_window, A_BOLD);
mvwprintw(control_window, 0, maxx/2 - sizeof(control_title),
control_title);
wattroff(control_window, A_BOLD);
wrefresh(control_window);
}
void initialize_curses(void)
{ if (tui_disabled) return;
initscr();
start_color();
keypad(stdscr, TRUE); /* enable keyboard mapping */
nonl(); /* tell curses not to do NL->CR/NL on output */
cbreak(); /* take input chars one at a time */
noecho(); /* dont echo input */
curs_set(0); /* turn off cursor */
use_default_colors();
keypad(cooling_device_window, TRUE); while ((ch = wgetch(cooling_device_window)) != EOF) { if (tmon_exit) break; /* when term size is too small, no dialogue panels are set. * we need to filter out such cases.
*/ if (!data_panel || !dialogue_panel ||
!cooling_device_window ||
!dialogue_window) {
continue;
}
pthread_mutex_lock(&input_lock); if (dialogue_on) {
handle_input_choice(ch); /* top panel filter */ if (ch == 'q' || ch == 'Q')
ch = 0;
} switch (ch) { case KEY_LEFT:
box(cooling_device_window, 10, 0); break; case 9: /* TAB */
top = (PANEL *)panel_userptr(top);
top_panel(top); if (top == dialogue_panel) {
dialogue_on = 1;
show_dialogue();
} else {
dialogue_on = 0; /* force refresh */
show_data_w();
show_control_w();
} break; case'q': case'Q':
tmon_exit = 1; break;
}
update_panels();
doupdate();
pthread_mutex_unlock(&input_lock);
}
if (arg)
*(int *)arg = 0; /* make gcc happy */
return NULL;
}
/* draw a horizontal bar in given pattern */ staticvoid draw_hbar(WINDOW *win, int y, int start, int len, unsignedlong ptn, bool end)
{
mvwaddch(win, y, start, ptn);
whline(win, ptn, len); if (end)
mvwaddch(win, y, MAX_DISP_TEMP+TDATA_LEFT, ']');
}
staticchar trip_type_to_char(int type)
{ switch (type) { case THERMAL_TRIP_CRITICAL: return'C'; case THERMAL_TRIP_HOT: return'H'; case THERMAL_TRIP_PASSIVE: return'P'; case THERMAL_TRIP_ACTIVE: return'A'; default: return'?';
}
}
/* fill a string with trip point type and value in one line * e.g. P(56) C(106) * maintain the distance one degree per char
*/ staticvoid draw_tp_line(int tz, int y)
{ int j; int x;
for (j = 0; j < ptdata.tzi[tz].nr_trip_pts; j++) {
x = ptdata.tzi[tz].tp[j].temp / 1000;
mvwprintw(thermal_data_window, y + 0, x + TDATA_LEFT, "%c%d", trip_type_to_char(ptdata.tzi[tz].tp[j].type),
x);
syslog(LOG_INFO, "%s:tz %d tp %d temp = %lu\n", __func__,
tz, j, ptdata.tzi[tz].tp[j].temp);
}
}
constchar data_win_title[] = " THERMAL DATA "; void show_data_w(void)
{ int i;
if (tui_disabled || !thermal_data_window) return;
werase(thermal_data_window);
wattron(thermal_data_window, A_BOLD);
mvwprintw(thermal_data_window, 0, maxx/2 - sizeof(data_win_title),
data_win_title);
wattroff(thermal_data_window, A_BOLD); /* draw a line as ruler */ for (i = 10; i < MAX_DISP_TEMP; i += 10)
mvwprintw(thermal_data_window, 1, i+TDATA_LEFT, "%2d", i);
for (i = 0; i < ptdata.nr_tz_sensor; i++) { int temp = trec[cur_thermal_record].temp[i] / 1000; int y = 0;
y = i * NR_LINES_TZDATA + 2; /* y at tz temp data line */
mvwprintw(thermal_data_window, y, 1, "%6.6s%2d:[%3d][",
ptdata.tzi[i].type,
ptdata.tzi[i].instance, temp);
draw_hbar(thermal_data_window, y, TDATA_LEFT, temp, ACS_RARROW, true);
draw_tp_line(i, y);
}
wborder(thermal_data_window, 0, 0, 0, 0, 0, 0, 0, 0);
wrefresh(thermal_data_window);
}
constchar tz_title[] = "THERMAL ZONES(SENSORS)";
void show_sensors_w(void)
{ int i, j; char buffer[512];
mvwprintw(tz_sensor_window, 1, TZ_LEFT_ALIGN, "%s", buffer); /* fill trip points for each tzone */
wattron(tz_sensor_window, A_BOLD);
mvwprintw(tz_sensor_window, 2, 1, "Trip Points:");
wattroff(tz_sensor_window, A_BOLD);
/* draw trip point from low to high for each tz */ for (i = 0; i < ptdata.nr_tz_sensor; i++) { int inst = ptdata.tzi[i].instance;
mvwprintw(tz_sensor_window, 1,
TZ_LEFT_ALIGN+TZONE_RECORD_SIZE * inst, "%.9s%02d",
ptdata.tzi[i].type, ptdata.tzi[i].instance); for (j = ptdata.tzi[i].nr_trip_pts - 1; j >= 0; j--) { /* loop through all trip points */ char type; int tp_pos; /* reverse the order here since trips are sorted * in ascending order in terms of temperature.
*/
tp_pos = ptdata.tzi[i].nr_trip_pts - j - 1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.