android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Android / InternalSensors.hpp
bloba01e829e4f5dad6e8ca8292c93ec702df4afa66d
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_ANDROID_INTERNAL_SENSORS_HPP
25 #define XCSOAR_ANDROID_INTERNAL_SENSORS_HPP
27 #include "Java/Object.hpp"
28 #include "Java/Class.hpp"
29 #include "Compiler.h"
31 #include <jni.h>
32 #include <vector>
34 class Context;
36 // Consolidated class for handling Java objects that work with Android GPS
37 // and sensor facilities. Public methods handle activation and deactivation of
38 // specific sensors.
39 class InternalSensors {
40 static Java::TrivialClass gps_cls, sensors_cls;
42 // IDs for methods in InternalGPS.java.
43 static jmethodID gps_ctor_id, close_method;
45 // IDs for methods in NonGPSSensors.java.
46 static jmethodID sensors_ctor_id;
47 static jmethodID mid_sensors_getSubscribableSensors;
48 static jmethodID mid_sensors_subscribeToSensor_;
49 static jmethodID mid_sensors_cancelSensorSubscription_;
50 static jmethodID mid_sensors_subscribedToSensor_;
51 static jmethodID mid_sensors_cancelAllSensorSubscriptions_;
53 public:
54 static bool Initialise(JNIEnv *env);
55 static void Deinitialise(JNIEnv *env);
57 private:
58 // Java objects working with the GPS and the other sensors respectively.
59 Java::Object obj_InternalGPS_;
60 Java::Object obj_NonGPSSensors_;
61 std::vector<int> subscribable_sensors_;
63 InternalSensors(JNIEnv* env, jobject gps_obj, jobject sensors_obj);
64 void getSubscribableSensors(JNIEnv* env, jobject sensors_obj);
65 public:
66 ~InternalSensors();
68 /* Sensor type identifier constants for use with subscription
69 methods below. These must have the same numerical values as
70 their counterparts in the Android API's Sensor class. */
71 static constexpr int TYPE_ACCELEROMETER = 0x1;
72 static constexpr int TYPE_GYROSCOPE = 0x4;
73 static constexpr int TYPE_MAGNETIC_FIELD = 0x2;
74 static constexpr int TYPE_PRESSURE = 0x6;
76 // For information on these methods, see comments around analogous methods
77 // in NonGPSSensors.java.
78 const std::vector<int>& getSubscribableSensors() const {
79 return subscribable_sensors_;
81 bool subscribeToSensor(int id);
82 bool cancelSensorSubscription(int id);
83 bool subscribedToSensor(int id) const;
84 void cancelAllSensorSubscriptions();
86 gcc_malloc
87 static InternalSensors *create(JNIEnv* env, Context* native_view,
88 unsigned int index);
91 #endif