void CLCDOutput::SetDeviceFamiliesSupported(DWORD dwDeviceFamiliesSupported, DWORD dwReserved1) { m_dwDeviceFamiliesSupported = dwDeviceFamiliesSupported; m_dwDeviceFamiliesSupportedReserved1 = dwReserved1; if (LGLCD_INVALID_CONNECTION == m_hConnection) { if (ERROR_SUCCESS == lgLcdConnectEx(&m_lcdConnectCtxEx)) { // make sure we don't work with a stale device handle m_hConnection = m_lcdConnectCtxEx.connection; m_hDevice = LGLCD_INVALID_CONNECTION; } else { return; } } // close the lcd device before we open up another if (LGLCD_INVALID_DEVICE != m_hDevice) { lgLcdClose(m_hDevice); m_hDevice = LGLCD_INVALID_DEVICE; } // Setup the device family to use next time lgLcdSetDeviceFamiliesToUse(m_hConnection, m_dwDeviceFamiliesSupported, m_dwDeviceFamiliesSupportedReserved1); }
G15LCDEngineLGLCD::G15LCDEngineLGLCD() : LCDEngine() { DWORD dwErr; ZeroMemory(&llcceConnect, sizeof(llcceConnect)); ZeroMemory(&llcContext, sizeof(llcContext)); llcceConnect.appFriendlyName = G15_WIDGET_NAME; llcceConnect.isAutostartable = FALSE; llcceConnect.isPersistent = FALSE; llcceConnect.dwAppletCapabilitiesSupported =LGLCD_APPLET_CAP_BASIC | LGLCD_APPLET_CAP_BW; llcceConnect.connection = LGLCD_INVALID_CONNECTION; llcContext.device = LGLCD_INVALID_DEVICE; dwErr = lgLcdInit(); if (dwErr != ERROR_SUCCESS) { qWarning() << "LGLCD: Unable to initialize Logitech LCD library" << dwErr; return; } dwErr = lgLcdConnectEx(&llcceConnect); if (dwErr != ERROR_SUCCESS) { qWarning() << "LGLCD: Unable to connect to Logitech LCD manager" << dwErr; return; } qlDevices << new G15LCDDeviceLGLCD(this); QMetaObject::connectSlotsByName(this); }
void CLCDOutput::EnumerateDevices() { lgLcdDeviceDescEx descEx; if (LGLCD_INVALID_CONNECTION == m_hConnection) { if (ERROR_SUCCESS == lgLcdConnectEx(&m_lcdConnectCtxEx)) { // make sure we don't work with a stale device handle m_hConnection = m_lcdConnectCtxEx.connection; m_hDevice = LGLCD_INVALID_CONNECTION; } else { return; } } // close the lcd device before we open up another if (LGLCD_INVALID_DEVICE != m_hDevice) { lgLcdClose(m_hDevice); m_hDevice = LGLCD_INVALID_DEVICE; } // Setup the device family to use next time lgLcdSetDeviceFamiliesToUse(m_hConnection, m_dwDeviceFamiliesSupported, m_dwDeviceFamiliesSupportedReserved1); ZeroMemory(&descEx, sizeof(lgLcdDeviceDescEx)); DWORD res = ERROR_SUCCESS; res = lgLcdEnumerateEx(m_hConnection, 0, &descEx); if (ERROR_SUCCESS != res) { if(ERROR_NO_MORE_ITEMS != res) { // something happened. Let's close this. CloseAndDisconnect(); } return; } // ERROR_NO_MORE_ITEMS lgLcdOpenContext open_ctx; ZeroMemory(&open_ctx, sizeof(open_ctx)); open_ctx.connection = m_hConnection; open_ctx.index = 0; res = lgLcdOpen(&open_ctx); if (ERROR_SUCCESS != res) return; m_hDevice = open_ctx.device; m_dwButtonState = 0; // restores SetAsForeground(m_bSetAsForeground); }
BOOL CLCDOutput::AnyDeviceOfThisFamilyPresent(DWORD dwDeviceFamilyWanted, DWORD dwReserved1) { lgLcdDeviceDescEx descEx; if (LGLCD_INVALID_CONNECTION == m_hConnection) { if (ERROR_SUCCESS == lgLcdConnectEx(&m_lcdConnectCtxEx)) { // make sure we don't work with a stale device handle m_hConnection = m_lcdConnectCtxEx.connection; m_hDevice = LGLCD_INVALID_CONNECTION; } else { return FALSE; } } // Setup the device family to use next time lgLcdSetDeviceFamiliesToUse(m_hConnection, dwDeviceFamilyWanted, dwReserved1); ZeroMemory(&descEx, sizeof(lgLcdDeviceDescEx)); DWORD res = ERROR_SUCCESS; res = lgLcdEnumerateEx(m_hConnection, 0, &descEx); if (ERROR_SUCCESS != res) { if(ERROR_NO_MORE_ITEMS != res) { // something happened. Let's close this. CloseAndDisconnect(); return FALSE; } // Go back to the previous device family we were using lgLcdSetDeviceFamiliesToUse(m_hConnection, m_dwDeviceFamiliesSupported, m_dwDeviceFamiliesSupportedReserved1); return FALSE; } // Go back to what was being used lgLcdSetDeviceFamiliesToUse(m_hConnection, m_dwDeviceFamiliesSupported, m_dwDeviceFamiliesSupportedReserved1); return TRUE; }
//************************************************************************ // connects to the device //************************************************************************ bool CLCDConnectionLogitech::Connect(int iIndex) { DWORD rc; lgLcdOpenByTypeContext OpenContext; if (m_bConnected && (iIndex == 0 || iIndex == GetConnectedDevice()->GetIndex())) return true; if (m_hConnection == LGLCD_INVALID_CONNECTION) { rc = lgLcdConnectEx(&m_connectContext); // establish the connection if (ERROR_SUCCESS == rc) { m_hConnection = m_connectContext.connection; m_hDevice = LGLCD_INVALID_CONNECTION; TRACE(_T("CLCDConnectionLogitech: Connection to LCDManager established successfully!\n")); } else { return false; } } // check if the specified device exists m_pConnectedDevice = GetAttachedDevice(iIndex); if (m_pConnectedDevice == NULL) { iIndex = (!iIndex || iIndex == LGLCD_DEVICE_BW) ? LGLCD_DEVICE_BW : LGLCD_DEVICE_QVGA; m_pConnectedDevice = GetAttachedDevice(iIndex); if (m_pConnectedDevice == NULL) { return false; } } // close the lcd device before we open up another if (LGLCD_INVALID_DEVICE != m_hDevice) { Disconnect(); } // Now lets open the LCD. We must initialize the g_OpenContext structure. memset(&OpenContext, 0, sizeof(OpenContext)); OpenContext.connection = m_hConnection; OpenContext.deviceType = m_pConnectedDevice->GetIndex();//LGLCD_DEVICE_QVGA; OpenContext.device = LGLCD_INVALID_DEVICE; // softbutton callbacks are not needed OpenContext.onSoftbuttonsChanged.softbuttonsChangedCallback = softButtonCallback; OpenContext.onSoftbuttonsChanged.softbuttonsChangedContext = (PVOID)this; // open the lcd rc = lgLcdOpenByType(&OpenContext); // failed to open the lcd if (rc != ERROR_SUCCESS) return false; m_hDevice = OpenContext.device; // Create the pixel buffer m_lcdBitmap.hdr.Format = OpenContext.deviceType == LGLCD_DEVICE_QVGA ? LGLCD_BMP_FORMAT_QVGAx32 : LGLCD_BMP_FORMAT_160x43x1; if (m_pDrawingBuffer != NULL) { free(m_pDrawingBuffer); } m_pPixels = OpenContext.deviceType == LGLCD_DEVICE_QVGA ? m_lcdBitmap.bmp_qvga32.pixels : m_lcdBitmap.bmp_mono.pixels; m_iPixels = OpenContext.deviceType == LGLCD_DEVICE_QVGA ? sizeof(m_lcdBitmap.bmp_qvga32.pixels) : sizeof(m_lcdBitmap.bmp_mono.pixels); m_pDrawingBuffer = (PBYTE)malloc(m_iPixels); memset(m_pDrawingBuffer, 0, m_iPixels); m_iPriority = LGLCD_PRIORITY_NORMAL; m_bConnected = true; HIDInit(); m_bReconnect = true; CLCDOutputManager::GetInstance()->OnDeviceConnected(); return true; }
void LH_LgLcdCallbackThread::run() { int index, retv; lgLcdConnectContextEx connectContextEx; bw_cxt.connection = LGLCD_INVALID_CONNECTION; bw_cxt.deviceType = LGLCD_DEVICE_BW; bw_cxt.onSoftbuttonsChanged.softbuttonsChangedCallback = LH_LogitechButtonCB; bw_cxt.onSoftbuttonsChanged.softbuttonsChangedContext = this; bw_cxt.device = LGLCD_INVALID_DEVICE; qvga_cxt.connection = LGLCD_INVALID_CONNECTION; qvga_cxt.deviceType = LGLCD_DEVICE_QVGA; qvga_cxt.onSoftbuttonsChanged.softbuttonsChangedCallback = LH_LogitechButtonCB; qvga_cxt.onSoftbuttonsChanged.softbuttonsChangedContext = this; qvga_cxt.device = LGLCD_INVALID_DEVICE; while( stayAlive() ) { /* Ignore errors here to avoid spamming errors when G15 broken on not present */ if( lgLcdInit() == ERROR_SUCCESS ) { memset( &connectContextEx, 0, sizeof(connectContextEx) ); connectContextEx.appFriendlyName = appname_; connectContextEx.isPersistent = 0; connectContextEx.isAutostartable = 0; connectContextEx.onConfigure.configCallback = NULL; connectContextEx.onConfigure.configContext = NULL; connectContextEx.connection = LGLCD_INVALID_CONNECTION; connectContextEx.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW | LGLCD_APPLET_CAP_QVGA; connectContextEx.onNotify.notificationCallback = LH_LogitechCB; connectContextEx.onNotify.notifyContext = this; retv = lgLcdConnectEx( &connectContextEx ); /* Don't report file not found errors */ if( retv != -1 && retv != ERROR_FILE_NOT_FOUND && retv != ERROR_ALREADY_EXISTS && LCD_ERR( retv ) ) { QTime last_enum; last_enum.start(); online_ = true; while( stayAlive() && online_ ) { sem_.tryAcquire( 1, 100 ); if( !stayAlive() ) break; if( !render( connectContextEx.connection ) ) break; } if( bw_cxt.device != LGLCD_INVALID_DEVICE ) { lgLcdClose( bw_cxt.device ); bw_cxt.device = LGLCD_INVALID_DEVICE; } if( qvga_cxt.device != LGLCD_INVALID_DEVICE ) { lgLcdClose( qvga_cxt.device ); qvga_cxt.device = LGLCD_INVALID_DEVICE; } if( online_ ) { retv = lgLcdDisconnect(connectContextEx.connection); if( retv != ERROR_PIPE_NOT_CONNECTED ) LCD_ERR( retv ); online_ = false; } connectContextEx.connection = LGLCD_INVALID_CONNECTION; } lgLcdDeInit(); } for( index=0; stayAlive() && index<20; index ++ ) msleep(100); } return; }
int main(int argc, char *argv[]) { int dwErr; BOOL bDetect = FALSE; int i; lgLcdConnectContextEx conn; lgLcdOpenByTypeContext ctx; lgLcdBitmap160x43x1 bitmap; if (argc > 1 && (strcmp(argv[1], "/detect") == 0)) { warn("Detect mode!"); bDetect = TRUE; } else if (!(argc > 1) || (strcmp(argv[1], "/mumble") != 0)) { CFUserNotificationDisplayAlert(0, 0, NULL, NULL, NULL, CFSTR("Nothing to see here"), CFSTR("This program is run by Mumble, and should not be started separately."), CFSTR("OK"), NULL, NULL, NULL); return 0; } /* * Clear and set up initial structures. */ memset(&conn, 0, sizeof(conn)); memset(&ctx, 0, sizeof(ctx)); memset(&bitmap, 0, sizeof(bitmap)); conn.appFriendlyName = G15_WIDGET_NAME; conn.isAutostartable = FALSE; conn.isPersistent = FALSE; conn.dwAppletCapabilitiesSupported =LGLCD_APPLET_CAP_BASIC | LGLCD_APPLET_CAP_BW; conn.connection = LGLCD_INVALID_CONNECTION; /* * Initialize and connect. */ dwErr = lgLcdInit(); if (dwErr != ERROR_SUCCESS) die(G15_ERR_INIT, "Unable to initialize Logitech LCD library. (Error: %i)", dwErr); dwErr = lgLcdConnectEx(&conn); if (dwErr != ERROR_SUCCESS) die(G15_ERR_CONNECT, "Unable to connect to Logitech LCD manager. (Error: %i)", dwErr); ctx.connection = conn.connection; ctx.device = LGLCD_INVALID_DEVICE; ctx.deviceType =LGLCD_DEVICE_BW; dwErr = lgLcdOpenByType(&ctx); warn("That returned %d %d", dwErr, ERROR_SUCCESS); if (bDetect) return (dwErr != ERROR_SUCCESS); else if (dwErr != ERROR_SUCCESS) die(G15_ERR_OPEN, "Unable to open device. (Error: %i)", dwErr); /* * Diplay buffer format. */ bitmap.hdr.Format = LGLCD_BMP_FORMAT_160x43x1; /* * Main drawing loop. */ while (1) { int ret; int remain = 0; BYTE bPriority; ret = read(0, &bPriority, 1); if (ret == -1 || ret != 1) die(G15_ERR_READFILE, "Error while reading priority."); do { ret = read(0, bitmap.pixels + remain, G15_MAX_FBMEM - remain); if (ret < 1) die(G15_ERR_READFILE, "Error while reading framebuffer. %d (%s)", ret, strerror(errno)); remain += ret; } while (remain < G15_MAX_FBMEM); dwErr = lgLcdUpdateBitmap(ctx.device, (const lgLcdBitmapHeader *) &bitmap, bPriority ? LGLCD_SYNC_UPDATE(LGLCD_PRIORITY_ALERT) : LGLCD_SYNC_UPDATE(LGLCD_PRIORITY_NORMAL)); if (dwErr != ERROR_SUCCESS) warn("Unable to update bitmap for device #%i successfully. (Error: %i)", i, dwErr); } /* * Close device connections. */ dwErr = lgLcdClose(ctx.device); if (dwErr != ERROR_SUCCESS) die(G15_ERR_CLOSE, "Unable to close LCD device. (Error: %i)", dwErr); /* * Disconnect from LCD monitor. */ dwErr = lgLcdDisconnect(conn.connection); if (dwErr != ERROR_SUCCESS) die(G15_ERR_DISCONNECT, "Unable to disconnect from LCD manager. (Error: %i)", dwErr); /* * Deinitialize G15 library. */ dwErr = lgLcdDeInit(); if (dwErr != ERROR_SUCCESS) die(G15_ERR_DEINIT, "Unable to deinitialize LCD library. (Error: %i)", dwErr); warn("Terminated successfully."); return 0; }