2015-05-01 19:23:00 +00:00
|
|
|
|
#include <ncurses.h>
|
2015-05-02 13:37:58 +00:00
|
|
|
|
#include <string>
|
2015-05-01 21:22:13 +00:00
|
|
|
|
#include "display.h"
|
2015-05-01 19:23:00 +00:00
|
|
|
|
|
2015-05-02 18:52:46 +00:00
|
|
|
|
const int Curses::cmd_kbd_lines = 7;
|
|
|
|
|
const int Curses::cmd_kbd_columns = 55;
|
2015-05-02 17:24:54 +00:00
|
|
|
|
|
2015-05-02 13:37:58 +00:00
|
|
|
|
const int Curses::cmd_speed_lines = 4;
|
2015-05-02 18:52:46 +00:00
|
|
|
|
const int Curses::cmd_speed_columns = 55;
|
2015-05-01 19:23:00 +00:00
|
|
|
|
|
2015-05-02 17:24:54 +00:00
|
|
|
|
const int Curses::get_lines = 1;
|
|
|
|
|
const int Curses::get_columns = 1;
|
|
|
|
|
|
2015-05-02 18:52:46 +00:00
|
|
|
|
const int Curses::nav_data_lines = 3;
|
|
|
|
|
const int Curses::nav_data_columns = 55;
|
2015-05-02 17:24:54 +00:00
|
|
|
|
|
|
|
|
|
const int Curses::log_sent_w_lines = 12;
|
|
|
|
|
const int Curses::log_sent_w_columns = 40;
|
|
|
|
|
|
2015-05-01 19:23:00 +00:00
|
|
|
|
Curses::Curses() {
|
|
|
|
|
initscr();
|
|
|
|
|
cbreak();
|
2015-05-02 17:58:04 +00:00
|
|
|
|
start_color();
|
2015-05-01 22:00:28 +00:00
|
|
|
|
//noecho();
|
2015-05-02 17:24:54 +00:00
|
|
|
|
|
2015-05-02 13:37:58 +00:00
|
|
|
|
cmd_kbd = newwin(cmd_kbd_lines, cmd_kbd_columns, 0, 0);
|
2015-05-02 17:24:54 +00:00
|
|
|
|
|
|
|
|
|
get = newwin(get_lines, get_columns,
|
|
|
|
|
cmd_kbd_lines, cmd_kbd_columns/2);
|
|
|
|
|
|
|
|
|
|
cmd_speed = newwin(cmd_speed_lines, cmd_speed_columns,
|
|
|
|
|
cmd_kbd_lines + get_lines, 0);
|
|
|
|
|
|
2015-05-02 17:58:04 +00:00
|
|
|
|
log_sent_title = newwin(1, log_sent_w_columns,
|
|
|
|
|
0, cmd_kbd_columns + 1);
|
|
|
|
|
waddstr(log_sent_title, "SENT COMMANDS");
|
|
|
|
|
wrefresh(log_sent_title);
|
|
|
|
|
log_sent_w = newwin(log_sent_w_lines - 1, log_sent_w_columns,
|
|
|
|
|
1, cmd_kbd_columns + 1);
|
|
|
|
|
log_line_number = log_sent_w_lines - 2;
|
2015-05-02 17:46:02 +00:00
|
|
|
|
wattron(log_sent_w, A_BOLD);
|
|
|
|
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
|
|
|
|
wattron(log_sent_w, COLOR_PAIR(1));
|
2015-05-02 17:24:54 +00:00
|
|
|
|
scrollok(log_sent_w, TRUE);
|
|
|
|
|
|
|
|
|
|
nav_data = newwin(nav_data_lines, nav_data_columns,
|
2015-05-02 18:52:46 +00:00
|
|
|
|
cmd_kbd_lines + get_lines + cmd_speed_lines + 1, 0);
|
2015-05-02 17:24:54 +00:00
|
|
|
|
|
2015-05-02 18:52:46 +00:00
|
|
|
|
print_nav_data();
|
2015-05-02 13:37:58 +00:00
|
|
|
|
print_cmd_kbd();
|
|
|
|
|
print_cmd_speed();
|
2015-05-02 17:24:54 +00:00
|
|
|
|
|
2015-05-01 22:00:28 +00:00
|
|
|
|
wmove(get, 0, 0);
|
|
|
|
|
wrefresh(get);
|
2015-05-01 19:23:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Curses::~Curses() {
|
2015-05-02 13:37:58 +00:00
|
|
|
|
delwin(cmd_kbd);
|
|
|
|
|
delwin(cmd_speed);
|
|
|
|
|
delwin(log_sent_w);
|
2015-05-02 17:58:04 +00:00
|
|
|
|
delwin(log_sent_title);
|
2015-05-02 13:37:58 +00:00
|
|
|
|
delwin(nav_data);
|
2015-05-01 22:00:28 +00:00
|
|
|
|
delwin(get);
|
2015-05-01 19:23:00 +00:00
|
|
|
|
endwin();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 13:37:58 +00:00
|
|
|
|
char Curses::getchar() {
|
2015-05-01 22:00:28 +00:00
|
|
|
|
return wgetch(get);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 13:37:58 +00:00
|
|
|
|
void Curses::print_cmd_kbd() {
|
2015-05-02 18:52:46 +00:00
|
|
|
|
wmove(cmd_kbd, 0, 0);
|
|
|
|
|
waddstr(cmd_kbd, " ---------------------\n");
|
|
|
|
|
waddstr(cmd_kbd, "takeoff>| t|⇑ y|↖ u|↑ i|↗ o|\n");
|
|
|
|
|
waddstr(cmd_kbd, " |---|---|---|---|---|----\n");
|
|
|
|
|
waddstr(cmd_kbd, " reset>| g|⇐ h|← j| k|→ l|⇒ m|\n");
|
|
|
|
|
waddstr(cmd_kbd, " |---|---|---|---|---|----\n");
|
|
|
|
|
waddstr(cmd_kbd, " land>| b|⇓ n|↙ ,|↓ ;|↘ :|\n");
|
|
|
|
|
waddstr(cmd_kbd, " ---------------------\n");
|
2015-05-02 13:37:58 +00:00
|
|
|
|
wrefresh(cmd_kbd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Curses::print_cmd_speed() {
|
2015-05-02 18:52:46 +00:00
|
|
|
|
wmove(cmd_speed, 0, 0);
|
|
|
|
|
waddstr(cmd_speed, " `x` cmd speed : (a/w : increase/decrease)\n");
|
|
|
|
|
waddstr(cmd_speed, " `y` cmd speed : (z/x : increase/decrease)\n");
|
|
|
|
|
waddstr(cmd_speed, " `z` cmd speed : (e/c : increase/decrease)\n");
|
|
|
|
|
waddstr(cmd_speed, "rotation speed : (r/v : increase/decrease)\n");
|
|
|
|
|
wrefresh(cmd_speed);
|
2015-05-02 13:37:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Curses::update_cmd_speed(const char& coord, const float& v) {
|
2015-05-02 18:52:46 +00:00
|
|
|
|
switch(coord) {
|
|
|
|
|
case 'x':
|
|
|
|
|
wmove(cmd_speed, 0, 16);
|
|
|
|
|
wprintw(cmd_speed, "%f", v);
|
|
|
|
|
break;
|
|
|
|
|
case 'y':
|
|
|
|
|
wmove(cmd_speed, 1, 16);
|
|
|
|
|
wprintw(cmd_speed, "%f", v);
|
|
|
|
|
break;
|
|
|
|
|
case 'z':
|
|
|
|
|
wmove(cmd_speed, 2, 16);
|
|
|
|
|
wprintw(cmd_speed, "%f", v);
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
wmove(cmd_speed, 3, 16);
|
|
|
|
|
wprintw(cmd_speed, "%f", v);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
wrefresh(cmd_speed);
|
2015-05-02 13:37:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Curses::log_sent(const std::string& str) {
|
2015-05-02 17:24:54 +00:00
|
|
|
|
wmove(log_sent_w, log_line_number++, 0);
|
|
|
|
|
waddstr(log_sent_w, (str + "\n").c_str() );
|
|
|
|
|
wrefresh(log_sent_w);
|
2015-05-02 13:37:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 18:52:46 +00:00
|
|
|
|
|
|
|
|
|
void Curses::print_nav_data() {
|
|
|
|
|
wmove(nav_data, 0, 0);
|
|
|
|
|
waddstr(nav_data, "Battery :\n State :\n Time :");
|
|
|
|
|
wrefresh(nav_data);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 13:37:58 +00:00
|
|
|
|
void Curses::update_navdata(const float& batteryPercent,
|
|
|
|
|
const int& state,
|
|
|
|
|
const float& time) {
|
2015-05-01 19:23:00 +00:00
|
|
|
|
}
|