Esempio n. 1
0
void USART3_callback_fn(uint8_t byte)
{
	if(fsm_get_state() == STATE_1 || fsm_get_state() == STATE_RESET){
		USART2_putchar(byte); //forward to console
	}
	else if(fsm_get_state() == STATE_2){
		//Store the received byte in the Ping structure
		Wifly_Receive_Ping(byte);
	}
}
Esempio n. 2
0
void systick_callback_fn(){
	if(fsm_lock() == FSM_LOCK_ACQUIRED){
		if(fsm_get_state() == STATE_2){
			fsm_set_state(STATE_2_READ);
		}
		else if(fsm_get_state() == STATE_2_READ){
			fsm_set_state(STATE_2);
		}
		else{
			USART2_putstr("BAD STATE IN SYSTICK CALLBACK \n\r\0");
		}
		fsm_unlock();
	}
}
Esempio n. 3
0
void userbutton_callback_fn(void)
{
	if( fsm_lock() == FSM_LOCK_ACQUIRED )
	{
		if(fsm_get_state() == STATE_1 || fsm_get_state() == STATE_RESET){
			fsm_set_state(STATE_2);
		}
		else if(fsm_get_state() == STATE_2 || fsm_get_state() == STATE_2_READ){
			fsm_set_state(STATE_1);
		}
		else{
			USART2_putstr("Userbutton: Bad state!\n\r\0");
		}
		fsm_unlock();
	}
}
Esempio n. 4
0
int keyboard_event_generate( int fd )
{
	char buf[64];
	int n;

	fgets( buf, 32, stdin );
	n = strlen( buf );
	buf[n-1] = '\0';
	DPRINTF( "From Client keyboard: %s (%d bytes received) \n", buf, n-1 );

	if( strcmp(buf, "") == 0 )
		fsm_event_insert( C0_K0_INPUT_NULL ); 
	else if( strcmp(buf, "new") == 0 )
		fsm_event_insert( C2_K1_INPUT_NEW ); 
	else    
	{	// should be K_INPUT_STRING
		switch( fsm_get_state() )
		{
			case S3_WAIT_USER_NAME:
				fsm_event_insert( C4_K2_INPUT_NAME ); 
				break;
			case S5_WAIT_USER_INFO:
				fsm_event_insert( C6_K3_INPUT_INFO ); 
				break;
			default:
				fsm_event_insert( C0_K0_INPUT_NULL ); 
				break;
		}		
	}

	return 0;
}
Esempio n. 5
0
void userbutton_callback_fn(void)
{
	//Advance the fsm to the next state.
	if( fsm_lock() == FSM_LOCK_ACQUIRED )
	{
		if(fsm_get_state() == STATE_RESET){
			USART2_putstr("SWITCHING TO STATE 2! \n\r\0");
			fsm_set_state(STATE_2);
		}
		else if(fsm_get_state() == STATE_1){
			USART2_putstr("SWITCHING TO STATE 2! \n\r\0");
			fsm_set_state(STATE_2);
		}
		else if(fsm_get_state() == STATE_2){
			USART2_putstr("SWITCHING TO STATE 1! \n\r\0");
			fsm_set_state(STATE_1);
		}
		fsm_unlock();
	}
}
Esempio n. 6
0
File: fsm.c Progetto: gapry/ARM_Labs
void receive_message_systick_callback(){
	//Print out the received message
	USART2_putstr("\n\rReceived!\n\r\0");
	Wifly_Print_Last_Received_Message();
	//Set the message reported flag to 1;
	message_reported = 1;
	//Disable the systick timer
	set_systick_disabled();
	//Restart the state to send the message again.
	if( fsm_lock() == FSM_LOCK_ACQUIRED )
		{
			if(fsm_get_state() == STATE_2){
				fsm_set_state(STATE_2);
			}
			fsm_unlock();
		}
}
Esempio n. 7
0
void USART2_callback_fn(uint8_t byte)
{
	if(fsm_get_state() == STATE_1 || fsm_get_state() == STATE_RESET){
		USART3_putchar(byte); //forward to wifi module
	}
}
void vControl ( void *pvParameters )
{
	portTickType xLastWakeTime;
	signed char valx, valy;
	unsigned char ls, rs, lb, rb;

	can_frame_t out_frame;
	can_frame_t in_frame;
	out_frame.id = 1;
	out_frame.dlc = 6;

	xLastWakeTime = xTaskGetTickCount ();

	/* Button init */
	buttons_init ();

	/* FSM init */
	fsm_init ();

	/* CAN init */
	can_init ();

	/* ADC init */
	adc_init ( ctrlNUM_ADC_VALUES );

	/* Touch init */
	touch_init ( 30, 30, 30, 30 );

	while (1)
	{
		vTaskDelayUntil ( &xLastWakeTime, ctrlTASK_FREQUENCY );

		if ( adc_conversion_complete () == pdTRUE )
		{
			adc_disable ();
			adc_get_value ( &valx, 0 );
			adc_get_value ( &valy, 0 );
			touch_measure ( &ls, &rs, &lb, &rb );

			out_frame.data[0] = valx;
			out_frame.data[1] = valy;
			out_frame.data[2] = ls;
			out_frame.data[3] = rs;
			out_frame.data[4] = lb;
			out_frame.data[5] = rb;

			if (fsm_get_state() == ST_PLAY)
			{
				can_transmit (&out_frame);
			}
						
			can_receive (&in_frame, 0);

			if (in_frame.data[0] == GAME_SENSOR_TRIGGERED)
			{
				// TODO: set triggered state
				fsm_event_t *event = pvPortMalloc (sizeof (fsm_event_t));
				event->type = EV_STOP;
				event->ptr = NULL;
				fsm_event_put (event, portMAX_DELAY);
				in_frame.data[0] = 0;
			}
			else if (in_frame.data[0] == GAME_SENSOR_CLEARED)
			{
				// TODO: set cleared state
				in_frame.data[0] = 0;
			}

			adc_enable ();
			adc_conversion_start ();
		}

		fsm_update ();
	}
}
Esempio n. 9
0
File: fsm.c Progetto: gapry/ARM_Labs
void state_INIT_USART3_callback_fn(uint8_t byte){
	USART2_putchar(byte);
	*init_input_end = byte;
	init_input_end++;
	init_input_end = '\0';
	if(strcmp(&init_input,"AOK\0") || strcmp(&init_input,"ERR\0")){
		out_of_CMD = 1;
	}
	if(fsm_get_state() == STATE_INIT && has_been_initialized != 1 && out_of_CMD == 1){
		fsm_set_state(STATE_INIT_a);
	}
	if(strcmp(&init_input,"AOK\0") == 1){
		//Advance the fsm to the next state.
			if( fsm_lock() == FSM_LOCK_ACQUIRED )
			{
				if(fsm_get_state() == STATE_INIT_a){
					fsm_set_state(STATE_INIT_b);
				}
				else if(fsm_get_state() == STATE_INIT_b){
					fsm_set_state(STATE_INIT_c);
				}
				else if(fsm_get_state() == STATE_INIT_c){
									fsm_set_state(STATE_INIT_d);
								}
				else if(fsm_get_state() == STATE_INIT_d){
									fsm_set_state(STATE_INIT_e);
								}
				else if(fsm_get_state() == STATE_INIT_e){
									fsm_set_state(STATE_INIT_f);
								}
				else if(fsm_get_state() == STATE_INIT_f){
									fsm_set_state(STATE_INIT_g);
								}
				else if(fsm_get_state() == STATE_INIT_g){
									fsm_set_state(STATE_INIT_h);
								}
				else if(fsm_get_state() == STATE_INIT_h){
									fsm_set_state(STATE_INIT_i);
								}
				else if(fsm_get_state() == STATE_INIT_i){
									fsm_set_state(STATE_INIT_j);
								}
				else if(fsm_get_state() == STATE_INIT_j){
									fsm_set_state(STATE_RESET);
								}

				fsm_unlock();
			}
	}
}