Ticket #8338: touchscreen.diff

File touchscreen.diff, 9.1 KB (added by X512, 12 years ago)

My hacks on driver. It enables touchscreen and tries to introduce multitouch. WARNING! This is experimental modifications and not a patch for fixing this ticket.

  • headers/os/drivers/usb/USB_hid_page_digitizers.h

    diff --git a/headers/os/drivers/usb/USB_hid_page_digitizers.h b/headers/os/drivers/usb/USB_hid_page_digitizers.h
    index 1bfc9ba..66460a8 100644
    a b enum {  
    5454    B_HID_UID_DIG_SECONDARY_TIP_SWITCH,
    5555    B_HID_UID_DIG_BARREL_SWITCH,
    5656    B_HID_UID_DIG_ERASER,
    57     B_HID_UID_DIG_TABLET_PICK
     57    B_HID_UID_DIG_TABLET_PICK,
     58    B_HID_UID_DIG_CONFIDENCE,
     59    B_HID_UID_DIG_CONTACT_IDENTIFIER = 0x51,
    5860};
    5961
    6062
  • headers/private/input/keyboard_mouse_driver.h

    diff --git a/headers/private/input/keyboard_mouse_driver.h b/headers/private/input/keyboard_mouse_driver.h
    index 99306fd..5eab743 100644
    a b typedef struct {  
    111111    int32       wheel_xdelta;
    112112    float       tilt_x;
    113113    float       tilt_y;
     114    uint32      contact_id;
    114115} tablet_movement;
    115116
    116117
  • src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp

    diff --git a/src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp b/src/add-ons/input_server/devices/tablet/TabletInputDevice.cpp
    index 283231a..2e20997 100644
    a b  
    3333
    3434
    3535#undef TRACE
    36 //#define TRACE_TABLET_DEVICE
     36// #define TRACE_TABLET_DEVICE
    3737#ifdef TRACE_TABLET_DEVICE
    3838
    3939    class FunctionTracer {
    TabletDevice::_ControlThread()  
    289289    }
    290290
    291291    _UpdateSettings();
    292 
     292   
     293    struct {
     294        uint32 buttons;
     295        float xpos, ypos;
     296    } trackingState[4];
     297    memset(&trackingState, 0, sizeof(trackingState));
     298   
    293299    static const bigtime_t kTransferDelay = 1000000 / 125;
    294300        // 125 transfers per second should be more than enough
    295301    bigtime_t nextTransferTime = system_time() + kTransferDelay;
    296     uint32 lastButtons = 0;
    297     float lastXPosition = 0;
    298     float lastYPosition = 0;
    299302
    300303    while (fActive) {
    301304        tablet_movement movements;
    TabletDevice::_ControlThread()  
    309312            return;
    310313        }
    311314
     315        if (movements.contact_id >= 4)
     316            continue;
     317
    312318        // take care of updating the settings first, if necessary
    313319        if (fUpdateSettings) {
    314320            fUpdateSettings = false;
    TabletDevice::_ControlThread()  
    324330
    325331        // Send single messages for each event
    326332
    327         uint32 buttons = lastButtons ^ movements.buttons;
     333        if (movements.xpos != trackingState[movements.contact_id].xpos
     334            || movements.ypos != trackingState[movements.contact_id].ypos) {
     335            BMessage* message = _BuildMouseMessage(B_MOUSE_MOVED,
     336                movements.timestamp, trackingState[movements.contact_id].buttons, movements.xpos,
     337                movements.ypos);
     338            if (message != NULL) {
     339                message->AddFloat("be:tablet_x", movements.xpos);
     340                message->AddFloat("be:tablet_y", movements.ypos);
     341                message->AddFloat("be:tablet_pressure", movements.pressure);
     342                message->AddInt32("be:tablet_eraser", movements.eraser);
     343                if (movements.tilt_x != 0.0 || movements.tilt_y != 0.0) {
     344                    message->AddFloat("be:tablet_tilt_x", movements.tilt_x);
     345                    message->AddFloat("be:tablet_tilt_y", movements.tilt_y);
     346                }
     347               
     348                if (movements.contact_id != 0)
     349                    message->AddInt32("be:tablet_contact_id", movements.contact_id);
     350
     351                fTarget.EnqueueMessage(message);
     352                trackingState[movements.contact_id].xpos = movements.xpos;
     353                trackingState[movements.contact_id].ypos = movements.ypos;
     354            }
     355        }
     356
     357        uint32 buttons = trackingState[movements.contact_id].buttons ^ movements.buttons;
    328358        if (buttons != 0) {
    329359            bool pressedButton = (buttons & movements.buttons) > 0;
    330360            BMessage* message = _BuildMouseMessage(
    TabletDevice::_ControlThread()  
    339369                    LOG_EVENT("B_MOUSE_UP\n");
    340370
    341371                fTarget.EnqueueMessage(message);
    342                 lastButtons = movements.buttons;
    343             }
    344         }
    345 
    346         if (movements.xpos != lastXPosition
    347             || movements.ypos != lastYPosition) {
    348             BMessage* message = _BuildMouseMessage(B_MOUSE_MOVED,
    349                 movements.timestamp, movements.buttons, movements.xpos,
    350                 movements.ypos);
    351             if (message != NULL) {
    352                 message->AddFloat("be:tablet_x", movements.xpos);
    353                 message->AddFloat("be:tablet_y", movements.ypos);
    354                 message->AddFloat("be:tablet_pressure", movements.pressure);
    355                 message->AddInt32("be:tablet_eraser", movements.eraser);
    356                 if (movements.tilt_x != 0.0 || movements.tilt_y != 0.0) {
    357                     message->AddFloat("be:tablet_tilt_x", movements.tilt_x);
    358                     message->AddFloat("be:tablet_tilt_y", movements.tilt_y);
    359                 }
    360 
    361                 fTarget.EnqueueMessage(message);
    362                 lastXPosition = movements.xpos;
    363                 lastYPosition = movements.ypos;
     372                trackingState[movements.contact_id].buttons = movements.buttons;
    364373            }
    365374        }
    366375
  • src/add-ons/kernel/drivers/input/usb_hid/Driver.h

    diff --git a/src/add-ons/kernel/drivers/input/usb_hid/Driver.h b/src/add-ons/kernel/drivers/input/usb_hid/Driver.h
    index 3b7528e..e857d3c 100644
    a b const char ** publish_devices();  
    3434device_hooks *  find_device(const char *name);
    3535}
    3636
    37 #define TRACE(x...)         /*dprintf(DRIVER_NAME ": " x)*/
     37#define TRACE(x...)         // dprintf(DRIVER_NAME ": " x)
    3838#define TRACE_ALWAYS(x...)  dprintf(DRIVER_NAME ": " x)
    3939
    4040#endif //_USB_HID_DRIVER_H_
  • src/add-ons/kernel/drivers/input/usb_hid/MouseProtocolHandler.cpp

    diff --git a/src/add-ons/kernel/drivers/input/usb_hid/MouseProtocolHandler.cpp b/src/add-ons/kernel/drivers/input/usb_hid/MouseProtocolHandler.cpp
    index 0ba0680..c9238e8 100644
    a b MouseProtocolHandler::MouseProtocolHandler(HIDReport &report, bool tablet,  
    5353
    5454    fWheel = report.FindItem(B_HID_USAGE_PAGE_GENERIC_DESKTOP,
    5555        B_HID_UID_GD_WHEEL);
     56   
     57    fTipSwitch = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER,
     58        B_HID_UID_DIG_TIP_SWITCH);
    5659
     60    fInRange = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER,
     61        B_HID_UID_DIG_IN_RANGE);
     62
     63    fContactId = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER,
     64        B_HID_UID_DIG_CONTACT_IDENTIFIER);
     65
     66    fConfidence = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER,
     67        B_HID_UID_DIG_CONFIDENCE);
     68   
    5769    TRACE("mouse device with %lu buttons and %swheel\n", buttonCount,
    5870        fWheel == NULL ? "no " : "");
    5971    TRACE("report id: %u\n", report.ID());
    MouseProtocolHandler::AddHandlers(HIDDevice &device, HIDCollection &collection,  
    127139
    128140        if (!xAxis->Relative() && !yAxis->Relative())
    129141            tablet = true;
    130 
     142       
     143        /* W500 hack */
     144        if (tablet && (inputReport->ID() != 4))
     145            continue;
     146       
    131147        ProtocolHandler *newHandler = new(std::nothrow) MouseProtocolHandler(
    132148            *inputReport, tablet, *xAxis, *yAxis);
    133149        if (newHandler == NULL) {
    MouseProtocolHandler::_ReadReport(void *buffer)  
    223239        wheelData = fWheel->Data();
    224240
    225241    uint32 buttons = 0;
    226     for (uint32 i = 0; i < B_MAX_MOUSE_BUTTONS; i++) {
    227         HIDReportItem *button = fButtons[i];
    228         if (button == NULL)
    229             break;
     242    uint32 tipSwitchData, inRangeData, contactIdData, confidenceData;
    230243
    231         if (button->Extract() == B_OK && button->Valid())
    232             buttons |= (button->Data() & 1) << (button->UsageID() - 1);
     244    if (fTablet) {
     245        if (fTipSwitch != NULL && fTipSwitch->Extract() == B_OK && fTipSwitch->Valid())
     246            tipSwitchData = fTipSwitch->Data();
     247           
     248        if (fInRange != NULL && fInRange->Extract() == B_OK && fInRange->Valid())
     249            inRangeData = fInRange->Data();
     250       
     251        if (fContactId != NULL && fContactId->Extract() == B_OK && fContactId->Valid())
     252            contactIdData = fContactId->Data();
     253
     254        if (fConfidence != NULL && fConfidence->Extract() == B_OK && fConfidence->Valid())
     255            confidenceData = fConfidence->Data();
     256       
     257        TRACE("tipSwitch = %ld, inRange = %ld, contactId = %ld, confidence = %ld\n", tipSwitchData, inRangeData, contactIdData, confidenceData);
     258       
     259        if (tipSwitchData != 0)
     260            buttons = 1;
     261        else
     262            buttons = 0;
     263       
     264    } else {
     265        for (uint32 i = 0; i < B_MAX_MOUSE_BUTTONS; i++) {
     266            HIDReportItem *button = fButtons[i];
     267            if (button == NULL)
     268                break;
     269   
     270            if (button->Extract() == B_OK && button->Valid())
     271                buttons |= (button->Data() & 1) << (button->UsageID() - 1);
     272        }
    233273    }
    234 
     274   
     275   
    235276    fReport.DoneProcessing();
    236277    TRACE("got mouse report\n");
    237278
    MouseProtocolHandler::_ReadReport(void *buffer)  
    257298
    258299        info->xpos = axisAbsoluteData[0];
    259300        info->ypos = axisAbsoluteData[1];
    260         info->has_contact = true;
     301        info->has_contact = buttons & 0x1;
    261302        info->pressure = 1.0;
    262303        info->eraser = false;
    263304        info->tilt_x = 0.0;
    MouseProtocolHandler::_ReadReport(void *buffer)  
    267308        info->clicks = clicks;
    268309        info->timestamp = timestamp;
    269310        info->wheel_ydelta = -wheelData;
     311       
     312        info->contact_id = contactIdData;
    270313    } else {
    271314        mouse_movement *info = (mouse_movement *)buffer;
    272315        memset(info, 0, sizeof(mouse_movement));
  • src/add-ons/kernel/drivers/input/usb_hid/MouseProtocolHandler.h

    diff --git a/src/add-ons/kernel/drivers/input/usb_hid/MouseProtocolHandler.h b/src/add-ons/kernel/drivers/input/usb_hid/MouseProtocolHandler.h
    index ec6121b..b14665e 100644
    a b private:  
    4343            HIDReportItem &     fYAxis;
    4444            HIDReportItem *     fWheel;
    4545            HIDReportItem *     fButtons[B_MAX_MOUSE_BUTTONS];
     46            HIDReportItem *     fTipSwitch;
     47            HIDReportItem *     fInRange;
     48            HIDReportItem *     fContactId;
     49            HIDReportItem *     fConfidence;
    4650
    4751            uint32              fLastButtons;
    4852            uint32              fClickCount;