Commit 13153d1b authored by Timothy Stack's avatar Timothy Stack

Print out the camera bounds when exiting

parent 5dab87f1
......@@ -18,6 +18,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <signal.h>
#include <float.h>
#include <sys/types.h>
#include <netdb.h>
......@@ -29,6 +31,23 @@
#include "mtp.h"
static int looping = 1;
#define min(x, y) ((x) < (y)) ? (x) : (y)
#define max(x, y) ((x) > (y)) ? (x) : (y)
/**
* Signal handler for SIGINT, SIGQUIT, and SIGTERM that sets looping to zero.
*
* @param signal The actual signal received.
*/
static void sigquit(int signal)
{
assert((signal == SIGINT) || (signal == SIGQUIT) || (signal == SIGTERM));
looping = 0;
}
static int mygethostbyname(struct sockaddr_in *host_addr, char *host)
{
struct hostent *host_ent;
......@@ -60,6 +79,10 @@ int main(int argc, char *argv[])
int port = 0, max_packets = 0, retval = EXIT_FAILURE;
struct sockaddr_in sin;
signal(SIGQUIT, sigquit);
signal(SIGTERM, sigquit);
signal(SIGINT, sigquit);
memset(&sin, 0, sizeof(sin));
if (argc < 3) {
......@@ -97,13 +120,25 @@ int main(int argc, char *argv[])
fprintf(stderr, "error: mtp_init_handle\n");
}
else {
float minx = FLT_MAX, miny = FLT_MAX;
float maxx = FLT_MIN, maxy = FLT_MIN;
struct mtp_packet mp;
int lpc = 0;
while (((max_packets == 0) || (lpc < max_packets)) &&
while (looping && ((max_packets == 0) || (lpc < max_packets)) &&
(mtp_receive_packet(mh, &mp) == MTP_PP_SUCCESS)) {
mtp_print_packet(stdout, &mp);
if (mp.data.opcode == MTP_UPDATE_POSITION) {
struct mtp_update_position *mup;
mup = &mp.data.mtp_payload_u.update_position;
minx = min(minx, mup->position.x);
maxx = max(maxx, mup->position.x);
miny = min(miny, mup->position.y);
maxy = max(maxy, mup->position.y);
}
mtp_print_packet(stdout, &mp);
mtp_free_packet(&mp);
lpc += 1;
......@@ -114,6 +149,12 @@ int main(int argc, char *argv[])
mtp_delete_handle(mh);
mh = NULL;
printf(" minx = %.2f; miny = %.2f\n"
" maxx = %.2f; maxy = %.2f (width = %.2f, height = %.2f\n",
minx, miny,
maxx, maxy,
maxx - minx, maxy - miny);
}
retval = EXIT_SUCCESS;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment