//************************************************************************
// Initializes the connection to the LCD
//************************************************************************
bool CLCDConnectionLogitech::Initialize(tstring strAppletName, bool bAutostart, bool bConfigDialog)
{

	m_strAppletName = strAppletName;
	// initialize the library
	if (lgLcdInit() != ERROR_SUCCESS)
		return false;

	memset(&m_connectContext, 0, sizeof(m_connectContext));
	m_connectContext.connection = LGLCD_INVALID_CONNECTION;

	m_connectContext.appFriendlyName = m_strAppletName.c_str();
	m_connectContext.isAutostartable = bAutostart;
	m_connectContext.isPersistent = bAutostart;
	m_connectContext.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW | LGLCD_APPLET_CAP_QVGA;
	m_connectContext.onNotify.notificationCallback = notificationCallback;
	m_connectContext.onNotify.notifyContext = (PVOID)this;

	if (bConfigDialog) {
		m_connectContext.onConfigure.configCallback = CLCDOutputManager::configDialogCallback;
	}
	else {
		m_connectContext.onConfigure.configCallback = NULL;
	}
	m_connectContext.onConfigure.configContext = NULL;

	lgLcdSetDeviceFamiliesToUse(m_connectContext.connection, LGLCD_DEVICE_FAMILY_ALL, NULL);

	return true;
}
Beispiel #2
0
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);
}
Beispiel #3
0
extern "C" LCDWRAPPER_API int initLCD(void)
{
	lcdA.hdr.Format = LGLCD_BMP_FORMAT_160x43x1;
	notConnected = lgLcdInit(); //0 if the Logitech LCD dll exists
	connectLCD();
	oldestEvent = 0;
	eventCounter = 0;
	events = new t_event[32];
	ZeroMemory(events, sizeof(events) * 32);
	return notConnected;
}
Beispiel #4
0
HRESULT CLCDOutput::Initialize(lgLcdConnectContext* pContext, BOOL bUseWindow)
{    

    UNREFERENCED_PARAMETER(bUseWindow);

    DWORD res = ERROR_SUCCESS;

    CLCDManager::Initialize();

    // initialize our screens
    LCD_MGR_LIST::iterator it = m_LCDMgrList.begin();
    while(it != m_LCDMgrList.end())
    {
        CLCDManager *pMgr = *it;
        LCDUIASSERT(NULL != pMgr);

        pMgr->Initialize();
        ++it;
    }

    // LCD Stuff
    LCDUIASSERT(lInitCount >= 0);
    if(1 == InterlockedIncrement(&lInitCount))
    {
        // need to call lgLcdInit once
        res = lgLcdInit();
        if (ERROR_SUCCESS != res)
        {
            InterlockedDecrement(&lInitCount);
            LCDUITRACE(_T("WARNING: lgLcdInit failed\n"));
            return E_FAIL;
        }
    }

    m_lcdConnectCtxEx.appFriendlyName = _T("My App");
    m_lcdConnectCtxEx.isPersistent = FALSE;
    m_lcdConnectCtxEx.isAutostartable = FALSE;
    m_lcdConnectCtxEx.connection = LGLCD_INVALID_CONNECTION;

    // Initialize the added version 3.0 API fields
    m_lcdConnectCtxEx.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BASIC;
    m_lcdConnectCtxEx.dwReserved1 = 0;
    m_lcdConnectCtxEx.onNotify.notificationCallback = NULL;
    m_lcdConnectCtxEx.onNotify.notifyContext = NULL;

    // if user passed in the context, fill it up
    if (NULL != pContext)
    {
        memcpy(&m_lcdConnectCtxEx, pContext, sizeof(lgLcdConnectContext));
    }

    return S_OK;
}
HRESULT CLCDOutput::Initialize(lgLcdConnectContext* pContext, BOOL bUseWindow)
{    

    UNREFERENCED_PARAMETER(bUseWindow);

    DWORD res = ERROR_SUCCESS;

    CLCDManager::Initialize();

    // initialize our screens
    LCD_MGR_LIST::iterator it = m_LCDMgrList.begin();
    while(it != m_LCDMgrList.end())
    {
        CLCDManager *pMgr = *it;
        LOGIASSERT(NULL != pMgr);

        pMgr->Initialize();
        ++it;
    }

    // LCD Stuff
    LOGIASSERT(lInitCount >= 0);
    if(1 == InterlockedIncrement(&lInitCount))
    {
        // need to call lgLcdInit once
        res = lgLcdInit();
        if (ERROR_SUCCESS != res)
        {
            InterlockedDecrement(&lInitCount);
            LOGITRACE(_T("WARNING: lgLcdInit failed\n"));
            return E_FAIL;
        }
    }

    
    m_lcdConnectCtx.appFriendlyName = _T("My App");
    m_lcdConnectCtx.isPersistent = FALSE;
    m_lcdConnectCtx.isAutostartable = FALSE;
    m_lcdConnectCtx.connection = LGLCD_INVALID_CONNECTION;

    // if user passed in the context, fill it up
    if (NULL != pContext)
    {
        memcpy(&m_lcdConnectCtx, pContext, sizeof(lgLcdConnectContext));
    }

    return S_OK;
}
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;
}
Beispiel #7
0
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;
}
Beispiel #8
0
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;
}