Пример #1
0
void printMenu()
{
	int menuLine = MENU_START_Y;

	gotoXY(PROMPT_X,PROMPT_Y);
	setColor(CYAN);
	printf("Please Enter Command: ");
	saveCursor();

	gotoXY(MENU_START_X, menuLine++);
	printf("(P)ing Sensor");

	gotoXY(MENU_START_X, menuLine++);
	printf("(L)ight LED");
	
	gotoXY(MENU_START_X, menuLine++);
	printf("(T)oggle ADC");
	
	gotoXY(MENU_START_X, menuLine++);
	printf("(R)eset ADC");

	gotoXY(MENU_START_X, menuLine++);
	printf("(G)et Voltage");

	gotoXY(MENU_START_X, menuLine++);
	printf("(D)isplay Graph");

	gotoXY(MENU_START_X, menuLine++);
	printf("(Q)uit");

	recallCursor();
}
void UndoChangeScriptCommand::undo()
{
    // Save text value and cursor position
    saveCursor();
    after = QString::fromStdString(n->getScript());

    n->setScript(before.toStdString());

    // Restore cursor to previous position
    restoreCursor(cursor_before);
}
Пример #3
0
void Screen::reset(bool clearScreen)
{
    setMode(MODE_Wrap  ); saveMode(MODE_Wrap  );  // wrap at end of margin
    resetMode(MODE_Origin); saveMode(MODE_Origin);  // position refere to [1,1]
    resetMode(MODE_Insert); saveMode(MODE_Insert);  // overstroke
    setMode(MODE_Cursor);                         // cursor visible
    resetMode(MODE_Screen);                         // screen not inverse
    resetMode(MODE_NewLine);

    _topMargin=0;
    _bottomMargin=lines-1;

    setDefaultRendition();
    saveCursor();

    if ( clearScreen )
        clear();
}
Пример #4
0
int main() {
	int width, height, cursorx, cursory, cbsize;

	init(&width, &height);				   // Graphics initialization
	cursorx = width / 2;
	cursory = height / 2;
	cbsize = (CUR_SIZ * 2) + 1;
	VGImage CursorBuffer = vgCreateImage(VG_sABGR_8888, cbsize, cbsize, VG_IMAGE_QUALITY_BETTER);

	if (mouseinit(width, height) != 0) {
		fprintf(stderr, "Unable to initialize the mouse\n");
		exit(1);
	}
	Start(width, height);				   // Start the picture
	Background(0, 0, 0);				   // Black background
	Fill(44, 77, 232, 1);				   // Big blue marble
	Circle(width / 2, 0, width);			   // The "world"
	Fill(255, 255, 255, 1);				   // White text
	TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10);	// Greetings 
	End();						   // update picture

	// MAIN LOOP
	while (left_count < 2) {			   // Loop until the left mouse button pressed & released
		// if the mouse moved...
		if (mouse.x != cursorx || mouse.y != cursory) {
			restoreCursor(CursorBuffer);
			cursorx = mouse.x;
			cursory = mouse.y;
			saveCursor(CursorBuffer, cursorx, cursory, width, height, CUR_SIZ);
			circleCursor(cursorx, cursory, width, height, CUR_SIZ);
			End();				   // update picture
		}
	}
	restoreCursor(CursorBuffer);			   // not strictly necessary as display will be closed
	vgDestroyImage(CursorBuffer);			   // tidy up memory
	finish();					   // Graphics cleanup
	exit(0);
}
Пример #5
0
/* Function: main

	Purpose: main program performs UI controls and forwards cmd
	 through function calls  

	Input:
		void 

	Returns: o if clean termnation 
*/
int main (void)
{
	char cmd;
	message msgOut;
	message msgIn;
	int i;
	int strobeHandle;
	int adcValue;
	float voltage;
	int dataPath[DATA_PATH_SIZE] = {GP_4, GP_5, GP_6, GP_7};
	pthread_t displayThread;
	pthread_mutex_init (&cGmutex, NULL);


	initiateGPIO(Strobe);
	initiateGPIOArray(dataPath, DATA_PATH_SIZE);
	strobeHandle = openGPIO(Strobe, GPIO_DIRECTION_OUT);
	writeGPIO(strobeHandle,1);
	close(strobeHandle);

	clearPAGE();
	

	while (1)
	{
		printMenu();

		cmd = getchar();

		clearInputBuffer();

		clearBelowLine(MSG_Y);

		saveCursor();



		switch (cmd)
		{
			case 'L':
			{
				
				msgOut.data = 0xD;

				sendMessage(msgOut, dataPath);

				msgIn = receiveMessage(dataPath);

				gotoXY(MSG_X,MSG_Y);
				clearLine(MSG_Y);

				printf("Message Received: %X", msgIn.data);

				gotoXY(STATUS_X,STATUS_Y);
				clearLine(STATUS_Y);
				setColor(RESET);

				if (msgIn.data == 0xE)
				{
					printf("[\033[0;32m OK \033[m]\t LED Always On");
				}
				else if (msgIn.data == 0xC)
				{
					printf("[\033[0;32m OK \033[m]\t LED Triggered By Sensor");
				}
				else
				{
					printf("[\033[0;31m Error \033[m]\t Message Acknowledgment Failed");
				}
				break;

			}
			case 'P' :
			{
				
				msgOut.data = 0x1;
				sendMessage(msgOut, dataPath);
				msgIn = receiveMessage(dataPath);

				gotoXY(MSG_X,MSG_Y);
				clearLine(MSG_Y);

				printf("Message Received: %X", msgIn.data);

				gotoXY(STATUS_X,STATUS_Y);
				clearLine(STATUS_Y);
				setColor(RESET);

				if (msgIn.data == 0xE)
				{
					printf("[\033[0;32m OK \033[m]\t Ping Successful");
				}
				else
				{
					printf("[\033[0;31m Error \033[m]\t Message Acknowledgment Failed");
				}
				break;
			}
			case 'R' :
			{
				
				msgOut.data = 0x0;
				sendMessage(msgOut, dataPath);
				msgIn = receiveMessage(dataPath);

				gotoXY(MSG_X,MSG_Y);
				clearLine(MSG_Y);

				printf("Message Received: %X", msgIn.data);

				gotoXY(STATUS_X,STATUS_Y);
				clearLine(STATUS_Y);
				setColor(RESET);

				if (msgIn.data == 0xE)
				{
					printf("[\033[0;32m OK \033[m]\t Reset Successful");
				}
				else
				{
					printf("[\033[0;31m Error \033[m]\t Message Acknowledgment Failed");
				}
				break;
			}
			case 'G' :
			{	

				adcValue = 0;
				voltage = 0;
				msgOut.data = 0x2;
				sendMessage(msgOut, dataPath);

				
				for (i = 2; i >= 0; i--)
				{
					msgIn = receiveMessage(dataPath);
					adcValue |= (msgIn.data << (i * DATA_PATH_SIZE));
					gotoXY(MSG_X,MSG_Y);
					clearLine(MSG_Y);
					printf("Message Received: %X", msgIn.data);
				}

				msgIn = receiveMessage(dataPath);

				if (msgIn.data == 0xE)
				{
					adcValue &= 0x3FF;
					voltage = (float) ((adcValue/1024.0) * 5.0); 
					setColor(YELLOW);
					gotoXY(MSG_X,MSG_Y + 1);
					printf("ADC Value: 0x%X", adcValue);
					gotoXY(MSG_X,MSG_Y + 2);
					printf("Voltage: %lf \033[u", voltage);
					gotoXY(STATUS_X,STATUS_Y);
					setColor(RESET);
					printf("[\033[0;32m OK \033[m]\t ADC Read Successful \033[u");
				}
				else
				{
					gotoXY(STATUS_X,STATUS_Y);
					clearLine(STATUS_Y);
					setColor(RESET);
					printf("[\033[0;31m Error \033[m]\t Message Acknowledgment Failed \033[u");
				}

				break;

			}
			case 'T' :
			{	
				msgOut.data = 0x3;
				sendMessage(msgOut, dataPath);
				msgIn = receiveMessage(dataPath);

				gotoXY(MSG_X,MSG_Y);
				clearLine(MSG_Y);

				printf("Message Received: %X", msgIn.data);

				gotoXY(STATUS_X,STATUS_Y);
				clearLine(STATUS_Y);
				setColor(RESET);


				if (msgIn.data == 0xE)
				{
					printf("[\033[0;32m OK \033[m]\t ADC Toggled On");
				}
				else if (msgIn.data == 0xC)
				{
					printf("[\033[0;32m OK \033[m]\t ADC Toggled Off");
				}
				

				break;
			}
			case 'D':
			{
				pthread_mutex_lock (&cGmutex);
				continueGraphing = true;
				pthread_mutex_unlock (&cGmutex);

				pthread_create(&displayThread, NULL, graphVoltage, &dataPath);


				getchar();


				pthread_mutex_lock (&cGmutex);
				continueGraphing = false;
				pthread_mutex_unlock (&cGmutex);

				pthread_join(displayThread, NULL);

				clearPAGE();

				break;
			}
			case 'Q':
			{
				gotoXY(MSG_X,MSG_Y);
				clearLine(MSG_Y);
				printf("[\033[0;32m OK \033[m]\t ThankYou For UsingLightSensor");
				unexport(Strobe);
				unexportArray(dataPath, DATA_PATH_SIZE);
				printf("\033[2J\033[0;0H\033[m");
				exit(0);
			}


		}
		recallCursor();

	}

	return (0);
}