summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2013-10-18 15:26:48 -0700
committerMichael Wright <michaelwr@google.com>2014-03-11 14:52:18 -0700
commited28fc89e3085a88c6bd8b4269988150f3eceb56 (patch)
tree75104173d5bcb047968215a419f4597a4c9bca44 /libs
parent5f0c0498a1382ef955cccca95920ec878fe2a64c (diff)
downloadframeworks_base-ed28fc89e3085a88c6bd8b4269988150f3eceb56.zip
frameworks_base-ed28fc89e3085a88c6bd8b4269988150f3eceb56.tar.gz
frameworks_base-ed28fc89e3085a88c6bd8b4269988150f3eceb56.tar.bz2
Utilize new Android LED constants. DO NOT MERGE
Also, have EventHub manage game controllers' player LEDs Change-Id: Ic7dba19ad236a3c7d1aff5d3f938bd239b98d51d
Diffstat (limited to 'libs')
-rw-r--r--libs/input/EventHub.cpp35
-rw-r--r--libs/input/EventHub.h6
-rw-r--r--libs/input/InputReader.cpp12
3 files changed, 43 insertions, 10 deletions
diff --git a/libs/input/EventHub.cpp b/libs/input/EventHub.cpp
index fc64656..0f1da51 100644
--- a/libs/input/EventHub.cpp
+++ b/libs/input/EventHub.cpp
@@ -509,8 +509,9 @@ bool EventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const {
bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device && led >= 0 && led <= LED_MAX) {
- if (test_bit(led, device->ledBitmask)) {
+ int32_t sc;
+ if (device && mapLed(device, led, &sc) == NO_ERROR) {
+ if (test_bit(sc, device->ledBitmask)) {
return true;
}
}
@@ -520,12 +521,17 @@ bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
void EventHub::setLedState(int32_t deviceId, int32_t led, bool on) {
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device && !device->isVirtual() && led >= 0 && led <= LED_MAX) {
+ setLedStateLocked(device, led, on);
+}
+
+void EventHub::setLedStateLocked(Device* device, int32_t led, bool on) {
+ int32_t sc;
+ if (device && !device->isVirtual() && mapLed(device, led, &sc) != NAME_NOT_FOUND) {
struct input_event ev;
ev.time.tv_sec = 0;
ev.time.tv_usec = 0;
ev.type = EV_LED;
- ev.code = led;
+ ev.code = sc;
ev.value = on ? 1 : 0;
ssize_t nWrite;
@@ -1239,6 +1245,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_GAMEPAD)) {
device->controllerNumber = getNextControllerNumberLocked(device);
+ setLedForController(device);
}
// Register with epoll.
@@ -1378,6 +1385,11 @@ void EventHub::releaseControllerNumberLocked(Device* device) {
mControllerNumbers.clearBit(static_cast<uint32_t>(num - 1));
}
+void EventHub::setLedForController(Device* device) {
+ for (int i = 0; i < MAX_CONTROLLER_LEDS; i++) {
+ setLedStateLocked(device, ALED_CONTROLLER_1 + i, device->controllerNumber == i + 1);
+ }
+}
bool EventHub::hasKeycodeLocked(Device* device, int keycode) const {
if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) {
@@ -1397,6 +1409,21 @@ bool EventHub::hasKeycodeLocked(Device* device, int keycode) const {
return false;
}
+status_t EventHub::mapLed(Device* device, int32_t led, int32_t* outScanCode) const {
+ if (!device->keyMap.haveKeyLayout() || !device->ledBitmask) {
+ return NAME_NOT_FOUND;
+ }
+
+ int32_t scanCode;
+ if(device->keyMap.keyLayoutMap->findScanCodeForLed(led, &scanCode) != NAME_NOT_FOUND) {
+ if(scanCode >= 0 && scanCode <= LED_MAX && test_bit(scanCode, device->ledBitmask)) {
+ *outScanCode = scanCode;
+ return NO_ERROR;
+ }
+ }
+ return NAME_NOT_FOUND;
+}
+
status_t EventHub::closeDeviceByPathLocked(const char *devicePath) {
Device* device = getDeviceByPathLocked(devicePath);
if (device) {
diff --git a/libs/input/EventHub.h b/libs/input/EventHub.h
index ae28f01..0d63849 100644
--- a/libs/input/EventHub.h
+++ b/libs/input/EventHub.h
@@ -231,6 +231,8 @@ public:
uint8_t* outFlags) const = 0;
virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
+
+ /* LED related functions expect Android LED constants, not scan codes or HID usages */
virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
@@ -393,6 +395,10 @@ private:
int32_t getNextControllerNumberLocked(Device* device);
void releaseControllerNumberLocked(Device* device);
+ void setLedForController(Device* device);
+
+ status_t mapLed(Device* device, int32_t led, int32_t* outScanCode) const;
+ void setLedStateLocked(Device* device, int32_t led, bool on);
// Protect all internal state.
mutable Mutex mLock;
diff --git a/libs/input/InputReader.cpp b/libs/input/InputReader.cpp
index b1b7c7d..d4e1a00 100644
--- a/libs/input/InputReader.cpp
+++ b/libs/input/InputReader.cpp
@@ -2197,9 +2197,9 @@ int32_t KeyboardInputMapper::getMetaState() {
}
void KeyboardInputMapper::resetLedState() {
- initializeLedState(mCapsLockLedState, LED_CAPSL);
- initializeLedState(mNumLockLedState, LED_NUML);
- initializeLedState(mScrollLockLedState, LED_SCROLLL);
+ initializeLedState(mCapsLockLedState, ALED_CAPS_LOCK);
+ initializeLedState(mNumLockLedState, ALED_NUM_LOCK);
+ initializeLedState(mScrollLockLedState, ALED_SCROLL_LOCK);
updateLedState(true);
}
@@ -2210,11 +2210,11 @@ void KeyboardInputMapper::initializeLedState(LedState& ledState, int32_t led) {
}
void KeyboardInputMapper::updateLedState(bool reset) {
- updateLedStateForModifier(mCapsLockLedState, LED_CAPSL,
+ updateLedStateForModifier(mCapsLockLedState, ALED_CAPS_LOCK,
AMETA_CAPS_LOCK_ON, reset);
- updateLedStateForModifier(mNumLockLedState, LED_NUML,
+ updateLedStateForModifier(mNumLockLedState, ALED_NUM_LOCK,
AMETA_NUM_LOCK_ON, reset);
- updateLedStateForModifier(mScrollLockLedState, LED_SCROLLL,
+ updateLedStateForModifier(mScrollLockLedState, ALED_SCROLL_LOCK,
AMETA_SCROLL_LOCK_ON, reset);
}