Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame^] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2010, Linaro |
| 3 | * Copyright (C) 2010, IBM Corporation |
| 4 | * |
| 5 | * This file is part of PowerDebug. |
| 6 | * |
| 7 | * All rights reserved. This program and the accompanying materials |
| 8 | * are made available under the terms of the Eclipse Public License v1.0 |
| 9 | * which accompanies this distribution, and is available at |
| 10 | * http://www.eclipse.org/legal/epl-v10.html |
| 11 | * |
| 12 | * Contributors: |
| 13 | * Amit Arora <amit.arora@linaro.org> (IBM Corporation) |
| 14 | * - initial API and implementation |
| 15 | *******************************************************************************/ |
| 16 | |
| 17 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 18 | #include "powerdebug.h" |
| 19 | |
| 20 | #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) |
| 21 | #define NUM_FOOTER_ITEMS 5 |
| 22 | |
| 23 | static WINDOW *header_win; |
| 24 | static WINDOW *regulator_win; |
| 25 | static WINDOW *footer_win; |
| 26 | |
| 27 | int maxx, maxy; |
| 28 | char footer_items[NUM_FOOTER_ITEMS][64]; |
| 29 | |
| 30 | |
| 31 | void fini_curses(void) { |
| 32 | endwin(); |
| 33 | } |
| 34 | |
| 35 | void killall_windows(void) |
| 36 | { |
| 37 | if (header_win) { |
| 38 | delwin(header_win); |
| 39 | header_win = NULL; |
| 40 | } |
| 41 | if (regulator_win) { |
| 42 | delwin(regulator_win); |
| 43 | regulator_win = NULL; |
| 44 | } |
| 45 | if (footer_win) { |
| 46 | delwin(footer_win); |
| 47 | footer_win = NULL; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void init_curses(void) |
| 52 | { |
| 53 | initscr(); |
| 54 | start_color(); |
| 55 | keypad(stdscr, TRUE); |
| 56 | noecho(); |
| 57 | cbreak(); |
| 58 | curs_set(0); |
| 59 | nonl(); |
| 60 | use_default_colors(); |
| 61 | |
| 62 | init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); |
| 63 | init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE); |
| 64 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); |
| 65 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED); |
| 66 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); |
| 67 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); |
| 68 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE); |
| 69 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); |
| 70 | |
| 71 | atexit(fini_curses); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | void create_windows(void) |
| 76 | { |
| 77 | |
| 78 | getmaxyx(stdscr, maxy, maxx); |
| 79 | killall_windows(); |
| 80 | |
| 81 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
| 82 | regulator_win = subwin(stdscr, maxy-3, maxx, 1, 0); |
| 83 | |
| 84 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 85 | |
| 86 | strcpy(footer_items[0], " Q (Quit) "); |
| 87 | strcpy(footer_items[1], " R (Refresh) "); |
| 88 | |
| 89 | werase(stdscr); |
| 90 | refresh(); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | |
| 95 | void show_header(void) |
| 96 | { |
| 97 | int i, j = 0; |
| 98 | |
| 99 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 100 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 101 | werase(header_win); |
| 102 | |
| 103 | print(header_win, 0, 0, "PowerDebug version %s (C) Linaro", |
| 104 | VERSION); |
| 105 | |
| 106 | wrefresh(header_win); |
| 107 | |
| 108 | werase(footer_win); |
| 109 | |
| 110 | for (i=0; i<NUM_FOOTER_ITEMS; i++) { |
| 111 | if (strlen(footer_items[i])==0) |
| 112 | continue; |
| 113 | wattron(footer_win, A_REVERSE); |
| 114 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 115 | wattroff(footer_win, A_REVERSE); |
| 116 | j+= strlen(footer_items[i])+1; |
| 117 | } |
| 118 | wrefresh(footer_win); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | void show_regulator_info(int verbose) |
| 123 | { |
| 124 | int i, count = 2; |
| 125 | |
| 126 | werase(regulator_win); |
| 127 | wattron(regulator_win, A_BOLD); |
| 128 | wattron(regulator_win, A_STANDOUT); |
| 129 | print(regulator_win, 0, 0, "Regulator Information"); |
| 130 | wattroff(regulator_win, A_STANDOUT); |
| 131 | print(regulator_win, 0, 1, "Name"); |
| 132 | print(regulator_win, 12, 1, "Status"); |
| 133 | print(regulator_win, 24, 1, "State"); |
| 134 | print(regulator_win, 36, 1, "Type"); |
| 135 | print(regulator_win, 48, 1, "Microvolts"); |
| 136 | print(regulator_win, 60, 1, "Min u-volts"); |
| 137 | print(regulator_win, 72, 1, "Max u-volts"); |
| 138 | wattroff(regulator_win, A_BOLD); |
| 139 | |
| 140 | for (i=0; i<numregulators; i++) { |
| 141 | int col = 0; |
| 142 | |
| 143 | if((i + 2) > (maxy-2)) |
| 144 | break; |
| 145 | |
| 146 | if(!verbose && !strncmp(regulators_info[i].state, "disabled", 8)) |
| 147 | continue; |
| 148 | |
| 149 | print(regulator_win, col, count, "%s", |
| 150 | regulators_info[i].name); |
| 151 | col += 12; |
| 152 | print(regulator_win, col, count, "%s", |
| 153 | regulators_info[i].status); |
| 154 | col += 12; |
| 155 | print(regulator_win, col, count, "%s", |
| 156 | regulators_info[i].state); |
| 157 | col += 12; |
| 158 | print(regulator_win, col, count, "%s", |
| 159 | regulators_info[i].type); |
| 160 | col += 12; |
| 161 | print(regulator_win, col, count, "%d", |
| 162 | regulators_info[i].microvolts); |
| 163 | col += 12; |
| 164 | print(regulator_win, col, count, "%d", |
| 165 | regulators_info[i].min_microvolts); |
| 166 | col += 12; |
| 167 | print(regulator_win, col, count, "%d", |
| 168 | regulators_info[i].max_microvolts); |
| 169 | |
| 170 | count++; |
| 171 | } |
| 172 | wrefresh(regulator_win); |
| 173 | } |
| 174 | |