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;
}
Пример #2
0
BOOL CLCDOutput::OpenByType(lgLcdOpenByTypeContext &OpenContext)
{
    //Close the old device if there is one
    Close();

    DWORD res = lgLcdOpenByType(&OpenContext);
    if (ERROR_SUCCESS != res)
    {
        if( res == ERROR_INVALID_PARAMETER )
        {
            LCDUITRACE( _T("Open failed: invalid parameter.\n") );
            return FALSE;
        }
        else if( res == ERROR_ALREADY_EXISTS )
        {
            LCDUITRACE( _T("Open failed: already exists.\n") );
            return FALSE;
        }
        return FALSE;
    }

    m_hDevice = OpenContext.device;
    m_dwButtonState = 0;

    // restores
    SetAsForeground(m_bSetAsForeground);

    m_OpenByTypeContext = OpenContext;

    OnOpenedDevice(m_hDevice);

    return TRUE;
}
Пример #3
0
void connectLCD()
{
	if (!notConnected) {
		//connecting to LCDmon
		lgLcdConnectContext connection;
		ZeroMemory(&connection, sizeof(connection));
		connection.appFriendlyName = L"KCV Warner Bros";
		connection.isAutostartable = FALSE;
		connection.isPersistent = FALSE;
		connection.onConfigure.configCallback = NULL;
		connection.onConfigure.configContext = NULL;
		connection.connection = LGLCD_INVALID_CONNECTION;
		notConnected = lgLcdConnect(&connection);
		//connect to a compatible device
		lgLcdOpenByTypeContext opener;
		lgLcdSoftbuttonsChangedContext buttonCB;
		buttonCB.softbuttonsChangedCallback = buttonCall;
		ZeroMemory(&opener, sizeof(opener));
		opener.connection = connection.connection;
		opener.deviceType = LGLCD_DEVICE_BW;
		opener.onSoftbuttonsChanged = buttonCB;
		lgLcdOpenByType(&opener);
		
		//opener.onSoftbuttonsChanged = buttonHandler;
	}
}
Пример #4
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;
    }
}
Пример #5
0
//************************************************************************
// 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;
}
Пример #6
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;
}