diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-03-04 13:07:49 -0800 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2011-03-04 19:12:41 -0800 |
commit | 8529745b27877d98a0c76692295a3fcac238b1e6 (patch) | |
tree | 0327e434025461d9ed376ef6982855fd7f1e5a35 /libs | |
parent | 54bb98698a3550250b332b2f4d756b1a5c7473f5 (diff) | |
download | frameworks_base-8529745b27877d98a0c76692295a3fcac238b1e6.zip frameworks_base-8529745b27877d98a0c76692295a3fcac238b1e6.tar.gz frameworks_base-8529745b27877d98a0c76692295a3fcac238b1e6.tar.bz2 |
Joystick tweaks. (DO NOT MERGE)
Ensure that the joystick can always reach -1.0, 0.0 and 1.0 positions
even when noise filtering is applied. (Bug: 3514510)
Add support for a few more standard axes.
Add additional mapping modes for axes.
Some axes are inverted from standard interpretation
or are actually intended to be split into two distict axes
such as left/right trigger controls or accelerator/brake.
Add key layout file for a G25 racing wheel and XBox 360 controller
to tweak behavior. They work fine without them but the axis mappings
are not ideal.
Change-Id: I0fddd90309af4dc14d35f34fe99ed6e521c0b7c7
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ui/KeyLayoutMap.cpp | 97 |
1 files changed, 85 insertions, 12 deletions
diff --git a/libs/ui/KeyLayoutMap.cpp b/libs/ui/KeyLayoutMap.cpp index 2ed0e66..8626a03 100644 --- a/libs/ui/KeyLayoutMap.cpp +++ b/libs/ui/KeyLayoutMap.cpp @@ -113,20 +113,23 @@ status_t KeyLayoutMap::findScanCodesForKey(int32_t keyCode, Vector<int32_t>* out return NO_ERROR; } -status_t KeyLayoutMap::mapAxis(int32_t scanCode, int32_t* axis) const { +status_t KeyLayoutMap::mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const { ssize_t index = mAxes.indexOfKey(scanCode); if (index < 0) { #if DEBUG_MAPPING LOGD("mapAxis: scanCode=%d ~ Failed.", scanCode); #endif - *axis = -1; return NAME_NOT_FOUND; } - *axis = mAxes.valueAt(index); + *outAxisInfo = mAxes.valueAt(index); #if DEBUG_MAPPING - LOGD("mapAxis: scanCode=%d ~ Result axis=%d.", scanCode, *axis); + LOGD("mapAxis: scanCode=%d ~ Result mode=%d, axis=%d, highAxis=%d, " + "splitValue=%d, flatOverride=%d.", + scanCode, + outAxisInfo->mode, outAxisInfo->axis, outAxisInfo->highAxis, + outAxisInfo->splitValue, outAxisInfo->flatOverride); #endif return NO_ERROR; } @@ -249,19 +252,89 @@ status_t KeyLayoutMap::Parser::parseAxis() { return BAD_VALUE; } + AxisInfo axisInfo; + mTokenizer->skipDelimiters(WHITESPACE); - String8 axisToken = mTokenizer->nextToken(WHITESPACE); - int32_t axis = getAxisByLabel(axisToken.string()); - if (axis < 0) { - LOGE("%s: Expected axis label, got '%s'.", mTokenizer->getLocation().string(), - axisToken.string()); - return BAD_VALUE; + String8 token = mTokenizer->nextToken(WHITESPACE); + if (token == "invert") { + axisInfo.mode = AxisInfo::MODE_INVERT; + + mTokenizer->skipDelimiters(WHITESPACE); + String8 axisToken = mTokenizer->nextToken(WHITESPACE); + axisInfo.axis = getAxisByLabel(axisToken.string()); + if (axisInfo.axis < 0) { + LOGE("%s: Expected inverted axis label, got '%s'.", + mTokenizer->getLocation().string(), axisToken.string()); + return BAD_VALUE; + } + } else if (token == "split") { + axisInfo.mode = AxisInfo::MODE_SPLIT; + + mTokenizer->skipDelimiters(WHITESPACE); + String8 splitToken = mTokenizer->nextToken(WHITESPACE); + axisInfo.splitValue = int32_t(strtol(splitToken.string(), &end, 0)); + if (*end) { + LOGE("%s: Expected split value, got '%s'.", + mTokenizer->getLocation().string(), splitToken.string()); + return BAD_VALUE; + } + + mTokenizer->skipDelimiters(WHITESPACE); + String8 lowAxisToken = mTokenizer->nextToken(WHITESPACE); + axisInfo.axis = getAxisByLabel(lowAxisToken.string()); + if (axisInfo.axis < 0) { + LOGE("%s: Expected low axis label, got '%s'.", + mTokenizer->getLocation().string(), lowAxisToken.string()); + return BAD_VALUE; + } + + mTokenizer->skipDelimiters(WHITESPACE); + String8 highAxisToken = mTokenizer->nextToken(WHITESPACE); + axisInfo.highAxis = getAxisByLabel(highAxisToken.string()); + if (axisInfo.highAxis < 0) { + LOGE("%s: Expected high axis label, got '%s'.", + mTokenizer->getLocation().string(), highAxisToken.string()); + return BAD_VALUE; + } + } else { + axisInfo.axis = getAxisByLabel(token.string()); + if (axisInfo.axis < 0) { + LOGE("%s: Expected axis label, 'split' or 'invert', got '%s'.", + mTokenizer->getLocation().string(), token.string()); + return BAD_VALUE; + } + } + + for (;;) { + mTokenizer->skipDelimiters(WHITESPACE); + if (mTokenizer->isEol()) { + break; + } + String8 keywordToken = mTokenizer->nextToken(WHITESPACE); + if (keywordToken == "flat") { + mTokenizer->skipDelimiters(WHITESPACE); + String8 flatToken = mTokenizer->nextToken(WHITESPACE); + axisInfo.flatOverride = int32_t(strtol(flatToken.string(), &end, 0)); + if (*end) { + LOGE("%s: Expected flat value, got '%s'.", + mTokenizer->getLocation().string(), flatToken.string()); + return BAD_VALUE; + } + } else { + LOGE("%s: Expected keyword 'flat', got '%s'.", + mTokenizer->getLocation().string(), keywordToken.string()); + return BAD_VALUE; + } } #if DEBUG_PARSER - LOGD("Parsed axis: scanCode=%d, axis=%d.", scanCode, axis); + LOGD("Parsed axis: scanCode=%d, mode=%d, axis=%d, highAxis=%d, " + "splitValue=%d, flatOverride=%d.", + scanCode, + axisInfo.mode, axisInfo.axis, axisInfo.highAxis, + axisInfo.splitValue, axisInfo.flatOverride); #endif - mMap->mAxes.add(scanCode, axis); + mMap->mAxes.add(scanCode, axisInfo); return NO_ERROR; } |