-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.c
202 lines (151 loc) · 6.58 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <ncurses.h>
#include <menu.h>
#include "global.h"
//#include "phidget.h"
int kbhit(void)
{
timeout(1);
int ch = getch();
if (ch != ERR) {
ungetch(ch);
return 1;
} else {
return 0;
}
}
void init_display(void){
initscr();
//printf("\033[2J\033[1;1H");
printw(" ______________________________________________________________________________\n");
printw("| |\n");
printw("| Ground Control |\n");
printw("| Menu: (c) Calibration |\n");
printw("|______________________________________________________________________________|\n");
printw("| |\n");
printw("| Phidget: |\n");
printw("| UAV: |\n");
printw("|______________________________________________________________________________|\n");
printw("| |\n");
printw("| ForceX: |\n");
printw("| ForceY: |\n");
printw("| Total force: |\n");
printw("| Angle: |\n");
printw("| Force: |\n");
printw("|______________________________________________________________________________|\n");
printw("| |\n");
printw("| <Backspace> : Back to Menu |\n");
printw("| <r> : Reset Statistics |\n");
printw("| <Esc> / <s> : Stop Program |\n");
printw("|______________________________________________________________________________|\n");
mvprintw(24,10,"");
refresh();
}
void display_calibration(void){
double noLoadX,noLoadY, loadX, loadY, load;
load = 0.5; // calibration load
// clear screen
clear();
// No load
mvprintw(0,0," ______________________________________________________________________________\n");
printw("| |\n");
printw("| Ground Control |\n");
printw("| CALIBRATION |\n");
printw("|______________________________________________________________________________|\n");
printw("| |\n");
printw("| ForceX: |\n");
printw("| ForceY: |\n");
printw("| Total force: |\n");
printw("|______________________________________________________________________________|\n");
printw("| |\n");
printw("| 1. No load |\n");
printw("| Remove all load from the cable and winch the cable all in. |\n");
printw("| Hit any key when ready |\n");
printw("|______________________________________________________________________________|\n");
mvprintw(6,27,"%lf", forceX);
mvprintw(7,27,"%lf", forceY);
mvprintw(8,27,"%lf", forceX+forceY);
refresh();
while(!kbhit()){
mvprintw(6,27,"%lf", forceX);
mvprintw(7,27,"%lf", forceY);
mvprintw(8,27,"%lf", forceX+forceY);
refresh();
}
// clear buffer
getch();
noLoadX = loadcellX.input;
noLoadY = loadcellY.input;
// Known load X
mvprintw(11,0,"| 2. X load |\n");
printw("| Put 0.5kg load on X-loadcell in positiv direction. |\n");
printw("| Hit any key when ready |\n");
//printw("|______________________________________________________________________________|\n");
refresh();
while(!kbhit()){
mvprintw(6,27,"%lf", forceX);
mvprintw(7,27,"%lf", forceY);
mvprintw(8,27,"%lf", forceX+forceY);
refresh();
}
// clear buffer
getch();
// update X gain
loadX = loadcellX.input;
// Known load Y
mvprintw(11,0,"| 3. Y load |\n");
printw("| Put 0.5kg load on Y-loadcell in positiv direction. |\n");
printw("| Hit any key when ready |\n");
//printw("|______________________________________________________________________________|\n");
refresh();
while(!kbhit()){
mvprintw(6,27,"%lf", forceX);
mvprintw(7,27,"%lf", forceY);
mvprintw(8,27,"%lf", forceX+forceY);
refresh();
}
// clear buffer
getch();
// update gain Y
loadY = loadcellY.input;
// clear screen
clear();
// return
Calibration(noLoadX, noLoadY, loadX, loadY, load);
}
void update_display(void){
time_t current_time;
char* c_time_string;
current_time = time(NULL);
c_time_string = ctime(¤t_time);
mvprintw(2,40,"%s",c_time_string);
mvprintw(6,27,"%s", MsgPhidgets);
mvprintw(10,27,"%lf\t%lf", loadcellX.input, loadcellX.force);
mvprintw(11,27,"%lf\t%lf", loadcellY.input, loadcellY.force);
mvprintw(12,27,"%lf", loadcellX.input+loadcellY.input);
mvprintw(13,27,"%lf", phi);
mvprintw(14,27,"%lf", r);
//mvprintw("\033[16;1H");
refresh();
}
void display(void){
init_display();
char cmd;
while(stop == 0){
if(kbhit()){
cmd = getch();
// Calibration
if(cmd == 'c'){
display_calibration();
init_display();
}
} // end kbhit()
update_display();
sleep(1);
}
endwin();
}