Guest User

Untitled

a guest
Dec 13th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <curses.h>
  3. #include <cstring>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. int Key;
  7.  
  8. //c++ CursesExample.cpp -lcurses -ocurses
  9. //OR
  10. //c++ CursesExample.cpp -lncurses -ocurses
  11. //./curses
  12.  
  13. WINDOW *create_newwin(int height, int width, int posy, int posx);
  14. void destroy_window(WINDOW *local_win);
  15. void print_middle(WINDOW *win, char *string);
  16.  
  17.  
  18. int main() {
  19.  
  20.  int Kp = 0; //P
  21.  int Ti = 0; //I
  22.  int Td = 0; //D
  23.  int posx, posy;
  24.  int height, width;
  25.  WINDOW *menu_window;
  26.  char str[10];
  27.  
  28.  initscr();
  29.  noecho();
  30.  //raw();
  31.  //keypad(stscr, TRUE);
  32.  curs_set(0);
  33.  timeout(0);
  34.  
  35.  height = 10;
  36.  width = 40;
  37.  posx = (COLS - width)/2;
  38.  posy = (LINES - height)/2;
  39.  
  40.  
  41.  mvprintw( 9,10, "Select one of the following");
  42.  mvprintw(10,10, "--------------------------------------------");
  43.  mvprintw(11,10, "1. P to change Kp");
  44.  mvprintw(12,10, "2. I to change Ti");
  45.  mvprintw(13,10, "3. D to change Td");
  46.  mvprintw(14,10, "4. N to change derivative filter");
  47.  mvprintw(15,10, "5. S to change setpoint signal s(t)");
  48.  mvprintw(16,10, "---------------------------------------------");
  49.  
  50.  mvprintw(18,10, "6. Q to Quit program");
  51.  
  52.  while((Key = toupper(getch()))!= 'Q') {
  53.   switch(Key) {
  54.     case 'p' : case 'P' :
  55.       menu_window = create_newwin(height, width, posy, posx);
  56.       //*string = ;
  57.       print_middle(menu_window, "Enter value of Kp");
  58.       timeout(5000);
  59.       getstr(str);
  60.       Kp = atoi(str);
  61.       print_middle(menu_window, "                  ");
  62.       //print_middle(menu_window, "Kp set to: %d", Kp);
  63.       timeout(0);
  64.       destroy_window(menu_window);
  65.       refresh();
  66.       //wrefresh(stdscr);
  67.       break;
  68.     default :
  69.       timeout(0);
  70.   }  
  71.  }
  72.   curs_set(1);
  73.   endwin();
  74.   return 0;
  75. }
  76.  
  77. WINDOW *create_newwin(int height, int width, int posy, int posx) {
  78.   WINDOW *local_win;
  79.   local_win = newwin(height, width, posy, posx);
  80.   box(local_win, 0, 0);
  81.   wrefresh(local_win);
  82.   return local_win;  
  83. }
  84. void destroy_window(WINDOW *local_win) {
  85.   wborder(local_win, '|', '|', '-','-','+','+','+','+');
  86.   wrefresh(local_win);
  87.   delwin(local_win);
  88. }
  89. void print_middle(WINDOW *win, char *string) {
  90.  int length, x, y;
  91.  int width, height;
  92.  
  93.  
  94.  getmaxyx(win, height, width);
  95.  
  96.  length = strlen(string);
  97.  x = (int)(width - length) /2.0;
  98.  y = height/2;
  99.  
  100.  mvwprintw(win, y, x, "%s", string);
  101.  wrefresh(win);
  102. }
Add Comment
Please, Sign In to add comment