Exemple #1
0
void SetGLFormat()
{
	PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
			PFD_TYPE_RGBA,
			SCRDEPTH,
			0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters
			16,
			0,0,PFD_MAIN_PLANE,0,0,0,0
	};
	
	// Choose the closest pixel format available
	if ( !(indexPixelFormat = ChoosePixelFormat( hdc, &pfd )) )
	{
		MessageBox(hwnd, "Failed to find pixel format", "Pixel Format Error", MB_OK);
		SysShutdown();
	}
	
	// Set the pixel format for the provided window DC
	if ( !SetPixelFormat( hdc, indexPixelFormat, &pfd ) )
	{
		MessageBox( hwnd, "Failed to Set Pixel Format", "Pixel Format Error", MB_OK );
		SysShutdown();
	}
}
Exemple #2
0
int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const struct timespec* abstime)
{
	printf("pthread_cond_timedwait\n");
	SysShutdown(0);
	while (1);
	return 0;
}
int tps6586x_power_off(void)
{
//++Charles
	printk("%s\n", __func__);
	SysShutdown();
//--
	return 0;
}
Exemple #4
0
// The event handler
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_CREATE:
	{
					  break;
	}
	case WM_DESTROY:
	{
					   SysShutdown();
					   break;
	}
	case WM_SIZE:
	{
					break;
	}
		return DefWindowProc(hwnd, msg, wparam, lparam);
	}
}
Exemple #5
0
void SysSetDisplayMode( int width, int height, int depth )
{	
	DEVMODE dmode;
	
	memset( &dmode, 0, sizeof(DEVMODE) );
	dmode.dmSize = sizeof(DEVMODE);
	dmode.dmPelsWidth = width;
	dmode.dmPelsHeight = height;
	dmode.dmBitsPerPel = depth;
	dmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
	
	// change resolution, if possible
	if ( ChangeDisplaySettings( &dmode, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
	{
		// if not... failed to change resolution

		screenmode = 0;	// this prevents SysShutdown from changing resolution back

		MessageBox( NULL, "Your system doesn't support this screen resolution", "Display Error", MB_OK );
		SysShutdown();
	}
}
Exemple #6
0
// The main loop
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
	MSG msg;

	// Create a windows class for subsequently creating windows
	WNDCLASSEX ex;
	ex.cbSize = sizeof(WNDCLASSEX);
	ex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	ex.lpfnWndProc = WinProc;
	ex.cbClsExtra = 0;
	ex.cbWndExtra = 0;
	ex.hInstance = hinstance;
	ex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	ex.hCursor = LoadCursor(NULL, IDC_ARROW);
	ex.hbrBackground = NULL;
	ex.lpszMenuName = NULL;
	ex.lpszClassName = WNDCLASSNAME;
	ex.hIconSm = NULL;

	if (!RegisterClassEx(&ex))
	{
		MessageBox(NULL, "Failed to register the windows class", "Window Reg Error", MB_OK);
		return 1;
	}

	// Create the windows
	CreateWnd(hinstance, SCRWIDTH, SCRHEIGHT, SCRDEPTH);

	// Prompt the user for a filename and directory
	OPENFILENAME ofn;       // common dialog box structure
	ZeroMemory(&ofn, sizeof(ofn));
	char szFile[260];       // buffer for file name

	HWND hwndsave;

	// create the save as window
	hwndsave = CreateWindowEx(NULL,
		WNDCLASSNAME,
		WNDNAME,
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
		100, 100,
		600, 600,
		NULL,
		NULL,
		hinstance,
		NULL);
	HANDLE hf;              // file handle

	szFile[0] = '\0';
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwndsave;
	ofn.lpstrFilter = "Text\0*.TXT\0";
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile) / sizeof(*szFile);
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = NULL;
	ofn.lpstrInitialDir = (LPSTR)NULL;
	ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
	ofn.lpstrTitle = "Specify the filename";
	ofn.lpstrDefExt = "txt";

	GetSaveFileName(&ofn);

	//Create a file to store the offset position at each point in time
	FILE *str;
	fopen_s(&str, ofn.lpstrFile, "w");

	//Set the filename for the DAQ data
	strncpy_s(syncfnamebuf, 100, ofn.lpstrFile, strlen(ofn.lpstrFile) - 4);
	strcat_s(syncfnamebuf, 100, "_SYNC.txt");
	syncfname = syncfnamebuf;

	// Print local time as a string.
	char s[30];
	size_t i;
	struct tm tim;
	time_t now;
	now = time(NULL);
	localtime_s(&tim, &now);
	i = strftime(s, 30, "%b %d, %Y; %H:%M:%S\n", &tim);
	fprintf(str, "Current date and time: %s\n", s);

	// Variables to store the treadmill update signal
	float dx0Now = 0.0f;
	float dx1Now = 0.0f;
	float dy0Now = 0.0f;
	float dy1Now = 0.0f;
	InitOffset();
	Sleep(1000);

	int cw = 1; // Move the open loop stripe in a clockwise direction
	int ccw = -1; // Move the open loop stripe in a counterclockwise direction
	int randomreset = 1;

	PFNWGLSWAPINTERVALEXTPROC       wglSwapIntervalEXT = NULL;
	PFNWGLGETSWAPINTERVALEXTPROC    wglGetSwapIntervalEXT = NULL;
	wglSwapIntervalEXT =
		(PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
	wglGetSwapIntervalEXT =
		(PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT");

	// The main loop
	while (!quit)
	{
		if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				quit = true;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}


		// Timestamp closed loop output in order to recreate later
		QueryPerformanceCounter(&li);
		float netTime = (li.QuadPart - CounterStart) / PCFreq;

		if (randomreset)
		{
			//Generate a random starting offset
			srand(time(0));
			io_mutex.lock();
			BallOffsetRot = fmod(rand(), 180) - 90;
			BallOffsetFor = 0.0f;//-dist2stripe*0.5;
			BallOffsetSide = 0.0f;
			io_mutex.unlock();
			randomreset = 0;
		}

		/////////////////////// EXPERIMENT SPECIFICS LIVE HERE /////////////////////////////
		if (netTime < 1)
		{
			closed = 1;
			olsdir = 0;
		}
		if (netTime > 1 && netTime < 0.5 * 60)
		{
			closed = 1;		
			olsdir = 0;
		}
		if (netTime > 0.5 * 60 && netTime < 4.5 * 60)
		{
			closed = 1;
			olsdir = 1;
		}
		if (netTime > 4.5 * 60 && netTime < 5 * 60)
		{
			closed = 1;
			olsdir = 0;
		}
		if (netTime > 5 * 60)
			break;
		////////////////////////////////////////////////////////////////////////////////////

		//Switch contexts and draw
		wglMakeCurrent(hdc1, hglrc);
		RenderFrame(olsdir);

		//Swapbuffers
		SwapBuffers(hdc1);

		// Note the time that's passed
		QueryPerformanceCounter(&li);
		netTime = (li.QuadPart - CounterStart) / PCFreq;

		// Pull out the relevant values
		io_mutex.lock();
		if (closed)
			BallOffsetRotNow = BallOffsetRot;
		BallOffsetForNow = BallOffsetFor;
		BallOffsetSideNow = BallOffsetSide;
		dx0Now = dx0;
		dx1Now = dx1;
		dy0Now = dy0;
		dy1Now = dy1;
		io_mutex.unlock();

		//Print the elapsed time
		fprintf(str, "Elapsed time:\t%f\t", netTime);
		//Print the offset to the log file
		fprintf(str, "Rotational Offset:\t%f\t", BallOffsetRotNow);
		fprintf(str, "Forward Offset:\t%f\t", BallOffsetForNow);
		fprintf(str, "Lateral Offset:\t%f\t", BallOffsetSideNow);
		fprintf(str, "dx0:\t%f\t", dx0Now);
		fprintf(str, "dx1:\t%f\t", dx1Now);
		fprintf(str, "dy0:\t%f\t", dy0Now);
		fprintf(str, "dy1:\t%f\t", dy1Now);
		fprintf(str, "closed:\t%d\t", closed);
		fprintf(str, "olsdir:\t%d\n", olsdir);

		if (GetAsyncKeyState(VK_ESCAPE) || (netTime > 30 * 60))
			SysShutdown();
	}
	GLShutdown();
	fclose(str);
	return msg.lParam;
}
Exemple #7
0
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd )
{
	MSG msg;
	WNDCLASSEX ex;
	int argc;
	char cmdline[512];
	const char* argv[32];
	char* tok;

	// Convert command line into C-style argc & argv.
	strcpy( cmdline, lpcmdline );
	argv[0] = "cylindrix";
	argc = 1;
	tok = strtok( cmdline, " \t" );
	while ( tok )
	{
		argv[argc++] = tok;		
		tok = strtok( 0, " \t" );
	}

	ex.cbSize = sizeof(WNDCLASSEX);
	ex.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
	ex.lpfnWndProc = WinProc;
	ex.cbClsExtra = 0;
	ex.cbWndExtra = 0;
	ex.hInstance = hinstance;
	ex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	ex.hCursor = LoadCursor(NULL, IDC_ARROW);
	ex.hbrBackground = NULL;
	ex.lpszMenuName = NULL;
	ex.lpszClassName = WNDCLASSNAME;
	ex.hIconSm = NULL;

	if ( !RegisterClassEx( &ex ) )
	{
		MessageBox( NULL, "Failed to register the window class", "Window Reg Error", MB_OK );
		return 1;
	}

	// Create the window
	CreateWnd( hinstance, screenw, screenh, SCRDEPTH, WINDOWED );

	GameInit( argc, argv );

	// The message loop
	while ( !quit )
	{
		quit = GameLoop();

		// clear keys pressed.
		memset( keysPressed, 0, 255 );

		SwapBuffers( hdc );

		if ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
		{
			if (msg.message == WM_QUIT)
				quit = TRUE;

			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
	}
	
	GameShutdown();
	SysShutdown();

	return msg.lParam;
}
Exemple #8
0
LRESULT CALLBACK WinProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
	unsigned char key;
	switch ( msg )
	{
		case WM_CREATE:
			if ( (hdc = GetDC(hwnd)) == NULL )				// get device context
			{
				MessageBox( hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK );
				SysShutdown();
				break;
			}

			SetGLFormat();					// select pixel format, needed before wglCreateContext call
			
			if ( (hglrc = wglCreateContext( hdc )) == NULL )	// create the rendering context
			{
				MessageBox( hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK );
				SysShutdown();
				break;
			}
			
			if ( wglMakeCurrent( hdc, hglrc ) == FALSE)		// make hglrc current rc
			{
				MessageBox( hwnd, "Failed to Make OpenGL Rendering Context Current", "OpenGL Rendering Context Error", MB_OK );
				SysShutdown();					
			}

			Resize( SCRWIDTH, SCRHEIGHT );

			SetVSync( 0 );  // turn off vsync.

			InitOpenGL();					// initialize OpenGL before showing the window

			ShowWindow( hwnd, SW_SHOW );	// everything went OK, show the window
			UpdateWindow( hwnd );
			break;			

		case WM_DESTROY:
			PostQuitMessage( 0 );
			break;
	
		case WM_SIZE:
			// resize the viewport after the window had been resized
			Resize( LOWORD( lparam ), HIWORD( lparam ) );
			
			screenw = LOWORD( lparam );
			screenh = HIWORD( lparam );			
			break;			

		case WM_KEYDOWN:
		case WM_SYSKEYDOWN:
			key = VirtualKeyToSysKey( wparam );
			keysDown[key] = 1;
			keysPressed[key] = 1; 
			break;			

		case WM_KEYUP:
		case WM_SYSKEYUP:
			key = VirtualKeyToSysKey( wparam );
			keysDown[key] = 0;
			break;
	}

	return DefWindowProc( hwnd, msg, wparam, lparam );
}
Exemple #9
0
int ConKeyboardThread(void *param)
{
    uint32_t ch, code;
    handle_t keyboard;
    //void *old_buffer;
    //unsigned i;

    keyboard = FsOpen(SYS_DEVICES L"/keyboard", FILE_READ);
    while (FsRead(keyboard, &ch, 0, sizeof(ch), NULL))
    {
        code = ch & ~KBD_BUCKY_ANY;
        if ((ch & KBD_BUCKY_ALT) != 0 &&
            code >= KEY_F1 && 
            code <= KEY_F12)
        {
            /*LmuxAcquire(&lmux_consoles);
            LmuxAcquire(&current->lmux);
            ConDrawCursor(current, false);

            old_buffer = current->cookie;
            current = consoles + code - KEY_F1;

            if (old_buffer != current->buffer)
                for (i = 0; i < num_consoles; i++)
                    if (consoles[i].buffer == current->buffer)
                        ConRedraw(consoles + i);

            ConDrawCursor(current, true);
            LmuxRelease(&current->lmux);
            LmuxRelease(&lmux_consoles);*/
        }
        else if (ch == (KBD_BUCKY_CTRL | KBD_BUCKY_ALT | KEY_DEL))
            SysShutdown(SHUTDOWN_REBOOT);
        else if (ch == (KBD_BUCKY_ALT | '\t') || 
            ch == (KBD_BUCKY_ALT | KBD_BUCKY_SHIFT | '\t'))
        {
            LmuxAcquire(&lmux_consoles);

            LmuxAcquire(&current->lmux);
            ConDrawCursor(current, false);
            LmuxRelease(&current->lmux);

            if (ch & KBD_BUCKY_SHIFT)
            {
                if (current - consoles - 1 < 0)
                    current = consoles + num_consoles - 1;
                else
                    current--;
            }
            else
            {
                if (current - consoles + 1 >= num_consoles)
                    current = consoles;
                else
                    current++;
            }

            LmuxAcquire(&current->lmux);
            ConDrawCursor(current, true);
            LmuxRelease(&current->lmux);

            LmuxRelease(&lmux_consoles);
        }
        else
        {
            LmuxAcquire(&lmux_consoles);
            if (current != NULL && current->client != NULL)
                FsWrite(current->client, &ch, 0, sizeof(ch), NULL);
            LmuxRelease(&lmux_consoles);
        }
    }

    _wdprintf(L"console(keyboard): FsRead failed, %s\n", _wcserror(errno));
    return errno;
}