Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <curses.h>
- #include <cstring>
- #include <stdlib.h>
- #include <stdio.h>
- int Key;
- //c++ CursesExample.cpp -lcurses -ocurses
- //OR
- //c++ CursesExample.cpp -lncurses -ocurses
- //./curses
- WINDOW *create_newwin(int height, int width, int posy, int posx);
- void destroy_window(WINDOW *local_win);
- void print_middle(WINDOW *win, char *string);
- int main() {
- int Kp = 0; //P
- int Ti = 0; //I
- int Td = 0; //D
- int posx, posy;
- int height, width;
- WINDOW *menu_window;
- char str[10];
- initscr();
- noecho();
- //raw();
- //keypad(stscr, TRUE);
- curs_set(0);
- timeout(0);
- height = 10;
- width = 40;
- posx = (COLS - width)/2;
- posy = (LINES - height)/2;
- mvprintw( 9,10, "Select one of the following");
- mvprintw(10,10, "--------------------------------------------");
- mvprintw(11,10, "1. P to change Kp");
- mvprintw(12,10, "2. I to change Ti");
- mvprintw(13,10, "3. D to change Td");
- mvprintw(14,10, "4. N to change derivative filter");
- mvprintw(15,10, "5. S to change setpoint signal s(t)");
- mvprintw(16,10, "---------------------------------------------");
- mvprintw(18,10, "6. Q to Quit program");
- while((Key = toupper(getch()))!= 'Q') {
- switch(Key) {
- case 'p' : case 'P' :
- menu_window = create_newwin(height, width, posy, posx);
- //*string = ;
- print_middle(menu_window, "Enter value of Kp");
- timeout(5000);
- getstr(str);
- Kp = atoi(str);
- print_middle(menu_window, " ");
- //print_middle(menu_window, "Kp set to: %d", Kp);
- timeout(0);
- destroy_window(menu_window);
- refresh();
- //wrefresh(stdscr);
- break;
- default :
- timeout(0);
- }
- }
- curs_set(1);
- endwin();
- return 0;
- }
- WINDOW *create_newwin(int height, int width, int posy, int posx) {
- WINDOW *local_win;
- local_win = newwin(height, width, posy, posx);
- box(local_win, 0, 0);
- wrefresh(local_win);
- return local_win;
- }
- void destroy_window(WINDOW *local_win) {
- wborder(local_win, '|', '|', '-','-','+','+','+','+');
- wrefresh(local_win);
- delwin(local_win);
- }
- void print_middle(WINDOW *win, char *string) {
- int length, x, y;
- int width, height;
- getmaxyx(win, height, width);
- length = strlen(string);
- x = (int)(width - length) /2.0;
- y = height/2;
- mvwprintw(win, y, x, "%s", string);
- wrefresh(win);
- }
Add Comment
Please, Sign In to add comment