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; }
static int lcd_init (void) { DWORD ret; lgLcdOpenContext octx; HBITMAP bmp; BITMAP binfo; HDC dc; int x, y; old_pri = 0; ret = lgLcdInit (); if (ret != ERROR_SUCCESS) { if (ret == RPC_S_SERVER_UNAVAILABLE || ret == ERROR_OLD_WIN_VERSION) { write_log (_T("LCD: Logitech LCD system not detected\n")); return 0; } write_log (_T("LCD: lgLcdInit() returned %d\n"), ret); return 0; } memset (&cctx, 0, sizeof (cctx)); cctx.appFriendlyName = _T("WinUAE"); cctx.isPersistent = TRUE; cctx.isAutostartable = FALSE; ret = lgLcdConnect (&cctx); if (ret != ERROR_SUCCESS) { write_log (_T("LCD: lgLcdConnect() returned %d\n"), ret); lcd_close (); return 0; } ret = lgLcdEnumerateEx (cctx.connection, 0, &desc); if (ret != ERROR_SUCCESS) { write_log (_T("LCD: lgLcdEnumerateEx() returned %d\n"), ret); lcd_close (); return 0; } lbh = (lgLcdBitmapHeader*)xcalloc (uae_u8, sizeof (lgLcdBitmapHeader) + desc.Width * (desc.Height + 20)); lbh->Format = LGLCD_BMP_FORMAT_160x43x1; bitmap = (uae_u8*)lbh + sizeof (lgLcdBitmapHeader); origbitmap = xcalloc (uae_u8, desc.Width * desc.Height); memset (&octx, 0, sizeof (octx)); octx.connection = cctx.connection; octx.index = 0; ret = lgLcdOpen (&octx); if (ret != ERROR_SUCCESS) { write_log (_T("LCD: lgLcdOpen() returned %d\n"), ret); lcd_close (); return 0; } device = octx.device; bmp = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_LCD160X43)); dc = CreateCompatibleDC (NULL); SelectObject (dc, bmp); GetObject (bmp, sizeof (binfo), &binfo); for (y = 0; y < binfo.bmHeight; y++) { for (x = 0; x < binfo.bmWidth; x++) { bitmap[y * binfo.bmWidth + x] = GetPixel (dc, x, y) == 0 ? 0xff : 0; } } numbers = bitmap + desc.Width * desc.Height; memcpy (origbitmap, bitmap, desc.Width * desc.Height); DeleteDC (dc); write_log (_T("LCD: '%s' enabled\n"), desc.deviceDisplayName); return 1; }