Fleshed out monitor example

This commit is contained in:
Jason Watkins
2015-06-11 12:15:14 -07:00
parent 9359a93068
commit 337182f241

View File

@@ -35,6 +35,10 @@ void setCursor(short x, short y)
if (!console) if (!console)
{ {
console = GetStdHandle(STD_OUTPUT_HANDLE); console = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 0;
info.bVisible = FALSE;
SetConsoleCursorInfo(console, &info);
} }
COORD dwCursorPosition; COORD dwCursorPosition;
dwCursorPosition.X = x; dwCursorPosition.X = x;
@@ -48,10 +52,19 @@ void setCursor(short x, short y)
} }
} }
#else #else
#include "time.h"
void setCursor(short x, short y) void setCursor(short x, short y)
{ {
// ??? // ???
} }
void Sleep(int ms)
{
struct timespec tv;
tv.tv_nsec = ms * 1000 * 1000;
nanosleep(tv, NULL);
}
#endif #endif
void printChrome() void printChrome()
@@ -62,12 +75,16 @@ void printChrome()
printf("+======================================================================+\n"); printf("+======================================================================+\n");
printf("| X-Plane Connect Status Monitor Example Application |\n"); printf("| X-Plane Connect Status Monitor Example Application |\n");
printf("+===================+==================================================+\n"); printf("+===================+==================================================+\n");
printf("| Aircraft Position | |\n"); printf("| Aircraft Position | Aircraft Orientation | Aircraft Control Surfaces |\n");
printf("+-------------------+ |\n"); printf("+-------------------+----------------------+---------------------------+\n");
printf("| Lat: | |\n"); printf("| Lat: | Roll: | Aileron: |\n");
printf("| Lon: | |\n"); printf("| Lon: | Pitch: | Elevator: |\n");
printf("| Alt: | |\n"); printf("| Alt: | Yaw: | Rudder: |\n");
printf("+-------------------+ |\n"); printf("| | | Flaps: |\n");
printf("+-------------------+----------------------+---------------------------+\n");
printf("| Throttle: | Gear: | |\n");
printf("+-------------------+----------------------+---------------------------+\n");
printf("| Press Ctrl+C to quit. |\n");
printf("+======================================================================+\n"); printf("+======================================================================+\n");
} }
@@ -81,16 +98,59 @@ void printLocation(float lat, float lon, float alt)
printf("%2fm", alt); printf("%2fm", alt);
} }
void printOrientation(float roll, float pitch, float yaw)
{
setCursor(29, 5);
printf("%4f", roll);
setCursor(29, 6);
printf("%4f", pitch);
setCursor(29, 7);
printf("%4f", yaw);
}
void printControls(float aileron, float elevator, float rudder, float flaps)
{
setCursor(55, 5);
printf("%4f", aileron);
setCursor(55, 6);
printf("%4f", elevator);
setCursor(55, 7);
printf("%4f", rudder);
setCursor(55, 8);
printf("%4f", flaps);
}
void printThrottle(float throttle)
{
setCursor(12, 10);
printf("%2f", throttle);
}
void printGear(float gear)
{
setCursor(28, 10);
printf("%2f", gear);
}
int main(void) int main(void)
{ {
printChrome(); printChrome();
XPCSocket client = openUDP("127.0.0.1"); XPCSocket client = openUDP("127.0.0.1");
const int aircraftNum = 0;
while (1) while (1)
{ {
float posi[7]; float posi[7];
getPOSI(client, posi, 0); getPOSI(client, posi, aircraftNum);
printLocation(posi[0], posi[1], posi[2]); printLocation(posi[0], posi[1], posi[2]);
printOrientation(posi[4], posi[3], posi[5]);
float ctrl[7];
getCTRL(client, ctrl, aircraftNum);
printControls(ctrl[1], ctrl[0], ctrl[2], ctrl[5]);
printThrottle(ctrl[3]);
printGear(ctrl[4]);
Sleep(100);
} }
return 0; return 0;
} }