예제 #1
0
파일: Pixel_Demo.c 프로젝트: ruffsl/ECE425
// ============================ CBOT_main =================================== //
void CBOT_main(void) {
	unsigned char sensors;

	// Initialize.
	init_bot();

	// Clear the screen.
	LCD_clear();

	printMainMenu();
	while (1) {
        // Delay a little so that the 'Tiny is not overwhelmed with requests.
        TMRSRVC_delay( 100 ); // Wait 100ms.

        // Get state of all sensors.
        sensors = ATTINY_get_sensors();
        if ( sensors & SNSR_SW3_EDGE ) {
                SPKR_play_tone( SPKR_FREQ( 293.7 ), 250, 80 );
                all_pixel_test();
                printMainMenu();
        } else if ( sensors & SNSR_SW4_EDGE ) {
                SPKR_play_tone( SPKR_FREQ( 440 ), 250, 80 );
                pixel_sensor_test();
                printMainMenu();
        } else if ( sensors & SNSR_SW5_EDGE ) {
                SPKR_play_tone( SPKR_FREQ( 659.3 ), 250, 80 );
				draw_smiley();
                printMainMenu();
        }
	}
}
//========PUBLIC FUNCTIONS==========
void Interface::start()
{
    char ch = ' ';

    while(ch != 'q')
    {
        checkRelation();

        printMainMenu();
        setStatus(""); //reset status message

        cout << "Choice: ";
        cin >> ch;
        switch(ch)
        {
        case 'a':
            about();
            break;
        case 's':
            enterTheMatrixQuestion();
            break;
        case '1':
            addCompOrPerson();
            break;
        case '2':
            viewCompsOrPersons();
            break;
        case '3':
            settingsMain();
            break;
        default:
            break;
        }
    }
}
예제 #3
0
// toggles between the display states On/Off
void SabreController::toggleDisplay()
{
	
	if (this->NoDisplay)
	{
		switch (GUI_State)
		{
			case HomeScreen:
			printHomeScreen(this->SelectedInput, this->sabreDAC.Attenuation);
			break;
			case InputSettingsMenu:
			printInputSettingsMenu(SelectedInput);
			break;
			case MainMenu:
			printMainMenu();
			break;
			default:
			/* Your code here */
			break;
		}
		this->NoDisplay = false;
	}
	else
	{
		OLED.clear();
		this->NoDisplay = true;
	}
}
예제 #4
0
파일: full_shop.c 프로젝트: hronos/AC21008
int main()
{

    char choice;
    initProducts();

    do
    {
        choice = printMainMenu();
    }while(choice != 3);

    return 0;
}
예제 #5
0
void mainMenu(){
    /* Prints main menu screen and gets user choice */
    int userOption; /* Stores user chosen menu option */
    
    /* Initial message */
    system("clear");
    printf("Bem vindo ao jogo: Batalha Naval\n\n[Pressione ENTER para ir ao menu principal]\n");
    getchar(); /* Waits for ENTER keypress */
    
    /* Menu Loop */
    do{
        printMainMenu(); /* Prints menu options */
        scanf("%i", &userOption); /* Listens to user input */
        switch(userOption){  /* Executes input */
            case 1:
                startGame();
                break;

            case 2:
                configureGame();
                break;

            case 3:
                getRanking();
                break;

            case 0:
                break;

            default:
                printf("Por favor escolha uma entrada valida!\n");
                printf("\n[Pressione ENTER para continuar]");
                getchar();
                getchar();
        }
    
    
    }while(userOption != 0);
        
    return;
}
예제 #6
0
파일: PMS.c 프로젝트: pavitarsidhu/C
int main(int argc, char *arg[]) {

	int originalPid = getpid(); 
	
	//Must be set once to ensure random generator function works properly
	srand (time(NULL));

	if(argc < 2) {
		printf("Please provide the number of processes you would like to start.\n");
	} else {
	
		//initiate number of wanted processes
		numberOfProcesses = atoi(arg[1]);
		ProGen();
		
		//Only the main process will provide the user with a PMS menu
		if((int)getpid() == originalPid) {
		
		//Initiates an array with all children descendants of parent
		int arraySize = numberOfProcesses + 5; 
		int runningProcesses[arraySize]; 
		
		int counter = 0; 
		int i; 
		for(i = 0; i<numberOfProcesses; i++) {
			runningProcesses[i] = (int)getpid() + i + 1;
			counter++; 
		}
		runningProcesses[counter] = -999;
		
		printMainMenu(runningProcesses);	
		} else {
		/*All children except the root are put in an endless while loop in order
		to ensure that they continue to execute throughout the program. */
			while(1); 
		}
	}		
	return 0; 
}
예제 #7
0
void nextPage(GlobalState* globalData, int cursorPos) {
    // Beep off
    TRISBbits.RB5 = 1;

    switch (cursorPos) {
        // Send a 0 to go to main menu
        case 0:
            globalData->displayPage = 0;
            printMainMenu(globalData);
            break;
        // Getting a position of 1 does singleplayer
        case 1:
            globalData->displayPage = 1;
            // Print singleplayer menu
            clean(BLACK);
            prints(0, 0, WHITE, BLACK, "Nothing here. Press B to go back.", 1);
            break;
        // Getting a position of 2 does multiplayer
        case 2:
            globalData->displayPage = 2;
            // Print multiplayer menu
            clean(WHITE);
            prints(0, 0, BLACK, WHITE, "Nothing here. Press B to go back.", 1);
            break;
        // Getting a position of 3 does build cards
        case 3:
            globalData->displayPage = 3;
            // Print build cards menu
            printBuildCard1(globalData);
            break;
        // Error
        default:
            // BSOD
            clean(BLUE);
            globalData->keyFlag = TRUE;
            globalData->displayedKey = FALSE;
            globalData->displayPage = 255;
    }
}
예제 #8
0
void main() {
    int i = 0;
    int j = 0;
    char test[2] = {'2', '\0'};

    systemSetup(&globalData);

#if FRONT_NOT_BACK
    TRISAbits.RA0 = 0;
    ANSELAbits.ANSA0 = 0;

    printMainMenu(&globalData);
#else
    //    TRISDbits.RD4 = 0;
    //    ANSELDbits.ANSD4 = 0;
    //    PORTDbits.RD4 = 1;
#endif



    while (1) {
#if FRONT_NOT_BACK


        // get the updated cards
        if (globalData.runGetUpdatedCards == 1) {
            getUpdatedCards();
            globalData.runGetUpdatedCards = FALSE;
        }
#else
        // move the reader -- if we had one -- to the proper location


        /*
         * run LED driver
         */
        if (globalData.updateLEDFlag) {
            globalData.updateLEDFlag = FALSE;
            updateLEDs();
        }
#endif

        // process pending i2c tasks
        if (globalData.sendI2C == 1) {
            sendBytes(i2cData.dataOut, i2cData.outLength);
            globalData.sendI2C = FALSE;
        }
        if (globalData.gotI2C == 1) {
            processI2C();
            globalData.gotI2C = 0;
        }

#if FRONT_NOT_BACK
        if (!globalData.keyFlag) {
            // Check keystroke
            keypad(&globalData);
        }

        if (globalData.keyFlag && !globalData.displayedKey || globalData.myRequestStatus != 0) {
            globalData.keyFlag = FALSE;
            globalData.displayedKey = TRUE;

            switch (globalData.displayPage) {
                case 0: // main menu
                    processPrintCursor(&globalData, 3, BLUE, WHITE);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to singleplayer
                                globalData.displayPage = 1;
                                printSelectGame(&globalData);
                                break;
                            case 1: // multi
                                globalData.displayPage = 2;
                                printSelectGame(&globalData);
                                break;
                            case 2: // build
                                globalData.displayPage = 3;
                                printBuild(&globalData);
                                break;
                            case 0xFF: // back
                                globalData.displayPage = 0;
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                    }
                    break;
                case 1: // display sp game menu
                    processPrintCursor(&globalData, 4, GREEN, BLACK);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to monster game
                                globalData.displayPage = 4;
                                singlePlayer(&globalData);
                                break;
                            case 1: // go to clue
                                globalData.displayPage = 5;
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                break;
                            case 2: // go to error
                                globalData.displayPage = 6;
                                printBSOD();
                                break;
                            case 3: // go to error
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                globalData.displayPage = 7;
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                        globalData.cursorPos = 0;
                    }
                    break;
                case 2: // display mp game menu
                    processPrintCursor(&globalData, 4, GREEN, BLACK);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to monster game
                                globalData.displayPage = 4;
                                printSelectGame(&globalData);
                                break;
                            case 1: // go to clue
                                globalData.displayPage = 5;
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                break;
                            case 2: // go to error
                                globalData.displayPage = 6;
                                printBSOD();
                                break;
                            case 3: // go to error
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                globalData.displayPage = 7;
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                        globalData.cursorPos = 0;
                    }
                    break;
                case 3: // build cards
                    processPrintCursor(&globalData, 4, RED, BLACK);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to monster game
                                buildCard(&globalData, 0);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            case 1: // go to clue
                                buildCard(&globalData, 1);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            case 2: // go to error
                                buildCard(&globalData, 2);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            case 3: // go to error
                                buildCard(&globalData, 3);
                                clean(BLACK);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                        globalData.cursorPos = 0;
                    }
                    break;
                case 4: // singleplayer monster
                    singlePlayer(&globalData);
                    break;
                case 5: // clue sp
                    break;
                case 6: // bsod
                    break;
                case 7: // in progress, b goes back
                    if (globalData.keyPress == 0x0B) {
                        globalData.displayPage = 0;
                        printMainMenu(&globalData);
                    }
                    break;
            }
        }


        //        if (!globalData.keyFlag) {
        //            keypad(&globalData);
        //        }

        //        mainMenu(&globalData);

        //
        //        if (globalData.keyFlag && !globalData.displayedKey) { // TODO this goes into a display function
        //            globalData.keyFlag = FALSE;
        //            globalData.displayedKey = TRUE;
        //
        ////            processDisplay(globalData);
        //
        //        }


#else
        //Doing an inventory command from the Build card menu
        if (globalData.readCard != 0) {

            //            globalData.getInventory = TRUE;
            //        }
            //        if (globalData.getInventory == TRUE) {
            // get the inventory of cards
            inventoryRFID();

            // Print out each on to the LCD
            for (i = 0; i < readerData.availableUIDs; i++) {
                if (readerData.readUID[i][0] != ',') {
                    // Get rid of commas
                    processUID(readerData.readUID[i]);
                    //                    printrs(0, 24 + 8 * i, BLACK, RED, readerData.readUID[i], 1); // print first UID
                }
            }

            // got inventory, tell frontend
            i2cData.dataOut[0] = CARD_CHANGE;
            i2cData.outLength = 1;
            globalData.sendI2C = TRUE;
            i2cData.transmissionNum = 0; // begin counting slots

            // Tell UID to be quiet - Works but needs to have at least one uid in this state
            // quietRFID(readerData.readUID[0]);

            //            if (readerData.availableUIDs > 0) {
            //
            //                // block 0 high bits being 0x0000 indicates factory card, not custom
            //                // block 0 high bits being 0x0001 indicates custom card
            //                // block 0 low bits indicate the game the card is for. 0x0001 is the monster game
            //                writeRFID(readerData.readUID[0], 0x00, 0x0000, 0x0001); // 7654 3210
            //                writeRFID(readerData.readUID[0], 0x01, 0x0010, 0x0001); // hex 7-5 are for level 0x001 is level 1
            //                // hex 4 is for type 0 1 2 3
            //                // 0x0 fire, 0x1 water, 0x3 earth
            //                // last 4 are monster ID
            //
            //                //writes 8 chars in 2 addresses of memory (0x02 and 0x03 here)
            //                char8RFID(readerData.readUID[0], 0x02, "FIREDUDE");
            //                writeRFID(readerData.readUID[0], 0x04, 0x0003, 0x0201); // Move list by id, has moves 03, 02, and 01
            //                readRFID(readerData.readUID[0], 0x00);
            //                printrs(0, 32, BLACK, RED, readerData.readData, 1); // print 1st block
            //                readRFID(readerData.readUID[0], 0x01);
            //                printrs(0, 40, BLACK, RED, readerData.readData, 1); // print 2nd block
            //                readRFID(readerData.readUID[0], 0x02);
            //                printrs(0, 48, BLACK, RED, readerData.readData, 1); // print 3rd block
            //                readRFID(readerData.readUID[0], 0x03);
            //                printrs(0, 56, BLACK, RED, readerData.readData, 1); // print 4th block
            //                readRFID(readerData.readUID[0], 0x04);
            //                printrs(0, 64, BLACK, RED, readerData.readData, 1); // print 5th block
            //            }
            //
            //
            //            readRFID(readerData.readUID[0], 0x01);
            //            // Print out block on to the LCD
            //            for (j = 0; j < readerData.availableUIDs; j++) {
            //                if (readerData.readUID[j][0] != ',') {
            //                    // Get rid of commas
            //                    printrs(0, 24 + 8 * i + 8 * j, BLACK, RED, readerData.readUID[j], 1); // print first UID
            //                }
            //            }
            //
            //            prints(0, H - 8, BLACK, RED, "Press B to go back.", 1);
            //            // Turn off inventory flag

            //            globalData.getInventory = FALSE;
            globalData.readCard = 0;
        }
#endif
    }
    return;


}
예제 #9
0
파일: PMS.c 프로젝트: pavitarsidhu/C
void printMainMenu(int runningProcesses[]) {
	
	const char* prompt = "Please input your selection: \n 1. List \n 2. Suspend \n 3. Resume \n 4. Terminate \n 5. Exit \n";
	char *reply = readline(prompt);
	int userSelection = atoi(reply);
	
	if(userSelection == 5) {
		killpg(getpgrp(),SIGTERM);
		
	} else if(userSelection == 1) {	
	
		char buffer[10];
		int value = (int)getsid(getpid());
		sprintf(buffer, "%d", value);
		
		//The parameters needed to produce the PID,PPID,Time of each child
		char *const parmList[] = {"ps","-o","pid,ppid,time","-g","-r",buffer,NULL};
		
		int childrenListProcess = fork();
		if(childrenListProcess<0) {
			printf("The fork has failed."); 
			exit(EXIT_FAILURE); 
		} else if(childrenListProcess == 0) {
			setsid();
			printf("\n");
			execvp("/bin/ps", parmList);
		} else {
			int status;
			waitpid(childrenListProcess, &status, 0); 
		}
		
		const char* prompt = "";
		char* reply = readline(prompt);
		printMainMenu(runningProcesses); 

	} else if(userSelection == 2) {
		const char* prompt = "Please Enter Process ID: ";
		char* reply = readline(prompt);
		
		int result = validateProcess(runningProcesses, atoi(reply));
		if(result == 0) {
			int returnedValue = kill(atoi(reply),SIGSTOP); 
			printMainMenu(runningProcesses);	
		} else {
			printf("That was not a valid Process ID.\n");
			printMainMenu(runningProcesses);
		}
	} else if(userSelection == 3) {
		const char* prompt = "Please Enter Process ID: ";
		char* reply = readline(prompt);
		
		int result = validateProcess(runningProcesses, atoi(reply));
		if(result == 0) {
			int returnedValue = kill(atoi(reply),SIGCONT); 
			printMainMenu(runningProcesses);
		} else {
			printf("That was not a valid Process ID.\n");
			printMainMenu(runningProcesses);
		}
	} else if(userSelection == 4) {
		const char* prompt = "Please Enter Process ID: ";
		char* reply = readline(prompt);
		
		int result = validateProcess(runningProcesses, atoi(reply));
		if(result == 0) {
		
			/*This will remove the process that we are about to terminate
			 from our running list of on-going processes
			 */
			int i = 0;
			while(runningProcesses[i] != -999) {
				if(runningProcesses[i] == atoi(reply)) {
				runningProcesses[i] = -777;
				}
				i++;
			}
		
			int returnedValue = kill(atoi(reply),SIGTERM); 	
			int status;
			waitpid(atoi(reply),&status, 0); 
			printMainMenu(runningProcesses);	
		
			} else {
				printf("That was not a valid Process ID.\n"); 
				printMainMenu(runningProcesses);
			}
	} else {
		printMainMenu(runningProcesses);
	}
}
예제 #10
0
int main()
{
    char filename[100];
    int sum,cmd;
    RBTree IDTree=NULL,NameTree=NULL;
    setlocale(LC_ALL,"");
    printStartMenu();
    inputCorrectInt(&cmd,1,2);
    if (cmd==1)
    {
        wprintf(L"请输入文件名:\n");
        scanf("%s",filename);
        strcat(filename,".db");
        sum=LoadDatabase(filename,&IDTree,&NameTree);
        wprintf(L"正在尝试读取数据...\n");
        if (sum<0)
        {
            wprintf(L"读取失败。\n\n");
            system("pause");
            return 0;
        }
        else
        {
            system("cls");
            wprintf(L"已读取%d名学生信息。\n",sum);
        }
    }
    else
    {
        wprintf(L"请输入文件名:\n");
        scanf("%s",filename);
        strcat(filename,".db");
    }

    while(1)
    {
        printMainMenu();
        inputCorrectInt(&cmd,1,5);
        switch (cmd)
        {
        case 1: //output information
            printAllStudent(IDTree);
            system("cls");
            break;
        case 2: //search student
            printSearchStudent(IDTree,NameTree);
            system("cls");
            break;
        case 3:
            printAddStudent(IDTree,NameTree);
            system("cls");
            break;
        case 4:
            if (printSaveAndExit(IDTree,filename))
                return 0;
            system("cls");
            break;
        case 5:
            if (printDirectExit())
                return 0;
            system("cls");
            break;
        };
    }/*
    int i;
    int ID;
    wchar_t name[20];
    Student* Student;
    FILE* file=fopen("data.txt","rb");
    for (i=1;i<=34;i++)
    {
        fscanf(file,"%d%ls",&ID,name);
        Student=BuildStudent(ID,name,10,Male,"19700101");
        Insert(&IDTree,Student,IDSort);
        wprintf(L"%d %s\n",ID,name);
    }
    fclose(file);
    SaveDatabase(IDTree,"database.db");*/
    return 0;
}
예제 #11
0
// --- MAIN ---
int main() {
	char choice;
	int device_id;
	int aux_int;
	short int aux_sint;
	unsigned char aux_uchar;
	float pid_control[3];
	short int offsets[NUM_OF_SENSORS];


	assert(open_port());

	printMainMenu();
	scanf("%c", &choice);
	printf("choice: %c\n", choice);

	switch(choice) {
		case 'g':
			get_or_set = choice;
			break;
		case 's':
			get_or_set = choice;
			break;
		case 'm':
			initMemory();
			break;
		case 'c':
			calibrate();
			break;

		default:
			break;
	}

	if (get_or_set == 'g' || get_or_set == 's') {
		printParamMenu();

		scanf(" %c", &choice);

		if (get_or_set == 's') {
			switch(choice) {
				// Set new ID
				case 'i':
					printf("Choose a new ID: ");
					scanf("%d", &device_id);

					commSetParam(&comm_settings_t, BROADCAST_ID,
	            		PARAM_ID, &device_id, 1);
					usleep(100000);
					commStoreDefaultParams(&comm_settings_t, BROADCAST_ID);
					usleep(500000);
					break;

				// Set new PID parameters
				case 'k':
					printf("Set the new values for the PID controller:\nK_p: ");
		            scanf("%f", pid_control);
		            printf("K_i: ");
		            scanf("%f", pid_control + 1);
		            printf("K_d: ");
		            scanf("%f", pid_control + 2);

		            commSetParam(&comm_settings_t, BROADCAST_ID,
		            	PARAM_PID_CONTROL, pid_control, 3);
			        usleep(100000);
			        commStoreDefaultParams(&comm_settings_t, BROADCAST_ID);
			        usleep(500000);
					break;
				// Set startup activation flag
				case 'a':
					printf("Do you want the motor to be ON [1] or OFF [0] at startup?: ");
					scanf("%d", &aux_int);

					if (aux_int == 0) {
						aux_uchar = 0;
						commSetParam(&comm_settings_t, BROADCAST_ID,
            				PARAM_STARTUP_ACTIVATION, &aux_uchar, 1);
					} else {
						aux_uchar = 3;
						commSetParam(&comm_settings_t, BROADCAST_ID,
            				PARAM_STARTUP_ACTIVATION, &aux_uchar, 1);
					}
					commStoreDefaultParams(&comm_settings_t, BROADCAST_ID);
					break;


				case 'm':
					break;
				case 's':
					break;
				case 'o':
					printf("Set the new offsets:\n");
					printf("Offset 1: ");
					scanf("%hd", &aux_sint);
					offsets[0] = aux_sint;
					printf("Offset 2: ");
					scanf("%hd", &aux_sint);
					offsets[1] = aux_sint;
					printf("Offset 3: ");
					scanf("%hd", &aux_sint);
					offsets[2] = aux_sint;

					commSetParam(&comm_settings_t, BROADCAST_ID, PARAM_MEASUREMENT_OFFSET,
				            offsets, NUM_OF_SENSORS);
				    usleep(100000);
				    commStoreDefaultParams(&comm_settings_t, BROADCAST_ID);
				    usleep(1000000);
					break;
				case 'u':
					break;
				case 'f':
					break;
				case 'l':
					break;
			}
		} else {
			switch(choice) {
				case 'i':
					break;
				case 'k':
					break;
				case 'a':
					break;
				case 'm':
					break;
				case 's':
					break;
				case 'o':
					break;
				case 'u':
					break;
				case 'f':
					break;
				case 'l':
					break;
			}

		}

	}

	return 1;
}
예제 #12
0
파일: GameMain.c 프로젝트: cfj2k5/Chess
State onMainMenu(Game* game) {
	int choice = 0;
	char cmd[255];
	char userInput[255];
	cmd[0] = 0;

	/* Print initial Main Menu */
	printMainMenu(game);

	/* get choices: Possible choices are New Game, Load Game, Set up board, How to play */
	choice = getInput();

	/* Added by Cesar 1/26/2014 */
	/* handling the cases mentioned above */
	switch(choice){
	case 0:
		/* Start a new game */
		return NewGame;
	case 1:
		/* Load an old game */
		printf("Enter the file name you want to load: ");
		scanf("%s", userInput);
		printf("\n");
		fseek(stdin,0,SEEK_END);		
		loadGame(game, userInput);
		return NewGame;
	case 2:
		/* Setup custom board */
		
		while(cmd[0]!='0')
		{
			/*
			printf("Enter the file name you want to save \n");
			scanf("%s", userInput);
			saveLog(game, userInput);
			fseek(stdin,0,SEEK_END);
			*/
			printBoard(game);
			printf("Please input move to move piece (input 0 to start game): ");
			getGameInput(cmd);
			printf("\n");
			directMoveNotation(game, cmd);
		}
		return NewGame;
	case 3:
		/* How to play */
		printRules();
		return MainMenu;
	case 4:
		/* Reset board/game */
		resetGame(game);
		printf("Board/game has been reset.\n\n");
		return MainMenu;
	case 5:
		/* displays help */
		help();
		return MainMenu;
	case 9:
		return Exit;
	default:
		return MainMenu;
	}
	/* end code added by Cesar */

	/* old code, commented out on 1/26/2014
	switch(choice) {
	case 0:
		return NewGame;
	case 1:
		loadGame(game);
		return NewGame;
	case 2:
		game->setting->allowRedo ^= 1;
		return MainMenu;
	case 3:
		game->setting->allowIllegalMove ^= 1;
		return MainMenu;
	case 4:
		selectOpponent(game);
		return MainMenu;
	case 5:
		selectDifficulty(game);
		return MainMenu;
	case 6:
		return Exit;
	default:
		return MainMenu;
		}
		End old code */
	
}
예제 #13
0
파일: lab08.c 프로젝트: amar47shah/IntroC
// Main function: Program execution begins.
main()
{

    /* Phonebook points to (the first element) of an array of structures
     * of ContactType.  Each element of the array contains all the
     * information for one record: first name, last name, and phone
     * number. Integer variables iLength and iCapacity each contain
     * information about the array.  iCapacity indicates the number of
     * entries which can be stored according to current memory allocation;
     * when iCapacity = 5, then no more than 5 records can be stored.
     * iLength indicates the number of records that are currently stored.
     * (Therefore, the last element in the array is indexed by iLength - 1.)
     */
    ContactType *PhoneBook;
    int iLength = 0;
    int iCapacity = 0;

    /* PhoneBook is allocated enough memory to match its current listed
     * capacity.  Of course, here, the listed capacity is 0, so PhoneBook
     * is not assigned any memory according to the calloc function. This
     * assignment is included for form's sake, to match the free(PhoneBook)
     * statement at the end of the main() function.  Adhering to the form
     * of matching memory allocation and memory freeing will ensure careful
     * programming.
     */
    PhoneBook = (ContactType *) calloc(iCapacity, sizeof(ContactType));

    /* cUserChoice will take on the value of the user's main menu choice.
     * The following loop will continue to execute until the user chooses
     * to exit.  The constant identifier cLastChoice contains the character
     * representing the last available choice ('Exit').  If the program
     * is modified to accommodate a larger or smaller menu, this constant
     * can be changed conveniently.
     */
    char cUserChoice = '\0';
    const char cLastChoice = '9';

    do {

        // The menu is displayed and the user enters her choice.
        printMainMenu ();
        getChoice (&cUserChoice, cLastChoice);

        // The appropriate function is called.
        switch (cUserChoice) {
        case '1':
            showAllContacts (PhoneBook, &iLength);
            break;
        case '2':
            addContact (&PhoneBook, &iLength, &iCapacity);
            break;
        case '3':
            findContact (PhoneBook, &iLength);
            break;
        case '4':
            getRandomContact (PhoneBook, &iLength);
            break;
        case '5':
            deleteContact (PhoneBook, &iLength);
            break;
        case '6':
            deleteAllContacts (&iLength, &iCapacity);
            break;
        case '7':
            saveContactsToFile (PhoneBook, &iLength);
            break;
        case '8':
            loadContactsFromFile (&PhoneBook, &iLength, &iCapacity);
            break;
        }
        // The application continues until the user chooses to exit.
    } while (cUserChoice != cLastChoice);

    // Freeing allocated memory.
    free (PhoneBook);

    printf ("\nGoodbye!\n\n");
}
예제 #14
0
/**
 * @brief      This method runs when the 'task_user' is called.
 *
 * @details    This method runs inifitely when the task is called so all logic
 *             is contained in here. A for(;;) loop runs until it gets to the
 *             end where it delays for 1 ms to allow other lower level
 *             priority tasks a chance to run.
 */
void task_user::run (void)
{
    time_stamp a_time;             // Holds the time so it can be displayed
    number_entered = 0;            // Holds a number being entered by user

    //
    for (;;)
    {
        switch (state)
        {
        // Initialize first task where we wait for
        case (0):
            printMainMenu();
            // If the user typed a character, read
            if (hasUserInput())
            {
                // In this switch statement, we respond to different characters as commands typed in by the user
                switch (char_in)
                {
                // The 't' command asks what time it is right now
                case ('m'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << endl
                            << endl
                            << PMS ("\t->Switching to Motor Module..")
                            << endl
                            << PMS ("\t->Clearing Registers and Menus..")
                            << endl
                            << PMS ("\t->Intializing Motors..")
                            << endl;

                    // Reset the visible menu flag
                    resetMenus();
                    // Sets the variable to true so it doesn't go into single module yet
                    in_main_motor_module = true;
                    // go to case 1 over all
                    transition_to(1);
                    break;
                // Enter encoder test module
                case ('e'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << ATERM_CLEAR_SCREEN << ATERM_CURSOR_TO_YX(1, 1)
                            << PMS ("\t->Switching to Encoder Module..")
                            << endl
                            << PMS ("\t->Clearing Registers and Menus..")
                            << endl
                            << PMS ("\t->Intializing Encoder..")
                            << endl << endl;

                    // Reset the visible menu flag
                    resetMenus();
                    // Sets the variable to true so it doesn't go into single module yet
                    in_encoder_module = true;
                    // go to case 1 over all
                    transition_to(3);
                    break;
                // The 't' command asks what time it is right now
                // Enter encoder test module
                case ('i'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << ATERM_CLEAR_SCREEN << ATERM_CURSOR_TO_YX(1, 1)
                            << PMS ("\t->Switching to IMU Module..")
                            << endl
                            << PMS ("\t->Clearing Registers and Menus..")
                            << endl
                            << PMS ("\t->Intializing IMU..")
                            << endl << endl;

                    // Reset the visible menu flag
                    resetMenus();
                    // Sets the variable to true so it doesn't go into single module yet
                    in_imu_module = true;
                    // go to case 1 over all
                    transition_to(4);
                    break;
                // The 't' command asks what time it is right now
                case ('t'):
                    *p_serial << (a_time.set_to_now ()) << endl;
                    break;

                // The 's' command asks for version and status information
                case ('s'):
                    show_status ();
                    break;
                // The 'd' means drive control
                case ('d'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << ATERM_CLEAR_SCREEN << ATERM_CURSOR_TO_YX(1, 1)
                            << PMS ("\t->Switching to Drive Mode..")
                            << endl << endl;
                    transition_to(5);
                    in_drive_mode = true;
                    resetMenus();
                    break;
                //case ('d'):
                // The 'h' command is a plea for help; '?' works also
                case ('h'):
                case ('?'):
                    print_help_message ();
                    break;

                // The 'n' command runs a test of entering a number
                case ('n'):
                    while (char_in != 'q')
                    {
                        *p_serial << PMS ("Enter decimal numeric digits, "
                                          "then RETURN or ESC") << endl;
                        getNumberInput();
                        *p_serial << endl << endl << PMS("\t->You Entered: ") << number_entered << endl;
                    }
                    break;

                // A control-C character causes the CPU to restart
                case (3):
                    *p_serial << PMS ("Resetting AVR") << endl;
                    wdt_enable (WDTO_120MS);
                    for (;;);
                    break;

                // If character isn't recognized, ask What's That Function?
                default:
                    *p_serial << '"' << char_in << PMS ("\": WTF?") << endl;
                    break;
                }; // End switch for characters
            } // End if a character was received

            break; // End of state 0

        // Motor Control BASE module
        case (1):
            if (in_main_motor_module) //first time here run menu and get input
            {
                // prints the menu for this module
                printMotorMenu();

                // user is going to input motor number or q
                getNumberInput();

                if (char_in == 'q')
                {
                    *p_serial << PMS("->Selected: ") << char_in << endl
                              << endl
                              << endl
                              << PMS("\t->Returning to Mission Control.. ")
                              << endl
                              << PMS("\t->Releasing Motors..") << endl
                              << PMS("\t->Resetting AVR..") << endl;
                    //wdt_enable (WDTO_120MS);
                    //for (;;);
                    //break;
                    //release motors
                    //motor_select->put(1);

                    //motor_directive -> put(FREEWHEEL);
                    //
                    // no longer in this module, leaving
                    in_main_motor_module = false;
                    transition_to(0);
                    resetMenus();
                    break;
                    //reset menu flag
                    //resetMenus();
                    // set the transition & wait for break
                    //transition_to(0);

                }
                // if the number entered is valid
                else if (isValidMotor(number_entered))
                {
                    // re print user input and give them confirmation message.
                    *p_serial
                            << endl
                            << endl
                            << PMS("\t->Switching to Control of Motor ") << number_entered << dec << PMS(".") << endl
                            << PMS ("\t->Return to the Main Motor Module to swap Motors.") << endl;
                    // set local motor select value
                    local_motor_select = number_entered;
                    //reset menus
                    resetMenus();
                    //set flag to off so we can go into the single motor module
                    in_main_motor_module = false;
                    // go back to the top of this menu
                    // since in_main_motor_module flag is set off, we will go into single motor control when this state reloops
                    transition_to(1);
                }
                else
                {
                    *p_serial << PMS("Try Again. ") << endl;
                    in_main_motor_module = true;

                }

                break;
            }
            if (!in_main_motor_module) //already were here now we go deeper
            {


                printSingleMotorOptions();
                // They now select the motor task
                if (hasUserInput())
                {
                    switch (char_in)
                    {
                    case ('s'):
                        *p_serial
                                << PMS("->Selected: ") << char_in << endl;
                        *p_serial
                                << endl
                                << PMS ("Enter the Power Value (-255 to 255);")
                                << endl
                                << PMS("  *Note: Negative Values = Reverse")
                                << endl;

                        //motor_directive -> put(1);
                        getNumberInput();
                        //setPower(motor_select->get(), number_entered);
                        setMotor(local_motor_select, (int16_t)number_entered, SETPOWER);
                        *p_serial
                                << endl << endl
                                << PMS ("\tPower set at ") << number_entered
                                << PMS(". ") << endl;

                        resetMenus();
                        printDashBoard();

                        //now that operation is complete, ask for more
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select << PMS(" operation: ")
                                << PMS("\t(Press 'o' for options)")
                                << endl;
                        break;
                    case ('b'):
                        *p_serial
                                << PMS("->Selected: ") << char_in
                                << endl;
                        *p_serial
                                << PMS ("\t->Enter the Brake Force(0 - 255)")
                                << endl;
                        getNumberInput();
                        *p_serial
                                << endl << endl
                                << PMS ("\tBrake set at ") << number_entered
                                << PMS(". ") << endl;

                        setMotor(local_motor_select, number_entered, BRAKE);
                        resetMenus();

                        printDashBoard();
                        //now that operation is complete, ask for more
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select << PMS(" operation: ")
                                << PMS("\t(Press 'o' for options)")
                                << endl;
                        break;
                    case ('f'):
                        *p_serial
                                << PMS("->Selected: ") << char_in << endl;
                        *p_serial
                                << PMS ("\t->Releasing Motor..") << endl;
                        setMotor(0, 0, FREEWHEEL);
                        resetMenus();
                        printDashBoard();
                        //now that operation is complete, ask for more
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select << PMS(" operation: ")
                                << PMS("\t(Press 'o' for options)")
                                << endl;

                        break;
                    case ('p'):
                        *p_serial
                                << endl << PMS("->Selected: ")
                                << char_in << endl
                                << PMS("\t->Entering Potentiometer Control... ") << endl;
                        *p_serial << PMS ("\t->Potentiometer Activated.") << endl << endl;
                        *p_serial << endl << endl
                                  << PMS ("\t->Press 'q' to return to the Motor ") << local_motor_select << PMS(" Control")
                                  << endl << PMS ("\t->Press 'r' to refresh the DashBoard ") << endl;
                        transition_to(2);
                        resetMenus();
                        break;
                    case ('o'):
                        resetMenus();
                        printSingleMotorOptions();
                        break;
                    case ('q'):
                        *p_serial
                                << PMS("->Selected: ") << char_in << endl
                                << PMS(" Returning to Main Motor Module.. ")
                                << endl;
                        transition_to(1);
                        resetMenus();

                        in_main_motor_module = true;
                        break;
                    default:
                        *p_serial
                                << endl << PMS("'") << char_in
                                << PMS ("' is not a valid entry.") << endl;
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select
                                << PMS(" operation: ") << endl;
                        break;
                    }
                }
            }

            break;
        //Potentiometer Mode
        case (2):
            if (hasUserInput())
            {
                if (char_in  == 'q')
                {
                    *p_serial << endl << PMS("->Selected: ") << char_in << endl;
                    transition_to(1);
                    resetMenus();
                    break;
                    //
                }
                if (char_in == 'r')
                {
                    *p_serial << endl << PMS("->Selected: ") << char_in << endl;
                    resetMenus();
                    printDashBoard();
                    *p_serial << endl << endl
                              << PMS ("\t->Press 'q' to return to the Motor ") << local_motor_select << PMS(" Control")
                              << endl << PMS ("\t->Press 'r' to refresh the DashBoard ") << endl;

                }
            }

            setMotor(local_motor_select, motor_power -> get(), POTENTIOMETER);
            printDashBoard();
            break;
        //for use later [3,4]
        case (3):
            if (in_encoder_module)
            {
                printEncoderModuleOptions();
                if (hasUserInput())
                    switch (char_in)
                    {
                    case ('q'):
                        *p_serial << ATERM_CLEAR_SCREEN << ATERM_BKG_WHITE
                                  << PMS("->Selected: ") << char_in << endl
                                  << endl
                                  << endl
                                  << PMS("\t->Returning to Mission Control.. ")
                                  << endl
                                  << PMS("\t->Releasing Encoder..") << endl;
                        transition_to(0);
                        in_main_motor_module = true;
                        in_encoder_module = false;
                        resetMenus();
                        *p_serial
                                << ATERM_CLEAR_SCREEN
                                << ATERM_CURSOR_TO_YX(1, 1) << endl;

                        break;
                    case ('r'):
                        //constant refreshing already
                        transition_to(1)
                        in_imu_module = true;
                        break;
                    default:
                        
                        break;
                    }
            }
            break;
        case (4):
            if (in_imu_module)
            {
                printIMUModuleOptions();
                if (hasUserInput())
                    switch (char_in)
                    {
                    case ('q'):
                        *p_serial << ATERM_CLEAR_SCREEN
                                  << PMS("->Selected: ") << char_in << endl
                                  << endl
                                  << endl
                                  << PMS("\t->Returning to Mission Control.. ")
                                  << endl
                                  << PMS("\t->Releasing IMU..") << endl;
                        transition_to(0);

                        in_imu_module = false;
                        resetMenus();   

                        break;
                        default:
                        break;
                        *p_serial << ATERM_CLEAR_SCREEN;
                    }




                    case ('r'):
                        
                        break;
                    default:
                        break;
                    }
            }
            break;
        // Drive Mode
        case (5):
            if (in_drive_mode)
            {
                printDriveModeOptions();
                // printDashBoard();
                if (hasUserInput())
                    switch (char_in)
                    {
                    case ('q'):
                        *p_serial << ATERM_CLEAR_SCREEN
                                  << PMS("->Selected: ") << char_in << endl
                                  << endl
                                  << endl
                                  << PMS("\t->Returning to Mission Control.. ")
                                  << endl
                                  << PMS("\t->Releasing Drive Mode..") << endl;
                        transition_to(0);
                        in_drive_mode = false;
                        resetMenus();
                        break;
                    case ('s'):
                        *p_serial << endl
                                  << PMS("Input Power Value for Motor: ")
                                  << endl;
                        getNumberInput();
                        setMotor(0, (int16_t)number_entered, SETPOWER);
                        *p_serial
                                << endl << endl
                                << PMS ("\tPower set at ") << number_entered
                                << PMS (". ") << endl << endl
                                << PMS ("Printing DashBoard.. ") << endl
                                << endl;
                        resetMenus();
                        printDashBoard();
                        break;
                    case ('r'):
                        *p_serial
                                << PMS ("Printing DashBoard.. ")
                                << endl
                                << endl;
                        resetMenus();
                        printDashBoard();

                        break;
                    default:
                        break;
                    }
                int16_t x_direction = y_joystick -> get();
                int16_t map_x = x_direction - 526;
                if (x_direction > 526)
                {
                    map_x = 2 * (x_direction - 526);
                }
                else
                {
                    map_x = -2 * (526 - x_direction);
                }

                motor_setpoint -> put(map_x);

                motor_directive -> put(SETPOWER);

                // *p_serial
                //         << ATERM_CURSOR_TO_YX(19, 1)
                //         << ATERM_ERASE_IN_LINE(0)
                //         << gear_state -> get()
                //         << PMS ("\t\t")
                //         << motor_setpoint -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << motor_power -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << encoder_count -> get()
                //         << PMS("\t")
                //         << ATERM_CURSOR_TO_YX(23, 1)
                //         << ATERM_ERASE_IN_LINE(0)
                //         << steering_power -> get()
                //         << PMS("    \t")
                //         << encoder_ticks_per_task -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << x_joystick -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << y_joystick -> get()
                //         << PMS("\t");
                *p_serial << encoder_ticks_per_task -> get() << endl;

            }
            break;
        //JoyStick test
        case (6):
            break;
        default:
            *p_serial << PMS ("Illegal state! Resetting AVR") << endl;
            wdt_enable (WDTO_120MS);
            for (;;);
            break;

        } // End switch state

        runs++;                             // Increment counter for debugging

        // No matter the state, wait for approximately a millisecond before we
        // run the loop again. This gives lower priority tasks a chance to run
        delay_ms (5);
    }