bool LH_LgLcdCallbackThread::render( int conn )
{
    // Close open contexts no longer in use
    if( !bw_bm.hdr.Format && bw_cxt.device != LGLCD_INVALID_DEVICE )
    {
        lgLcdClose(bw_cxt.device);
        bw_cxt.device = LGLCD_INVALID_DEVICE;
    }
    if( !qvga_bm.hdr.Format && qvga_cxt.device != LGLCD_INVALID_DEVICE )
    {
        lgLcdClose(qvga_cxt.device);
        qvga_cxt.device = LGLCD_INVALID_DEVICE;
    }

    // Open context that are available and needed
    if( bw_bm.hdr.Format && bw_cxt.device == LGLCD_INVALID_DEVICE )
    {
        Q_ASSERT( bw_cxt.onSoftbuttonsChanged.softbuttonsChangedContext == this );
        bw_cxt.connection = conn;
        if( LCD_ERR( lgLcdOpenByType(&bw_cxt) ) )
            lgLcdSetAsLCDForegroundApp(bw_cxt.device,LGLCD_LCD_FOREGROUND_APP_YES);
    }
    if( qvga_bm.hdr.Format && qvga_cxt.device == LGLCD_INVALID_DEVICE )
    {
        Q_ASSERT( qvga_cxt.onSoftbuttonsChanged.softbuttonsChangedContext == this );
        qvga_cxt.connection = conn;
        if( LCD_ERR( lgLcdOpenByType(&qvga_cxt) ) )
            lgLcdSetAsLCDForegroundApp(qvga_cxt.device,LGLCD_LCD_FOREGROUND_APP_YES);
    }

    // Push bits to open devices that has images
    if( bw_cxt.device != LGLCD_INVALID_DEVICE && bw_bm.hdr.Format )
    {
        if( lgLcdUpdateBitmap( bw_cxt.device, &bw_bm.hdr, LGLCD_PRIORITY_NORMAL ) != ERROR_SUCCESS )
        {
            lgLcdClose(bw_cxt.device);
            bw_cxt.device = LGLCD_INVALID_DEVICE;
        }
    }

    if( qvga_cxt.device != LGLCD_INVALID_DEVICE && qvga_bm.hdr.Format )
    {
        if( lgLcdUpdateBitmap( qvga_cxt.device, &qvga_bm.hdr, LGLCD_PRIORITY_NORMAL ) != ERROR_SUCCESS )
        {
            lgLcdClose(qvga_cxt.device);
            qvga_cxt.device = LGLCD_INVALID_DEVICE;
        }
    }

    return true;
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
void CLCDOutput::Close(void)
{
    if( LGLCD_INVALID_DEVICE != m_hDevice )
    {
        OnClosingDevice(m_hDevice);
        lgLcdClose(m_hDevice);
        m_hDevice = LGLCD_INVALID_DEVICE;
    }
}
Esempio n. 4
0
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);
}
void CLCDOutput::OnClosingDevice(int hDevice)
{
    UNREFERENCED_PARAMETER(hDevice);
    LOGITRACE(_T("CLCDOutput::OnClosingDevice\n"));
    if (IsOpened())
    {
        lgLcdClose(m_hDevice);
        m_hDevice = LGLCD_INVALID_DEVICE;
    }
}
Esempio n. 6
0
G15LCDEngineLGLCD::~G15LCDEngineLGLCD() {
    if (llcContext.device != LGLCD_INVALID_DEVICE) {
        lgLcdClose(llcContext.device);
        llcContext.device = LGLCD_INVALID_DEVICE;
    }
    if (llcceConnect.connection != LGLCD_INVALID_CONNECTION) {
        lgLcdDisconnect(llcceConnect.connection);
        llcceConnect.connection = LGLCD_INVALID_CONNECTION;
    }
    lgLcdDeInit();
}
void CLCDOutput::EnumerateDevices()
{
    lgLcdDeviceDesc desc;

    if (LGLCD_INVALID_CONNECTION == m_hConnection)
    {
        if (ERROR_SUCCESS == lgLcdConnect(&m_lcdConnectCtx))
        {
            // make sure we don't work with a stale device handle
            m_hConnection = m_lcdConnectCtx.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;
    }
    
    ZeroMemory(&desc, sizeof(desc));
    DWORD res = ERROR_SUCCESS;
    
    res = lgLcdEnumerate(m_hConnection, 0, &desc);
    if (ERROR_SUCCESS != res)
    {
        if(ERROR_NO_MORE_ITEMS != res)
        {
            // something happened. Let's close this.
            CloseAndDisconnect();
        }
        return;
    }

    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;
}
Esempio n. 8
0
void G15LCDDeviceLGLCD::setEnabled(bool b) {
    bEnabled = b;

    if (bEnabled && (engine->llcContext.device == LGLCD_INVALID_DEVICE)) {
        ZeroMemory(&engine->llcContext, sizeof(engine->llcContext));
        engine->llcContext.connection = engine->llcceConnect.connection;
        engine->llcContext.device = LGLCD_INVALID_DEVICE;
        engine->llcContext.deviceType =LGLCD_DEVICE_BW;

        DWORD dwErr = lgLcdOpenByType(&engine->llcContext);

    } else if (! bEnabled && (engine->llcContext.device != LGLCD_INVALID_DEVICE)) {
        lgLcdClose(engine->llcContext.device);
        engine->llcContext.device = LGLCD_INVALID_DEVICE;
    }
}
//************************************************************************
// disconnects the device
//************************************************************************
bool CLCDConnectionLogitech::Disconnect() {
	if (!m_bConnected)
		return false;

	if (m_pConnectedDevice != NULL) {
		delete m_pConnectedDevice;
		m_pConnectedDevice = NULL;
	}

	m_bReconnect = false;

	HIDDeInit();
	lgLcdClose(m_hDevice);
	m_hDevice = LGLCD_INVALID_DEVICE;

	CLCDOutputManager::GetInstance()->OnDeviceDisconnected();

	m_bConnected = false;
	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;
}
Esempio n. 11
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;
}