73b99da026dd1f01333a31b13f6c8f034163019f
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / Examples / Linux / Protocol / app.c
1 /*
2  * AR Drone demo
3  *
4  * originally based on Android NDK "San Angeles" demo app
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <assert.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include <pthread.h>
14 #include <sys/time.h>
15 #include <time.h>
16
17 #include "app.h"
18
19 static int screen_width = 0;
20 static int screen_height = 0;
21 static int gAppAlive = 0;
22
23 void appInit()
24 {
25         int status;
26
27    //Run AT command process
28    at_run();
29    
30    //Run Navdata process
31    navdata_run();
32
33    //Run Stream process
34    stream_run();
35
36 #ifdef BUILD_OGLES
37         // video rendering
38         video_init();
39 #endif
40    gAppAlive = 1;
41 }
42
43 void appDeinit()
44 {
45         INFO("shutting down application...\n");
46
47    gAppAlive = 0;
48
49 #ifdef BUILD_OGLES
50         video_deinit();
51 #endif
52         // all threads should implement a loop polling gAppAlive
53         navdata_stop();
54         stream_stop();
55    at_stop();
56
57         INFO("application was cleanly exited\n");
58 }
59
60 #ifdef BUILD_OGLES
61 void appRender(long tick, int width, int height)
62 {
63         if (!gAppAlive) {
64                 return;
65         }
66    screen_width = width;
67    screen_height = height;
68         video_render(tick, screen_width, screen_height);
69 }
70 #endif
71
72 void get_screen_dimensions(int *w, int *h)
73 {
74         if (screen_width) {
75                 *w = screen_width;
76                 *h = screen_height;
77         }
78         else {
79                 // dummy dimensions
80                 *w = 480;
81                 *h = 320;
82         }
83 }
84