void vg_highlight(int win, int x, int y) { int j; const static int modus = A_BOLD; move(0,0); clrtoeol(); //Nötig, da der Rand 1 dick ist x++; y++; // Hebe die gewinnende Kombination hervor if(win & WINX) for(j=0;j<4;j++) mvchgat(y, x+j, 1, modus, 0, NULL); if(win & WINY) for(j=0;j<4;j++) mvchgat(y+j, x, 1, modus, 0, NULL); if(win &WINR) for(j=0;j<4;j++) mvchgat(y+j, x+j, 1, modus, 0, NULL); if(win & WINL) for(j=0;j<4;j++) mvchgat(y+j, x-j, 1, modus, 0, NULL); }
/* Show standard header line */ void nhexScreenHeader(void) { if(nhexScreen.iChunks == -1) return; mvprintw(0, 0, "%s-v%s",PACKAGE,VERSION); clrtoeol(); mvprintw(0, nhexScreen.iCols-21, "|Press <F12> for menu"); mvchgat(0, 0, -1, A_REVERSE, 0, NULL); mvchgat(nhexScreen.iRows+1, 0, -1, A_REVERSE, 0, NULL); refresh(); }
void FalloutDisplay::highlight(const std::vector < Character > & hl_list, int on) { for (auto hl : hl_list) { if (on) { mvchgat(hl.get_y(), hl.get_x(), 1, A_REVERSE, 1, NULL); } else { mvchgat(hl.get_y(), hl.get_x(), 1, A_NORMAL, 1, NULL); } } refresh(); }
void flash_box(const int x0, const int y0, const int x1, const int y1) { int j; /* if (!visual_feedback) return;*/ for (j = y0; j <= y1; ++j) mvchgat(j, x0, -1 /*x1 - x0 + 1*/, A_REVERSE, 0, NULL); refresh(); usleep(500000); for (j = y0; j <= y1; ++j) mvchgat(j, x0, x1 - x0 + 1, A_NORMAL, 0, NULL); refresh(); }
static void test_chgat(void) { STATUS st; init_status(stdscr, &st); do { switch (st.ch) { case '.': /* change from current position */ chgat(st.count, st.attr, st.pair, (void *) 0); touch_if_needed(stdscr, st.y_val); break; case ',': /* change from beginning of window */ mvchgat(0, 0, st.count, st.attr, st.pair, (void *) 0); touch_if_needed(stdscr, 0); move(st.y_val, st.x_val); break; case 'w': do_subwindow(stdscr, &st, test_wchgat); break; case 'q': return; default: update_status(stdscr, &st); break; } } while ((st.ch = getch()) != ERR); }
/** highlight the first n characters of the call input field * * \param n number of characters to highlight */ void highlightCall(unsigned int n) { attr_t attrib = modify_attr(A_NORMAL); /* use NORMAL here as normal display uses STANDOUT */ mvchgat(12, 29, n, attrib, C_INPUT, NULL); }
void set_foreground_color_at(int x, int y, const color_t& color) { int index = y * sys::get_terminal_width() + x; _foreground_color_index_map[index] = color; color_t current_back = get_background_color_at(x, y); int colors = color_to_curses_color(color, current_back); if (colors & A_BOLD) { colors &= ~A_BOLD; mvchgat( y, x, 1, A_BOLD, colors, 0 ); } else { mvchgat( y, x, 1, 0, colors, 0 ); } }
void showprocs(struct myproc **procs, struct procstat *pst) { int y = -pos_top + TOP_OFFSET - 1; struct myproc *topproc; // this f***s up everything. why? /* for(topproc = gui_proc_first(procs)->child_first; topproc; topproc = topproc->child_next) */ topproc = gui_proc_first(procs); showproc(topproc, &y, 0); if(++y < LINES){ move(y, 0); clrtobot(); } if(search){ const int red = !search_proc && *search_str;; if(red) attron(COLOR_PAIR(1 + COLOR_RED)); mvprintw(0, 0, "%d %c%s", search_offset, "/?"[search_pid], search_str); if(red) attroff(COLOR_PAIR(1 + COLOR_RED)); clrtoeol(); if(search_proc){ int ty; if(search_proc_to_idx(&ty, procs)){ pos_top = ty - LINES / 2; if(pos_top < 0) pos_top = 0; } } }else{ int y; time_t now; time(&now); STATUS(0, 0, "%d processes, %d running, %d owned, %d zombies, load averages: %.2f, %.2f, %.2f, uptime: %s", pst->count, pst->running, pst->owned, pst->zombies, pst->loadavg[0], pst->loadavg[1], pst->loadavg[2], uptime_from_boottime(pst->boottime.tv_sec)); // Mem stuf STATUS(1, 0, "Mem: %s", format_memory(pst->memory)); // CPU % STATUS(2,0, "CPU: %s", format_cpu_pct(pst->cpu_pct)); clrtoeol(); y = 3 + pos_y - pos_top; mvchgat(y, 0, 47, A_UNDERLINE, 0, NULL); move(y, 47); } }
// do the business with curses void render_line (int linenum, const char *legend, double barpercent, int bar_colour, int bg_colour, const char *shownrate) { int startpos, graphcols, graphlimit; int barchar; int i; // are we below what is visible or above? // first return if not this many lines on the screen if(linenum < start_row || linenum > (start_row+(screen_max_rows-1))) { mvprintw(linenum, 0, "linenum=%d, < start_row = %d name=%s percent %f %s\n", linenum, start_row,legend, barpercent, shownrate); return; } linenum -= start_row; // displaying this section on screen startpos = 0; graphcols = screen_max_cols - startpos; graphlimit = int(graphcols * (barpercent/100)); // hack for mono terminals - translate bar colour if(bar_colour == COLOR_GREEN) barchar = ACS_HLINE; if(bar_colour == COLOR_YELLOW) barchar = ACS_BOARD; if(bar_colour == COLOR_RED) barchar = ACS_BLOCK; mvprintw(linenum,0,"%s", legend); clrtoeol(); if(!has_colors()) { // need the line of whatever character is appropriate for(i = 0; i < graphlimit;i++) addch(barchar); } // now the rate - put on top of the bar in the case of the no color version mvprintw(linenum, 35, "%d", graphlimit); mvprintw(linenum, 40 + ((screen_max_cols-startpos)/2-strlen((const char *)shownrate)),(const char *)shownrate); if(has_colors()) { // whole line background mvchgat(linenum,0,screen_max_cols,A_NORMAL,bg_colour,NULL); // show the graph part as a colour if possible mvchgat(linenum,startpos,graphlimit, A_NORMAL,bar_colour, NULL ); } }
static void show_path(struct regedit *regedit) { int start_pad = 0; int start_win = PATH_START_X; if (PATH_START_X + regedit->path_len > COLS) { start_pad = 3 + PATH_START_X + regedit->path_len - COLS; mvprintw(PATH_START_Y, start_win, "..."); start_win += 3; } copywin(regedit->path_label, regedit->main_window, 0, start_pad, PATH_START_Y, start_win, PATH_START_Y, PATH_MAX_Y, false); mvchgat(0, 0, COLS, A_BOLD, PAIR_YELLOW_CYAN, NULL); }
void ConsoleView::initView() { initscr(); raw(); keypad(stdscr, TRUE); start_color(); init_pair(1, COLOR_WHITE, COLOR_BLACK); getmaxyx(stdscr, m_height, m_width); attron(A_BOLD); printw("Welcome"); mvchgat(0, 0, -1, A_BLINK, 1, NULL); attroff(A_BOLD); refresh(); m_UARTState = createNewWindow(4, m_width, 0, 0); m_RtFinderView = createNewWindow(m_height - 10, (m_width >> 1) - 1, 5, 0); m_ObjFinderView = createNewWindow(m_height - 10, (m_width >> 1) - 1, 5, (m_width >> 1) + 1); m_ControllerView = createNewWindow(4, m_width, m_height - 5, 0); refresh(); }
static void exe_instruction(t_proc *proc, t_env *e) { int i; i = -1; while (g_op_tab[++i].nb_arg) { if (proc->inst.opc == g_op_tab[i].op_code) { g_op_tab[i].f(e, proc); if ((e->verbose & VERBOSE_PC) == VERBOSE_PC) print_adv(proc, e, 1); mvchgat(proc->pos / 64 + 2, proc->pos % 64 * 3 + 6, 2, A_NORMAL,\ proc->champ_color, NULL); proc->pos = proc->pc; break ; } } proc->pos = proc->pc; }
int main(int argc, char *argv[]) { initscr(); /* Start curses mode */ start_color(); /* Start color functionality */ init_pair(1, COLOR_CYAN, COLOR_BLACK); printw("A Big string which i didn't care to type fully "); mvchgat(0, 0, -1, A_BLINK, 1, NULL); /* * First two parameters specify the position at which to start * Third parameter number of characters to update. -1 means till * end of line * Forth parameter is the normal attribute you wanted to give * to the charcter * Fifth is the color index. It is the index given during init_pair() * use 0 if you didn't want color * Sixth one is always NULL */ refresh(); getch(); endwin(); /* End curses mode */ return 0; }
void printcall(void) { extern char hiscall[]; extern int miniterm; extern int cqmode; extern int cwstart; int currentterm; attr_t attrib = modify_attr(A_STANDOUT); currentterm = miniterm; miniterm = 0; attron(COLOR_PAIR(C_INPUT) | attrib); mvprintw(12, 29, " "); mvprintw(12, 29, hiscall); if ((cqmode == CQ) && (cwstart > 0)) mvchgat(12, 29 + cwstart, 12 - cwstart, attrib | A_UNDERLINE, C_INPUT, NULL); refreshp(); miniterm = currentterm; }
int draw_sidebar(int menu) { BUFFY *tmp; #ifndef USE_SLANG_CURSES attr_t attrs; #endif /* ifndef USE_SLANG_CURSES */ short delim_len = strlen(SidebarDelim); short color_pair; static bool initialized = false; static int prev_show_value; static short saveSidebarWidth; int lines = 0; int SidebarHeight; if (globals.has_option(OPTSTATUSONTOP) || globals.has_option(OPTHELP)) lines++; /* either one will occupy the first line */ /* initialize first time */ if (!initialized) { prev_show_value = globals.has_option(OPTSIDEBAR); saveSidebarWidth = SidebarWidth; if (!globals.has_option(OPTSIDEBAR)) SidebarWidth = 0; initialized = true; } /* save or restore the value SidebarWidth */ if (prev_show_value != globals.has_option(OPTSIDEBAR)) { if (prev_show_value && !globals.has_option(OPTSIDEBAR)) { saveSidebarWidth = SidebarWidth; SidebarWidth = 0; } else if (!prev_show_value && globals.has_option(OPTSIDEBAR)) { mutt_buffy_check(1); /* we probably have bad or no numbers */ SidebarWidth = saveSidebarWidth; } prev_show_value = globals.has_option(OPTSIDEBAR); } /* if ( SidebarWidth == 0 ) return 0; */ if ((SidebarWidth > 0) && globals.has_option(OPTSIDEBAR) && (delim_len >= SidebarWidth)) { globals.unset_option(OPTSIDEBAR); /* saveSidebarWidth = SidebarWidth; */ if (saveSidebarWidth > delim_len) { SidebarWidth = saveSidebarWidth; mutt_error(_( "Value for sidebar_delim is too long. Disabling sidebar.")); sleep(2); } else { SidebarWidth = 0; mutt_error(_( "Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value.")); sleep(4); /* the advise to set a sane value should be seen long enough */ } saveSidebarWidth = 0; return 0; } if ((SidebarWidth == 0) || !globals.has_option(OPTSIDEBAR)) { if (SidebarWidth > 0) { saveSidebarWidth = SidebarWidth; SidebarWidth = 0; } globals.unset_option(OPTSIDEBAR); return 0; } /* get attributes for divider */ SETCOLOR(MT_COLOR_STATUS); #ifndef USE_SLANG_CURSES attr_get(&attrs, &color_pair, 0); #else /* ifndef USE_SLANG_CURSES */ color_pair = attr_get(); #endif /* ifndef USE_SLANG_CURSES */ SETCOLOR(MT_COLOR_NORMAL); /* draw the divider */ SidebarHeight = LINES - 1; if (globals.has_option(OPTHELP) || !globals.has_option(OPTSTATUSONTOP)) SidebarHeight--; for (; lines < SidebarHeight; lines++) { move(lines, SidebarWidth - delim_len); addstr(NONULL(SidebarDelim)); #ifndef USE_SLANG_CURSES mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL); #endif /* ifndef USE_SLANG_CURSES */ } if (Incoming == 0) return 0; lines = 0; if (globals.has_option(OPTSTATUSONTOP) || globals.has_option(OPTHELP)) lines++; /* either one will occupy the first line */ if ((known_lines != LINES) || (TopBuffy == 0) || (BottomBuffy == 0)) calc_boundaries(menu); if (CurBuffy == 0) CurBuffy = Incoming; tmp = TopBuffy; SETCOLOR(MT_COLOR_NORMAL); for (; tmp && lines < SidebarHeight; tmp = tmp->next) { if (tmp == CurBuffy) SETCOLOR(MT_COLOR_INDICATOR); else if (tmp->msg_unread > 0) SETCOLOR(MT_COLOR_NEW); else if (tmp->msg_flagged > 0) SETCOLOR(MT_COLOR_FLAGGED); else SETCOLOR(MT_COLOR_NORMAL); move(lines, 0); if (Context && (!strcmp(tmp->path, Context->path) || !strcmp(tmp->realpath, Context->path))) { tmp->msg_unread = Context->unread; tmp->msgcount = Context->msgcount; tmp->msg_flagged = Context->flagged; } /* check whether Maildir is a prefix of the current folder's path */ short maildir_is_prefix = 0; if ((strlen(tmp->path) > strlen(Maildir)) && (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0)) maildir_is_prefix = 1; /* calculate depth of current folder and generate its display name with indented spaces */ int sidebar_folder_depth = 0; char *sidebar_folder_name = globals.has_option(OPTSIDEBARSHORTPATH) ? (char *) mutt_basename(tmp->path) : (char *)(tmp->path + maildir_is_prefix * (strlen(Maildir) + 1)); if (maildir_is_prefix && globals.has_option(OPTSIDEBARFOLDERINDENT)) { char *tmp_folder_name; int i; tmp_folder_name = tmp->path + strlen(Maildir) + 1; for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) { if ((tmp_folder_name[i] == '/') || (tmp_folder_name[i] == '.')) sidebar_folder_depth++; } if (sidebar_folder_depth > 0) { if (globals.has_option(OPTSIDEBARSHORTPATH)) { tmp_folder_name = strrchr(tmp->path, '.'); if (tmp_folder_name == NULL) tmp_folder_name = (__typeof__(tmp_folder_name)) mutt_basename(tmp->path); else tmp_folder_name++; } else tmp_folder_name = tmp->path + strlen(Maildir) + 1; sidebar_folder_name = (__typeof__(sidebar_folder_name)) malloc(strlen(tmp_folder_name) + sidebar_folder_depth * strlen(NONULL(SidebarIndentStr)) + 1); sidebar_folder_name[0] = 0; for (i = 0; i < sidebar_folder_depth; i++) strncat(sidebar_folder_name, NONULL( SidebarIndentStr), strlen(NONULL(SidebarIndentStr))); strncat(sidebar_folder_name, tmp_folder_name, strlen(tmp_folder_name)); } } printw("%.*s", SidebarWidth - delim_len + 1, make_sidebar_entry(sidebar_folder_name, tmp->msgcount, tmp->msg_unread, tmp->msg_flagged)); if (sidebar_folder_depth > 0) free(sidebar_folder_name); lines++; } SETCOLOR(MT_COLOR_NORMAL); for (; lines < SidebarHeight; lines++) { int i = 0; move(lines, 0); for (; i < SidebarWidth - delim_len; i++) addch(' '); } return 0; }
void draw() { int y, x; int color; void *dumb; int snowbar, hpbar; erase(); offset_x = player->x - (COLS / 2); offset_y = player->y - (LINES / 2); for(y=0; y<LINES; y++) for(x=0; x<COLS; x++) { if(x+offset_x < 0 || x+offset_x >= map->width || y+offset_y < 0 || y+offset_y >= map->height) continue; color = map->snow[y+offset_y][x+offset_x] + 1; if(map->trees[y+offset_y][x+offset_x]) { mvprintw(y, x, "&"); mvchgat(y, x, 1, COLOR_PAIR(color+4) | A_BOLD, color+4, dumb); } else mvchgat(y, x, 1, COLOR_PAIR(color), color, dumb); } color = map->snow[player->y][player->x] + 1; mvprintw(player->y-offset_y, player->x-offset_x, "@"); mvchgat(player->y-offset_y, player->x-offset_x, 1, COLOR_PAIR(color)|A_BOLD, color, dumb); for(x = al_first(monsters); x != al_end(monsters); x = al_next(x, monsters)) { monster curr = (monster)al_retrieve(x, monsters); ai(curr); if(curr->hidden) continue; color = map->snow[curr->y][curr->x] + 1; mvprintw(curr->y-offset_y, curr->x-offset_x, "%c", curr->symbol); mvchgat(curr->y-offset_y, curr->x-offset_x, 1, COLOR_PAIR(color)|A_BOLD, color, dumb); } snowbar = (double)(LINES+1) * ((double)snow_count / (double)100); hpbar = (double)(LINES+1) * ((double)player->hp / (double)100); for(y=0; y<snowbar; y++) { mvprintw(LINES-y, 0, " "); mvchgat(LINES-y, 0, 1, COLOR_PAIR(9), 9, dumb); } for(y=0; y<hpbar; y++) { mvprintw(LINES-y, 1, " "); mvchgat(LINES-y, 1, 1, COLOR_PAIR(10), 10, dumb); } while(!al_empty(messages)) { mvprintw(0, 2, "%s", al_retrieve(al_first(messages),messages)); al_delete(al_first(messages), messages); if(!al_empty(messages)) getch(); } refresh(); }
static char *_get_input(CTX *ctx, char *str, char *dflt) { //TODO KEY_ESC cancelation static char in[1000]; char *ptr = in; noecho(); attron( COLOR_PAIR( 2 ) ); mvchgat( ctx->rows - 4, 2, -1, A_INVIS, 0, NULL ); move( ctx->rows - 3, 2 ); for( int i = 0; i < ctx->cols; i++ ) addch( ' ' ); mvprintw( ctx->rows - 3, 2, "%s > ", str ); int y, x; getyx( stdscr, y, x ); attron( A_BOLD ); curs_set( 2 ); if( dflt ) { strcpy( ptr, dflt ); printw( dflt ); ptr += strlen( ptr ); } else memset( in, 0, sizeof( in ) ); int end = 0, c = getch(); do { refresh(); switch( c ) { case KEY_BACKSPACE: if( ptr != in ) *(--ptr) = '\0'; break; case '\n': end = 1; c = '\0'; default: if( strspn( (char*)&c, " ()*,._") || BTWN( c, 0x30, 0x39 ) || BTWN( c, 0x41, 0x5a ) || BTWN( c, 0x61, 0x7a ) ) *(ptr++) = c; } mvprintw( y, x, "%s", in ); for( int i = 0; i < ctx->cols - strlen( in ) - 3; i++ ) addch( ' ' ); move( y, x + strlen( in ) ); } while ( !end && ( c = getch() ) ); curs_set( 0 ); attroff( A_BOLD ); attroff( COLOR_PAIR( 2 ) ); noecho(); return in; }
int do_mode_zero() { int err; /* Generic error variable for function calls */ int busCount; /* Number of WAMs defined in the configuration file */ int i; /* For iterating through the pucks */ /* GUI stuff */ enum { MODE_TOZERO, MODE_CANCEL, MODE_PRINTVALS, MODE_JSELECT, MODE_EDIT } mode; int joint; int decplace; vect_n * jangle; char newhome[80]; char zeromag[80]; clear(); mvprintw(0,0,"Starting Zero Calibration Mode"); /* Ensure the WAM is set up, power cycled, and in the home position */ mvprintw(2,0,"To begin the calibration, follow the following steps:"); mvprintw(3,0," a) Ensure that all WAM power and signal cables are securely fastened."); mvprintw(4,0," b) Ensure that the WAM is powered on (receiving power)."); mvprintw(5,0," c) E-STOP the WAM (Important!)."); mvprintw(6,0," d) Release all E-STOPs."); mvprintw(7,0," e) Place the WAM in Shift+Idle mode."); mvprintw(8,0," f) Carefully ensure that the WAM is in its home (folded) position."); mvprintw(9,0,"Press [Enter] to continue."); refresh(); while (btkey_get()!=BTKEY_ENTER) usleep(10000); /* Initialize system buses */ err = ReadSystemFromConfig("../../wam.conf", &busCount); if(err) return -1; /* Spin off the CAN thread */ startDone = 0; btrt_thread_create(&can_thd,"can",45,(void*)can_thd_function,NULL); while (!startDone) usleep(10000); /* Spin off the magenc thread, which also detecs puck versions into mechset */ /* EEK! Why must this be such high priority? */ mz_mechset = (int *) malloc( wam->dof * sizeof(int) ); mz_magvals = (int *)calloc( wam->dof, sizeof(int) ); mz_magvals_set = 0; btrt_thread_create(&magenc_thd, "mage", 91, (void*)magenc_thd_function, NULL); /* Spin off the WAM thread */ wam_thd.period = 0.002; /* Control loop period in seconds */ btrt_thread_create(&wam_thd,"ctrl",90,(void*)WAMControlThread,(void*)wam); /* Allow the user to shift-activate */ mvprintw(11,0,"Place the WAM in Shift+Activate mode,"); mvprintw(12,0,"and press [Enter] to continue."); refresh(); while (btkey_get()!=BTKEY_ENTER) usleep(10000); /* Hold position */ SetJointSpace(wam); MoveSetup(wam, 1.0, 1.0); MoveWAM(wam,wam->Jpos); /* Start the user interface */ mode = MODE_TOZERO; joint = 0; jangle = new_vn(wam->dof); set_vn(jangle,wam->Jpos); clear(); done = 0; signal(SIGINT, sigint); while (!done) { char buf[80]; int j; int line; enum btkey key; /* Display the Zeroing calibration stuff ... */ mz_magvals_set = 1; mvprintw(0, 0, "Joint Position (rad): %s", sprint_vn(buf, wam->Jpos)); line = 2; if (mode == MODE_TOZERO) { attron(A_BOLD); mvprintw(line++, 0, "--> ] Move To Current Zero"); attroff(A_BOLD); } else mvprintw(line++, 0, " ] Move To Current Zero"); if (mode == MODE_CANCEL) { attron(A_BOLD); mvprintw(line++, 0, "--> ] Cancel Calibration"); attroff(A_BOLD); } else mvprintw(line++, 0, " ] Cancel Calibration"); if (mode == MODE_PRINTVALS) { attron(A_BOLD); mvprintw(line++, 0, "--> ] Print Calibrated Values and Exit"); attroff(A_BOLD); } else mvprintw(line++, 0, " ] Print Calibrated Values and Exit"); if (mode == MODE_JSELECT) { attron(A_BOLD); mvprintw(line, 0, "--> ] Joint:"); attroff(A_BOLD); } else mvprintw(line, 0, " ] Joint:"); mvprintw(line+1, 5, "-------"); if (mode == MODE_EDIT) attron(A_BOLD); mvprintw(line+2, 5, " Set:"); if (mode == MODE_EDIT) attroff(A_BOLD); mvprintw(line+3, 5, "Actual:"); mvprintw(line+5, 5, " Motor:"); mvprintw(line+6, 5, "MagEnc:"); for (j=0; j<wam->dof; j++) { if ((mode == MODE_JSELECT || mode == MODE_EDIT) && j==joint) { attron(A_BOLD); mvprintw(line+0, 13 + 9*j, "[Joint %d]",j+1); attroff(A_BOLD); } else mvprintw(line+0, 13 + 9*j, " Joint %d ",j+1); /* total with 8, 5 decimal points (+0.12345) */ if ( mode==MODE_EDIT && j==joint ) { int boldplace; mvprintw(line+1, 13 + 9*j, " _._____ ",j+1); mvprintw(line+2, 13 + 9*j, "% 08.5f ",jangle->q[j]); boldplace = decplace + 1; if (decplace) boldplace++; mvprintw(line+1, 13 + 9*j + boldplace,"x"); mvchgat(line+2, 13 + 9*j+boldplace, 1, A_BOLD, 0, NULL ); } else { mvprintw(line+1, 13 + 9*j, " ------- ",j+1); mvprintw(line+2, 13 + 9*j, "% 08.5f ",jangle->q[j]); } mvprintw(line+3, 13 + 9*j, "% 08.5f ",getval_vn(wam->Jpos,j)); mvprintw(line+5, 13 + 9*j, " Motor %d",j+1); if (mz_mechset[j]) mvprintw(line+6, 13 + 9*j, " %04d",mz_magvals[j]); else mvprintw(line+6, 13 + 9*j, " (None)",mz_magvals[j]); } refresh(); /* Wait a bit ... */ usleep(5E4); key = btkey_get(); /* If the user is in menu mode, work the menu ... */ if (mode != MODE_EDIT) switch (key) { case BTKEY_UP: mode--; if ((signed int)mode < 0) mode = 0; break; case BTKEY_DOWN: mode++; if (mode > MODE_JSELECT) mode = MODE_JSELECT; break; case BTKEY_ENTER: switch (mode) { case MODE_TOZERO: if (!MoveIsDone(wam)) break; fill_vn(jangle,0.0); MoveWAM(wam,jangle); break; case MODE_CANCEL: done = -1; break; case MODE_PRINTVALS: if (!MoveIsDone(wam)) break; done = 1; break; case MODE_JSELECT: mode = MODE_EDIT; decplace = 4; break; } break; default: if (mode == MODE_JSELECT) switch (key) { case BTKEY_LEFT: joint--; if (joint < 0) joint = 0; break; case BTKEY_RIGHT: joint++; if (joint >= wam->dof) joint = wam->dof - 1; break; } break; } /* We're in joint edit mode */ else switch (key) { case BTKEY_LEFT: decplace--; if (decplace < 0) decplace = 0; break; case BTKEY_RIGHT: decplace++; if (decplace > 5) decplace = 5; break; case BTKEY_BACKSPACE: mode = MODE_JSELECT; break; /* Actually do the moves */ case BTKEY_UP: if (!MoveIsDone(wam)) break; jangle->q[joint] += pow(10,-decplace); MoveWAM(wam,jangle); break; case BTKEY_DOWN: if (!MoveIsDone(wam)) break; jangle->q[joint] -= pow(10,-decplace); MoveWAM(wam,jangle); break; default: break; } } if (done == 1) { vect_n * vec; /* Save the new home location */ vec = new_vn(wam->dof); set_vn( vec, sub_vn(wam->park_location,jangle) ); sprint_vn(newhome,vec); destroy_vn(&vec); /* Save the zeromag values */ for (i=0; i<wam->dof; i++) if (!mz_mechset[i]) mz_magvals[i] = -1; sprintf(zeromag,"< %d",mz_magvals[0]); for (i=1; i<wam->dof; i++) sprintf(zeromag+strlen(zeromag),", %d",mz_magvals[i]); sprintf(zeromag+strlen(zeromag)," >"); } /* Re-fold, print, and exit */ clear(); mvprintw(0,0,"Moving back to the park location ..."); refresh(); MoveWAM(wam,wam->park_location); while (!MoveIsDone(wam)) usleep(10000); mvprintw(1,0,"Shift+Idle, and press [Enter] to continue."); refresh(); while (btkey_get()!=BTKEY_ENTER) usleep(10000); /* Stop threads ... */ wam_thd.done = 1; usleep(10000); can_thd.done = 1; usleep(50000); /* Stop ncurses ... */ endwin(); if (done == 1) { /* Print the results */ printf("\n"); printf("Zeroing calibration ended.\n"); printf("\n"); for (i=0; i<wam->dof; i++) if (!mz_mechset[i]) { printf("Note: Some (or all) of your pucks do not support absolute\n"); printf("position measurement, either because they do not use magnetic\n"); printf("encoders, or because they have not been updated to firmware r118.\n"); printf("\n"); break; } printf("Copy the following lines into your wam.conf file,\n"); printf("near the top, in the %s{} group.\n",wam->name); printf("Make sure it replaces the old home = < ... > definition.\n"); printf("--------\n"); printf(" # Calibrated zero values ...\n"); printf(" home = %s\n",newhome); for (i=0; i<wam->dof; i++) if (mz_mechset[i]) { printf(" zeromag = %s\n",zeromag); break; } printf("--------\n"); { FILE * logfile; logfile = fopen("cal-zero.log","w"); if (logfile) { fprintf(logfile," # Calibrated zero values ...\n"); fprintf(logfile," home = %s\n",newhome); for (i=0; i<wam->dof; i++) if (mz_mechset[i]) { fprintf(logfile," zeromag = %s\n",zeromag); break; } fclose(logfile); printf("This text has been saved to cal-zero.log.\n"); printf("\n"); } else { syslog(LOG_ERR,"Could not write to cal-zero.log."); printf("Error: Could not write to cal-zero.log.\n"); printf("\n"); } } printf("Note that you must E-Stop (or power-cycle) your WAM\n"); printf("for the calibrated settings to take effect!\n"); printf("\n"); } return 0; }
void showproc(struct myproc *proc, int *py, int indent) { struct myproc *p; int y = *py; if(y >= LINES) return; /* FIXME */ if(y > 0){ // otherwise we're iterating over a process that's above pos_top if(proc->pid != 0) { //dummy root node excluded extern uid_t global_uid; extern int max_unam_len, max_gnam_len; const int owned = proc->uid == global_uid; char buf[256]; int len = LINES; int lock = proc->pid == lock_proc_pid; int x; move(y, 0); if(lock) attron(ATTR_LOCK); else if(proc == search_proc) attron(ATTR_SEARCH); else if(proc->flag & P_JAILED) attron(ATTR_JAILED); else if(!owned) attron(ATTR_NOT_OWNED); if(!(proc->flag & P_JAILED)){ // non-jailed processes len -= snprintf(buf, sizeof buf, "% 7d %-7s " "%-*s %-*s " "%3.1f" , proc->pid, proc->state_str, max_unam_len, proc->unam, max_gnam_len, proc->gnam, proc->pc_cpu ); } else { // processes in a jail; display Jail ID len -= snprintf(buf, sizeof buf, "% 7d %3d %-7s " "%-*s %-*s " "%3.1f" , proc->pid, proc->jid, proc->state_str, max_unam_len, proc->unam, max_gnam_len, proc->gnam, proc->pc_cpu ); } addstr(buf); getyx(stdscr, y, x); if(proc->state == SRUN){ mvchgat(y, 14, 7, 0, COLOR_RUNNING + 1, NULL); move(y, x); } clrtoeol(); /* position for process name */ // TODO: add some define that adjusts offset here x+=5; /* one after the state */ for(int indent_copy = indent; indent_copy > 0; indent_copy--) x += INDENT; mvprintw(y, x, "%s", proc->cmd, COLS - indent - len - 1); /* basename shading */ if(owned && !lock){ const int bn_len = strlen(proc->basename); int min_len = COLS - indent - len - 1; if(min_len > bn_len) min_len = bn_len; x += proc->basename_offset; attron(ATTR_BASENAME); mvaddnstr(y, x, proc->basename, min_len); } if(lock) attroff(ATTR_LOCK); else if(proc == search_proc) attroff(ATTR_SEARCH); else if(owned) attroff(ATTR_BASENAME); else if(proc->flag & P_JAILED) attroff(ATTR_JAILED); else attroff(ATTR_NOT_OWNED); } } /* * need to iterate over all children, * since we may currently be on a process above the top */ for(p = proc->child_first; p; p = p->child_next){ y++; showproc(p, &y, indent + 1); } *py = y; }