|
|
|
@ -17,10 +17,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <jni.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <android/sensor.h>
|
|
|
|
#include <android/sensor.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <android_native_app_glue.h>
|
|
|
|
#include <android_native_app_glue.h>
|
|
|
|
@ -303,6 +301,9 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
|
|
|
* event loop for receiving input events and doing other things.
|
|
|
|
* event loop for receiving input events and doing other things.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void android_main(struct android_app* state) {
|
|
|
|
void android_main(struct android_app* state) {
|
|
|
|
|
|
|
|
time_t t1 = time(NULL), t2 = time(NULL);
|
|
|
|
|
|
|
|
struct gps_data *gpspos;
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure glue isn't stripped.
|
|
|
|
// Make sure glue isn't stripped.
|
|
|
|
app_dummy();
|
|
|
|
app_dummy();
|
|
|
|
|
|
|
|
|
|
|
|
@ -340,8 +341,7 @@ void android_main(struct android_app* state) {
|
|
|
|
// If not animating, we will block forever waiting for events.
|
|
|
|
// If not animating, we will block forever waiting for events.
|
|
|
|
// If animating, we loop until all events are read, then continue
|
|
|
|
// If animating, we loop until all events are read, then continue
|
|
|
|
// to draw the next frame of animation.
|
|
|
|
// to draw the next frame of animation.
|
|
|
|
while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
|
|
|
|
while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
|
|
|
|
(void**)&source)) >= 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Process this event.
|
|
|
|
// Process this event.
|
|
|
|
if (source != NULL) {
|
|
|
|
if (source != NULL) {
|
|
|
|
@ -367,18 +367,14 @@ void android_main(struct android_app* state) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t1 = time(NULL);
|
|
|
|
if (engine.animating) {
|
|
|
|
if (t1 != t2) {
|
|
|
|
// Done with events; draw next animation frame.
|
|
|
|
t2 = t1;
|
|
|
|
engine.state.angle += .01f;
|
|
|
|
if (gps_isrunning () > 0) {
|
|
|
|
if (engine.state.angle > 1) {
|
|
|
|
if ((gpspos = gps_loop ())) {
|
|
|
|
engine.state.angle = 0;
|
|
|
|
drawgps_set_pos (gpspos);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Drawing is throttled to the screen update rate, so there
|
|
|
|
|
|
|
|
// is no need to do timing here.
|
|
|
|
|
|
|
|
draw();
|
|
|
|
|
|
|
|
// test_draw ();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -394,3 +390,88 @@ void main_wnd_loop (long long int cur, long long int max) {
|
|
|
|
void main_wnd_update () {
|
|
|
|
void main_wnd_update () {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* calling java code here for using the internal GPS devices.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int gps_android_device_open () {
|
|
|
|
|
|
|
|
d_printf ("gps_android_device_open:");
|
|
|
|
|
|
|
|
ANativeActivity* activity = engine.app->activity;
|
|
|
|
|
|
|
|
JavaVM* jvm = engine.app->activity->vm;
|
|
|
|
|
|
|
|
JNIEnv* env = NULL;
|
|
|
|
|
|
|
|
(*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
|
|
|
|
|
|
|
|
jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
|
|
|
|
|
|
|
|
if (res == JNI_ERR) {
|
|
|
|
|
|
|
|
// Failed to retrieve JVM environment
|
|
|
|
|
|
|
|
d_printf ("gps_android_device_open: JNI_Error");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
|
|
|
|
|
|
|
|
jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataStart", "()V");
|
|
|
|
|
|
|
|
(*env)->CallVoidMethod(env, activity->clazz, methodID);
|
|
|
|
|
|
|
|
(*jvm)->DetachCurrentThread(jvm);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void gps_android_device_close () {
|
|
|
|
|
|
|
|
ANativeActivity* activity = engine.app->activity;
|
|
|
|
|
|
|
|
JavaVM* jvm = engine.app->activity->vm;
|
|
|
|
|
|
|
|
JNIEnv* env = NULL;
|
|
|
|
|
|
|
|
(*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
|
|
|
|
|
|
|
|
jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
|
|
|
|
|
|
|
|
if (res == JNI_ERR) {
|
|
|
|
|
|
|
|
// Failed to retrieve JVM environment
|
|
|
|
|
|
|
|
d_printf ("gps_android_device_close: JNI_Error");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
|
|
|
|
|
|
|
|
jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataStop", "()V");
|
|
|
|
|
|
|
|
(*env)->CallVoidMethod(env, activity->clazz, methodID);
|
|
|
|
|
|
|
|
(*jvm)->DetachCurrentThread(jvm);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int gps_android_device_read (char *ptr, int ptrsize) {
|
|
|
|
|
|
|
|
ANativeActivity* activity = engine.app->activity;
|
|
|
|
|
|
|
|
JavaVM* jvm = engine.app->activity->vm;
|
|
|
|
|
|
|
|
JNIEnv* env = NULL;
|
|
|
|
|
|
|
|
jstring jstr;
|
|
|
|
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
|
|
|
|
|
|
|
|
jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
|
|
|
|
|
|
|
|
if (res == JNI_ERR) {
|
|
|
|
|
|
|
|
// Failed to retrieve JVM environment
|
|
|
|
|
|
|
|
d_printf ("gps_android_device_read: JNI_Error");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d_printf ("gps_android_device_read:");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
|
|
|
|
|
|
|
|
jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataGetLine", "()V");
|
|
|
|
|
|
|
|
(*env)->CallVoidMethod(env, activity->clazz, methodID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d_printf ("try to get line");
|
|
|
|
|
|
|
|
jfieldID fid = (*env)->GetFieldID(env, clazz, "gpsline", "Ljava/lang/String;");
|
|
|
|
|
|
|
|
jobject obj = (*env)->AllocObject(env, clazz);
|
|
|
|
|
|
|
|
if (!obj) {
|
|
|
|
|
|
|
|
d_printf ("error getting obj");
|
|
|
|
|
|
|
|
exit (1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jstr = (*env)->GetObjectField(env, obj, fid);
|
|
|
|
|
|
|
|
str = (*env)->GetStringUTFChars(env, jstr, 0);
|
|
|
|
|
|
|
|
d_printf(" c.s = \"%s\"\n", str);
|
|
|
|
|
|
|
|
(*env)->ReleaseStringUTFChars(env, jstr, str);
|
|
|
|
|
|
|
|
d_printf ("release string");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(*jvm)->DetachCurrentThread(jvm);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
};
|
|
|
|
|