Browse Source

TUI: Implement beginnings of generic device management interface

Luke Dashjr 12 years ago
parent
commit
0513deacd1
2 changed files with 89 additions and 12 deletions
  1. 7 1
      README
  2. 82 11
      miner.c

+ 7 - 1
README

@@ -322,7 +322,13 @@ WHILE RUNNING:
 
 The following options are available while running with a single keypress:
 
-[P]ool management [G]PU management [S]ettings [D]isplay options [Q]uit
+[M]anage devices [P]ool management [G]PU management [S]ettings [D]isplay options [Q]uit
+
+M gives you something like:
+
+Select processor to manage using up/down arrow keys
+ ICA 0 :                | 212.4/340.6/448.7Mh/s | A:4 R:0+0(none) HW:0/none
+
 
 P gives you:
 

+ 82 - 11
miner.c

@@ -276,6 +276,11 @@ const
 #endif
 bool curses_active;
 
+#ifdef HAVE_CURSES
+bool selecting_device;
+unsigned selected_device;
+#endif
+
 static char current_block[40];
 
 /* Protected by ch_lock */
@@ -2387,7 +2392,7 @@ percentf2(double p, double t, char *buf)
 static void adj_width(int var, int *length);
 #endif
 
-static void get_statline2(char *buf, struct cgpu_info *cgpu, bool for_curses)
+static void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_show_procs)
 {
 #ifdef HAVE_CURSES
 	static int awidth = 1, rwidth = 1, swidth = 1, hwwidth = 1;
@@ -2559,7 +2564,8 @@ static void get_statline2(char *buf, struct cgpu_info *cgpu, bool for_curses)
 	}
 }
 
-#define get_statline(buf, cgpu)  get_statline2(buf, cgpu, false)
+#define get_statline(buf, cgpu)               get_statline3(buf, cgpu, false, opt_show_procs)
+#define get_statline2(buf, cgpu, for_curses)  get_statline3(buf, cgpu, for_curses, opt_show_procs)
 
 static void text_print_status(int thr_id)
 {
@@ -2637,7 +2643,7 @@ static void curses_print_status(void)
 		  current_hash, block_diff, net_hashrate, blocktime);
 	mvwhline(statuswin, 6, 0, '-', 80);
 	mvwhline(statuswin, statusy - 1, 0, '-', 80);
-	mvwprintw(statuswin, devcursor - 1, 1, "[P]ool management %s[S]ettings [D]isplay options [Q]uit",
+	mvwprintw(statuswin, devcursor - 1, 1, "[M]anage devices [P]ool management %s[S]ettings [D]isplay options [Q]uit",
 		have_opencl ? "[G]PU management " : "");
 }
 
@@ -2677,10 +2683,26 @@ static void curses_print_devstatus(struct cgpu_info *cgpu)
 		return;
 	
 	get_statline2(logline, cgpu, true);
+	if (selecting_device && (opt_show_procs ? (selected_device == cgpu->cgminer_id) : (devices[selected_device]->device == cgpu)))
+		wattron(statuswin, A_REVERSE);
 	waddstr(statuswin, logline);
+	wattroff(statuswin, A_REVERSE);
 
 	wclrtoeol(statuswin);
 }
+
+static
+void refresh_devstatus() {
+	if (curses_active_locked()) {
+		int i;
+		for (i = 0; i < total_devices; i++)
+			curses_print_devstatus(get_devices(i));
+		touchwin(statuswin);
+		wrefresh(statuswin);
+		unlock_curses();
+	}
+}
+
 #endif
 
 static void print_status(int thr_id)
@@ -5904,6 +5926,59 @@ retry:
 	opt_loginput = false;
 }
 
+void manage_device(void)
+{
+	char logline[256];
+	struct cgpu_info *cgpu;
+	
+	opt_loginput = true;
+	selecting_device = true;
+	immedok(logwin, true);
+	
+devchange:
+	cgpu = devices[selected_device];
+	refresh_devstatus();
+	
+	clear_logwin();
+	wlogprint("Select processor to manage using up/down arrow keys\n");
+	
+	get_statline3(logline, cgpu, true, true);
+	wattron(logwin, A_BOLD);
+	waddstr(logwin, logline);
+	wattroff(logwin, A_BOLD);
+	
+	wlogprint("\n");
+	logwin_update();
+	
+	while (true)
+	{
+		int input = getch();
+		switch (input) {
+			case KEY_DOWN:
+				if (selected_device >= total_devices - 1)
+					break;
+				++selected_device;
+				goto devchange;
+			case KEY_UP:
+				if (selected_device <= 0)
+					break;
+				--selected_device;
+				goto devchange;
+			case 'Q': case 'q':
+			case KEY_BREAK: case KEY_BACKSPACE: case KEY_CANCEL: case KEY_CLOSE: case KEY_EXIT:
+			case '\x1b':  // ESC
+			case '\n':
+				goto out;
+		}
+	}
+
+out:
+	selecting_device = false;
+	clear_logwin();
+	immedok(logwin, false);
+	opt_loginput = false;
+}
+
 static void *input_thread(void __maybe_unused *userdata)
 {
 	RenameThread("input");
@@ -5922,6 +5997,9 @@ static void *input_thread(void __maybe_unused *userdata)
 		case 'd': case 'D':
 			display_options();
 			break;
+		case 'm': case 'M':
+			manage_device();
+			break;
 		case 'p': case 'P':
 			display_pools();
 			break;
@@ -5941,14 +6019,7 @@ static void *input_thread(void __maybe_unused *userdata)
 			if (devsummaryYOffset == 0)
 				break;
 			++devsummaryYOffset;
-			if (curses_active_locked()) {
-				int i;
-				for (i = 0; i < total_devices; i++)
-					curses_print_devstatus(get_devices(i));
-				touchwin(statuswin);
-				wrefresh(statuswin);
-				unlock_curses();
-			}
+			refresh_devstatus();
 			break;
 #endif
 		}