示例#1
0
void CSVSortList::enumMonitor(string &szDeviceIndex)
{
    OBJECT objDevice = GetEntity(szDeviceIndex,  m_szIDCUser, m_szIDCPwd);
    if(objDevice != INVALID_VALUE)
    {
        list<string> lsMonitorID;
        list<string>::iterator lstItem;
        if (GetSubMonitorsIDByEntity(objDevice, lsMonitorID))
        {
            string szDeviceName ("");
            MAPNODE mainnode = GetEntityMainAttribNode(objDevice);
            if(mainnode != INVALID_VALUE)
                FindNodeValue(mainnode, "sv_name", szDeviceName);
            
            int nIndex = 0;
            base_param monitor;
            for(lstItem = lsMonitorID.begin(); lstItem != lsMonitorID.end(); lstItem ++)
            {
                string szMonitorId = (*lstItem).c_str();
                OBJECT objMonitor = GetMonitor(szMonitorId, m_szIDCUser, m_szIDCPwd);
                if(objMonitor != INVALID_VALUE)
                {
                    MAPNODE node = GetMonitorMainAttribNode(objMonitor);
                    if(node != INVALID_VALUE)
                    {
                        string szName (""), szIndex ("");
                        FindNodeValue(node, "sv_name", szName);
                        FindNodeValue(node, "sv_index", szIndex);
                        if(szIndex.empty())
                            nIndex = FindIndexByID(szMonitorId);
                        else
                            nIndex = atoi(szIndex.c_str());

                        monitor.szIndex = szMonitorId;
                        monitor.szName = szDeviceName + ":" + szName;
                        m_sortList[nIndex] = monitor;
                    }
                    CloseMonitor(objMonitor);
                }
            }
        }
        CloseEntity(objDevice);
    }
}
bool ConnexionClient::TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput) {
    bool bIsForeground = (nInputCode == RIM_INPUT);

    // We are not interested in keyboard or mouse data received via raw input
    if (pRawInput->header.dwType != RIM_TYPEHID) {
        return false;
    }

    if (TRACE_RIDI_DEVICENAME == 1) {
        UINT dwSize = 0;
        if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICENAME, NULL, &dwSize) == 0) {
            std::vector<wchar_t> szDeviceName(dwSize + 1);
            if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICENAME, &szDeviceName[0], &dwSize) > 0) {
                qDebug("Device Name = %s\nDevice handle = 0x%x\n", &szDeviceName[0], pRawInput->header.hDevice);
            }
        }
    }

    RID_DEVICE_INFO sRidDeviceInfo;
    sRidDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO);
    UINT cbSize = sizeof(RID_DEVICE_INFO);

    if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICEINFO, &sRidDeviceInfo, &cbSize) == cbSize) {
        if (TRACE_RIDI_DEVICEINFO == 1) {
            switch (sRidDeviceInfo.dwType) {
                case RIM_TYPEMOUSE:
                    qDebug("\tsRidDeviceInfo.dwType=RIM_TYPEMOUSE\n");
                    break;
                case RIM_TYPEKEYBOARD:
                    qDebug("\tsRidDeviceInfo.dwType=RIM_TYPEKEYBOARD\n");
                    break;
                case RIM_TYPEHID:
                    qDebug("\tsRidDeviceInfo.dwType=RIM_TYPEHID\n");
                    qDebug("\tVendor=0x%x\n\tProduct=0x%x\n\tUsagePage=0x%x\n\tUsage=0x%x\n",
                           sRidDeviceInfo.hid.dwVendorId,
                           sRidDeviceInfo.hid.dwProductId,
                           sRidDeviceInfo.hid.usUsagePage,
                           sRidDeviceInfo.hid.usUsage);
                    break;
            }
        }

        if (sRidDeviceInfo.hid.dwVendorId == LOGITECH_VENDOR_ID) {
            if (pRawInput->data.hid.bRawData[0] == 0x01) { // Translation vector
                TInputData& deviceData = fDevice2Data[pRawInput->header.hDevice];
                deviceData.fTimeToLive = kTimeToLive;
                if (bIsForeground) {
                    short* pnRawData = reinterpret_cast<short*>(&pRawInput->data.hid.bRawData[1]);
                    // Cache the pan zoom data
                    deviceData.fAxes[0] = static_cast<float>(pnRawData[0]);
                    deviceData.fAxes[1] = static_cast<float>(pnRawData[1]);
                    deviceData.fAxes[2] = static_cast<float>(pnRawData[2]);

                    //qDebug("Pan/Zoom RI Data =\t0x%x,\t0x%x,\t0x%x\n", pnRawData[0], pnRawData[1], pnRawData[2]);

                    if (pRawInput->data.hid.dwSizeHid >= 13) { // Highspeed package
                        // Cache the rotation data
                        deviceData.fAxes[3] = static_cast<float>(pnRawData[3]);
                        deviceData.fAxes[4] = static_cast<float>(pnRawData[4]);
                        deviceData.fAxes[5] = static_cast<float>(pnRawData[5]);
                        deviceData.fIsDirty = true;

                        //qDebug("Rotation RI Data =\t0x%x,\t0x%x,\t0x%x\n", pnRawData[3], pnRawData[4], pnRawData[5]);
                        return true;
                    }
                } else { // Zero out the data if the app is not in forground
                    deviceData.fAxes.assign(6, 0.f);
                }
            } else if (pRawInput->data.hid.bRawData[0] == 0x02) { // Rotation vector
                // If we are not in foreground do nothing
                // The rotation vector was zeroed out with the translation vector in the previous message
                if (bIsForeground) {
                    TInputData& deviceData = fDevice2Data[pRawInput->header.hDevice];
                    deviceData.fTimeToLive = kTimeToLive;

                    short* pnRawData = reinterpret_cast<short*>(&pRawInput->data.hid.bRawData[1]);
                    // Cache the rotation data
                    deviceData.fAxes[3] = static_cast<float>(pnRawData[0]);
                    deviceData.fAxes[4] = static_cast<float>(pnRawData[1]);
                    deviceData.fAxes[5] = static_cast<float>(pnRawData[2]);
                    deviceData.fIsDirty = true;

                    //qDebug("Rotation RI Data =\t0x%x,\t0x%x,\t0x%x\n", pnRawData[0], pnRawData[1], pnRawData[2]);

                    return true;
                }
            } else if (pRawInput->data.hid.bRawData[0] == 0x03) { // Keystate change
                // this is a package that contains 3d mouse keystate information
                // bit0=key1, bit=key2 etc.

                unsigned long dwKeystate = *reinterpret_cast<unsigned long*>(&pRawInput->data.hid.bRawData[1]);

                //qDebug("ButtonData =0x%x\n", dwKeystate);

                // Log the keystate changes
                unsigned long dwOldKeystate = fDevice2Keystate[pRawInput->header.hDevice];
                if (dwKeystate != 0) {
                    fDevice2Keystate[pRawInput->header.hDevice] = dwKeystate;
                } else {
                    fDevice2Keystate.erase(pRawInput->header.hDevice);
                }

                //  Only call the keystate change handlers if the app is in foreground
                if (bIsForeground) {
                    unsigned long dwChange = dwKeystate ^ dwOldKeystate;

                    for (int nKeycode = 1; nKeycode<33; nKeycode++) {
                        if (dwChange & 0x01) {
                            int nVirtualKeyCode = HidToVirtualKey(sRidDeviceInfo.hid.dwProductId, nKeycode);
                            if (nVirtualKeyCode) {
                                if (dwKeystate & 0x01) {
                                    On3dmouseKeyDown(pRawInput->header.hDevice, nVirtualKeyCode);
                                } else {
                                    On3dmouseKeyUp(pRawInput->header.hDevice, nVirtualKeyCode);
                                }
                            }
                        }
                        dwChange >>= 1;
                        dwKeystate >>= 1;
                    }
                }
            }
        }
    }