Utilize new Android LED constants. DO NOT MERGE

Also, have EventHub manage game controllers' player LEDs

Change-Id: Ic7dba19ad236a3c7d1aff5d3f938bd239b98d51d
This commit is contained in:
Michael Wright
2013-10-18 15:26:48 -07:00
parent 5f0c0498a1
commit ed28fc89e3
4 changed files with 56 additions and 10 deletions

View File

@@ -423,3 +423,16 @@ axis 0x09 GAS
axis 0x0a BRAKE
axis 0x10 HAT_X
axis 0x11 HAT_Y
# LEDs
led 0x00 NUM_LOCK
led 0x01 CAPS_LOCK
led 0x02 SCROLL_LOCK
led 0x03 COMPOSE
led 0x04 KANA
led 0x05 SLEEP
led 0x06 SUSPEND
led 0x07 MUTE
led 0x08 MISC
led 0x09 MAIL
led 0x0a CHARGING

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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);
}