Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b6318d3 authored by Manas Abichandani's avatar Manas Abichandani Committed by Ricardo Cerqueira
Browse files

TSLib: Changes made for using TSLib

These changes are made to make use of TSLib to calibrate events
generated from touch screen.

ts_read in tslib reads raw events written by touchscreen driver in
/dev/input/event0. ts_read then packages all the events between each
EV_SYN and sends the final calibrated values to EventHub.cpp along with
the list of events raw read. We then send each event seperately in this
list to the upper layer.

Change-Id: If529e5687620df50cf725edbaa321953df50c0a5
parent bc097e94
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@

#include <linux/input.h>

#ifdef HAVE_TSLIB
    #include "tslib-private.h"
#endif

struct pollfd;

namespace android {
@@ -150,6 +154,15 @@ private:
    bool            mOpened;
    List<String8>   mExcludedDevices;

    //tslib
#ifdef HAVE_TSLIB
    struct tsdev *mTS;
    //Keeps track of number of events sent to the upper layer
    //out of total number of events raw read by input-raw plugin
    int numOfEventsSent;
    struct ts_sample samp;
#endif

    // device ids that report particular switches.
#ifdef EV_SW
    int32_t         mSwitches[SW_MAX+1];
+6 −0
Original line number Diff line number Diff line
@@ -47,6 +47,12 @@ LOCAL_SRC_FILES+= \

endif

ifeq ($(TARGET_HAVE_TSLIB),true)
	LOCAL_CFLAGS += -DHAVE_TSLIB
	LOCAL_SHARED_LIBRARIES += libtslib
	LOCAL_C_INCLUDES += external/tslib/src
endif

LOCAL_MODULE:= libui

ifeq ($(TARGET_SIMULATOR),true)
+136 −48
Original line number Diff line number Diff line
@@ -97,6 +97,9 @@ EventHub::EventHub(void)
    , mDevicesById(0), mNumDevicesById(0)
    , mOpeningDevices(0), mClosingDevices(0)
    , mDevices(0), mFDs(0), mFDCount(0), mOpened(false)
#ifdef HAVE_TSLIB
    , mTS(), numOfEventsSent(0), samp()
#endif
{
    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
#ifdef EV_SW
@@ -326,7 +329,10 @@ bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,
    }

    while(1) {

#ifdef HAVE_TSLIB
        //Checks if we have to send any more events read by input-raw plugin.
        if(!samp.total_events) {
#endif
            // First, report any devices that had last been added/removed.
            if (mClosingDevices != NULL) {
                device_t* device = mClosingDevices;
@@ -371,8 +377,39 @@ bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,
                if(mFDs[i].revents) {
                    LOGV("revents for %d = 0x%08x", i, mFDs[i].revents);
                    if(mFDs[i].revents & POLLIN) {
#ifdef HAVE_TSLIB
                        LOGV("Inside EventHub.cpp with mFDs[i].fd=%d \n", mFDs[i].fd);
                        if (mTS != NULL) {
                            if (mFDs[i].fd != mTS->fd ) {
                                LOGV("mFDs[%d].fd = %d and mTS->fd = %d", i, mFDs[i].fd, mTS->fd);
#endif
                                res = read(mFDs[i].fd, &iev, sizeof(iev));
                    if (res == sizeof(iev)) {
#ifdef HAVE_TSLIB
                            }
                            else{
                                LOGI("mTS->fd = %d", mTS->fd);
                                LOGI("tslib: calling ts_read from eventhub\n");
                                res = ts_read(mTS, &samp, 1);

                                if (res < 0) {
                                    LOGE("[EventHub.cpp:: After Poll] Error in ts_read()\n");
                                }
                                else {
                                    numOfEventsSent = 0;
                                    samp.tsIndex = i;
                                    break;
                                }
                            }
                        }
                        else {
                            LOGE("ERROR in setup of mTS: mTS is NULL!\n");
                        }
#endif
                        if (res == sizeof(iev)
#ifdef HAVE_TSLIB
                            || ((iev.code == 0x1d || iev.code == 0x1e) && res >= 0)
#endif
                        ) {
                        LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d",
                             mDevices[i]->path.string(),
                             (int) iev.time.tv_sec, (int) iev.time.tv_usec,
@@ -412,6 +449,40 @@ bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,
            if(mFDs[0].revents & POLLIN) {
                read_notify(mFDs[0].fd);
            }
#ifdef HAVE_TSLIB
        }

        if(samp.total_events) {
            *outDeviceId = mDevices[samp.tsIndex]->id;
            *outType = samp.ev[numOfEventsSent].type;
            *outScancode = samp.ev[numOfEventsSent].code;
            if (samp.ev[numOfEventsSent].type == EV_KEY) {
                err = mDevices[samp.tsIndex]->layoutMap->map(samp.ev[numOfEventsSent].code, outKeycode, outFlags);
                if (err != 0) {
                    *outKeycode = 0;
                    *outFlags = 0;
                }
            }
            else {
                *outKeycode =  samp.ev[numOfEventsSent].code;
            }
            if(*outType == EV_ABS) {
                if(*outScancode == ABS_X)
                    *outValue = samp.x;
                if(*outScancode == ABS_Y)
                    *outValue = samp.y;
                if(*outScancode == ABS_PRESSURE)
                    *outValue = samp.pressure;
            }
            else {
                *outValue = samp.ev[numOfEventsSent].value;
                *outWhen = s2ns(iev.time.tv_sec) + us2ns(iev.time.tv_usec);
            }
            if(++numOfEventsSent == samp.total_events)
                samp.total_events = 0;
            return true;
        }
#endif
    }
}

@@ -420,9 +491,16 @@ bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,
 */
bool EventHub::openPlatformInput(void)
{
    /*
     * Open platform-specific input device(s).
     */
#ifdef HAVE_TSLIB
    mTS = (tsdev*)malloc(sizeof(struct tsdev));
    if(mTS == NULL)
    {
          LOGE("No Memory");
          return(false);
    }
    memset(mTS, 0, sizeof(struct tsdev));
#endif

    int res;

    mFDCount = 1;
@@ -664,6 +742,16 @@ int EventHub::open_device(const char *deviceName)
    } else if (test_bit(BTN_TOUCH, key_bitmask)
            && test_bit(ABS_X, abs_bitmask) && test_bit(ABS_Y, abs_bitmask)) {
        device->classes |= CLASS_TOUCHSCREEN;
#ifdef HAVE_TSLIB
                mTS->fd = fd;

                //Configure here
                LOGV("Device name = %s, fd = %d", deviceName,fd);
                LOGV("tslib: calling ts_config from eventhub\n");
                if(ts_config(mTS)) {
                    LOGE("Error in Configuring tslib. Device Name = %s \n", deviceName);
                }
#endif
    }

#ifdef EV_SW
+5 −1
Original line number Diff line number Diff line
@@ -35,7 +35,11 @@ ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
	LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
endif

ifeq ($(TARGET_HAVE_TSLIB),true)
	LOCAL_CFLAGS += -DHAVE_TSLIB
	LOCAL_C_INCLUDES += external/tslib/src
endif

LOCAL_MODULE:= libandroid_servers

include $(BUILD_SHARED_LIBRARY)