ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / Examples / Linux / Navigation / Sources / common / mobile_main.c
1 /**
2  * @file mobile_main.c
3  * @author aurelien.morelle@parrot.com & sylvain.gaeremynck@parrot.com
4  * @date 2006/05/01
5  */
6
7 #include <ATcodec/ATcodec_api.h>
8
9 #include <ardrone_tool/ardrone_tool.h>
10 #include <ardrone_tool/Control/ardrone_control.h>
11 #include <ardrone_tool/Navdata/ardrone_navdata_client.h>
12 #include <ardrone_tool/Com/config_com.h>
13
14 #include <common/mobile_config.h>
15 //#include <UI/gamepad.h>
16 //#include <UI/wiimote.h>
17 #include <ihm/ihm.h>
18 #include <ihm/ihm_stages_o_gtk.h>
19 #include <navdata_client/navdata_client.h>
20
21 #ifdef USE_ARDRONE_VICON
22 #include <libViconDataStreamSDK/vicon.h>
23 #endif // USE_ARDRONE_VICON
24
25 #ifdef PC_USE_POLARIS
26 #include <libPolaris/polaris.h>
27 #endif // PC_USE_POLARIS
28
29 #ifdef USE_TABLE_PILOTAGE
30 #include "libTestBenchs/novadem.h"
31 #endif // USE_TABLE_PILOTAGE
32
33 #ifdef RAW_CAPTURE
34 PROTO_THREAD_ROUTINE(raw_capture, params);
35 #endif
36 PROTO_THREAD_ROUTINE(remote_console, params);
37
38 static mobile_config_t cfg;
39
40 static int32_t exit_ihm_program = 1;
41
42 extern Controller_info *default_control;
43 extern GList *devices;
44
45 C_RESULT ardrone_tool_init_custom(int argc, char **argv)
46 {
47   gtk_init(&argc, &argv);
48
49   /// Init specific code for application
50   ardrone_navdata_handler_table[NAVDATA_IHM_PROCESS_INDEX].data   = &cfg;
51
52   // Add inputs
53   //ardrone_tool_input_add( &gamepad );
54   /*ardrone_tool_input_add( &radioGP );
55   ardrone_tool_input_add( &ps3pad );
56   ardrone_tool_input_add( &joystick );
57   ardrone_tool_input_add( &wiimote_device );*/
58
59   
60   load_ini();
61   printf("Default control : %s (0x%08x, %s)\n", default_control->name, default_control->serial, default_control->filename);
62   ardrone_tool_input_add( &control_device );
63   cfg.default_control = default_control;
64   cfg.devices = devices;
65
66 #ifdef USE_ARDRONE_VICON
67   START_THREAD( vicon, &cfg);
68 #endif // USE_ARDRONE_VICON
69
70   START_THREAD(ihm, &cfg);
71 #ifdef RAW_CAPTURE
72   START_THREAD(raw_capture, &cfg);
73 #endif
74   START_THREAD(remote_console, &cfg);
75         START_THREAD(ihm_stages_vision, &cfg);
76 #ifdef PC_USE_POLARIS
77   START_THREAD( polaris, &cfg );
78 #endif // PC_USE_POLARIS
79 #ifdef USE_TABLE_PILOTAGE
80   START_THREAD( novadem, (void*)("/dev/ttyUSB0") );
81 #endif // USE_TABLE_PILOTAGE
82
83   return C_OK;
84 }
85
86 C_RESULT ardrone_tool_shutdown_custom()
87 {
88 #ifdef USE_TABLE_PILOTAGE
89   JOIN_THREAD( novadem );
90 #endif // USE_TABLE_PILOTAGE
91 #ifdef PC_USE_POLARIS
92   JOIN_THREAD( polaris );
93 #endif // PC_USE_POLARIS
94 #ifdef USE_ARDRONE_VICON
95   JOIN_THREAD( vicon );
96 #endif // USE_ARDRONE_VICON
97   JOIN_THREAD(ihm);
98   JOIN_THREAD(ihm_stages_vision);
99 #ifdef RAW_CAPTURE
100   JOIN_THREAD(raw_capture);
101 #endif
102   JOIN_THREAD(remote_console);
103
104   /*ardrone_tool_input_remove( &gamepad );
105   ardrone_tool_input_remove( &radioGP );
106   ardrone_tool_input_remove( &ps3pad );
107   ardrone_tool_input_remove( &wiimote_device );*/
108   ardrone_tool_input_remove( &control_device );
109
110   return C_OK;
111 }
112
113 C_RESULT signal_exit()
114 {
115   exit_ihm_program = 0;
116
117   ihm_destroyCurves();
118
119   return C_OK;
120 }
121
122 bool_t ardrone_tool_exit()
123 {
124   return exit_ihm_program == 0;
125 }
126
127 BEGIN_THREAD_TABLE
128   THREAD_TABLE_ENTRY( ihm, 20 )
129 #ifdef RAW_CAPTURE
130   THREAD_TABLE_ENTRY( raw_capture, 20 )
131 #endif
132   THREAD_TABLE_ENTRY( remote_console, 20 )
133   THREAD_TABLE_ENTRY( ihm_stages_vision, 20 )
134   THREAD_TABLE_ENTRY( navdata_update, 20 )
135   THREAD_TABLE_ENTRY( ATcodec_Commands_Client, 20 )
136   THREAD_TABLE_ENTRY( ardrone_control, 20 )
137 #ifdef PC_USE_POLARIS
138   THREAD_TABLE_ENTRY( polaris, 20 )
139 #endif // PC_USE_POLARIS
140 #ifdef USE_ARDRONE_VICON
141   THREAD_TABLE_ENTRY( vicon, 20 )
142 #endif // USE_ARDRONE_VICON
143 #ifdef USE_TABLE_PILOTAGE
144   THREAD_TABLE_ENTRY( novadem, 20 )
145 #endif // USE_TABLE_PILOTAGE
146 END_THREAD_TABLE
147