ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / Examples / Multiplatform / 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 <sys/time.h>
14 #include <time.h>
15
16 #include <app.h>
17
18 THREAD_HANDLE nav_thread;
19 THREAD_HANDLE at_thread;
20 THREAD_HANDLE stream_thread;
21
22 int gAppAlive   = 0;
23
24 static int screen_width = 0;
25 static int screen_height = 0;
26
27 void appInit()
28 {
29         int status;
30
31         gAppAlive = 1;
32
33         // navigation
34         if (!nav_thread) {
35       vp_os_thread_create( thread_navdata_loop, 0, &nav_thread);
36         }
37
38         // video stream
39         if (!stream_thread) {
40       vp_os_thread_create( thread_stream_loop, 0, &stream_thread);
41         }
42
43         // AT cmds loop
44         if (!at_thread) {
45       vp_os_thread_create( thread_at_cmds_loop, 0, &at_thread);
46         }
47
48 #ifdef BUILD_OGLES
49         // video rendering
50         video_init();
51 #endif
52 }
53
54 void appDeinit()
55 {
56         gAppAlive = 0;
57
58         INFO("shutting down application...\n");
59
60 #ifdef BUILD_OGLES
61         video_deinit();
62 #endif
63         // all threads should implement a loop polling gAppAlive
64         vp_os_thread_join( nav_thread );
65         vp_os_thread_join( at_thread );
66         vp_os_thread_join( stream_thread );
67
68         nav_thread = 0;
69         at_thread = 0;
70         stream_thread = 0;
71
72         INFO("application was cleanly exited\n");
73 }
74
75 #ifdef BUILD_OGLES
76 void appRender(long tick, int width, int height)
77 {
78         if (!gAppAlive) {
79                 return;
80         }
81    screen_width = width;
82    screen_height = height;
83         video_render(tick, screen_width, screen_height);
84 }
85 #endif
86
87 void get_screen_dimensions(int *w, int *h)
88 {
89         if (screen_width) {
90                 *w = screen_width;
91                 *h = screen_height;
92         }
93         else {
94                 // dummy dimensions
95                 *w = 480;
96                 *h = 320;
97         }
98 }
99