Beispiel #1
0
static void prvSetupHardware( void )
{
	SystemCoreClockUpdate();

	/* Disable the Watch Dog Timer */
	MSS_WD_disable( );

	/* Initialise the GPIO */
	MSS_GPIO_init();

	/* Set up GPIO for the LEDs. */
    MSS_GPIO_config( MSS_GPIO_0 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_1 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_2 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_3 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_4 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_5 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_6 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_7 , MSS_GPIO_OUTPUT_MODE );

    /* All LEDs start off. */
    ulGPIOState = 0xffffffffUL;
    MSS_GPIO_set_outputs( ulGPIOState );

	/* Setup the GPIO and the NVIC for the switch used in this simple demo. */
	NVIC_SetPriority( GPIO8_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
    NVIC_EnableIRQ( GPIO8_IRQn );
    MSS_GPIO_config( MSS_GPIO_8, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_NEGATIVE );
    MSS_GPIO_enable_irq( MSS_GPIO_8 );
}
Beispiel #2
0
void init_rgb_pwm(uint8_t _gpio_r, uint8_t _gpio_g, uint8_t _gpio_b, uint8_t _gpio_i){
	timer_init();

	MSS_GPIO_config((gpio_r_i = _gpio_r), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);
	MSS_GPIO_config((gpio_g_i = _gpio_g), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);
	MSS_GPIO_config((gpio_b_i = _gpio_b), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);
	MSS_GPIO_config((gpio_i_i = _gpio_i), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);

	MSS_GPIO_enable_irq(_gpio_r);
	MSS_GPIO_enable_irq(_gpio_g);
	MSS_GPIO_enable_irq(_gpio_b);
	MSS_GPIO_enable_irq(_gpio_i);

	// add the timer peripherals to the timer module
	red_timer_id   = add_timer(TIMER_RED);
	green_timer_id = add_timer(TIMER_GREEN);
	blue_timer_id  = add_timer(TIMER_BLUE);
	pulse_timer_id = add_timer(TIMER_PULSE);

	// all colors overflow at their max pwm value
	timer_setOverflowVal(red_timer_id, 1000000);
	timer_setOverflowVal(blue_timer_id, 1000000);
	timer_setOverflowVal(green_timer_id, 1000000);

	// pulse uses overflow only
	//timer_enable_allInterrupts(pulse_timer_id);
	timer_enable_overflowInt(pulse_timer_id);
	timer_disable_compareInt(pulse_timer_id);

	// colors require overflow and compare registers
	timer_enable_allInterrupts(red_timer_id);
	timer_enable_allInterrupts(blue_timer_id);
	timer_enable_allInterrupts(green_timer_id);

	timer_enable_compareInt(red_timer_id);
	timer_enable_compareInt(blue_timer_id);
	timer_enable_compareInt(green_timer_id);

	timer_enable_overflowInt(red_timer_id);
	timer_enable_overflowInt(blue_timer_id);
	timer_enable_overflowInt(green_timer_id);

	timer_enable(red_timer_id);
	timer_enable(green_timer_id);
	timer_enable(blue_timer_id);
	//timer_enable(pulse_timer_id);


	// don't start the colors until set_brightness is called
}
Beispiel #3
0
void MY_GPIO_init (void)
{
	void MSS_GPIO_init( void );

	MSS_GPIO_config( MSS_GPIO_0 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_1 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_2 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_3 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_4 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_5 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_6 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_7 , MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config( MSS_GPIO_8 , MSS_GPIO_OUTPUT_MODE );
}
Beispiel #4
0
void rfid_init() {
	/* Initialize CoreUARTapb for bar code scanner settings */
	UART_init(&g_rfid_uart, RFID_UART_BASE_ADDR, RFID_BAUD_VALUE, DATA_8_BITS | NO_PARITY);

	/* Initialize the MSS GPIO & GPIO_0 Interrupt */
    MSS_GPIO_config( MSS_GPIO_1, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_BOTH );
    MSS_GPIO_enable_irq( MSS_GPIO_1 );
    NVIC_EnableIRQ(GPIO1_IRQn);

	vSemaphoreCreateBinary( rfid_top_sem );
	_rfid_init_done = 1;
}
Beispiel #5
0
void Yellowstone_Init(void)
{
	// MSS_GPIO_init( );
	MSS_GPIO_config( MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_set_output( MSS_GPIO_0, 0 );

	// Initialize SPI master
	MSS_SPI_init( &g_mss_spi0 );
	MSS_SPI_configure_master_mode
	(
		&g_mss_spi0,
		MSS_SPI_SLAVE_0,
		MSS_SPI_MODE0,
		MSS_SPI_PCLK_DIV_128,
		spi_frame_size
	);
	MSS_SPI_enable( &g_mss_spi0 );

	MSS_GPIO_config ( MSS_GPIO_SPI_0_IT, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_LEVEL_HIGH );
	MSS_GPIO_enable_irq( MSS_GPIO_SPI_0_IT );
	NVIC_EnableIRQ( MSS_GPIO_SPI_0_IT_IRQn );
}
Beispiel #6
0
void vParTestInitialise( void )
{
long x;

	/* Initialise MSS GPIOs. */
    MSS_GPIO_init();

    /* Ensure the LEDs are outputs and off to start. */
    for( x = 0; x < partstNUM_LEDS; x++ )
    {
    	MSS_GPIO_config( ucLEDs[ x ], MSS_GPIO_OUTPUT_MODE );
    	vParTestSetLED( x, pdFALSE );
    }
}
Beispiel #7
0
void MY_GPIO_init(void) {
	// Initialize MSS GPIOs.
	void MSS_GPIO_init(void);

	// Configure the MSS GPIO output pins
	MSS_GPIO_config(MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_1, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_2, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_3, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_4, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_5, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_6, MSS_GPIO_OUTPUT_MODE );
	MSS_GPIO_config(MSS_GPIO_7, MSS_GPIO_OUTPUT_MODE );

	// Configure the MSS GPIO input pins + configure interrupt mode (rising)
	MSS_GPIO_config(MSS_GPIO_8, MSS_GPIO_INPUT_MODE
			| MSS_GPIO_IRQ_EDGE_POSITIVE );
	MSS_GPIO_config(MSS_GPIO_9, MSS_GPIO_INPUT_MODE
			| MSS_GPIO_IRQ_EDGE_POSITIVE );

	// Enable the input pin interrupts in the MSS
    MSS_GPIO_enable_irq( MSS_GPIO_8 );
    MSS_GPIO_enable_irq( MSS_GPIO_9 );
}
void vParTestInitialise( void )
{
long x;

	/* Initialise the GPIO */
	MSS_GPIO_init();

	/* Set up GPIO for the LEDs. */
	for( x = 0; x < partstMAX_LEDS; x++ )
	{
		MSS_GPIO_config( ( mss_gpio_id_t ) x , MSS_GPIO_OUTPUT_MODE );
	}

	/* All LEDs start off. */
	ulGPIOState = 0xffffffffUL;
	MSS_GPIO_set_outputs( ulGPIOState );
}
int xbee_interface_init() {
  int check;
  check = _xbee_interface_alloc_init();
  if (check < 0) return check;

  MSS_GPIO_config(MSS_GPIO_5, MSS_GPIO_OUTPUT_MODE);
  MSS_GPIO_set_output(MSS_GPIO_5, 0x0);
  MSS_GPIO_set_output(MSS_GPIO_5, 0x1);

  MSS_UART_init(&g_mss_uart1,
                MSS_UART_57600_BAUD,
                MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT);

  _xbee_interface_rx_init();
  _xbee_interface_tx_init();

  return 0;
}
Beispiel #10
0
static void prvSetupHardware( void )
{
	SystemCoreClockUpdate();
	
	/* Disable the Watch Dog Timer */
	MSS_WD_disable( );

	/* Configure the GPIO for the LEDs. */
	vParTestInitialise();
	
	/* ACE Initialization */
	ACE_init();

	/* Setup the GPIO and the NVIC for the switch used in this simple demo. */
	NVIC_SetPriority( GPIO8_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
    NVIC_EnableIRQ( GPIO8_IRQn );
    MSS_GPIO_config( MSS_GPIO_8, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_NEGATIVE );
    MSS_GPIO_enable_irq( MSS_GPIO_8 );
}
void initGPIO() {
	//initalize MSS gpio block
	MSS_GPIO_init();

	//configure MSS gpio pins 0 to 3 as outputs
	MSS_GPIO_config(MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config(MSS_GPIO_1, MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config(MSS_GPIO_2, MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config(MSS_GPIO_3, MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config(MSS_GPIO_4, MSS_GPIO_INPUT_MODE);
	MSS_GPIO_config( MSS_GPIO_5, MSS_GPIO_INPUT_MODE);


}
Beispiel #12
0
int main()
{
	//uint32_t count;

	MSS_GPIO_init();
	MSS_GPIO_config( MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config( MSS_GPIO_1, MSS_GPIO_OUTPUT_MODE);


	MSS_I2C_init(&g_mss_i2c1 , IMU_ADDRESS_WRITE, MSS_I2C_PCLK_DIV_256 );
	imu_init();

	//one timer tick is 10ns at 100Mhz
	MSS_TIM1_init( MSS_TIMER_PERIODIC_MODE);
	MSS_TIM1_enable_irq();
	MSS_TIM1_load_background(100000);
	MSS_TIM1_start();

	MSS_TIM2_init( MSS_TIMER_ONE_SHOT_MODE);







	while( 1 ) {

		//int16_t x_accl = imu_accl_x();
		//int16_t y_accl = imu_accl_y();
		//int16_t z_accl = imu_accl_z();



	    X_GYRO = imu_gyro_x();
	    Y_ACCL = imu_accl_y();
		//uint16_t y_gyro = imu_gyro_y();
		//uint16_t z_gyro = imu_gyro_z();


		//printf("Avg X: %f\r\n", avg_x);
		//printf("Accel X: %i\n\r", x_accl);
		//printf("Accel Y: %u\n\r", y_accl);
		//printf("Accel Z: %u\n\r", z_accl);

		//printf("Gyro X: %u\r\n", x_gyro);
		//printf("Gyro Y: %u\r\n", y_gyro);
		//printf("Gyro Z: %u\r\n", z_gyro);



		//150000 = 1.5ms pulse
		//1.49ms pulse = equilibrium point
		uint32_t pulsewidth_right = 150000 + (angle/90.0)*100000;
		uint32_t pulsewidth_left = 150000 - (angle/90.0)*100000;
		uint32_t period = 2000000;
		MSS_TIM2_load_immediate(period);
	    MSS_TIM2_start();

	    while (MSS_TIM2_get_current_value() > 0) {

	    	if (MSS_TIM2_get_current_value() > (period - pulsewidth_right))
	    		MSS_GPIO_set_output( MSS_GPIO_0, 1);
	    	else
	    		MSS_GPIO_set_output( MSS_GPIO_0, 0);

	    	if (MSS_TIM2_get_current_value() > (period - pulsewidth_left))
                MSS_GPIO_set_output( MSS_GPIO_1, 1);
            else
                MSS_GPIO_set_output( MSS_GPIO_1, 0);
	    }
	}

	return 0;
}
Beispiel #13
0
// caller must have called MSS_GPIO_init();
// because we don't want to re-init and change other gpio's setup by caller
void init_rgb_led(uint8_t _gpio_r, uint8_t _gpio_g, uint8_t _gpio_b){
	MSS_GPIO_config((gpio_r = _gpio_r), MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config((gpio_g = _gpio_g), MSS_GPIO_OUTPUT_MODE);
	MSS_GPIO_config((gpio_b = _gpio_b), MSS_GPIO_OUTPUT_MODE);
}
Beispiel #14
0
int_t main(void)
{
   error_t error;
   NetInterface *interface;
   OsTask *task;
   MacAddr macAddr;
#if (APP_USE_DHCP == DISABLED)
   Ipv4Addr ipv4Addr;
#endif
#if (APP_USE_SLAAC == DISABLED)
   Ipv6Addr ipv6Addr;
#endif

   //Update system core clock
   SystemCoreClockUpdate();

   //Initialize kernel
   osInitKernel();
   //Configure debug UART
   debugInit(115200);

   //Start-up message
   TRACE_INFO("\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n");
   TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__);
   TRACE_INFO("Target: A2F200M3F\r\n");
   TRACE_INFO("\r\n");

   //LED configuration
   MSS_GPIO_init();
   MSS_GPIO_config(MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_1, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_2, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_3, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_4, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_5, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_6, MSS_GPIO_OUTPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_7, MSS_GPIO_OUTPUT_MODE);

   //Clear LEDs
   MSS_GPIO_set_output(MSS_GPIO_0, 1);
   MSS_GPIO_set_output(MSS_GPIO_1, 1);
   MSS_GPIO_set_output(MSS_GPIO_2, 1);
   MSS_GPIO_set_output(MSS_GPIO_3, 1);
   MSS_GPIO_set_output(MSS_GPIO_4, 1);
   MSS_GPIO_set_output(MSS_GPIO_5, 1);
   MSS_GPIO_set_output(MSS_GPIO_6, 1);
   MSS_GPIO_set_output(MSS_GPIO_7, 1);

   //Initialize SW1 and SW2
   MSS_GPIO_config(MSS_GPIO_8, MSS_GPIO_INPUT_MODE);
   MSS_GPIO_config(MSS_GPIO_9, MSS_GPIO_INPUT_MODE);

   //Initialize LCD display
   OLED_init();
   OLED_contrast(OLED_CONTRAST_VAL);
   OLED_clear_display(BOTH_LINES);

   //Welcome message
   lcdSetCursor(0, 0);
   printf("FTP Client Demo");

   //TCP/IP stack initialization
   error = tcpIpStackInit();
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n");
   }

   //Configure the first Ethernet interface
   interface = &netInterface[0];

   //Set interface name
   tcpIpStackSetInterfaceName(interface, "eth0");
   //Set host name
   tcpIpStackSetHostname(interface, "FTPClientDemo");
   //Select the relevant network adapter
   tcpIpStackSetDriver(interface, &a2fxxxm3EthDriver);
   tcpIpStackSetPhyDriver(interface, &dp83848PhyDriver);
   //Set host MAC address
   macStringToAddr(APP_MAC_ADDR, &macAddr);
   tcpIpStackSetMacAddr(interface, &macAddr);

   //Initialize network interface
   error = tcpIpStackConfigInterface(interface);
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name);
   }

#if (IPV4_SUPPORT == ENABLED)
#if (APP_USE_DHCP == ENABLED)
   //Get default settings
   dhcpClientGetDefaultSettings(&dhcpClientSettings);
   //Set the network interface to be configured by DHCP
   dhcpClientSettings.interface = interface;
   //Disable rapid commit option
   dhcpClientSettings.rapidCommit = FALSE;

   //DHCP client initialization
   error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings);
   //Failed to initialize DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize DHCP client!\r\n");
   }

   //Start DHCP client
   error = dhcpClientStart(&dhcpClientContext);
   //Failed to start DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start DHCP client!\r\n");
   }
#else
   //Set IPv4 host address
   ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr);
   ipv4SetHostAddr(interface, ipv4Addr);

   //Set subnet mask
   ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr);
   ipv4SetSubnetMask(interface, ipv4Addr);

   //Set default gateway
   ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr);
   ipv4SetDefaultGateway(interface, ipv4Addr);

   //Set primary and secondary DNS servers
   ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr);
   ipv4SetDnsServer(interface, 0, ipv4Addr);
   ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr);
   ipv4SetDnsServer(interface, 1, ipv4Addr);
#endif
#endif

#if (IPV6_SUPPORT == ENABLED)
#if (APP_USE_SLAAC == ENABLED)
   //Get default settings
   slaacGetDefaultSettings(&slaacSettings);
   //Set the network interface to be configured
   slaacSettings.interface = interface;

   //SLAAC initialization
   error = slaacInit(&slaacContext, &slaacSettings);
   //Failed to initialize SLAAC?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize SLAAC!\r\n");
   }

   //Start IPv6 address autoconfiguration process
   error = slaacStart(&slaacContext);
   //Failed to start SLAAC process?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start SLAAC!\r\n");
   }
#else
   //Set link-local address
   ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr);
   ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID);

   //Set IPv6 prefix
   ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr);
   ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH);

   //Set global address
   ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr);
   ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID);

   //Set router
   ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr);
   ipv6SetRouter(interface, &ipv6Addr);

   //Set primary and secondary DNS servers
   ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr);
   ipv6SetDnsServer(interface, 0, &ipv6Addr);
   ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr);
   ipv6SetDnsServer(interface, 1, &ipv6Addr);
#endif
#endif

   //Create user task
   task = osCreateTask("User Task", userTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Create a task to blink the LED
   task = osCreateTask("Blink", blinkTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Start the execution of tasks
   osStartKernel();

   //This function should never return
   return 0;
}
Beispiel #15
0
int main(){
	pwm_init();
	MSS_GPIO_init();
	range_init();
	MSS_GPIO_config(MSS_GPIO_31, MSS_GPIO_OUTPUT_MODE);
	UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, 162, (DATA_8_BITS | NO_PARITY));

	uint8_t buff[BUFFER_SIZE];
	int offset = 0;
	size_t received;
	int joyx, joyy, cx, cy, start, fire;
	int startDown = 0;
	int mode = 0; // 0 for manual, 1 for automatic
	uint8_t tx[100];
	int txSize;
	firing = 0;
	curr_angle = 0;

	MSS_GPIO_set_output(MSS_GPIO_31, 0);

	/*while(1) {
		wheel2(255);
		//wheel4(255);
		//wheel2(-255);
		//wheel3(255);
		//wheel4(-255);
	}*/
	while (1) {
		while (!(received = UART_get_rx(&g_uart, buff+offset, sizeof(buff)-offset)));
		offset += received;
		//printf("Received: %d\n\r", received);
		if (buff[offset-1] == '\0') { // message fully received
			//printf("%s\n\r", buff);
			if (6 != sscanf(buff, "%d %d %d %d %d %d", &joyx, &joyy, &cx, &cy, &fire, &start)) {
				bzero(buff, BUFFER_SIZE);
				continue;
			}
			offset = 0;

			if (start && !startDown) {
				mode = !mode;
				startDown = 1;
			}
			if (!start && startDown)
				startDown = 0;

			joyx = joyx * .65;
			joyy = joyy * .65;

			if (joyx < 0)
				joyx -= 150;
			else if (joyx > 0)
				joyx += 150;
			if (joyy < 0)
				joyy -= 150;
			else if (joyy > 0)
				joyy += 150;

			printf("JoyX: %3d, JoyY: %3d, CX: %3d, CY: %3d, Fire: %d, Start: %d\n\r", joyx, joyy, cx, cy, fire, start);

			wheel1(joyy);
			wheel2(joyx);
			wheel3(joyy);
			wheel4(joyx);

			moveTurret(cy);

			if (fire && !firing) {
				start_gun();
			}

			if (firing && fire_counter <= FIRE_TIME)
				fire_counter++;
			if (!fire && firing && fire_counter >= FIRE_TIME)
				stop_gun();

		}
		else continue;
		txSize = sprintf(tx, "%d %d", mode, get_range()) + 1;
		UART_send(&g_uart, tx, txSize);
	}
	/*while(1){
		set_gun_angle(0);
		wheel1(-255);
    }*/
    return 0;
}