From 3ea4de826d95c580c28d854c677ded0d15d220a8 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Sat, 19 Feb 2011 01:08:02 -0800 Subject: Add new axes for joysticks and mouse wheels. Added API on InputDevice to query the set of axes available. Added API on KeyEvent and MotionEvent to convert keycodes and axes to symbolic name strings for diagnostic purposes. Added API on KeyEvent to query if a given key code is a gamepad button. Added a new "axis" element to key layout files to specify the mapping between raw absolute axis values and motion axis ids. Expanded the axis bitfield to 64bits to allow for future growth. Modified the Makefile for keyboard prebuilts to run the keymap validation tool during the build. Added layouts for two game controllers. Added default actions for game pad button keys. Added more tests. Fixed a bunch of bugs. Change-Id: I73f9166c3b3c5bcf4970845b58088ad467525525 --- libs/ui/Input.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'libs/ui/Input.cpp') diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp index e3107d50fd..a80320e475 100644 --- a/libs/ui/Input.cpp +++ b/libs/ui/Input.cpp @@ -250,11 +250,59 @@ void KeyEvent::initialize(const KeyEvent& from) { // --- PointerCoords --- +float PointerCoords::getAxisValue(int32_t axis) const { + if (axis < 0 || axis > 63) { + return 0; + } + + uint64_t axisBit = 1LL << axis; + if (!(bits & axisBit)) { + return 0; + } + uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); + return values[index]; +} + +status_t PointerCoords::setAxisValue(int32_t axis, float value) { + if (axis < 0 || axis > 63) { + return NAME_NOT_FOUND; + } + + uint64_t axisBit = 1LL << axis; + uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); + if (!(bits & axisBit)) { + uint32_t count = __builtin_popcountll(bits); + if (count >= MAX_AXES) { + tooManyAxes(axis); + return NO_MEMORY; + } + bits |= axisBit; + for (uint32_t i = count; i > index; i--) { + values[i] = values[i - 1]; + } + } + values[index] = value; + return OK; +} + +float* PointerCoords::editAxisValue(int32_t axis) { + if (axis < 0 || axis > 63) { + return NULL; + } + + uint64_t axisBit = 1LL << axis; + if (!(bits & axisBit)) { + return NULL; + } + uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); + return &values[index]; +} + #ifdef HAVE_ANDROID_OS status_t PointerCoords::readFromParcel(Parcel* parcel) { - bits = parcel->readInt32(); + bits = parcel->readInt64(); - uint32_t count = __builtin_popcount(bits); + uint32_t count = __builtin_popcountll(bits); if (count > MAX_AXES) { return BAD_VALUE; } @@ -266,9 +314,9 @@ status_t PointerCoords::readFromParcel(Parcel* parcel) { } status_t PointerCoords::writeToParcel(Parcel* parcel) const { - parcel->writeInt32(bits); + parcel->writeInt64(bits); - uint32_t count = __builtin_popcount(bits); + uint32_t count = __builtin_popcountll(bits); for (uint32_t i = 0; i < count; i++) { parcel->writeInt32(values[i]); } -- cgit v1.2.3-59-g8ed1b