corrects how to get the char

This commit is contained in:
Louis-Guillaume DUBOIS 2015-05-02 00:00:28 +02:00
parent b3226f33b9
commit f09c762cb2
3 changed files with 22 additions and 10 deletions

View file

@ -9,18 +9,27 @@ const int Curses::speed_columns = 50;
Curses::Curses() { Curses::Curses() {
initscr(); initscr();
cbreak(); cbreak();
noecho(); //noecho();
kbd = newwin(kbd_lines, kbd_columns, 0, 0); kbd = newwin(kbd_lines, kbd_columns, 0, 0);
speed = newwin(speed_lines, speed_columns, speed = newwin(speed_lines, speed_columns, kbd_lines+1, 0);
kbd_lines+1, 0); get = newwin(1,1,kbd_lines+speed_lines+1,2);
print_kbd();
wmove(get, 0, 0);
wrefresh(get);
} }
Curses::~Curses() { Curses::~Curses() {
delwin(kbd); delwin(kbd);
delwin(speed); delwin(speed);
delwin(get);
endwin(); endwin();
} }
char Curses::getchar()
{
return wgetch(get);
}
void Curses::print_kbd() { void Curses::print_kbd() {
wmove(kbd, 0, 0); waddstr(kbd, " ---------------------"); wmove(kbd, 0, 0); waddstr(kbd, " ---------------------");
wmove(kbd, 1, 0); waddstr(kbd, "takeoff>| t|⇑ y|↖ u|↑ i|↗ o|"); wmove(kbd, 1, 0); waddstr(kbd, "takeoff>| t|⇑ y|↖ u|↑ i|↗ o|");

View file

@ -13,11 +13,13 @@ class Curses
static const int speed_lines; static const int speed_lines;
static const int speed_columns; static const int speed_columns;
WINDOW* speed; WINDOW* speed;
void print_kbd();
WINDOW* get;
public: public:
Curses(); Curses();
~Curses(); ~Curses();
void print_kbd(); char getchar();
}; };
#endif #endif

View file

@ -26,11 +26,12 @@ class Run
void reset() void reset()
{ pub_reset.publish(empty); }; { pub_reset.publish(empty); };
float x_speed, y_speed, z_speed, turn; float x_speed, y_speed, z_speed, turn;
Curses term; boost::shared_ptr<Curses> term;
void print_speed() { ; }; void print_speed() { ; };
public: public:
Run() : Run(boost::shared_ptr<Curses> terminal) :
term(terminal),
loop_rate(30), loop_rate(30),
x_speed(0.2), x_speed(0.2),
y_speed(0.3), y_speed(0.3),
@ -50,7 +51,7 @@ class Run
msg->linear.x = msg->linear.y = msg->linear.z = msg->linear.x = msg->linear.y = msg->linear.z =
msg->angular.x = msg->angular.y = msg->angular.z = 0.; msg->angular.x = msg->angular.y = msg->angular.z = 0.;
char c = getch(); char c = term->getchar();
switch(c) switch(c)
{ {
@ -212,9 +213,9 @@ int main(int argc, char** argv)
{ {
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
ros::init(argc, argv, "keyboard_cmd"); ros::init(argc, argv, "keyboard_cmd");
Curses terminal; boost::shared_ptr<Curses> term(new Curses());
terminal.print_kbd(); Run fun(term);
for(;;) ; fun();
return 0; return 0;
} }