Esempio n. 1
0
void buttonFSM(Button_t* button){
  int readBtn;
  switch(button->state){
    case IDLE:
      readBtn = readButton();
      if(button->prevState != readBtn)
      {
        button->recordedTime  = getTime();
        button->prevState     = readBtn;
        button->state         = WAIT;
      }
      break;
    case WAIT:
      if((getTime() - button->recordedTime) > 99)
      {
        button->curState  = readButton();
        if(button->prevState == button->curState)
        {
          button->output  = button->curState;
          button->state   = IDLE;
        }
        else
        {
          button->prevState = button->curState;
          button->state     = IDLE;
        }
      }
      break;
  }
}
void test_readButton(void){
  int buttonStateTable[] = {LOW,HIGH,LOW};
  setButtonPointerTable(buttonStateTable);
  TEST_ASSERT_EQUAL(OFF,readButton());
  TEST_ASSERT_EQUAL(ON,readButton());
  TEST_ASSERT_EQUAL(OFF,readButton());
}
void buttonFSM(ButtonSM* buttonX){
   
   int storeState;
   uint32_t currentTime;
  switch(buttonX->state){
    
    case IDLE:
    storeState = readButton();
    if( buttonX->prevState != storeState ){
      buttonX->prevState = storeState;
      buttonX->recordedTime = getTime();
      buttonX->state = WAIT;
    }
    break;
    
    case WAIT:
    currentTime = getTime();
    if(currentTime - buttonX->recordedTime >= buttonX->interval){
      buttonX->curState = readButton();
      if(buttonX->prevState == buttonX->curState){
       buttonX->output = buttonX->curState;
      }else{
       buttonX->prevState = buttonX->curState;
      } 
      buttonX->state = IDLE;
    }
    
    break;
  }
}
void test_readButton(void){

  int buttonStateTable[] = {LOW,HIGH,LOW};

  setButtonPointerTable(buttonStateTable);

  UnityAssertEqualNumber((_U_SINT)((OFF)), (_U_SINT)((readButton())), (((void *)0)), (_U_UINT)62, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((ON)), (_U_SINT)((readButton())), (((void *)0)), (_U_UINT)63, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((OFF)), (_U_SINT)((readButton())), (((void *)0)), (_U_UINT)64, UNITY_DISPLAY_STYLE_INT);

}
Esempio n. 5
0
void loop (){
  byte vButton1;
  ARCPOPacket vPacket;
  
  vButton1 = readButton(BUTTON_PIN);
  if (vButton1 == 0){
    ARCPOPacket vP;
    vP.Type = 98;
    vP.Content [0] = 'x';
    vP.Content [1] = 0;
    
    
    writePacket (vP);
    pika(LED1_PIN, 100);
  }
  
  
  vPacket = readPacket();
  
  if (readPacketSuccess()){
    delay(250);
    ProcessPacket (vPacket);
    //Serial.print ("Read a packet -->");
    //DEBUG_TRACE_ARCPOPACKET_TO_SERIAL (vPacket);
  }
  
  //system needs a small delay other keep on reading the same entries (COM problem?)
  delay(250);
}
Esempio n. 6
0
Button_t* createButton()
{
  Button_t* newButton = malloc(sizeof(Button_t));
  newButton->state      = IDLE;
  newButton->prevState  = readButton();
  newButton->output     = IS_RELEASED;
  newButton->curState   = IS_RELEASED;
  newButton->recordedTime = 0;
  
  return newButton;
}
Esempio n. 7
0
void runCredits(GameVars* gameVars)
{
#ifdef DEBUG
    debugPrint("CREDITS\x80");
#endif
    //Display credits
    drawCredits(0x80);
    
    //wait for user to go back with button 1
    readButton();
    
    //Player 1 Button 1 - Play
    if (_BTN_CUR_MASK & _JOY1_B1)
    {
        //Move to Play game state
        moveToNextGameState(gameVars, GENone);
    }
}
Esempio n. 8
0
void runMenu(GameVars* gameVars)
{
#ifdef DEBUG
    debugPrint("MENU\x80");
#endif
    
    //Display menu until user starts game
    drawMainMenu(0x50);
    
    //wait for user to start game with button 1
    readButton();
    
    //Player 1 Button 1 - Play
    if (_BTN_CUR_MASK & _JOY1_B1)
    {
        //Move to Play game state
        moveToNextGameState(gameVars, GEPlayAgain);
    }
    else if (_BTN_CUR_MASK & _JOY1_B2)
    {
        //Show credits screen
        moveToNextGameState(gameVars, GEShowCredits);
    }
}
Esempio n. 9
0
void game()
{


	uint8_t i;
	
	clear();

	column[0] = 0x18;
	column[7] = 0x18;
	sw1=0; sw2=0;
	score1=0; score2=0;	

	uint8_t btn1 = 0, btn2 = 0, btn3 = 0, btn4 = 0;
	uint8_t counter = 0;
	uint8_t counter2 = 0;
	uint8_t c1=column[0],c2=column[7];

	initBall();

	for(;;)
	{

///////////////////////////////
///////////Button Read/////////
		btn1 = readButton(1);
		btn2 = readButton(2);
		btn3 = readButton(3);
		btn4 = readButton(4);

        if(counter>PSPEED)
		{
			if (btn1)
			{
				if((column[7] << 1) <=192)
				c2=column[7] = column[7] << 1;
			}

			if (btn2)
			{
				if((column[7] >> 1) >= 3)
				c2=column[7] = column[7] >> 1;
			}

			if (btn3)
			{
				if((column[0] << 1) <=192)
				c1=column[0] = column[0] << 1;
			}

			if (btn4)
			{
				if((column[0] >> 1) >= 3)
				c1=column[0] = column[0] >> 1;
			}
			counter=0;
		}
		counter++;
////////////////////////////
////////////////////////////


////////////////////////
////////Score Update////
		if(score1>9 || score2>9)
		 { 
		   score1=0;
		   score2=0;
		   update_score(score1,score2);
		  }
////////////////////////
////////////////////////

		for(i=1; i<nrCol-1; i++)
			column[i]=0;

		//column[7]=c2; 
		//column[0]=c1;

///////////////////////
////////Ball movement//
		if(counter2>BSPEED)
		{
		 move_ball();
		 counter2=0;
		}
		counter2++;
//////////////////////
//////////////////////

		display(column);
				
	}
	
}
Esempio n. 10
0
void main(void) {

	//	WDTCTL = WDTPW | WDTHOLD;           // Stop watchdog timer

	initClock();
	initLFXT();

	SCB_CPACR = 0xf << 20; //enable the fpu

	DIO->rPADIR.b.bP2DIR = 0x07; //set onboard rgb led pins to output
	DIO->rPAOUT.b.bP2OUT = 0x00; //set onboard rgb led pins to off

	DIO->rPADIR.b.bP1DIR &= ~0x02; //button
	DIO->rPAREN.b.bP1REN |= 0x02; //button
	DIO->rPAOUT.b.bP1OUT |= 0x02; //button


	DIO->rPAOUT.b.bP2OUT |= 0x01;

	setUpUART();
//	testInitDMA();

//	PMAP->rKEYID = 0x2D52;
//	PMAP->rP2MAP23 = PM_UCA1SIMO;
//	PMAP->rP3MAP23 |= PM_UCA2SIMO;
//	PMAP->rKEYID = 0x00;

	initDisplay();
	setDisplayCurrentLimit(1.6f);



	ADC_init();

	ADC_setNumberOfChannels(4);
	ADC_setChannelSource(0, 15);
	ADC_setChannelSource(1, 14);
	ADC_setChannelSource(2, 13);
	ADC_setChannelSource(3, 8);

	initRandom();

//	uint16_t testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();
//	testRandom = getRandomMessageNumber();


	uint8_t lastButtonState = 0;

	uint16_t increment = 0;

	calcPalette();

	initTimer();
	getTimeDelta();
	float time = 0;

	float scrollRate = 25;
	float scrollStart = 0.0;

	int messageNumber = getRandomMessageNumber();
	int scrollTick = 0;
	int scrollDiv = 1;
	int scrollPosition = GFX_WIDTH;

	int staticHatIndex = 0;

	float textBrightness = 0.3;

	messageColours[staticHatIndex].h = 0.0;
	messageColours[staticHatIndex].s = 1.0;
	messageColours[staticHatIndex++].v = textBrightness;

	messageColours[staticHatIndex].h = 0.2;
	messageColours[staticHatIndex].s = 1.0;
	messageColours[staticHatIndex++].v = textBrightness;

	messageColours[staticHatIndex].h = 0.4;
	messageColours[staticHatIndex].s = 1.0;
	messageColours[staticHatIndex++].v = textBrightness;

	messageColours[staticHatIndex].h = 0.6;
	messageColours[staticHatIndex].s = 1.0;
	messageColours[staticHatIndex++].v = textBrightness;

	messageColours[staticHatIndex].h = 0.8;
	messageColours[staticHatIndex].s = 1.0;
	messageColours[staticHatIndex++].v = textBrightness;

	messageColours[staticHatIndex].h = 0.5;
	messageColours[staticHatIndex].s = 1.0;
	messageColours[staticHatIndex++].v = 0.0;

	getRandomColour();

	int showMessage = 0;

	int currentMessageColour = rand() % MESSAGE_COLOR_COUNT;

	while (1) {

		time += getTimeDelta();
		clearDisplay();
//		drawFlatBackground(0.5, 1.0, 0.1, 2.0);
		drawPlasma(time, 1.0, 0.05);

//		int16_t fontX = 0;

		if (showMessage) {
			setColourHSVf(randomColour.h, randomColour.s, randomColour.v);

			scrollTick++;
			if (scrollTick % scrollDiv == 0) {
				scrollPosition--;
				scrollTick = 0;
			}
			int textXPos = scrollPosition;

			textXPos = drawString(messages[messageNumber], textXPos, 0);

			if (textXPos < 0) {
//			scrollStart = time;
				scrollPosition = GFX_WIDTH;
				scrollTick = 0;
			messageNumber = (messageNumber + 1) % MESSGAE_COUNT;
//				messageNumber = getRandomMessageNumber();

				//skip empty ones
				while (messages[messageNumber][0] == '\0') {
//					messageNumber = getRandomMessageNumber();

					messageNumber = (messageNumber + 1) % MESSGAE_COUNT;
				}

				currentMessageColour = rand() % MESSAGE_COLOR_COUNT;
				getRandomColour();
			}

		}
		normaliseAndSwapBuffer();
//		EUSCI_A1->rTXBUF.a.bTXBUF = 'f';

		if (time > 600) {
			time = 0;
//			scrollStart = 0;
		}
//		increment = (increment + 1) % 2;
//
//		if (increment == 0) {
//			;
//		}
//		colourIndex = (colourIndex + 1) & 0x3f;

//		DIO->rPAOUT.b.bP2OUT ^= 0x01;

		uint8_t button  = readButton();
		if( button && !lastButtonState){
			//transition on
			DIO->rPAOUT.b.bP2OUT ^= 0x01;
			DIO->rPAOUT.b.bP2OUT ^= 0x02;
			showMessage ^= 0x01;

		}else if( !button && lastButtonState){
			//transition off;
		}

		lastButtonState = button;

	}

}
Esempio n. 11
0
void runGameplay(GameVars* gameVars)
{
    //GAME
    
    //Draw the court
    drawCourt();
    
    //Draw the scores
    drawScores(gameVars);
    
    //Game play states
    switch (gameVars->gameState) {
        case GSGameStart:
        {
#ifdef DEBUG
            debugPrint("START\x80");
#endif
            //Draw Ready message
            drawReady(0x80);
            
            //Wait for a number of frames
            waitForFramesThenMoveOnToNextState(60, gameVars);
        }
            break;
            
        case GSWaitForServe:
        {
#ifdef DEBUG
            debugPrint("SERVE\x80");
#endif
            //Score max?
            if (gameVars->player1.score >= maxScoreForPlayer
                || gameVars->player2.score >= maxScoreForPlayer)
            {
                //Served - move to next state
                moveToNextGameState(gameVars, GEWinner);
                return;
            }
            
            //Draw player paddles
            movePaddles(gameVars);

            //Inform who is about to serve
            drawServe(gameVars->player1ServeNext);
            
            //wait for user to start game with button 4
            readButton();
            
            //Player 1 Button 4 or P2 Button 4
            if (
                (gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY1_B4))
                ||
                (!gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY2_B4))
                )
            {
                //Position the ball and make visible
                serve(gameVars);
                
                //Served - move to next state
                moveToNextGameState(gameVars, GENone);
            }

        }
            break;
            
        case GSPlay:
        {
#ifdef DEBUG
            debugPrint("PLAY\x80");
#endif
            //GAME PLAY ACTION
            
            drawCenterLine(gameVars);
            
            //Draw player paddles
            movePaddles(gameVars);
            
            //Only deal with visible balls
            if(gameVars->ball.visibility == false) return;
            
            //Move ball - check for goal
            moveBallSprite(gameVars);
        }
            break;
            
        case GSScored:
        {
#ifdef DEBUG
            debugPrint("SCORED\x80");
#endif
            //Goal!
            drawPoint(!gameVars->player1ServeNext);
            
            waitForFramesThenMoveOnToNextState(60, gameVars);
        }
            break;
            
        case GSGameOver:
        {
#ifdef DEBUG
            debugPrint("GAMEOVER\x80");
#endif
            //Display 'Game Over'
            drawGameOver(gameVars->player1.score > gameVars->player2.score);
            
            //wait for user to select replay or menu
            readButton();
            //Player 1 Button 1
            if (_BTN_CUR_MASK & _JOY1_B1)
            {
                //Reset scores
                resetPlayerScores(gameVars);
                
                //Replay - move to next state
                moveToNextGameState(gameVars, GEPlayAgain);
            }
            else if (_BTN_CUR_MASK & _JOY1_B2)
            {
                //Reset scores
                resetPlayerScores(gameVars);
                
                //Menu - move to next state
                moveToNextGameState(gameVars, GEBackToMenu);
            }
        }
            break;
            
        default:
            break;
    }
    
}