summaryrefslogtreecommitdiff
path: root/include/input/InputDevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/input/InputDevice.h')
-rw-r--r--include/input/InputDevice.h156
1 files changed, 149 insertions, 7 deletions
diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h
index 20a17e3347..7f0324a4a8 100644
--- a/include/input/InputDevice.h
+++ b/include/input/InputDevice.h
@@ -17,8 +17,10 @@
#ifndef _LIBINPUT_INPUT_DEVICE_H
#define _LIBINPUT_INPUT_DEVICE_H
+#include <android/sensor.h>
#include <input/Input.h>
#include <input/KeyCharacterMap.h>
+#include <unordered_map>
#include <vector>
namespace android {
@@ -63,6 +65,126 @@ struct InputDeviceIdentifier {
std::string getCanonicalName() const;
};
+/* Types of input device sensors. Keep sync with core/java/android/hardware/Sensor.java */
+enum class InputDeviceSensorType : int32_t {
+ ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER,
+ MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD,
+ ORIENTATION = 3,
+ GYROSCOPE = ASENSOR_TYPE_GYROSCOPE,
+ LIGHT = ASENSOR_TYPE_LIGHT,
+ PRESSURE = ASENSOR_TYPE_PRESSURE,
+ TEMPERATURE = 7,
+ PROXIMITY = ASENSOR_TYPE_PROXIMITY,
+ GRAVITY = ASENSOR_TYPE_GRAVITY,
+ LINEAR_ACCELERATION = ASENSOR_TYPE_LINEAR_ACCELERATION,
+ ROTATION_VECTOR = ASENSOR_TYPE_ROTATION_VECTOR,
+ RELATIVE_HUMIDITY = ASENSOR_TYPE_RELATIVE_HUMIDITY,
+ AMBIENT_TEMPERATURE = ASENSOR_TYPE_AMBIENT_TEMPERATURE,
+ MAGNETIC_FIELD_UNCALIBRATED = ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
+ GAME_ROTATION_VECTOR = ASENSOR_TYPE_GAME_ROTATION_VECTOR,
+ GYROSCOPE_UNCALIBRATED = ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED,
+ SIGNIFICANT_MOTION = ASENSOR_TYPE_SIGNIFICANT_MOTION,
+};
+
+enum class InputDeviceSensorAccuracy : int32_t {
+ ACCURACY_NONE = 0,
+ ACCURACY_LOW = 1,
+ ACCURACY_MEDIUM = 2,
+ ACCURACY_HIGH = 3,
+};
+
+enum class InputDeviceSensorReportingMode : int32_t {
+ CONTINUOUS = 0,
+ ON_CHANGE = 1,
+ ONE_SHOT = 2,
+ SPECIAL_TRIGGER = 3,
+};
+
+enum class InputDeviceLightType : int32_t {
+ MONO = 0,
+ PLAYER_ID = 1,
+ RGB = 2,
+ MULTI_COLOR = 3,
+};
+
+struct InputDeviceSensorInfo {
+ explicit InputDeviceSensorInfo(std::string name, std::string vendor, int32_t version,
+ InputDeviceSensorType type, InputDeviceSensorAccuracy accuracy,
+ float maxRange, float resolution, float power, int32_t minDelay,
+ int32_t fifoReservedEventCount, int32_t fifoMaxEventCount,
+ std::string stringType, int32_t maxDelay, int32_t flags,
+ int32_t id)
+ : name(name),
+ vendor(vendor),
+ version(version),
+ type(type),
+ accuracy(accuracy),
+ maxRange(maxRange),
+ resolution(resolution),
+ power(power),
+ minDelay(minDelay),
+ fifoReservedEventCount(fifoReservedEventCount),
+ fifoMaxEventCount(fifoMaxEventCount),
+ stringType(stringType),
+ maxDelay(maxDelay),
+ flags(flags),
+ id(id) {}
+ // Name string of the sensor.
+ std::string name;
+ // Vendor string of this sensor.
+ std::string vendor;
+ // Version of the sensor's module.
+ int32_t version;
+ // Generic type of this sensor.
+ InputDeviceSensorType type;
+ // The current accuracy of sensor event.
+ InputDeviceSensorAccuracy accuracy;
+ // Maximum range of the sensor in the sensor's unit.
+ float maxRange;
+ // Resolution of the sensor in the sensor's unit.
+ float resolution;
+ // The power in mA used by this sensor while in use.
+ float power;
+ // The minimum delay allowed between two events in microsecond or zero if this sensor only
+ // returns a value when the data it's measuring changes.
+ int32_t minDelay;
+ // Number of events reserved for this sensor in the batch mode FIFO.
+ int32_t fifoReservedEventCount;
+ // Maximum number of events of this sensor that could be batched.
+ int32_t fifoMaxEventCount;
+ // The type of this sensor as a string.
+ std::string stringType;
+ // The delay between two sensor events corresponding to the lowest frequency that this sensor
+ // supports.
+ int32_t maxDelay;
+ // Sensor flags
+ int32_t flags;
+ // Sensor id, same as the input device ID it belongs to.
+ int32_t id;
+};
+
+struct InputDeviceLightInfo {
+ explicit InputDeviceLightInfo(std::string name, int32_t id, InputDeviceLightType type,
+ int32_t ordinal)
+ : name(name), id(id), type(type), ordinal(ordinal) {}
+ // Name string of the light.
+ std::string name;
+ // Light id
+ int32_t id;
+ // Type of the light.
+ InputDeviceLightType type;
+ // Ordinal of the light
+ int32_t ordinal;
+};
+
+struct InputDeviceBatteryInfo {
+ explicit InputDeviceBatteryInfo(std::string name, int32_t id) : name(name), id(id) {}
+ // Name string of the battery.
+ std::string name;
+ // Battery id
+ int32_t id;
+};
+
/*
* Describes the characteristics and capabilities of an input device.
*/
@@ -104,28 +226,41 @@ public:
void addMotionRange(int32_t axis, uint32_t source,
float min, float max, float flat, float fuzz, float resolution);
void addMotionRange(const MotionRange& range);
+ void addSensorInfo(const InputDeviceSensorInfo& info);
+ void addBatteryInfo(const InputDeviceBatteryInfo& info);
+ void addLightInfo(const InputDeviceLightInfo& info);
inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
inline int32_t getKeyboardType() const { return mKeyboardType; }
- inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
+ inline void setKeyCharacterMap(const std::shared_ptr<KeyCharacterMap> value) {
mKeyCharacterMap = value;
}
- inline sp<KeyCharacterMap> getKeyCharacterMap() const {
+ inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
return mKeyCharacterMap;
}
inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
inline bool hasVibrator() const { return mHasVibrator; }
+ inline void setHasBattery(bool hasBattery) { mHasBattery = hasBattery; }
+ inline bool hasBattery() const { return mHasBattery; }
+
inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }
+ inline void setHasSensor(bool hasSensor) { mHasSensor = hasSensor; }
+ inline bool hasSensor() const { return mHasSensor; }
+
inline const std::vector<MotionRange>& getMotionRanges() const {
return mMotionRanges;
}
+ std::vector<InputDeviceSensorInfo> getSensors();
+
+ std::vector<InputDeviceLightInfo> getLights();
+
private:
int32_t mId;
int32_t mGeneration;
@@ -136,18 +271,25 @@ private:
bool mHasMic;
uint32_t mSources;
int32_t mKeyboardType;
- sp<KeyCharacterMap> mKeyCharacterMap;
+ std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
bool mHasVibrator;
+ bool mHasBattery;
bool mHasButtonUnderPad;
+ bool mHasSensor;
std::vector<MotionRange> mMotionRanges;
+ std::unordered_map<InputDeviceSensorType, InputDeviceSensorInfo> mSensors;
+ /* Map from light ID to light info */
+ std::unordered_map<int32_t, InputDeviceLightInfo> mLights;
+ /* Map from battery ID to battery info */
+ std::unordered_map<int32_t, InputDeviceBatteryInfo> mBatteries;
};
/* Types of input device configuration files. */
-enum InputDeviceConfigurationFileType {
- INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */
- INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */
- INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
+enum class InputDeviceConfigurationFileType : int32_t {
+ CONFIGURATION = 0, /* .idc file */
+ KEY_LAYOUT = 1, /* .kl file */
+ KEY_CHARACTER_MAP = 2, /* .kcm file */
};
/*