summaryrefslogtreecommitdiffstats
path: root/libs/input
diff options
context:
space:
mode:
Diffstat (limited to 'libs/input')
-rw-r--r--libs/input/Input.cpp34
-rw-r--r--libs/input/KeyLayoutMap.cpp83
-rw-r--r--libs/input/Keyboard.cpp4
3 files changed, 102 insertions, 19 deletions
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 6f53996..d9f22e9 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -158,16 +158,10 @@ 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)) {
+ if (axis < 0 || axis > 63 || !BitSet64::hasBit(bits, axis)){
return 0;
}
- uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
- return values[index];
+ return values[BitSet64::getIndexOfBit(bits, axis)];
}
status_t PointerCoords::setAxisValue(int32_t axis, float value) {
@@ -175,22 +169,23 @@ status_t PointerCoords::setAxisValue(int32_t axis, float value) {
return NAME_NOT_FOUND;
}
- uint64_t axisBit = 1LL << axis;
- uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
- if (!(bits & axisBit)) {
+ uint32_t index = BitSet64::getIndexOfBit(bits, axis);
+ if (!BitSet64::hasBit(bits, axis)) {
if (value == 0) {
return OK; // axes with value 0 do not need to be stored
}
- uint32_t count = __builtin_popcountll(bits);
+
+ uint32_t count = BitSet64::count(bits);
if (count >= MAX_AXES) {
tooManyAxes(axis);
return NO_MEMORY;
}
- bits |= axisBit;
+ BitSet64::markBit(bits, axis);
for (uint32_t i = count; i > index; i--) {
values[i] = values[i - 1];
}
}
+
values[index] = value;
return OK;
}
@@ -213,11 +208,16 @@ void PointerCoords::scale(float scaleFactor) {
scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, scaleFactor);
}
+void PointerCoords::applyOffset(float xOffset, float yOffset) {
+ setAxisValue(AMOTION_EVENT_AXIS_X, getX() + xOffset);
+ setAxisValue(AMOTION_EVENT_AXIS_Y, getY() + yOffset);
+}
+
#ifdef HAVE_ANDROID_OS
status_t PointerCoords::readFromParcel(Parcel* parcel) {
bits = parcel->readInt64();
- uint32_t count = __builtin_popcountll(bits);
+ uint32_t count = BitSet64::count(bits);
if (count > MAX_AXES) {
return BAD_VALUE;
}
@@ -231,7 +231,7 @@ status_t PointerCoords::readFromParcel(Parcel* parcel) {
status_t PointerCoords::writeToParcel(Parcel* parcel) const {
parcel->writeInt64(bits);
- uint32_t count = __builtin_popcountll(bits);
+ uint32_t count = BitSet64::count(bits);
for (uint32_t i = 0; i < count; i++) {
parcel->writeFloat(values[i]);
}
@@ -248,7 +248,7 @@ bool PointerCoords::operator==(const PointerCoords& other) const {
if (bits != other.bits) {
return false;
}
- uint32_t count = __builtin_popcountll(bits);
+ uint32_t count = BitSet64::count(bits);
for (uint32_t i = 0; i < count; i++) {
if (values[i] != other.values[i]) {
return false;
@@ -259,7 +259,7 @@ bool PointerCoords::operator==(const PointerCoords& other) const {
void PointerCoords::copyFrom(const PointerCoords& other) {
bits = other.bits;
- uint32_t count = __builtin_popcountll(bits);
+ uint32_t count = BitSet64::count(bits);
for (uint32_t i = 0; i < count; i++) {
values[i] = other.values[i];
}
diff --git a/libs/input/KeyLayoutMap.cpp b/libs/input/KeyLayoutMap.cpp
index 2f5494b..0800a31 100644
--- a/libs/input/KeyLayoutMap.cpp
+++ b/libs/input/KeyLayoutMap.cpp
@@ -150,6 +150,40 @@ status_t KeyLayoutMap::mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
return NO_ERROR;
}
+status_t KeyLayoutMap::findScanCodeForLed(int32_t ledCode, int32_t* outScanCode) const {
+ const size_t N = mLedsByScanCode.size();
+ for (size_t i = 0; i < N; i++) {
+ if (mLedsByScanCode.valueAt(i).ledCode == ledCode) {
+ *outScanCode = mLedsByScanCode.keyAt(i);
+#if DEBUG_MAPPING
+ ALOGD("findScanCodeForLed: ledCode=%d, scanCode=%d.", ledCode, *outScanCode);
+#endif
+ return NO_ERROR;
+ }
+ }
+#if DEBUG_MAPPING
+ ALOGD("findScanCodeForLed: ledCode=%d ~ Not found.", ledCode);
+#endif
+ return NAME_NOT_FOUND;
+}
+
+status_t KeyLayoutMap::findUsageCodeForLed(int32_t ledCode, int32_t* outUsageCode) const {
+ const size_t N = mLedsByUsageCode.size();
+ for (size_t i = 0; i < N; i++) {
+ if (mLedsByUsageCode.valueAt(i).ledCode == ledCode) {
+ *outUsageCode = mLedsByUsageCode.keyAt(i);
+#if DEBUG_MAPPING
+ ALOGD("findUsageForLed: ledCode=%d, usage=%x.", ledCode, *outUsageCode);
+#endif
+ return NO_ERROR;
+ }
+ }
+#if DEBUG_MAPPING
+ ALOGD("findUsageForLed: ledCode=%d ~ Not found.", ledCode);
+#endif
+ return NAME_NOT_FOUND;
+}
+
// --- KeyLayoutMap::Parser ---
@@ -179,6 +213,10 @@ status_t KeyLayoutMap::Parser::parse() {
mTokenizer->skipDelimiters(WHITESPACE);
status_t status = parseAxis();
if (status) return status;
+ } else if (keywordToken == "led") {
+ mTokenizer->skipDelimiters(WHITESPACE);
+ status_t status = parseLed();
+ if (status) return status;
} else {
ALOGE("%s: Expected keyword, got '%s'.", mTokenizer->getLocation().string(),
keywordToken.string());
@@ -215,8 +253,7 @@ status_t KeyLayoutMap::Parser::parseKey() {
mapUsage ? "usage" : "scan code", codeToken.string());
return BAD_VALUE;
}
- KeyedVector<int32_t, Key>& map =
- mapUsage ? mMap->mKeysByUsageCode : mMap->mKeysByScanCode;
+ KeyedVector<int32_t, Key>& map = mapUsage ? mMap->mKeysByUsageCode : mMap->mKeysByScanCode;
if (map.indexOfKey(code) >= 0) {
ALOGE("%s: Duplicate entry for key %s '%s'.", mTokenizer->getLocation().string(),
mapUsage ? "usage" : "scan code", codeToken.string());
@@ -364,4 +401,46 @@ status_t KeyLayoutMap::Parser::parseAxis() {
return NO_ERROR;
}
+status_t KeyLayoutMap::Parser::parseLed() {
+ String8 codeToken = mTokenizer->nextToken(WHITESPACE);
+ bool mapUsage = false;
+ if (codeToken == "usage") {
+ mapUsage = true;
+ mTokenizer->skipDelimiters(WHITESPACE);
+ codeToken = mTokenizer->nextToken(WHITESPACE);
+ }
+ char* end;
+ int32_t code = int32_t(strtol(codeToken.string(), &end, 0));
+ if (*end) {
+ ALOGE("%s: Expected led %s number, got '%s'.", mTokenizer->getLocation().string(),
+ mapUsage ? "usage" : "scan code", codeToken.string());
+ return BAD_VALUE;
+ }
+
+ KeyedVector<int32_t, Led>& map = mapUsage ? mMap->mLedsByUsageCode : mMap->mLedsByScanCode;
+ if (map.indexOfKey(code) >= 0) {
+ ALOGE("%s: Duplicate entry for led %s '%s'.", mTokenizer->getLocation().string(),
+ mapUsage ? "usage" : "scan code", codeToken.string());
+ return BAD_VALUE;
+ }
+
+ mTokenizer->skipDelimiters(WHITESPACE);
+ String8 ledCodeToken = mTokenizer->nextToken(WHITESPACE);
+ int32_t ledCode = getLedByLabel(ledCodeToken.string());
+ if (ledCode < 0) {
+ ALOGE("%s: Expected LED code label, got '%s'.", mTokenizer->getLocation().string(),
+ ledCodeToken.string());
+ return BAD_VALUE;
+ }
+
+#if DEBUG_PARSER
+ ALOGD("Parsed led %s: code=%d, ledCode=%d.",
+ mapUsage ? "usage" : "scan code", code, ledCode);
+#endif
+
+ Led led;
+ led.ledCode = ledCode;
+ map.add(code, led);
+ return NO_ERROR;
+}
};
diff --git a/libs/input/Keyboard.cpp b/libs/input/Keyboard.cpp
index b6551ee..7d4ac92 100644
--- a/libs/input/Keyboard.cpp
+++ b/libs/input/Keyboard.cpp
@@ -203,6 +203,10 @@ const char* getAxisLabel(int32_t axisId) {
return lookupLabelByValue(axisId, AXES);
}
+int32_t getLedByLabel(const char* label) {
+ return int32_t(lookupValueByLabel(label, LEDS));
+}
+
static int32_t setEphemeralMetaState(int32_t mask, bool down, int32_t oldMetaState) {
int32_t newMetaState;
if (down) {