diff --git a/MINDdroidCV_MINDSTORMS/AndroidManifest.xml b/MINDdroidCV_MINDSTORMS/AndroidManifest.xml index 43bbd40..4feccf1 100644 --- a/MINDdroidCV_MINDSTORMS/AndroidManifest.xml +++ b/MINDdroidCV_MINDSTORMS/AndroidManifest.xml @@ -1,8 +1,8 @@ - + android:versionName="1.3"> + GetByteArrayElements(yuv, 0); jint* _bgra = env->GetIntArrayElements(bgra, 0); diff --git a/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/gdb.setup b/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/gdb.setup new file mode 100644 index 0000000..9cb5305 --- /dev/null +++ b/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/gdb.setup @@ -0,0 +1,2 @@ +set solib-search-path ./obj/local/armeabi-v7a +directory C:/android-ndk-r8b/platforms/android-14/arch-arm/usr/include C:/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++ C:/Users\miguel.astor\Documents\workspace\OpenCV-2.4.0\share\OpenCV\/../../include/opencv C:/Users\miguel.astor\Documents\workspace\OpenCV-2.4.0\share\OpenCV\/../../include C:/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include C:/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include jni diff --git a/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/gdbserver b/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/gdbserver new file mode 100644 index 0000000..1106165 Binary files /dev/null and b/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/gdbserver differ diff --git a/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/libmixed_sample.so b/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/libmixed_sample.so new file mode 100644 index 0000000..bfe61fd Binary files /dev/null and b/MINDdroidCV_MINDSTORMS/libs/armeabi-v7a/libmixed_sample.so differ diff --git a/MINDdroidCV_MINDSTORMS/libs/armeabi/gdb.setup b/MINDdroidCV_MINDSTORMS/libs/armeabi/gdb.setup deleted file mode 100644 index 402270c..0000000 --- a/MINDdroidCV_MINDSTORMS/libs/armeabi/gdb.setup +++ /dev/null @@ -1,2 +0,0 @@ -set solib-search-path /home/rics/projects/android/MINDdroidCV/android/obj/local/armeabi -directory /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++ /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include /home/rics/projects/android/MINDdroidCV/android/jni diff --git a/MINDdroidCV_MINDSTORMS/libs/armeabi/gdbserver b/MINDdroidCV_MINDSTORMS/libs/armeabi/gdbserver deleted file mode 100755 index 39634a8..0000000 Binary files a/MINDdroidCV_MINDSTORMS/libs/armeabi/gdbserver and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/libs/armeabi/libmixed_sample.so b/MINDdroidCV_MINDSTORMS/libs/armeabi/libmixed_sample.so deleted file mode 100755 index 7daee55..0000000 Binary files a/MINDdroidCV_MINDSTORMS/libs/armeabi/libmixed_sample.so and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/lint.xml b/MINDdroidCV_MINDSTORMS/lint.xml new file mode 100644 index 0000000..ee0eead --- /dev/null +++ b/MINDdroidCV_MINDSTORMS/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibjasper.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibjasper.a deleted file mode 100644 index f153e6b..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibjasper.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibjpeg.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibjpeg.a deleted file mode 100644 index 4072770..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibjpeg.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibpng.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibpng.a deleted file mode 100644 index a30e47f..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibpng.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibtiff.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibtiff.a deleted file mode 100644 index ac96345..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/liblibtiff.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libmixed_sample.so b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libmixed_sample.so deleted file mode 100755 index 5d7d476..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libmixed_sample.so and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_androidcamera.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_androidcamera.a deleted file mode 100644 index 6b31a2c..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_androidcamera.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_calib3d.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_calib3d.a deleted file mode 100644 index 2df40c0..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_calib3d.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_contrib.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_contrib.a deleted file mode 100644 index d8b610f..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_contrib.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_core.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_core.a deleted file mode 100644 index 1b4814b..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_core.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_features2d.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_features2d.a deleted file mode 100644 index 11f0e84..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_features2d.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_flann.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_flann.a deleted file mode 100644 index 7965b65..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_flann.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_highgui.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_highgui.a deleted file mode 100644 index 4f600f3..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_highgui.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_imgproc.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_imgproc.a deleted file mode 100644 index 142b65d..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_imgproc.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_legacy.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_legacy.a deleted file mode 100644 index 77ce2e9..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_legacy.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_ml.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_ml.a deleted file mode 100644 index 9beb65e..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_ml.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_objdetect.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_objdetect.a deleted file mode 100644 index 4a6112b..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_objdetect.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_video.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_video.a deleted file mode 100644 index 0dceba4..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libopencv_video.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libstdc++.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libstdc++.a deleted file mode 100644 index e0d160a..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libstdc++.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libzlib.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libzlib.a deleted file mode 100644 index 450cfd3..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/libzlib.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o deleted file mode 100644 index c848722..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o.d b/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o.d deleted file mode 100644 index 7f9ff3e..0000000 --- a/MINDdroidCV_MINDSTORMS/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o.d +++ /dev/null @@ -1,143 +0,0 @@ -/home/rics/projects/android/MINDdroidCV/android/obj/local/armeabi-v7a/objs-debug/mixed_sample/jni_part.o: \ - /home/rics/projects/android/MINDdroidCV/android/jni/jni_part.cpp \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/jni.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/types_c.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/assert.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs_elf.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdlib.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/string.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/malloc.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/alloca.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/strings.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdint.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/posix_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/stddef.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/compiler.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/posix_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/kernel.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/sysmacros.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/memory.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/math.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/internal_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/syslimits.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/version.hpp \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/algorithm \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/cmath \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/complex \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/map \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/vector \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/operations.hpp \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/limits \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/mat.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/imgproc.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/types_c.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core_c.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/features2d/features2d.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/miniflann.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/defines.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/config.h - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/jni.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/types_c.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/assert.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs_elf.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdlib.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/string.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/malloc.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/alloca.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/strings.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdint.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/posix_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/stddef.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/compiler.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/posix_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/kernel.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/sysmacros.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/memory.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/math.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/internal_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/syslimits.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/version.hpp: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/algorithm: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/cmath: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/complex: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/map: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/vector: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/operations.hpp: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/limits: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/mat.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/imgproc.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/types_c.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core_c.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/features2d/features2d.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/miniflann.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/defines.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/config.h: diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibjasper.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibjasper.a deleted file mode 100644 index bd6500e..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibjasper.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibjpeg.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibjpeg.a deleted file mode 100644 index 4aa844c..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibjpeg.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibpng.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibpng.a deleted file mode 100644 index 72bc042..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibpng.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibtiff.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibtiff.a deleted file mode 100644 index 8ce4206..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/liblibtiff.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libmixed_sample.so b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libmixed_sample.so deleted file mode 100755 index 066042e..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libmixed_sample.so and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_androidcamera.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_androidcamera.a deleted file mode 100644 index 49625b6..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_androidcamera.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_calib3d.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_calib3d.a deleted file mode 100644 index 4958010..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_calib3d.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_contrib.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_contrib.a deleted file mode 100644 index 8778271..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_contrib.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_core.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_core.a deleted file mode 100644 index 9d30835..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_core.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_features2d.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_features2d.a deleted file mode 100644 index eeae38f..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_features2d.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_flann.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_flann.a deleted file mode 100644 index 3e69537..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_flann.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_highgui.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_highgui.a deleted file mode 100644 index 2a6d6c5..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_highgui.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_imgproc.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_imgproc.a deleted file mode 100644 index 5b4dfc4..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_imgproc.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_legacy.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_legacy.a deleted file mode 100644 index 806e6c8..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_legacy.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_ml.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_ml.a deleted file mode 100644 index 0ed3f22..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_ml.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_objdetect.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_objdetect.a deleted file mode 100644 index b336187..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_objdetect.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_video.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_video.a deleted file mode 100644 index 81407a0..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libopencv_video.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libstdc++.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libstdc++.a deleted file mode 100644 index 2b0e571..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libstdc++.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libzlib.a b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libzlib.a deleted file mode 100644 index acfe729..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/libzlib.a and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o deleted file mode 100644 index 2016bef..0000000 Binary files a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o and /dev/null differ diff --git a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o.d b/MINDdroidCV_MINDSTORMS/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o.d deleted file mode 100644 index 4961c03..0000000 --- a/MINDdroidCV_MINDSTORMS/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o.d +++ /dev/null @@ -1,143 +0,0 @@ -/home/rics/projects/android/MINDdroidCV/android/obj/local/armeabi/objs-debug/mixed_sample/jni_part.o: \ - /home/rics/projects/android/MINDdroidCV/android/jni/jni_part.cpp \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/jni.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/types_c.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/assert.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs_elf.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdlib.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/string.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/malloc.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/alloca.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/strings.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdint.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/posix_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/stddef.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/compiler.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/posix_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/kernel.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/sysmacros.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/memory.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/math.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/internal_types.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/limits.h \ - /usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/syslimits.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/version.hpp \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/algorithm \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/cmath \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/complex \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/map \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/vector \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/operations.hpp \ - /usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/limits \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/mat.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/imgproc.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/types_c.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core_c.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/features2d/features2d.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/miniflann.hpp \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/defines.h \ - /usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/config.h - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/jni.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/types_c.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/assert.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/cdefs_elf.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdlib.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/string.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/malloc.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/alloca.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/strings.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/stdint.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/posix_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/stddef.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/compiler.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/posix_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/asm/types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/kernel.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/sysmacros.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/memory.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/math.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/linux/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/internal_types.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/machine/limits.h: - -/usr/local/android-ndk-r6/platforms/android-8/arch-arm/usr/include/sys/syslimits.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/version.hpp: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/algorithm: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/cmath: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/complex: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/map: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/vector: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/operations.hpp: - -/usr/local/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/include/limits: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/mat.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/imgproc.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/imgproc/types_c.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/core/core_c.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/features2d/features2d.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/miniflann.hpp: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/defines.h: - -/usr/local/opencv-2.3.1-android/OpenCV-2.3.1/share/OpenCV/../../include/opencv2/flann/config.h: diff --git a/MINDdroidCV_MINDSTORMS/project.properties b/MINDdroidCV_MINDSTORMS/project.properties new file mode 100644 index 0000000..b7c2081 --- /dev/null +++ b/MINDdroidCV_MINDSTORMS/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-10 diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/BTCommunicator.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/BTCommunicator.java index 90f41c1..762ff33 100644 --- a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/BTCommunicator.java +++ b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/BTCommunicator.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with MINDdroid. If not, see . -**/ + **/ package com.lego.minddroid; @@ -40,439 +40,490 @@ import android.os.Message; * by the owners, i.e. calling the send/recive methods by themselves. */ public class BTCommunicator extends Thread { - public static final int MOTOR_A = 0; - public static final int MOTOR_B = 1; - public static final int MOTOR_C = 2; - public static final int MOTOR_B_ACTION = 40; - public static final int MOTOR_RESET = 10; - public static final int DO_BEEP = 51; - public static final int DO_ACTION = 52; - public static final int READ_MOTOR_STATE = 60; - public static final int GET_FIRMWARE_VERSION = 70; - public static final int DISCONNECT = 99; + public static final int MOTOR_A = 0; + public static final int MOTOR_B = 1; + public static final int MOTOR_C = 2; + public static final int MOTOR_B_ACTION = 40; + public static final int MOTOR_RESET = 10; + public static final int DO_BEEP = 51; + public static final int DO_ACTION = 52; + public static final int READ_MOTOR_STATE = 60; + public static final int GET_FIRMWARE_VERSION = 70; + public static final int DISCONNECT = 99; + public static final int SET_LIGHT_SENSOR = 89; + public static final int GET_LIGHT_SENSOR = 90; + public static final int GET_TOUCH_SENSOR = 92; - public static final int DISPLAY_TOAST = 1000; - public static final int STATE_CONNECTED = 1001; - public static final int STATE_CONNECTERROR = 1002; - public static final int STATE_CONNECTERROR_PAIRING = 1022; - public static final int MOTOR_STATE = 1003; - public static final int STATE_RECEIVEERROR = 1004; - public static final int STATE_SENDERROR = 1005; - public static final int FIRMWARE_VERSION = 1006; - public static final int FIND_FILES = 1007; - public static final int START_PROGRAM = 1008; - public static final int STOP_PROGRAM = 1009; - public static final int GET_PROGRAM_NAME = 1010; - public static final int PROGRAM_NAME = 1011; - public static final int SAY_TEXT = 1030; - public static final int VIBRATE_PHONE = 1031; + public static final int DISPLAY_TOAST = 1000; + public static final int STATE_CONNECTED = 1001; + public static final int STATE_CONNECTERROR = 1002; + public static final int STATE_CONNECTERROR_PAIRING = 1022; + public static final int MOTOR_STATE = 1003; + public static final int STATE_RECEIVEERROR = 1004; + public static final int STATE_SENDERROR = 1005; + public static final int FIRMWARE_VERSION = 1006; + public static final int FIND_FILES = 1007; + public static final int START_PROGRAM = 1008; + public static final int STOP_PROGRAM = 1009; + public static final int GET_PROGRAM_NAME = 1010; + public static final int PROGRAM_NAME = 1011; + public static final int SAY_TEXT = 1030; + public static final int VIBRATE_PHONE = 1031; + public static final int UPDATE_SENSOR = 1042; - public static final int NO_DELAY = 0; + public static final int NO_DELAY = 0; - private static final UUID SERIAL_PORT_SERVICE_CLASS_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); - // this is the only OUI registered by LEGO, see http://standards.ieee.org/regauth/oui/index.shtml - public static final String OUI_LEGO = "00:16:53"; + private static final UUID SERIAL_PORT_SERVICE_CLASS_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); + // this is the only OUI registered by LEGO, see http://standards.ieee.org/regauth/oui/index.shtml + public static final String OUI_LEGO = "00:16:53"; - private Resources mResources; - private BluetoothAdapter btAdapter; - private BluetoothSocket nxtBTsocket = null; - private OutputStream nxtOutputStream = null; - private InputStream nxtInputStream = null; - private boolean connected = false; + private Resources mResources; + private BluetoothAdapter btAdapter; + private BluetoothSocket nxtBTsocket = null; + private OutputStream nxtOutputStream = null; + private InputStream nxtInputStream = null; + private boolean connected = false; - private Handler uiHandler; - private String mMACaddress; - private BTConnectable myOwner; + private Handler uiHandler; + private String mMACaddress; + private BTConnectable myOwner; - private byte[] returnMessage; + private byte[] returnMessage; - public BTCommunicator(BTConnectable myOwner, Handler uiHandler, BluetoothAdapter btAdapter, Resources resources) { - this.myOwner = myOwner; - this.uiHandler = uiHandler; - this.btAdapter = btAdapter; - this.mResources = resources; - } + public BTCommunicator(BTConnectable myOwner, Handler uiHandler, BluetoothAdapter btAdapter, Resources resources) { + this.myOwner = myOwner; + this.uiHandler = uiHandler; + this.btAdapter = btAdapter; + this.mResources = resources; + } - public Handler getHandler() { - return myHandler; - } + public Handler getHandler() { + return myHandler; + } - public byte[] getReturnMessage() { - return returnMessage; - } + public byte[] getReturnMessage() { + return returnMessage; + } - public void setMACAddress(String mMACaddress) { - this.mMACaddress = mMACaddress; - } + public void setMACAddress(String mMACaddress) { + this.mMACaddress = mMACaddress; + } - /** - * @return The current status of the connection - */ - public boolean isConnected() { - return connected; - } + /** + * @return The current status of the connection + */ + public boolean isConnected() { + return connected; + } - /** - * Creates the connection, waits for incoming messages and dispatches them. The thread will be terminated - * on closing of the connection. - */ - @Override - public void run() { + /** + * Creates the connection, waits for incoming messages and dispatches them. The thread will be terminated + * on closing of the connection. + */ + @Override + public void run() { - try { - createNXTconnection(); - } - catch (IOException e) { } + try { + createNXTconnection(); + + /* NUEVO */ + setInputMode(0, LCPMessage.LIGHT_ACTIVE, LCPMessage.RAWMODE); + setInputMode(1, LCPMessage.LIGHT_ACTIVE, LCPMessage.RAWMODE); + /* NUEVO */ + } + catch (IOException e) { } - while (connected) { - try { - returnMessage = receiveMessage(); - if ((returnMessage.length >= 2) && ((returnMessage[0] == LCPMessage.REPLY_COMMAND) || - (returnMessage[0] == LCPMessage.DIRECT_COMMAND_NOREPLY))) - dispatchMessage(returnMessage); + while (connected) { + try { + returnMessage = receiveMessage(); + if ((returnMessage.length >= 2) && ((returnMessage[0] == LCPMessage.REPLY_COMMAND) || + (returnMessage[0] == LCPMessage.DIRECT_COMMAND_NOREPLY))) + dispatchMessage(returnMessage); - } catch (IOException e) { - // don't inform the user when connection is already closed - if (connected) - sendState(STATE_RECEIVEERROR); - return; - } - } - } + } catch (IOException e) { + // don't inform the user when connection is already closed + if (connected) + sendState(STATE_RECEIVEERROR); + return; + } + } + } - /** - * Create a bluetooth connection with SerialPortServiceClass_UUID - * @see - * On error the method either sends a message to it's owner or creates an exception in the - * case of no message handler. - */ - public void createNXTconnection() throws IOException { - try { - BluetoothSocket nxtBTSocketTemporary; - BluetoothDevice nxtDevice = null; - nxtDevice = btAdapter.getRemoteDevice(mMACaddress); - if (nxtDevice == null) { - if (uiHandler == null) - throw new IOException(); - else { - sendToast(mResources.getString(R.string.no_paired_nxt)); - sendState(STATE_CONNECTERROR); - return; - } - } - nxtBTSocketTemporary = nxtDevice.createRfcommSocketToServiceRecord(SERIAL_PORT_SERVICE_CLASS_UUID); - try { - nxtBTSocketTemporary.connect(); - } - catch (IOException e) { - if (myOwner.isPairing()) { - if (uiHandler != null) { - sendToast(mResources.getString(R.string.pairing_message)); - sendState(STATE_CONNECTERROR_PAIRING); - } - else - throw e; - return; - } + /** + * Create a bluetooth connection with SerialPortServiceClass_UUID + * @see + * On error the method either sends a message to it's owner or creates an exception in the + * case of no message handler. + */ + public void createNXTconnection() throws IOException { + try { + BluetoothSocket nxtBTSocketTemporary; + BluetoothDevice nxtDevice = null; + nxtDevice = btAdapter.getRemoteDevice(mMACaddress); + if (nxtDevice == null) { + if (uiHandler == null) + throw new IOException(); + else { + sendToast(mResources.getString(R.string.no_paired_nxt)); + sendState(STATE_CONNECTERROR); + return; + } + } + nxtBTSocketTemporary = nxtDevice.createRfcommSocketToServiceRecord(SERIAL_PORT_SERVICE_CLASS_UUID); + try { + nxtBTSocketTemporary.connect(); + } + catch (IOException e) { + if (myOwner.isPairing()) { + if (uiHandler != null) { + sendToast(mResources.getString(R.string.pairing_message)); + sendState(STATE_CONNECTERROR_PAIRING); + } + else + throw e; + return; + } - // try another method for connection, this should work on the HTC desire, credits to Michael Biermann - try { - Method mMethod = nxtDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); - nxtBTSocketTemporary = (BluetoothSocket) mMethod.invoke(nxtDevice, Integer.valueOf(1)); - nxtBTSocketTemporary.connect(); - } - catch (Exception e1){ - if (uiHandler == null) - throw new IOException(); - else - sendState(STATE_CONNECTERROR); - return; - } - } - nxtBTsocket = nxtBTSocketTemporary; - nxtInputStream = nxtBTsocket.getInputStream(); - nxtOutputStream = nxtBTsocket.getOutputStream(); - connected = true; - } catch (IOException e) { - if (uiHandler == null) - throw e; - else { - if (myOwner.isPairing()) - sendToast(mResources.getString(R.string.pairing_message)); - sendState(STATE_CONNECTERROR); - return; - } - } - // everything was OK - if (uiHandler != null) - sendState(STATE_CONNECTED); - } + // try another method for connection, this should work on the HTC desire, credits to Michael Biermann + try { + Method mMethod = nxtDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); + nxtBTSocketTemporary = (BluetoothSocket) mMethod.invoke(nxtDevice, Integer.valueOf(1)); + nxtBTSocketTemporary.connect(); + } + catch (Exception e1){ + if (uiHandler == null) + throw new IOException(); + else + sendState(STATE_CONNECTERROR); + return; + } + } + nxtBTsocket = nxtBTSocketTemporary; + nxtInputStream = nxtBTsocket.getInputStream(); + nxtOutputStream = nxtBTsocket.getOutputStream(); + connected = true; + } catch (IOException e) { + if (uiHandler == null) + throw e; + else { + if (myOwner.isPairing()) + sendToast(mResources.getString(R.string.pairing_message)); + sendState(STATE_CONNECTERROR); + return; + } + } + // everything was OK + if (uiHandler != null) + sendState(STATE_CONNECTED); + } - /** - * Closes the bluetooth connection. On error the method either sends a message - * to it's owner or creates an exception in the case of no message handler. - */ - public void destroyNXTconnection() throws IOException { - try { - if (nxtBTsocket != null) { - connected = false; - nxtBTsocket.close(); - nxtBTsocket = null; - } + /** + * Closes the bluetooth connection. On error the method either sends a message + * to it's owner or creates an exception in the case of no message handler. + */ + public void destroyNXTconnection() throws IOException { + try { + if (nxtBTsocket != null) { + connected = false; + nxtBTsocket.close(); + nxtBTsocket = null; + } - nxtInputStream = null; - nxtOutputStream = null; + nxtInputStream = null; + nxtOutputStream = null; - } catch (IOException e) { - if (uiHandler == null) - throw e; - else - sendToast(mResources.getString(R.string.problem_at_closing)); - } - } + } catch (IOException e) { + if (uiHandler == null) + throw e; + else + sendToast(mResources.getString(R.string.problem_at_closing)); + } + } - /** - * Sends a message on the opened OutputStream - * @param message, the message as a byte array - */ - public void sendMessage(byte[] message) throws IOException { - if (nxtOutputStream == null) - throw new IOException(); + /** + * Sends a message on the opened OutputStream + * @param message, the message as a byte array + */ + public void sendMessage(byte[] message) throws IOException { + if (nxtOutputStream == null) + throw new IOException(); - // send message length - int messageLength = message.length; - nxtOutputStream.write(messageLength); - nxtOutputStream.write(messageLength >> 8); - nxtOutputStream.write(message, 0, message.length); - } + // send message length + int messageLength = message.length; + nxtOutputStream.write(messageLength); + nxtOutputStream.write(messageLength >> 8); + nxtOutputStream.write(message, 0, message.length); + } - /** - * Receives a message on the opened InputStream - * @return the message - */ - public byte[] receiveMessage() throws IOException { - if (nxtInputStream == null) - throw new IOException(); + /** + * Receives a message on the opened InputStream + * @return the message + */ + public byte[] receiveMessage() throws IOException { + if (nxtInputStream == null) + throw new IOException(); - int length = nxtInputStream.read(); - length = (nxtInputStream.read() << 8) + length; - byte[] returnMessage = new byte[length]; - nxtInputStream.read(returnMessage); - return returnMessage; - } + int length = nxtInputStream.read(); + length = (nxtInputStream.read() << 8) + length; + byte[] returnMessage = new byte[length]; + nxtInputStream.read(returnMessage); + return returnMessage; + } - /** - * Sends a message on the opened OutputStream. In case of - * an error the state is sent to the handler. - * @param message, the message as a byte array - */ - private void sendMessageAndState(byte[] message) { - if (nxtOutputStream == null) - return; + /** + * Sends a message on the opened OutputStream. In case of + * an error the state is sent to the handler. + * @param message, the message as a byte array + */ + private void sendMessageAndState(byte[] message) { + if (nxtOutputStream == null) + return; - try { - sendMessage(message); - } - catch (IOException e) { - sendState(STATE_SENDERROR); - } - } + try { + sendMessage(message); + } + catch (IOException e) { + sendState(STATE_SENDERROR); + } + } - private void dispatchMessage(byte[] message) { - switch (message[1]) { + private void dispatchMessage(byte[] message) { + switch (message[1]) { - case LCPMessage.GET_OUTPUT_STATE: + case LCPMessage.GET_OUTPUT_STATE: - if (message.length >= 25) - sendState(MOTOR_STATE); + if (message.length >= 25) + sendState(MOTOR_STATE); - break; + break; - case LCPMessage.GET_FIRMWARE_VERSION: + case LCPMessage.GET_FIRMWARE_VERSION: - if (message.length >= 7) - sendState(FIRMWARE_VERSION); + if (message.length >= 7) + sendState(FIRMWARE_VERSION); - break; + break; - case LCPMessage.FIND_FIRST: - case LCPMessage.FIND_NEXT: + case LCPMessage.FIND_FIRST: + case LCPMessage.FIND_NEXT: - if (message.length >= 28) { - // Success - if (message[2] == 0) - sendState(FIND_FILES); - } + /*if (message.length >= 28) { + // Success + if (message[2] == 0) + sendState(FIND_FILES); + }*/ - break; - - case LCPMessage.GET_CURRENT_PROGRAM_NAME: + break; - if (message.length >= 23) { - sendState(PROGRAM_NAME); - } - - break; - - case LCPMessage.SAY_TEXT: - - if (message.length == 22) { - sendState(SAY_TEXT); - } - - case LCPMessage.VIBRATE_PHONE: - if (message.length == 3) { - sendState(VIBRATE_PHONE); - } - } - } + case LCPMessage.GET_CURRENT_PROGRAM_NAME: - private void doBeep(int frequency, int duration) { - byte[] message = LCPMessage.getBeepMessage(frequency, duration); - sendMessageAndState(message); - waitSomeTime(20); - } - - private void doAction(int actionNr) { - byte[] message = LCPMessage.getActionMessage(actionNr); - sendMessageAndState(message); - } + if (message.length >= 23) { + sendState(PROGRAM_NAME); + } - private void startProgram(String programName) { - byte[] message = LCPMessage.getStartProgramMessage(programName); - sendMessageAndState(message); - } + break; - private void stopProgram() { - byte[] message = LCPMessage.getStopProgramMessage(); - sendMessageAndState(message); - } - - private void getProgramName() { - byte[] message = LCPMessage.getProgramNameMessage(); - sendMessageAndState(message); - } - - private void changeMotorSpeed(int motor, int speed) { - if (speed > 100) - speed = 100; + case LCPMessage.SAY_TEXT: - else if (speed < -100) - speed = -100; + if (message.length == 22) { + sendState(SAY_TEXT); + } - byte[] message = LCPMessage.getMotorMessage(motor, speed); - sendMessageAndState(message); - } + break; + + case LCPMessage.VIBRATE_PHONE: + if (message.length == 3) { + sendState(VIBRATE_PHONE); + } + + break; + + /* NUEVO */ + case LCPMessage.GET_INPUT_VALUES: + if(message[3] == LCPMessage.PORT_0 || message[3] == LCPMessage.PORT_1){ + sendState(UPDATE_SENSOR); + } + + break; + /* NUEVO */ + } + } - private void rotateTo(int motor, int end) { - byte[] message = LCPMessage.getMotorMessage(motor, -80, end); - sendMessageAndState(message); - } + private void doBeep(int frequency, int duration) { + byte[] message = LCPMessage.getBeepMessage(frequency, duration); + sendMessageAndState(message); + waitSomeTime(20); + } - private void reset(int motor) { - byte[] message = LCPMessage.getResetMessage(motor); - sendMessageAndState(message); - } + private void doAction(int actionNr) { + byte[] message = LCPMessage.getActionMessage(actionNr); + sendMessageAndState(message); + } - private void readMotorState(int motor) { - byte[] message = LCPMessage.getOutputStateMessage(motor); - sendMessageAndState(message); - } + private void startProgram(String programName) { + byte[] message = LCPMessage.getStartProgramMessage(programName); + sendMessageAndState(message); + } - private void getFirmwareVersion() { - byte[] message = LCPMessage.getFirmwareVersionMessage(); - sendMessageAndState(message); - } + private void stopProgram() { + byte[] message = LCPMessage.getStopProgramMessage(); + sendMessageAndState(message); + } - private void findFiles(boolean findFirst, int handle) { - byte[] message = LCPMessage.getFindFilesMessage(findFirst, handle, "*.*"); - sendMessageAndState(message); - } + private void getProgramName() { + byte[] message = LCPMessage.getProgramNameMessage(); + sendMessageAndState(message); + } - private void waitSomeTime(int millis) { - try { - Thread.sleep(millis); + private void changeMotorSpeed(int motor, int speed) { + if (speed > 100) + speed = 100; - } catch (InterruptedException e) { - } - } + else if (speed < -100) + speed = -100; - private void sendToast(String toastText) { - Bundle myBundle = new Bundle(); - myBundle.putInt("message", DISPLAY_TOAST); - myBundle.putString("toastText", toastText); - sendBundle(myBundle); - } + byte[] message = LCPMessage.getMotorMessage(motor, speed); + sendMessageAndState(message); + } - private void sendState(int message) { - Bundle myBundle = new Bundle(); - myBundle.putInt("message", message); - sendBundle(myBundle); - } + private void rotateTo(int motor, int end) { + byte[] message = LCPMessage.getMotorMessage(motor, -80, end); + sendMessageAndState(message); + } - private void sendBundle(Bundle myBundle) { - Message myMessage = myHandler.obtainMessage(); - myMessage.setData(myBundle); - uiHandler.sendMessage(myMessage); - } + private void reset(int motor) { + byte[] message = LCPMessage.getResetMessage(motor); + sendMessageAndState(message); + } - // receive messages from the UI - final Handler myHandler = new Handler() { - @Override - public void handleMessage(Message myMessage) { + private void readMotorState(int motor) { + byte[] message = LCPMessage.getOutputStateMessage(motor); + sendMessageAndState(message); + } - int message; + private void getFirmwareVersion() { + byte[] message = LCPMessage.getFirmwareVersionMessage(); + sendMessageAndState(message); + } - switch (message = myMessage.getData().getInt("message")) { - case MOTOR_A: - case MOTOR_B: - case MOTOR_C: - changeMotorSpeed(message, myMessage.getData().getInt("value1")); - break; - case MOTOR_B_ACTION: - rotateTo(MOTOR_B, myMessage.getData().getInt("value1")); - break; - case MOTOR_RESET: - reset(myMessage.getData().getInt("value1")); - break; - case START_PROGRAM: - startProgram(myMessage.getData().getString("name")); - break; - case STOP_PROGRAM: - stopProgram(); - break; - case GET_PROGRAM_NAME: - getProgramName(); - break; - case DO_BEEP: - doBeep(myMessage.getData().getInt("value1"), myMessage.getData().getInt("value2")); - break; - case DO_ACTION: - doAction(0); - break; - case READ_MOTOR_STATE: - readMotorState(myMessage.getData().getInt("value1")); - break; - case GET_FIRMWARE_VERSION: - getFirmwareVersion(); - break; - case FIND_FILES: - findFiles(myMessage.getData().getInt("value1") == 0, myMessage.getData().getInt("value2")); - break; - case DISCONNECT: - // send stop messages before closing - changeMotorSpeed(MOTOR_A, 0); - changeMotorSpeed(MOTOR_B, 0); - changeMotorSpeed(MOTOR_C, 0); - waitSomeTime(500); - try { - destroyNXTconnection(); - } - catch (IOException e) { } - break; - } - } - }; + private void findFiles(boolean findFirst, int handle) { + byte[] message = LCPMessage.getFindFilesMessage(findFirst, handle, "*.*"); + sendMessageAndState(message); + } + + /* NUEVO */ + private void setInputMode(int port, byte sensor, byte mode){ + byte [] message = LCPMessage.getSetInputModeMessage(port, sensor, mode); + sendMessageAndState(message); + } + + private void getInputValues(int port){ + byte [] message = LCPMessage.getGetInputValuesMessage(port); + sendMessageAndState(message); + } + /* NUEVO */ + + private void waitSomeTime(int millis) { + try { + Thread.sleep(millis); + + } catch (InterruptedException e) { + } + } + + private void sendToast(String toastText) { + Bundle myBundle = new Bundle(); + myBundle.putInt("message", DISPLAY_TOAST); + myBundle.putString("toastText", toastText); + sendBundle(myBundle); + } + + private void sendState(int message) { + Bundle myBundle = new Bundle(); + myBundle.putInt("message", message); + sendBundle(myBundle); + } + + private void sendBundle(Bundle myBundle) { + Message myMessage = myHandler.obtainMessage(); + myMessage.setData(myBundle); + uiHandler.sendMessage(myMessage); + } + + // receive messages from the UI + final Handler myHandler = new Handler() { + @Override + public void handleMessage(Message myMessage) { + + int message; + + switch (message = myMessage.getData().getInt("message")) { + case MOTOR_A: + case MOTOR_B: + case MOTOR_C: + changeMotorSpeed(message, myMessage.getData().getInt("value1")); + break; + case MOTOR_B_ACTION: + rotateTo(MOTOR_B, myMessage.getData().getInt("value1")); + break; + case MOTOR_RESET: + reset(myMessage.getData().getInt("value1")); + break; + case START_PROGRAM: + startProgram(myMessage.getData().getString("name")); + break; + case STOP_PROGRAM: + stopProgram(); + break; + case GET_PROGRAM_NAME: + getProgramName(); + break; + case DO_BEEP: + doBeep(myMessage.getData().getInt("value1"), myMessage.getData().getInt("value2")); + break; + case DO_ACTION: + doAction(0); + break; + case READ_MOTOR_STATE: + readMotorState(myMessage.getData().getInt("value1")); + break; + case GET_FIRMWARE_VERSION: + getFirmwareVersion(); + break; + case FIND_FILES: + findFiles(myMessage.getData().getInt("value1") == 0, myMessage.getData().getInt("value2")); + break; + case DISCONNECT: + // send stop messages before closing + changeMotorSpeed(MOTOR_A, 0); + changeMotorSpeed(MOTOR_B, 0); + changeMotorSpeed(MOTOR_C, 0); + waitSomeTime(500); + try { + /* NUEVO */ + setInputMode(0, LCPMessage.NO_SENSOR, LCPMessage.RAWMODE); + setInputMode(1, LCPMessage.NO_SENSOR, LCPMessage.RAWMODE); + /* NUEVO */ + destroyNXTconnection(); + } + catch (IOException e) { } + break; + /* NUEVO */ + case SET_LIGHT_SENSOR: + setInputMode(0, LCPMessage.LIGHT_ACTIVE, LCPMessage.RAWMODE); + break; + case GET_LIGHT_SENSOR: + getInputValues(0); + waitSomeTime(30); + break; + case GET_TOUCH_SENSOR: + getInputValues(1); + waitSomeTime(30); + break; + /* NUEVO */ + } + } + }; } diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/CameraGLRenderer.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/CameraGLRenderer.java new file mode 100644 index 0000000..4a2f512 --- /dev/null +++ b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/CameraGLRenderer.java @@ -0,0 +1,222 @@ +package com.lego.minddroid; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import android.hardware.Camera; +import android.hardware.Camera.PreviewCallback; +import android.opengl.GLSurfaceView.Renderer; +import android.os.Handler; + +public class CameraGLRenderer implements Renderer, PreviewCallback{ + private static final String TAG = "CAMERA_RENDERER"; + Quad t; + int tex; + int[] glCameraFrame = null; + int[] glTexture = null; + byte[] frame = null; + int[] cameraTexture; + public int w,h; + protected MINDdroidCV mActivity; + protected double[]buffer; + protected int left, right; + private Handler handler = new Handler(); + + static { + System.loadLibrary("mixed_sample"); + } + + public CameraGLRenderer(){ + handler.removeCallbacks(FrameProcessor); + handler.postDelayed(FrameProcessor, 100); + + w = 0; h = 0; + t = new Quad(); + + frame = new byte[1]; + buffer = new double[10]; + glCameraFrame = new int[240*160]; + glTexture = new int[256*256]; + for(int i = 0; i < 256; ++i){ + for(int j = 0; j < 256; ++j){ + glTexture[i*256 + j] = 0; + } + } + } + + public native void FindLight(int width, int height, byte yuv[], int[] rgba,double[] array); + + public void onDrawFrame( GL10 gl ) { + gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); + + gl.glMatrixMode(GL10.GL_MODELVIEW); + gl.glLoadIdentity(); + + bindCameraTexture(gl); + + gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); + gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); + + gl.glVertexPointer(3, GL10.GL_FLOAT, 0, t.vertexBuffer); + gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, t.texBuffer); + gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); + + gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); + + gl.glFinish(); + } + + public void setMActivity (MINDdroidCV activity){ + mActivity = activity; + } + + public void onSurfaceChanged( GL10 gl, int width, int height ) { + gl.glViewport( 0, 0, width, height ); + } + + public void onSurfaceCreated( GL10 gl, EGLConfig config ) { + gl.glEnable(GL10.GL_TEXTURE_2D); + } + + void bindCameraTexture(GL10 gl) { + if (cameraTexture==null) + cameraTexture=new int[1]; + else + gl.glDeleteTextures(1, cameraTexture, 0); + + gl.glGenTextures(1, cameraTexture, 0); + int tex = cameraTexture[0]; + gl.glBindTexture(GL10.GL_TEXTURE_2D, tex); + synchronized (glCameraFrame) { + int orgRow = 0; + int destRow = 0; + for(int i = 0; i < 160; ++i){ + System.arraycopy(glCameraFrame, orgRow, glTexture, destRow, 240); + orgRow += 240; + destRow += 256; + } + gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, 256, 256, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, IntBuffer.wrap(glTexture)); + } + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); + } + + public void onPreviewFrame(byte[] new_frame, Camera camera){ + w = camera.getParameters().getPreviewSize().width; + h = camera.getParameters().getPreviewSize().height; + + synchronized(frame){ + frame = new_frame.clone(); + } + } + + private void processFrame(byte[] data) { + synchronized (glCameraFrame) { + FindLight(w, h, data, glCameraFrame, buffer); + } + } + + void calculateMove() { + // buffer[1] holds the light direction info if the phone is in landscape format + // small values -> turn left + // large values -> turn right + // in portrait mode buffer[2] should be used + // large values -> turn right + // small values -> turn left + if(mActivity.isConnected()){ + mActivity.sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.GET_LIGHT_SENSOR, 0, 0); + mActivity.sendBTCmessage(40, BTCommunicator.GET_TOUCH_SENSOR, 0, 0); + } + if(mActivity.getLightSensorReading() > 600 || mActivity.getTouchSensorReading() > 0){ + left = 0; + right = 0; + }else{ + if( buffer[0] > 100 ) { // light is visible + int forwardSpeed = 50; + double upScale = 40; + double direction = (buffer[1] - 240/2)/160; + //double direction = -1.0 * (buffer[2] - w/2)/h; + left = (int)(upScale * direction) + forwardSpeed; + right = (int)(-1.0 * upScale * direction) + forwardSpeed; + } else { + left = 0; + right = 0; + } + left = Math.min(Math.max(left,0),100); + right = Math.min(Math.max(right,0),100); + } + + mActivity.updateMotorControl(left,right); + } + + private Runnable FrameProcessor = new Runnable(){ + public void run(){ + if(mActivity.isConnected()){ + synchronized(frame){ + processFrame(frame); + } + calculateMove(); + } + if(handler != null) + handler.postDelayed(this, 100); + } + }; +} + +class Quad { + public FloatBuffer vertexBuffer, texBuffer; + + // number of coordinates per vertex in this array + static final int COORDS_PER_VERTEX = 3; + float triangleCoords[] = { // in counterclockwise order: + -1.0f, -1.0f, 0.0f, // top + 1.0f, -1.0f, 0.0f, // bottom left + -1.0f, 1.0f, 0.0f, // bottom right + 1.0f, 1.0f, 0.0f, + }; + + float texCoords[] = { + 0.0f, 0.625f, + 0.9375f, 0.625f, + 0.0f, 0.0f, + 0.9375f, 0.0f + }; + + public Quad() { + // initialize vertex byte buffer for shape coordinates + ByteBuffer bb = ByteBuffer.allocateDirect( + // (number of coordinate values * 4 bytes per float) + triangleCoords.length * 4); + // use the device hardware's native byte order + bb.order(ByteOrder.nativeOrder()); + + // create a floating point buffer from the ByteBuffer + vertexBuffer = bb.asFloatBuffer(); + // add the coordinates to the FloatBuffer + vertexBuffer.put(triangleCoords); + // set the buffer to read the first coordinate + vertexBuffer.position(0); + + ByteBuffer bb2 = ByteBuffer.allocateDirect( + // (number of coordinate values * 4 bytes per float) + texCoords.length * 4); + // use the device hardware's native byte order + bb2.order(ByteOrder.nativeOrder()); + + // create a floating point buffer from the ByteBuffer + texBuffer = bb2.asFloatBuffer(); + // add the coordinates to the FloatBuffer + texBuffer.put(texCoords); + // set the buffer to read the first coordinate + texBuffer.position(0); + } +} + diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/LCPMessage.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/LCPMessage.java index 02de610..6273f96 100644 --- a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/LCPMessage.java +++ b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/LCPMessage.java @@ -20,6 +20,7 @@ package com.lego.minddroid; + /** * Class for composing the proper messages for simple * communication over bluetooth @@ -97,6 +98,87 @@ public class LCPMessage { public static final byte DIRECTORY_FULL = (byte) 0xFC; public static final byte UNDEFINED_ERROR = (byte) 0x8A; public static final byte NOT_IMPLEMENTED = (byte) 0xFD; + + // Sensor types + public static final byte NO_SENSOR = 0x00; + public static final byte SWITCH = 0x01; + public static final byte TEMPERATURE = 0x02; + public static final byte REFLECTION = 0x03; + public static final byte ANGLE = 0x04; + public static final byte LIGHT_ACTIVE = 0x05; + public static final byte LIGHT_INACTIVE = 0x06; + public static final byte SOUND_DB = 0x07; + public static final byte SOUND_DBA = 0x08; + public static final byte CUSTOM = 0x09; + public static final byte LOWSPEED = 0x0A; + public static final byte LOWSPEED_9V = 0x0B; + public static final byte NO_OF_SENSOR_TYPES = 0x0C; + + // Sensor modes + public static final byte RAWMODE = 0x00; + public static final byte BOOLEANMODE = 0x20; + public static final byte TRANSITIONCNTMODE = 0x40; + public static final byte PERIODCOUNTERMODE = 0x60; + public static final byte PCTFULLSCALEMODE = (byte) 0x80; + public static final byte CELSIUSMODE = (byte) 0xA0; + public static final byte FRAHRENHEITMODE = (byte) 0xC0; + public static final byte ANGLESTEPSMODE = (byte) 0xE0; + public static final byte SLOPEMASK = 0x1F; + public static final byte MODEMASK = (byte) 0xE0; + + // Ports + public static final byte PORT_0 = 0x00; + public static final byte PORT_1 = 0x01; + public static final byte PORT_2 = 0x02; + public static final byte PORT_3 = 0x03; + + public static byte[] getSetInputModeMessage(int input_port, byte sensor_type, byte sensor_mode){ + byte[] message = new byte[5]; + + message[0] = DIRECT_COMMAND_NOREPLY; + message[1] = SET_INPUT_MODE; + switch(input_port){ + case 0: + message[2] = PORT_0; + break; + case 1: + message[2] = PORT_1; + break; + case 2: + message[2] = PORT_2; + break; + case 3: + message[2] = PORT_3; + break; + } + message[3] = sensor_type; + message[4] = sensor_mode; + + return message; + } + + public static byte[] getGetInputValuesMessage(int input_port){ + byte[] message = new byte[3]; + + message[0] = DIRECT_COMMAND_REPLY; + message[1] = GET_INPUT_VALUES; + switch(input_port){ + case 0: + message[2] = PORT_0; + break; + case 1: + message[2] = PORT_1; + break; + case 2: + message[2] = PORT_2; + break; + case 3: + message[2] = PORT_3; + break; + } + + return message; + } // Firmware codes public static byte[] FIRMWARE_VERSION_LEJOSMINDDROID = { 0x6c, 0x4d, 0x49, 0x64 }; diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/MINDdroidCV.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/MINDdroidCV.java index f0d2951..79c0c31 100644 --- a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/MINDdroidCV.java +++ b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/MINDdroidCV.java @@ -35,15 +35,19 @@ import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.PixelFormat; +import android.opengl.GLSurfaceView; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Vibrator; import android.speech.tts.TextToSpeech; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.view.WindowManager; +import android.view.WindowManager.LayoutParams; import android.widget.Toast; /** @@ -54,734 +58,789 @@ import android.widget.Toast; */ public class MINDdroidCV extends Activity implements BTConnectable, TextToSpeech.OnInitListener { - public static final int UPDATE_TIME = 200; - public static final int MENU_TOGGLE_CONNECT = Menu.FIRST; - public static final int MENU_QUIT = Menu.FIRST + 1; - - private static final int REQUEST_CONNECT_DEVICE = 1000; - private static final int REQUEST_ENABLE_BT = 2000; - private BTCommunicator myBTCommunicator = null; - private boolean connected = false; - private ProgressDialog connectingProgressDialog; - private Handler btcHandler; - private Menu myMenu; - private GameView mView; - private Activity thisActivity; - private boolean btErrorPending = false; - private boolean pairing; - private static boolean btOnByUs = false; - int mRobotType; - int motorLeft; - private int directionLeft; // +/- 1 - int motorRight; - private boolean stopAlreadySent = false; - private int directionRight; // +/- 1 - private int motorAction; - private int directionAction; // +/- 1 - private List programList; - private static final int MAX_PROGRAMS = 20; - private String programToStart; - private Toast reusableToast; - - // experimental TTS support - private TextToSpeech mTts; - private final int TTS_CHECK_CODE = 9991; + public static final int UPDATE_TIME = 200; + public static final int MENU_TOGGLE_CONNECT = Menu.FIRST; + public static final int MENU_QUIT = Menu.FIRST + 1; - /** - * Asks if bluetooth was switched on during the runtime of the app. For saving - * battery we switch it off when the app is terminated. - * @return true, when bluetooth was switched on by the app - */ - public static boolean isBtOnByUs() { - return btOnByUs; - } + private static final int REQUEST_CONNECT_DEVICE = 1000; + private static final int REQUEST_ENABLE_BT = 2000; + private BTCommunicator myBTCommunicator = null; + private boolean connected = false; + private ProgressDialog connectingProgressDialog; + private Handler btcHandler; + private Menu myMenu; + private GameView mView; + private Activity thisActivity; + private boolean btErrorPending = false; + private boolean pairing; + private static boolean btOnByUs = false; + int mRobotType; + int motorLeft; + private int directionLeft; // +/- 1 + int motorRight; + private boolean stopAlreadySent = false; + private int directionRight; // +/- 1 + private int motorAction; + private int directionAction; // +/- 1 + private List programList; + private static final int MAX_PROGRAMS = 20; + private String programToStart; + private Toast reusableToast; - /** - * Sets a flag when bluetooth was switched on durin runtime - * @param btOnByUs true, when bluetooth was switched on by the app - */ - public static void setBtOnByUs(boolean btOnByUs) { - MINDdroidCV.btOnByUs = btOnByUs; - } + // experimental TTS support + private TextToSpeech mTts; + private final int TTS_CHECK_CODE = 9991; - /** - * @return true, when currently pairing - */ - @Override - public boolean isPairing() { - return pairing; - } + /* NUEVO */ + private int lightSensor = 0; + private int touchSensor = 0; + /* NUEVO */ - /** - * Called when the activity is first created. Inititializes all the - * graphical views. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - thisActivity = this; - mRobotType = this.getIntent().getIntExtra(SplashMenu.MINDDROID_ROBOT_TYPE, R.id.robot_type_1); - setUpByType(); + /** + * Asks if bluetooth was switched on during the runtime of the app. For saving + * battery we switch it off when the app is terminated. + * @return true, when bluetooth was switched on by the app + */ + public static boolean isBtOnByUs() { + return btOnByUs; + } - requestWindowFeature(Window.FEATURE_NO_TITLE); - StartSound mySound = new StartSound(this); - mySound.start(); - reusableToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); - if( mRobotType == R.id.robot_type_5 ) { // opencv usage - showToast("opencv", Toast.LENGTH_SHORT); - setContentView(new SampleView(getApplicationContext(), this)); - } else { - showToast("no opencv", Toast.LENGTH_SHORT); - // setup our view, give it focus and display. - mView = new GameView(getApplicationContext(), this); - mView.setFocusable(true); - setContentView(mView); - } + /** + * Sets a flag when bluetooth was switched on durin runtime + * @param btOnByUs true, when bluetooth was switched on by the app + */ + public static void setBtOnByUs(boolean btOnByUs) { + MINDdroidCV.btOnByUs = btOnByUs; + } - getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + /** + * @return true, when currently pairing + */ + @Override + public boolean isPairing() { + return pairing; + } - // experimental TTS support for the lejosMINDdroid project - mTts = new TextToSpeech(this, - this // TextToSpeech.OnInitListener - ); - } + /** + * Called when the activity is first created. Inititializes all the + * graphical views. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + thisActivity = this; + mRobotType = this.getIntent().getIntExtra(SplashMenu.MINDDROID_ROBOT_TYPE, R.id.robot_type_1); + setUpByType(); - /** - * Initialization of the motor commands for the different robot types. - */ - private void setUpByType() { - switch (mRobotType) { - case R.id.robot_type_2: - motorLeft = BTCommunicator.MOTOR_B; - directionLeft = 1; - motorRight = BTCommunicator.MOTOR_C; - directionRight = 1; - motorAction = BTCommunicator.MOTOR_A; - directionAction = 1; - break; - case R.id.robot_type_3: - motorLeft = BTCommunicator.MOTOR_C; - directionLeft = -1; - motorRight = BTCommunicator.MOTOR_B; - directionRight = -1; - motorAction = BTCommunicator.MOTOR_A; - directionAction = 1; - break; - case R.id.robot_type_5: - motorLeft = BTCommunicator.MOTOR_C; - directionLeft = 1; - motorRight = BTCommunicator.MOTOR_B; - directionRight = 1; - motorAction = BTCommunicator.MOTOR_A; - directionAction = 1; - break; - default: - // default - motorLeft = BTCommunicator.MOTOR_B; - directionLeft = 1; - motorRight = BTCommunicator.MOTOR_C; - directionRight = 1; - motorAction = BTCommunicator.MOTOR_A; - directionAction = 1; - break; - } - } + requestWindowFeature(Window.FEATURE_NO_TITLE); + StartSound mySound = new StartSound(this); + mySound.start(); + reusableToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); + if( mRobotType == R.id.robot_type_5 ) { // opencv usage + showToast("opencv", Toast.LENGTH_SHORT); - /** - * Updates the menus and possible buttons when connection status changed. - */ - private void updateButtonsAndMenu() { + /* NUEVO */ + GLSurfaceView glView = new GLSurfaceView( this ); + glView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0 ); + glView.getHolder().setFormat( PixelFormat.TRANSLUCENT ); - if (myMenu == null) - return; + CameraGLRenderer renderer = new CameraGLRenderer(); + glView.setRenderer(renderer); - myMenu.removeItem(MENU_TOGGLE_CONNECT); + SampleView sView = new SampleView(getApplicationContext(), renderer, this); + setContentView( sView ); - if (connected) { - myMenu.add(0, MENU_TOGGLE_CONNECT, 1, getResources().getString(R.string.disconnect)).setIcon(R.drawable.ic_menu_connected); + addContentView(glView, new LayoutParams( )); + /* NUEVO */ - } else { - myMenu.add(0, MENU_TOGGLE_CONNECT, 1, getResources().getString(R.string.connect)).setIcon(R.drawable.ic_menu_connect); - } + } else { + showToast("no opencv", Toast.LENGTH_SHORT); + // setup our view, give it focus and display. + mView = new GameView(getApplicationContext(), this); + mView.setFocusable(true); + setContentView(mView); + } - } + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - /** - * Creates a new object for communication to the NXT robot via bluetooth and fetches the corresponding handler. - */ - private void createBTCommunicator() { - // interestingly BT adapter needs to be obtained by the UI thread - so we pass it in in the constructor - myBTCommunicator = new BTCommunicator(this, myHandler, BluetoothAdapter.getDefaultAdapter(), getResources()); - btcHandler = myBTCommunicator.getHandler(); - } + // experimental TTS support for the lejosMINDdroid project + mTts = new TextToSpeech(this, + this // TextToSpeech.OnInitListener + ); + } - /** - * Creates and starts the a thread for communication via bluetooth to the NXT robot. - * @param mac_address The MAC address of the NXT robot. - */ - private void startBTCommunicator(String mac_address) { - connected = false; - connectingProgressDialog = ProgressDialog.show(this, "", getResources().getString(R.string.connecting_please_wait), true); + /** + * Initialization of the motor commands for the different robot types. + */ + private void setUpByType() { + switch (mRobotType) { + case R.id.robot_type_2: + motorLeft = BTCommunicator.MOTOR_B; + directionLeft = 1; + motorRight = BTCommunicator.MOTOR_C; + directionRight = 1; + motorAction = BTCommunicator.MOTOR_A; + directionAction = 1; + break; + case R.id.robot_type_3: + motorLeft = BTCommunicator.MOTOR_C; + directionLeft = -1; + motorRight = BTCommunicator.MOTOR_B; + directionRight = -1; + motorAction = BTCommunicator.MOTOR_A; + directionAction = 1; + break; + case R.id.robot_type_5: + motorLeft = BTCommunicator.MOTOR_C; + directionLeft = 1; + motorRight = BTCommunicator.MOTOR_B; + directionRight = 1; + motorAction = BTCommunicator.MOTOR_A; + directionAction = 1; + break; + default: + // default + motorLeft = BTCommunicator.MOTOR_B; + directionLeft = 1; + motorRight = BTCommunicator.MOTOR_C; + directionRight = 1; + motorAction = BTCommunicator.MOTOR_A; + directionAction = 1; + break; + } + } - if (myBTCommunicator != null) { - try { - myBTCommunicator.destroyNXTconnection(); - } - catch (IOException e) { } - } - createBTCommunicator(); - myBTCommunicator.setMACAddress(mac_address); - myBTCommunicator.start(); - updateButtonsAndMenu(); - } + /** + * Updates the menus and possible buttons when connection status changed. + */ + private void updateButtonsAndMenu() { - /** - * Sends a message for disconnecting to the communcation thread. - */ - public void destroyBTCommunicator() { + if (myMenu == null) + return; - if (myBTCommunicator != null) { - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DISCONNECT, 0, 0); - myBTCommunicator = null; - } + myMenu.removeItem(MENU_TOGGLE_CONNECT); - connected = false; - updateButtonsAndMenu(); - } + if (connected) { + myMenu.add(0, MENU_TOGGLE_CONNECT, 1, getResources().getString(R.string.disconnect)).setIcon(R.drawable.ic_menu_connected); - /** - * Gets the current connection status. - * @return the current connection status to the robot. - */ - public boolean isConnected() { - return connected; - } + } else { + myMenu.add(0, MENU_TOGGLE_CONNECT, 1, getResources().getString(R.string.connect)).setIcon(R.drawable.ic_menu_connect); + } - /** - * Method for performing the appropriate action when the ACTION button is pressed shortly. - */ - public void actionButtonPressed() { - if (myBTCommunicator != null) { - if( mView != null ) { - mView.getThread().mActionPressed = true; - } + } - // Wolfgang Amadeus Mozart "Zauberfloete - Der Vogelfaenger bin ich ja" - if (mRobotType != R.id.robot_type_4) { - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DO_BEEP, 392, 100); - sendBTCmessage(200, BTCommunicator.DO_BEEP, 440, 100); - sendBTCmessage(400, BTCommunicator.DO_BEEP, 494, 100); - sendBTCmessage(600, BTCommunicator.DO_BEEP, 523, 100); - sendBTCmessage(800, BTCommunicator.DO_BEEP, 587, 300); - sendBTCmessage(1200, BTCommunicator.DO_BEEP, 523, 300); - sendBTCmessage(1600, BTCommunicator.DO_BEEP, 494, 300); - } + /** + * Creates a new object for communication to the NXT robot via bluetooth and fetches the corresponding handler. + */ + private void createBTCommunicator() { + // interestingly BT adapter needs to be obtained by the UI thread - so we pass it in in the constructor + myBTCommunicator = new BTCommunicator(this, myHandler, BluetoothAdapter.getDefaultAdapter(), getResources()); + btcHandler = myBTCommunicator.getHandler(); + } - // MOTOR ACTION: forth an back - switch (mRobotType) { - - case R.id.robot_type_3: - // Robogator: bite the user ;-) - for (int bite=0; bite<3; bite++) { - sendBTCmessage(bite*400, motorAction, 75 * directionAction, 0); - sendBTCmessage(bite*400+200, motorAction, -75 * directionAction, 0); - } - sendBTCmessage(3*400, motorAction, 0, 0); - break; - - case R.id.robot_type_4: - // lejosMINDdroid: just send the message for button press - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DO_ACTION, 0, 0); - break; - - case R.id.robot_type_5: - // - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DO_ACTION, 0, 0); - break; - - default: - // other robots: 180 degrees forth and back - sendBTCmessage(BTCommunicator.NO_DELAY, motorAction, 75 * directionAction, 0); - sendBTCmessage(500, motorAction, -75 * directionAction, 0); - sendBTCmessage(1000, motorAction, 0, 0); - break; - } - } - } + /** + * Creates and starts the a thread for communication via bluetooth to the NXT robot. + * @param mac_address The MAC address of the NXT robot. + */ + private void startBTCommunicator(String mac_address) { + connected = false; + connectingProgressDialog = ProgressDialog.show(this, "", getResources().getString(R.string.connecting_please_wait), true); - /** - * Method for performing the appropriate action when the ACTION button is long pressed. - */ - public void actionButtonLongPress() { - if (myBTCommunicator != null) { - if( mView != null ) { - mView.getThread().mActionPressed = true; - } + if (myBTCommunicator != null) { + try { + myBTCommunicator.destroyNXTconnection(); + } + catch (IOException e) { } + } + createBTCommunicator(); + myBTCommunicator.setMACAddress(mac_address); + myBTCommunicator.start(); + updateButtonsAndMenu(); + } - if (programList.size() == 0) - showToast(R.string.no_files_found, Toast.LENGTH_SHORT); - - FileDialog myFileDialog = new FileDialog(this, programList); + /** + * Sends a message for disconnecting to the communcation thread. + */ + public void destroyBTCommunicator() { + + if (myBTCommunicator != null) { + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DISCONNECT, 0, 0); + myBTCommunicator = null; + } + + connected = false; + updateButtonsAndMenu(); + } + + /** + * Gets the current connection status. + * @return the current connection status to the robot. + */ + public boolean isConnected() { + return connected; + } + + /** + * Method for performing the appropriate action when the ACTION button is pressed shortly. + */ + public void actionButtonPressed() { + if (myBTCommunicator != null) { + if( mView != null ) { + mView.getThread().mActionPressed = true; + } + + // Wolfgang Amadeus Mozart "Zauberfloete - Der Vogelfaenger bin ich ja" + if (mRobotType != R.id.robot_type_4) { + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DO_BEEP, 392, 100); + sendBTCmessage(200, BTCommunicator.DO_BEEP, 440, 100); + sendBTCmessage(400, BTCommunicator.DO_BEEP, 494, 100); + sendBTCmessage(600, BTCommunicator.DO_BEEP, 523, 100); + sendBTCmessage(800, BTCommunicator.DO_BEEP, 587, 300); + sendBTCmessage(1200, BTCommunicator.DO_BEEP, 523, 300); + sendBTCmessage(1600, BTCommunicator.DO_BEEP, 494, 300); + } + + // MOTOR ACTION: forth an back + switch (mRobotType) { + + case R.id.robot_type_3: + // Robogator: bite the user ;-) + for (int bite=0; bite<3; bite++) { + sendBTCmessage(bite*400, motorAction, 75 * directionAction, 0); + sendBTCmessage(bite*400+200, motorAction, -75 * directionAction, 0); + } + sendBTCmessage(3*400, motorAction, 0, 0); + break; + + case R.id.robot_type_4: + // lejosMINDdroid: just send the message for button press + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DO_ACTION, 0, 0); + break; + + case R.id.robot_type_5: + // + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.DO_ACTION, 0, 0); + break; + + default: + // other robots: 180 degrees forth and back + sendBTCmessage(BTCommunicator.NO_DELAY, motorAction, 75 * directionAction, 0); + sendBTCmessage(500, motorAction, -75 * directionAction, 0); + sendBTCmessage(1000, motorAction, 0, 0); + break; + } + } + } + + /** + * Method for performing the appropriate action when the ACTION button is long pressed. + */ + public void actionButtonLongPress() { + if (myBTCommunicator != null) { + if( mView != null ) { + mView.getThread().mActionPressed = true; + } + + if (programList.size() == 0) + showToast(R.string.no_files_found, Toast.LENGTH_SHORT); + + FileDialog myFileDialog = new FileDialog(this, programList); myFileDialog.show(mRobotType == R.id.robot_type_4); - } + } - } + } - /** - * Starts a program on the NXT robot. - * @param name The program name to start. Has to end with .rxe on the LEGO firmware and with .nxj on the - * leJOS NXJ firmware. - */ - public void startProgram(String name) { - // for .rxe programs: get program name, eventually stop this and start the new one delayed - // is handled in startRXEprogram() - if (name.endsWith(".rxe")) { - programToStart = name; - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.GET_PROGRAM_NAME, 0, 0); - return; - } - - // for .nxj programs: stop bluetooth communication after starting the program - if (name.endsWith(".nxj")) { - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.START_PROGRAM, name); - destroyBTCommunicator(); - return; - } + /** + * Starts a program on the NXT robot. + * @param name The program name to start. Has to end with .rxe on the LEGO firmware and with .nxj on the + * leJOS NXJ firmware. + */ + public void startProgram(String name) { + // for .rxe programs: get program name, eventually stop this and start the new one delayed + // is handled in startRXEprogram() + if (name.endsWith(".rxe")) { + programToStart = name; + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.GET_PROGRAM_NAME, 0, 0); + return; + } - // for all other programs: just start the program - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.START_PROGRAM, name); - } + // for .nxj programs: stop bluetooth communication after starting the program + if (name.endsWith(".nxj")) { + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.START_PROGRAM, name); + destroyBTCommunicator(); + return; + } - /** - * Depending on the status (whether the program runs already) we stop it, wait and restart it again. - * @param status The current status, 0x00 means that the program is already running. - */ - public void startRXEprogram(byte status) { - if (status == 0x00) { - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.STOP_PROGRAM, 0, 0); - sendBTCmessage(1000, BTCommunicator.START_PROGRAM, programToStart); - } - else { - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.START_PROGRAM, programToStart); - } - } + // for all other programs: just start the program + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.START_PROGRAM, name); + } - /** - * Sends the motor control values to the communcation thread. - * @param left The power of the left motor from 0 to 100. - * @param rigth The power of the right motor from 0 to 100. - */ - public void updateMotorControl(int left, int right) { + /** + * Depending on the status (whether the program runs already) we stop it, wait and restart it again. + * @param status The current status, 0x00 means that the program is already running. + */ + public void startRXEprogram(byte status) { + if (status == 0x00) { + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.STOP_PROGRAM, 0, 0); + sendBTCmessage(1000, BTCommunicator.START_PROGRAM, programToStart); + } + else { + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.START_PROGRAM, programToStart); + } + } - if (myBTCommunicator != null) { - // don't send motor stop twice - if ((left == 0) && (right == 0)) { - if (stopAlreadySent) - return; - else - stopAlreadySent = true; - } - else - stopAlreadySent = false; - - // send messages via the handler - sendBTCmessage(BTCommunicator.NO_DELAY, motorLeft, left * directionLeft, 0); - sendBTCmessage(BTCommunicator.NO_DELAY, motorRight, right * directionRight, 0); - } - } + /** + * Sends the motor control values to the communcation thread. + * @param left The power of the left motor from 0 to 100. + * @param rigth The power of the right motor from 0 to 100. + */ + public void updateMotorControl(int left, int right) { - /** - * Sends the message via the BTCommuncator to the robot. - * @param delay time to wait before sending the message. - * @param message the message type (as defined in BTCommucator) - * @param value1 first parameter - * @param value2 second parameter - */ - void sendBTCmessage(int delay, int message, int value1, int value2) { - Bundle myBundle = new Bundle(); - myBundle.putInt("message", message); - myBundle.putInt("value1", value1); - myBundle.putInt("value2", value2); - Message myMessage = myHandler.obtainMessage(); - myMessage.setData(myBundle); + if (myBTCommunicator != null) { + // don't send motor stop twice + if ((left == 0) && (right == 0)) { + if (stopAlreadySent) + return; + else + stopAlreadySent = true; + } + else + stopAlreadySent = false; - if (delay == 0) - btcHandler.sendMessage(myMessage); + // send messages via the handler + sendBTCmessage(BTCommunicator.NO_DELAY, motorLeft, left * directionLeft, 0); + sendBTCmessage(BTCommunicator.NO_DELAY, motorRight, right * directionRight, 0); + } + } - else - btcHandler.sendMessageDelayed(myMessage, delay); - } + /** + * Sends the message via the BTCommuncator to the robot. + * @param delay time to wait before sending the message. + * @param message the message type (as defined in BTCommucator) + * @param value1 first parameter + * @param value2 second parameter + */ + void sendBTCmessage(int delay, int message, int value1, int value2) { + Bundle myBundle = new Bundle(); + myBundle.putInt("message", message); + myBundle.putInt("value1", value1); + myBundle.putInt("value2", value2); + Message myMessage = myHandler.obtainMessage(); + myMessage.setData(myBundle); - /** - * Sends the message via the BTCommuncator to the robot. - * @param delay time to wait before sending the message. - * @param message the message type (as defined in BTCommucator) - * @param String a String parameter - */ - void sendBTCmessage(int delay, int message, String name) { - Bundle myBundle = new Bundle(); - myBundle.putInt("message", message); - myBundle.putString("name", name); - Message myMessage = myHandler.obtainMessage(); - myMessage.setData(myBundle); + if (delay == 0) + btcHandler.sendMessage(myMessage); - if (delay == 0) - btcHandler.sendMessage(myMessage); - else - btcHandler.sendMessageDelayed(myMessage, delay); - } + else + btcHandler.sendMessageDelayed(myMessage, delay); + } - @Override - public void onResume() { - super.onResume(); - if( mView != null ) { - mView.registerListener(); - } - } + /** + * Sends the message via the BTCommuncator to the robot. + * @param delay time to wait before sending the message. + * @param message the message type (as defined in BTCommucator) + * @param String a String parameter + */ + void sendBTCmessage(int delay, int message, String name) { + Bundle myBundle = new Bundle(); + myBundle.putInt("message", message); + myBundle.putString("name", name); + Message myMessage = myHandler.obtainMessage(); + myMessage.setData(myBundle); - @Override - protected void onStart() { - super.onStart(); + if (delay == 0) + btcHandler.sendMessage(myMessage); + else + btcHandler.sendMessageDelayed(myMessage, delay); + } - if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { - Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); - startActivityForResult(enableIntent, REQUEST_ENABLE_BT); - } else { - selectNXT(); - } - } + @Override + public void onResume() { + super.onResume(); + if( mView != null ) { + mView.registerListener(); + } + } - @Override - protected void onDestroy() { - super.onDestroy(); - destroyBTCommunicator(); - } + @Override + protected void onStart() { + super.onStart(); - @Override - public void onPause() { - if( mView != null ) { - mView.unregisterListener(); - } - destroyBTCommunicator(); - super.onStop(); - } + if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { + Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); + startActivityForResult(enableIntent, REQUEST_ENABLE_BT); + } else { + selectNXT(); + } + } - @Override - public void onSaveInstanceState(Bundle icicle) { - super.onSaveInstanceState(icicle); - if( mView != null ) { - mView.unregisterListener(); - } - } + @Override + protected void onDestroy() { + super.onDestroy(); + destroyBTCommunicator(); + } - /** - * Creates the menu items - */ - @Override - public boolean onCreateOptionsMenu(Menu menu) { - myMenu = menu; - myMenu.add(0, MENU_TOGGLE_CONNECT, 1, getResources().getString(R.string.connect)).setIcon(R.drawable.ic_menu_connect); - myMenu.add(0, MENU_QUIT, 2, getResources().getString(R.string.quit)).setIcon(R.drawable.ic_menu_exit); - updateButtonsAndMenu(); - return true; - } + @Override + public void onPause() { + if( mView != null ) { + mView.unregisterListener(); + } + destroyBTCommunicator(); + super.onStop(); + } - /** - * Handles item selections - */ - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case MENU_TOGGLE_CONNECT: + @Override + public void onSaveInstanceState(Bundle icicle) { + super.onSaveInstanceState(icicle); + if( mView != null ) { + mView.unregisterListener(); + } + } - if (myBTCommunicator == null || connected == false) { - selectNXT(); + /** + * Creates the menu items + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + myMenu = menu; + myMenu.add(0, MENU_TOGGLE_CONNECT, 1, getResources().getString(R.string.connect)).setIcon(R.drawable.ic_menu_connect); + myMenu.add(0, MENU_QUIT, 2, getResources().getString(R.string.quit)).setIcon(R.drawable.ic_menu_exit); + updateButtonsAndMenu(); + return true; + } - } else { - destroyBTCommunicator(); - updateButtonsAndMenu(); - } + /** + * Handles item selections + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case MENU_TOGGLE_CONNECT: - return true; - case MENU_QUIT: - destroyBTCommunicator(); - finish(); + if (myBTCommunicator == null || connected == false) { + selectNXT(); - if (btOnByUs) - showToast(R.string.bt_off_message, Toast.LENGTH_SHORT); + } else { + destroyBTCommunicator(); + updateButtonsAndMenu(); + } - SplashMenu.quitApplication(); - return true; - } + return true; + case MENU_QUIT: + destroyBTCommunicator(); + finish(); - return false; - } + if (btOnByUs) + showToast(R.string.bt_off_message, Toast.LENGTH_SHORT); - /** - * Displays a message as a toast - * @param textToShow the message - * @param length the length of the toast to display - */ - private void showToast(String textToShow, int length) { - reusableToast.setText(textToShow); - reusableToast.setDuration(length); - reusableToast.show(); - } + SplashMenu.quitApplication(); + return true; + } - /** - * Displays a message as a toast - * @param resID the ressource ID to display - * @param length the length of the toast to display - */ - private void showToast(int resID, int length) { - reusableToast.setText(resID); - reusableToast.setDuration(length); - reusableToast.show(); - } - - /** - * Receive messages from the BTCommunicator - */ - final Handler myHandler = new Handler() { - @Override - public void handleMessage(Message myMessage) { - switch (myMessage.getData().getInt("message")) { - case BTCommunicator.DISPLAY_TOAST: - showToast(myMessage.getData().getString("toastText"), Toast.LENGTH_SHORT); - break; - case BTCommunicator.STATE_CONNECTED: - connected = true; - programList = new ArrayList(); - connectingProgressDialog.dismiss(); - updateButtonsAndMenu(); - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.GET_FIRMWARE_VERSION, 0, 0); - break; - case BTCommunicator.MOTOR_STATE: + return false; + } - if (myBTCommunicator != null) { - byte[] motorMessage = myBTCommunicator.getReturnMessage(); - int position = byteToInt(motorMessage[21]) + (byteToInt(motorMessage[22]) << 8) + (byteToInt(motorMessage[23]) << 16) - + (byteToInt(motorMessage[24]) << 24); - showToast(getResources().getString(R.string.current_position) + position, Toast.LENGTH_SHORT); - } + /** + * Displays a message as a toast + * @param textToShow the message + * @param length the length of the toast to display + */ + private void showToast(String textToShow, int length) { + reusableToast.setText(textToShow); + reusableToast.setDuration(length); + reusableToast.show(); + } - break; + /** + * Displays a message as a toast + * @param resID the ressource ID to display + * @param length the length of the toast to display + */ + private void showToast(int resID, int length) { + reusableToast.setText(resID); + reusableToast.setDuration(length); + reusableToast.show(); + } - case BTCommunicator.STATE_CONNECTERROR_PAIRING: - connectingProgressDialog.dismiss(); - destroyBTCommunicator(); - break; + /** + * Receive messages from the BTCommunicator + */ + final Handler myHandler = new Handler() { + @Override + public void handleMessage(Message myMessage) { + switch (myMessage.getData().getInt("message")) { + case BTCommunicator.DISPLAY_TOAST: + showToast(myMessage.getData().getString("toastText"), Toast.LENGTH_SHORT); + break; + case BTCommunicator.STATE_CONNECTED: + connected = true; + programList = new ArrayList(); + connectingProgressDialog.dismiss(); + updateButtonsAndMenu(); + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.GET_FIRMWARE_VERSION, 0, 0); + break; + case BTCommunicator.MOTOR_STATE: - case BTCommunicator.STATE_CONNECTERROR: - connectingProgressDialog.dismiss(); - case BTCommunicator.STATE_RECEIVEERROR: - case BTCommunicator.STATE_SENDERROR: + if (myBTCommunicator != null) { + byte[] motorMessage = myBTCommunicator.getReturnMessage(); + int position = byteToInt(motorMessage[21]) + (byteToInt(motorMessage[22]) << 8) + (byteToInt(motorMessage[23]) << 16) + + (byteToInt(motorMessage[24]) << 24); + showToast(getResources().getString(R.string.current_position) + position, Toast.LENGTH_SHORT); + } - destroyBTCommunicator(); - if (btErrorPending == false) { - btErrorPending = true; - // inform the user of the error with an AlertDialog - AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity); - builder.setTitle(getResources().getString(R.string.bt_error_dialog_title)) - .setMessage(getResources().getString(R.string.bt_error_dialog_message)).setCancelable(false) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - btErrorPending = false; - dialog.cancel(); - selectNXT(); - } - }); - builder.create().show(); - } + break; - break; + case BTCommunicator.STATE_CONNECTERROR_PAIRING: + connectingProgressDialog.dismiss(); + destroyBTCommunicator(); + break; - case BTCommunicator.FIRMWARE_VERSION: + case BTCommunicator.STATE_CONNECTERROR: + connectingProgressDialog.dismiss(); + case BTCommunicator.STATE_RECEIVEERROR: + case BTCommunicator.STATE_SENDERROR: - if (myBTCommunicator != null) { - byte[] firmwareMessage = myBTCommunicator.getReturnMessage(); - // check if we know the firmware - boolean isLejosMindDroid = true; - for (int pos=0; pos<4; pos++) { - if (firmwareMessage[pos + 3] != LCPMessage.FIRMWARE_VERSION_LEJOSMINDDROID[pos]) { - isLejosMindDroid = false; - break; - } - } - if (isLejosMindDroid) { - mRobotType = R.id.robot_type_4; - setUpByType(); - } - // afterwards we search for all files on the robot - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.FIND_FILES, 0, 0); - } + destroyBTCommunicator(); + if (btErrorPending == false) { + btErrorPending = true; + // inform the user of the error with an AlertDialog + AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity); + builder.setTitle(getResources().getString(R.string.bt_error_dialog_title)) + .setMessage(getResources().getString(R.string.bt_error_dialog_message)).setCancelable(false) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + btErrorPending = false; + dialog.cancel(); + selectNXT(); + } + }); + builder.create().show(); + } - break; + break; - case BTCommunicator.FIND_FILES: + case BTCommunicator.FIRMWARE_VERSION: - if (myBTCommunicator != null) { - byte[] fileMessage = myBTCommunicator.getReturnMessage(); - String fileName = new String(fileMessage, 4, 20); - fileName = fileName.replaceAll("\0",""); + if (myBTCommunicator != null) { + byte[] firmwareMessage = myBTCommunicator.getReturnMessage(); + // check if we know the firmware + boolean isLejosMindDroid = true; + for (int pos=0; pos<4; pos++) { + if (firmwareMessage[pos + 3] != LCPMessage.FIRMWARE_VERSION_LEJOSMINDDROID[pos]) { + isLejosMindDroid = false; + break; + } + } + if (isLejosMindDroid) { + mRobotType = R.id.robot_type_4; + setUpByType(); + } + // afterwards we search for all files on the robot + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.FIND_FILES, 0, 0); + } - if (mRobotType == R.id.robot_type_4 || fileName.endsWith(".nxj") || fileName.endsWith(".rxe")) { - programList.add(fileName); - } + break; - // find next entry with appropriate handle, - // limit number of programs (in case of error (endless loop)) - if (programList.size() <= MAX_PROGRAMS) - sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.FIND_FILES, - 1, byteToInt(fileMessage[3])); - } + case BTCommunicator.FIND_FILES: - break; - - case BTCommunicator.PROGRAM_NAME: - if (myBTCommunicator != null) { - byte[] returnMessage = myBTCommunicator.getReturnMessage(); - startRXEprogram(returnMessage[2]); - } - - break; - - case BTCommunicator.SAY_TEXT: - if (myBTCommunicator != null) { - byte[] textMessage = myBTCommunicator.getReturnMessage(); - // evaluate control byte - byte controlByte = textMessage[2]; - // BIT7: Language - if ((controlByte & 0x80) == 0x00) - mTts.setLanguage(Locale.US); - else - mTts.setLanguage(Locale.getDefault()); - // BIT6: Pitch - if ((controlByte & 0x40) == 0x00) - mTts.setPitch(1.0f); - else - mTts.setPitch(0.75f); - // BIT0-3: Speech Rate - switch (controlByte & 0x0f) { - case 0x01: - mTts.setSpeechRate(1.5f); - break; - case 0x02: - mTts.setSpeechRate(0.75f); - break; - - default: mTts.setSpeechRate(1.0f); - break; - } - - String ttsText = new String(textMessage, 3, 19); - ttsText = ttsText.replaceAll("\0",""); - showToast(ttsText, Toast.LENGTH_SHORT); - mTts.speak(ttsText, TextToSpeech.QUEUE_FLUSH, null); - } - - break; - - case BTCommunicator.VIBRATE_PHONE: - if (myBTCommunicator != null) { - byte[] vibrateMessage = myBTCommunicator.getReturnMessage(); - Vibrator myVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - myVibrator.vibrate(vibrateMessage[2]*10); - } - - break; - } - } - }; + if (myBTCommunicator != null) { + byte[] fileMessage = myBTCommunicator.getReturnMessage(); + String fileName = new String(fileMessage, 4, 20); + fileName = fileName.replaceAll("\0",""); - private int byteToInt(byte byteValue) { - int intValue = (byteValue & (byte) 0x7f); + if (mRobotType == R.id.robot_type_4 || fileName.endsWith(".nxj") || fileName.endsWith(".rxe")) { + programList.add(fileName); + } - if ((byteValue & (byte) 0x80) != 0) - intValue |= 0x80; + // find next entry with appropriate handle, + // limit number of programs (in case of error (endless loop)) + if (programList.size() <= MAX_PROGRAMS) + sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.FIND_FILES, + 1, byteToInt(fileMessage[3])); + } - return intValue; - } + break; - void selectNXT() { - Intent serverIntent = new Intent(this, DeviceListActivity.class); - startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); - } + case BTCommunicator.PROGRAM_NAME: + if (myBTCommunicator != null) { + byte[] returnMessage = myBTCommunicator.getReturnMessage(); + startRXEprogram(returnMessage[2]); + } - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case REQUEST_CONNECT_DEVICE: + break; - // When DeviceListActivity returns with a device to connect - if (resultCode == Activity.RESULT_OK) { - // Get the device MAC address and start a new bt communicator thread - String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); - pairing = data.getExtras().getBoolean(DeviceListActivity.PAIRING); - startBTCommunicator(address); - } - - break; - - case REQUEST_ENABLE_BT: + case BTCommunicator.SAY_TEXT: + if (myBTCommunicator != null) { + byte[] textMessage = myBTCommunicator.getReturnMessage(); + // evaluate control byte + byte controlByte = textMessage[2]; + // BIT7: Language + if ((controlByte & 0x80) == 0x00) + mTts.setLanguage(Locale.US); + else + mTts.setLanguage(Locale.getDefault()); + // BIT6: Pitch + if ((controlByte & 0x40) == 0x00) + mTts.setPitch(1.0f); + else + mTts.setPitch(0.75f); + // BIT0-3: Speech Rate + switch (controlByte & 0x0f) { + case 0x01: + mTts.setSpeechRate(1.5f); + break; + case 0x02: + mTts.setSpeechRate(0.75f); + break; - // When the request to enable Bluetooth returns - switch (resultCode) { - case Activity.RESULT_OK: - btOnByUs = true; - selectNXT(); - break; - case Activity.RESULT_CANCELED: - showToast(R.string.bt_needs_to_be_enabled, Toast.LENGTH_SHORT); - finish(); - break; - default: - showToast(R.string.problem_at_connecting, Toast.LENGTH_SHORT); - finish(); - break; - } - - break; + default: mTts.setSpeechRate(1.0f); + break; + } - // will not be called now, since the check intent is not generated - case TTS_CHECK_CODE: - if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { - // success, create the TTS instance - mTts = new TextToSpeech(this, this); - } - else { - // missing data, install it - Intent installIntent = new Intent(); - installIntent.setAction( - TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); - startActivity(installIntent); - } - - break; - } - } + String ttsText = new String(textMessage, 3, 19); + ttsText = ttsText.replaceAll("\0",""); + showToast(ttsText, Toast.LENGTH_SHORT); + mTts.speak(ttsText, TextToSpeech.QUEUE_FLUSH, null); + } - /** - * Initializing of the TTS engine. - */ - public void onInit(int status) { - // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. - if (status == TextToSpeech.SUCCESS) { - // Set preferred language to US english. - // Note that a language may not be available, and the result will indicate this. - int result = mTts.setLanguage(Locale.US); - // Try this someday for some interesting results. - if (result == TextToSpeech.LANG_MISSING_DATA || - result == TextToSpeech.LANG_NOT_SUPPORTED) { - // Language data is missing or the language is not supported. - if (mRobotType == R.id.robot_type_4) - showToast(R.string.tts_language_not_supported, Toast.LENGTH_LONG); - } - } else { - // Initialization failed. - if (mRobotType == R.id.robot_type_4) - showToast(R.string.tts_initialization_failure, Toast.LENGTH_LONG); - } - } + break; + + case BTCommunicator.VIBRATE_PHONE: + if (myBTCommunicator != null) { + byte[] vibrateMessage = myBTCommunicator.getReturnMessage(); + Vibrator myVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + myVibrator.vibrate(vibrateMessage[2]*10); + } + + break; + + /* NUEVO */ + case BTCommunicator.UPDATE_SENSOR: + /*String msg2str = ""; + Log.d("MINDDroidCV.java", "UPDATE SENSORS HANDLER");*/ + if(myBTCommunicator != null) { + byte[] sensor_message = myBTCommunicator.getReturnMessage(); + if(sensor_message[3] == 0){ + // Sensor de luz. + lightSensor = (sensor_message[9] << 8) + sensor_message[8]; + /*for(int i = 0; i < sensor_message.length; ++i) + msg2str += String.format("%02x ", sensor_message[i]); + msg2str = String.format("%s :: VALUE %d", msg2str, lightSensor);*/ + }else if(sensor_message[3] == 1){ + // Sensor de tacto. + touchSensor = (sensor_message[11] << 8) + sensor_message[10]; + /*for(int i = 0; i < sensor_message.length; ++i) + msg2str += String.format("%02x", sensor_message[i]); + msg2str = String.format("%s :: VALUE %d", msg2str, touchSensor);*/ + } + } + /*Log.d("MINDDroidCV.java", msg2str);*/ + + break; + /* NUEVO */ + } + } + }; + + private int byteToInt(byte byteValue) { + int intValue = (byteValue & (byte) 0x7f); + + if ((byteValue & (byte) 0x80) != 0) + intValue |= 0x80; + + return intValue; + } + + void selectNXT() { + Intent serverIntent = new Intent(this, DeviceListActivity.class); + startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case REQUEST_CONNECT_DEVICE: + + // When DeviceListActivity returns with a device to connect + if (resultCode == Activity.RESULT_OK) { + // Get the device MAC address and start a new bt communicator thread + String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); + pairing = data.getExtras().getBoolean(DeviceListActivity.PAIRING); + startBTCommunicator(address); + } + + break; + + case REQUEST_ENABLE_BT: + + // When the request to enable Bluetooth returns + switch (resultCode) { + case Activity.RESULT_OK: + btOnByUs = true; + selectNXT(); + break; + case Activity.RESULT_CANCELED: + showToast(R.string.bt_needs_to_be_enabled, Toast.LENGTH_SHORT); + finish(); + break; + default: + showToast(R.string.problem_at_connecting, Toast.LENGTH_SHORT); + finish(); + break; + } + + break; + + // will not be called now, since the check intent is not generated + case TTS_CHECK_CODE: + if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { + // success, create the TTS instance + mTts = new TextToSpeech(this, this); + } + else { + // missing data, install it + Intent installIntent = new Intent(); + installIntent.setAction( + TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); + startActivity(installIntent); + } + + break; + } + } + + /** + * Initializing of the TTS engine. + */ + public void onInit(int status) { + // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. + if (status == TextToSpeech.SUCCESS) { + // Set preferred language to US english. + // Note that a language may not be available, and the result will indicate this. + int result = mTts.setLanguage(Locale.US); + // Try this someday for some interesting results. + if (result == TextToSpeech.LANG_MISSING_DATA || + result == TextToSpeech.LANG_NOT_SUPPORTED) { + // Language data is missing or the language is not supported. + if (mRobotType == R.id.robot_type_4) + showToast(R.string.tts_language_not_supported, Toast.LENGTH_LONG); + } + } else { + // Initialization failed. + if (mRobotType == R.id.robot_type_4) + showToast(R.string.tts_initialization_failure, Toast.LENGTH_LONG); + } + } + + /* NUEVO */ + public int getLightSensorReading(){ + return lightSensor; + } + + public int getTouchSensorReading(){ + return touchSensor; + } + /* NUEVO */ } + diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/NXJUploader.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/NXJUploader.java index c3d5f66..0212b46 100644 --- a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/NXJUploader.java +++ b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/NXJUploader.java @@ -251,7 +251,6 @@ public class NXJUploader extends Activity implements UploadThreadListener, Dialo textView = (TextView) findViewById(R.id.nxt_name); textView.setText(text); break; - case DIALOG_FILE: textView = (TextView) findViewById(R.id.nxj_file_name); textView.setText(text); diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleView.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleView.java index 6e0665f..34ae7f1 100644 --- a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleView.java +++ b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleView.java @@ -1,29 +1,112 @@ package com.lego.minddroid; import android.content.Context; -import android.graphics.Bitmap; +import android.hardware.Camera; +import android.util.Log; +import android.view.SurfaceHolder; +import android.view.SurfaceView; -class SampleView extends SampleViewBase { - - public SampleView(Context context, MINDdroidCV uiActivity) { - super(context,uiActivity); +class SampleView extends SurfaceView implements SurfaceHolder.Callback { + private SurfaceHolder mHolder; + private Camera mCamera; + private static final String TAG = "CAMERA_PREVIEW"; + private int mFrameWidth; + private int mFrameHeight; + protected CameraGLRenderer mGLRender; + protected MINDdroidCV mActivity; + protected double[]buffer; + protected int left, right; + + public SampleView(Context context, CameraGLRenderer renderer, MINDdroidCV uiActivity) { + super(context); + mCamera = Camera.open(); + mGLRender = renderer; + mActivity = uiActivity; + + // Install a SurfaceHolder.Callback so we get notified when the + // underlying surface is created and destroyed. + mHolder = getHolder(); + mHolder.addCallback(this); + // deprecated setting, but required on Android versions prior to 3.0 + mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + + renderer.setMActivity(uiActivity); + + Log.i(TAG, "Instantiated new " + this.getClass()); } - - @Override - protected Bitmap processFrame(byte[] data) { - int frameSize = getFrameWidth() * getFrameHeight(); - int[] rgba = new int[frameSize]; - FindLight(getFrameWidth(), getFrameHeight(), data, rgba,buffer); + public void surfaceCreated(SurfaceHolder holder) { + // The Surface has been created, now tell the camera where to draw the preview. + try { - Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888); - bmp.setPixels(rgba, 0/* offset */, getFrameWidth() /* stride */, 0, 0, getFrameWidth(), getFrameHeight()); - return bmp; + /**/ + mCamera.setPreviewDisplay(mHolder); + mCamera.startPreview(); + + } catch (Exception e) { + Log.d(TAG, "Error setting camera preview: " + e.getMessage()); + } } - - public native void FindLight(int width, int height, byte yuv[], int[] rgba,double[] array); - static { - System.loadLibrary("mixed_sample"); + public int getFrameWidth() { + return mFrameWidth; + } + + public int getFrameHeight() { + return mFrameHeight; + } + + + public void surfaceDestroyed(SurfaceHolder holder) { + // Surface will be destroyed when we return, so stop the preview. + // Because the CameraDevice object is not a shared resource, it's very + // important to release it when the activity is paused. + try { + if (mCamera!=null) { + mCamera.stopPreview(); + mCamera.setPreviewCallback(null); + mCamera.release(); // release the camera for other applications + mCamera = null; + } + } catch (Exception e) { + + } + } + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + // If your preview can change or rotate, take care of those events here. + // Make sure to stop the preview before resizing or reformatting it. + + mFrameWidth = w; + mFrameHeight = h; + + if (mHolder.getSurface() == null){ + // preview surface does not exist + return; + } + + // stop preview before making changes + try { + mCamera.stopPreview(); + } catch (Exception e){ + // ignore: tried to stop a non-existent preview + } + + // set preview size and make any resize, rotate or + // reformatting changes here + + // start preview with new settings + try { + Camera.Parameters p = mCamera.getParameters(); + p.setPreviewSize(240, 160); + mCamera.setParameters(p); + mGLRender.w = w; + mGLRender.h = h; + mCamera.setPreviewDisplay(mHolder); + mCamera.startPreview(); + mCamera.setPreviewCallback(mGLRender); + } catch (Exception e){ + Log.d(TAG, "Error starting camera preview: " + e.getMessage()); + } } } diff --git a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleViewBase.java b/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleViewBase.java deleted file mode 100644 index 9644ceb..0000000 --- a/MINDdroidCV_MINDSTORMS/src/com/lego/minddroid/SampleViewBase.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.lego.minddroid; - -import java.io.IOException; -import java.text.DecimalFormat; -import java.util.List; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; -import android.hardware.Camera; -import android.hardware.Camera.PreviewCallback; -import android.util.Log; -import android.view.SurfaceHolder; -import android.view.SurfaceView; - -public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable { - private static final String TAG = "Sample::SurfaceView"; - - private Camera mCamera; - private SurfaceHolder mHolder; - private int mFrameWidth; - private int mFrameHeight; - private byte[] mFrame; - private boolean mThreadRun; - protected MINDdroidCV mActivity; - protected double[]buffer; - protected int left, right; - - public SampleViewBase(Context context, MINDdroidCV uiActivity) { - super(context); - mActivity = uiActivity; - - mHolder = getHolder(); - mHolder.addCallback(this); - buffer = new double[10]; - Log.i(TAG, "Instantiated new " + this.getClass()); - } - - public int getFrameWidth() { - return mFrameWidth; - } - - public int getFrameHeight() { - return mFrameHeight; - } - - public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) { - Log.i(TAG, "surfaceCreated"); - if (mCamera != null) { - Camera.Parameters params = mCamera.getParameters(); - List sizes = params.getSupportedPreviewSizes(); - mFrameWidth = width; - mFrameHeight = height; - - // selecting optimal camera preview size - { - double minDiff = Double.MAX_VALUE; - for (Camera.Size size : sizes) { - if (Math.abs(size.height - height) < minDiff) { - mFrameWidth = size.width; - mFrameHeight = size.height; - minDiff = Math.abs(size.height - height); - } - } - } - - params.setPreviewSize(getFrameWidth(), getFrameHeight()); - mCamera.setParameters(params); - //mCamera.setDisplayOrientation(180); - - try { - mCamera.setPreviewDisplay(null); - } catch (IOException e) { - Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e); - } - mCamera.startPreview(); - } - } - - public void surfaceCreated(SurfaceHolder holder) { - Log.i(TAG, "surfaceCreated"); - mCamera = Camera.open(); - mCamera.setPreviewCallback(new PreviewCallback() { - public void onPreviewFrame(byte[] data, Camera camera) { - synchronized (SampleViewBase.this) { - mFrame = data; - SampleViewBase.this.notify(); - } - } - }); - (new Thread(this)).start(); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - Log.i(TAG, "surfaceDestroyed"); - mThreadRun = false; - if (mCamera != null) { - synchronized (this) { - mCamera.stopPreview(); - mCamera.setPreviewCallback(null); - mCamera.release(); - mCamera = null; - } - } - } - - protected abstract Bitmap processFrame(byte[] data); - - public void run() { - mThreadRun = true; - Log.i(TAG, "Starting processing thread"); - while (mThreadRun) { - Bitmap bmp = null; - - synchronized (this) { - try { - this.wait(); - bmp = processFrame(mFrame); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - if (bmp != null) { - Canvas canvas = mHolder.lockCanvas(); - calculateMove(); - if (canvas != null) { - canvas.drawBitmap(bmp,0.0f,0.0f,null); //(canvas.getWidth() - getFrameWidth()) / 2, (canvas.getHeight() - getFrameHeight()) / 2, null); - - //drawText(canvas,buffer); - mHolder.unlockCanvasAndPost(canvas); - } - bmp.recycle(); - } - } - } - - void drawText(Canvas canvas,double[] buffer) { - Paint paint = new Paint(); - paint.setStyle(Paint.Style.FILL); - paint.setColor(Color.WHITE); - DecimalFormat twoPlaces = new DecimalFormat("0.00"); - String todraw = ":" + twoPlaces.format(buffer[0]) + ":" + - twoPlaces.format(buffer[1]) + ":" + - twoPlaces.format(buffer[2]) + ":" + - left + ":" + right + ":"; - Paint bpaint = new Paint(); - bpaint.setStyle(Paint.Style.FILL); - bpaint.setColor(Color.BLUE); - Rect rect = new Rect(0,0,250,50); - canvas.drawRect(rect , bpaint); - canvas.drawText(todraw, 0, todraw.length(), 10.0f, 10.0f, paint); - } - - void calculateMove() { - // buffer[1] holds the light direction info if the phone is in landscape format - // small values -> turn left - // large values -> turn right - // in portrait mode buffer[2] should be used - // large values -> turn right - // small values -> turn left - if( buffer[0] > 100 ) { // light is visible - int forwardSpeed = 50; - double upScale = 40; - //double direction = (buffer[1] - getFrameWidth()/2)/getFrameWidth(); - double direction = -1.0 * (buffer[2] - getFrameHeight()/2)/getFrameHeight(); - left = (int)(upScale * direction) + forwardSpeed; - right = (int)(-1.0 * upScale * direction) + forwardSpeed; - } else { - left = 0; - right = 0; - } - left = Math.min(Math.max(left,0),100); - right = Math.min(Math.max(right,0),100); - - mActivity.updateMotorControl(left,right); - } - -} \ No newline at end of file