void cj_state_update() {
    /*The implement is plain update for simplicity. Kalman filter is not implemented yet*/
    float delta_time = TM_DELAY_Time()/1000.0 - prev_t;
    prev_t = TM_DELAY_Time();

    angles.a = angles.a + delta_time*angles_v.a;
    angles.b = angles.b + delta_time*angles_v.b;
    angles.c = angles.c + delta_time*angles_v.c;

    KB_MPU9150_ReadAll(&MPU9150_Data);
    angles_v.a = MPU9150_Data.Gyroscope_X - vcali.a;
    angles_v.b = MPU9150_Data.Gyroscope_Y - vcali.b;
    angles_v.c = MPU9150_Data.Gyroscope_Z - vcali.c;
}
Пример #2
0
Файл: led.c Проект: furhat/STM32
// Blink LED function 
void blink_LED(void const *argument) { 
	
#if 0	
	/* Reset counter to 0 */
	TM_DELAY_SetTime(0);
	while (1) {
		/* If time is more than 500ms */
		if (TM_DELAY_Time() >= 500) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			/* Toggle leds here */
			TM_DISCO_LedToggle(LED_RED | LED_GREEN);
		}
		/* Place your code here */
		/* Code here will be checked without any delay */
		/* Constantly */
	}
#endif
	
#if 1
 for (;;) { 
 //LED_On (); // Switch LED on 
	osDelay(1000);
	TM_DISCO_LedToggle(LED_RED | LED_GREEN);
 }
#endif

} 
Пример #3
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize onboard leds */
	TM_DISCO_LedInit();

	/* Reset counter to 0 */
	TM_DELAY_SetTime(0);
	while (1) {
		/* If time is more than 500ms */
		if (TM_DELAY_Time() >= 500) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			/* Toggle leds here */
			TM_DISCO_LedToggle(LED_RED | LED_GREEN);
		}
		/* Place your code here */
		/* Code here will be checked without any delay */
		/* Constantly */
	}
}
Пример #4
0
/* This function is used to periodically update LaserLock variables */
void LaserLock_Timer_Task(void* UserParameters) {
  uint32_t current_time=TM_DELAY_Time();
    for (int i=0;i<10;i++)
      if (current_time > Remote_Data_Array[i].rcv_system_time + LASER_LOCK_TIMEOUT) {
    	  Remote_Data_Array[i].laser=0;
        Laser_Control(i,LD_OFF);
        TM_BKPSRAM_Write8(i,0);
      }

}
Пример #5
0
/* Called when connection is closed */
void ESP8266_Callback_ClientConnectionClosed(ESP8266_t* ESP8266, ESP8266_Connection_t* Connection) {
	printf("Client connection closed, connection: %d; Total bytes received: %d; Content-Length header: %d\r\n",
		Connection->Number, Connection->TotalBytesReceived, Connection->ContentLength
	);
	
	/* Calculate time */
	time = TM_DELAY_Time() - time;
	
	/* Print time we need to get data back from server */
	printf("Time for data: %u ms; speed: %d kb/s\r\n", time, Connection->TotalBytesReceived / time);
}
Пример #6
0
int main(void) {
	uint16_t values[2] = {0, 0};
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init DAC channel 1 = PA4 */
	TM_DAC_Init(TM_DAC_Channel_1);
	
	/* Init DAC channel 2 = PA5 */
	TM_DAC_Init(TM_DAC_Channel_2);
	
	while (1) {
		/* Toggle ALL leds */
		if (TM_DELAY_Time() > 200) {	
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_ALL);
		}
		
		/* Increase channel 1 value */
		values[0]++;
		
		/* Decrease channel 2 value */
		values[1]--;
		
		/* Check if channel 1 is overflowed 12 bit and set it to zero */
		if (values[0] > 0x0FFF) {
			values[0] = 0;
		}
		
		/* Check if channel 2 is less than zero (overflow to 0xFFFF) and set to to max 12 bit value */
		if (values[1] > 0x0FFF) {
			values[1] = 0x0FFF;
		}
		
		/* Set DAC channel 1 = PA4 */
		TM_DAC_SetValue(TM_DAC_Channel_1, values[0]);
		
		/* Set DAC channel 2 = PA5 */
		TM_DAC_SetValue(TM_DAC_Channel_2, values[1]);
		
		/* Delay 1ms */
		Delayms(1);
	}
}
Пример #7
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* Initialize RTC with internal clock */
	TM_RTC_Init(TM_RTC_ClockSource_Internal);
	
	/* Set RTC to generate wakeup interrupt every 10 seconds */
	TM_RTC_Interrupts(TM_RTC_Int_10s);
	
	/* Set time to 0 */
	TM_DELAY_SetTime(0);
	
	while (1) {
		/* Toggle LEDs every 200ms */
		if (TM_DELAY_Time() >= 200000) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_GREEN);
			
			/* Increase counter */
			i++;
			
			/* After 20 toggles, put STM32F4 into sleep mode */
			if (i == 20) {
				/* Reset counter */
				i = 0;
				
				/* Sleep until interrupt occur */
				/* Also disable systick with "1" as parameter */
				/* Because systick makes interrupts and it will wakeup */
				/* device back after some ticks. This is useless */
				
				/* If you set parameter to "0", then this function will not */
				/* affect to Systick timer */
				TM_LOWPOWER_SleepUntilInterrupt(1);
				
				/* Toggle RED LED to indicate wakeup from sleep mode */
				TM_DISCO_LedToggle(LED_RED);
			}
		}
	}
}
Пример #8
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* Initialize RTC with internal clock */
	TM_RTC_Init(TM_RTC_ClockSource_Internal);
	
	/* Set RTC to generate wakeup interrupt every 10 seconds */
	TM_RTC_Interrupts(TM_RTC_Int_10s);
	
	/* Set time to 0 */
	TM_DELAY_SetTime(0);
	
	while (1) {
		/* Toggle LEDs every 200ms */
		if (TM_DELAY_Time() >= 200) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_GREEN);
			
			/* Increase counter */
			i++;
			
			/* After 20 toggles, put STM32F4 into STOP mode */
			if (i == 20) {
				/* Reset counter */
				i = 0;
				
				/* Stop STM32F4 */
				/* If you stop device, then you can wake him up with interrupt/event on EXTI line */
				
				/* Put it into STOP mode, allowing EXTI interrupts to wake him up */
				/* RTC will wake him up after 10 seconds */
				TM_LOWPOWER_StopUntilInterrupt();
				
				/* Toggle RED LED to indicate wakeup from stop mode */
				TM_DISCO_LedToggle(LED_RED);
			}
		}
	}
}
void recalculate_state() {
    //since it is not in motion, angular velocity is 0
    angles_v.a = 0;
    angles_v.b = 0;
    angles_v.c = 0;

    struct Cj_helper_float3 g;
    g.a = 0;
    g.b = 0;
    g.c = 0;

    struct Cj_helper_float3 n;
    n.a = 0;
    n.b = 0;
    n.c = 0;

    int num_of_itr = 1000;
    int i = 0;
    for (; i < num_of_itr; i++) {
	KB_MPU9150_ReadAll(&MPU9150_Data);

	g.a += MPU9150_Data.Accelerometer_X;
	g.b += MPU9150_Data.Accelerometer_Y;
	g.c += MPU9150_Data.Accelerometer_Z;

	n.a += MPU9150_Data.Magnetometer_X;
	n.b += MPU9150_Data.Magnetometer_Y;
	n.c += MPU9150_Data.Magnetometer_Z;
    }

    //get two angles from g vector
    g.a = g.a/num_of_itr;
    g.b = g.b/num_of_itr;
    g.c = g.c/num_of_itr;
    float g_abs = sqrt(g.a*g.a + g.b*g.b + g.c*g.c);

    angles.b = asin(g.a/g_abs);
    angles.c = asin(-g.b/(g_abs*cos(angles.b)));

    //get the last angle
    n.a = n.a/num_of_itr;
    n.b = n.b/num_of_itr;
    n.c = n.c/num_of_itr;
    float n_abs = sqrt(n.a*n.a+n.b*n.b+n.c*n.c);

    angles.a = acos(n.a/(n_abs*cos(angles.b)));

    prev_t = TM_DELAY_Time()/1000.0;
}
Пример #10
0
void ESP8266_Callback_ClientConnectionDataReceived(ESP8266_t* ESP8266, ESP8266_Connection_t* Connection, char* Buffer) {
	/* Data received from server back to client */
	printf("Data received from server on connection: %s; Number of bytes received: %d; %d / %d;\r\n",
		Connection->Name,
		Connection->BytesReceived,
		Connection->TotalBytesReceived,
		Connection->ContentLength
	);
	
	/* Print message when first packet */
	if (Connection->FirstPacket) {
		/* Start counting time */
		time = TM_DELAY_Time();
		
		/* Print first message */
		printf("This is first packet received. Content length on this connection is: %d\r\n", Connection->ContentLength);
	}
}
Пример #11
0
int main(void) {
	TM_AM2301_Data_t data;
	char str[50];
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LCD on F429-Discovery board */
	TM_ILI9341_Init();
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	TM_ILI9341_Fill(ILI9341_COLOR_ORANGE);
	TM_ILI9341_Puts(10, 10, "AM2301 (DHT21)\nsensor", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
	TM_ILI9341_Puts(90, 310, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
	
	/* Initialize sensor */
	TM_AM2301_Init();
	
	/* Reset time */
	TM_DELAY_SetTime(0);
	while (1) {
		/* Every 1 second */
		if (TM_DELAY_Time() > 1000000) {
			TM_DELAY_SetTime(0);
			/* Data valid */
			if (TM_AM2301_Read(&data) == TM_AM2301_OK) {
				/* Show on LCD */
				sprintf(str, "Humidity: %2.1f %%\nTemperature: %2.1f C", (float)data.Hum / 10, (float)data.Temp / 10);
				TM_ILI9341_Puts(10, 100, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
			}
		}
		/* Do other stuff constantly */
	}
}
Пример #12
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	while (1) {
		/* Each 500ms */
		if (TM_DELAY_Time() >= 500) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle LED */
			TM_DISCO_LedToggle(LED_ALL);
		}
	}
}
int cj_state_init() {
    //configure the sensor
    if (KB_MPU9150_Init(&MPU9150_Data, KB_MPU9150_Accelerometer_4G, KB_MPU9150_Gyroscope_500s) != KB_MPU9150_Result_Ok) {
	return 0;
    }

    //since it is not in motion, angular velocity is 0
    angles_v.a = 0;
    angles_v.b = 0;
    angles_v.c = 0;

    vcali.a = 0;
    vcali.b = 0;
    vcali.c = 0;

    struct Cj_helper_float3 g;
    g.a = 0;
    g.b = 0;
    g.c = 0;

    struct Cj_helper_float3 n;
    n.a = 0;
    n.b = 0;
    n.c = 0;

    int num_of_itr = 1000;
    int i = 0;
    for (; i < num_of_itr; i++) {
	KB_MPU9150_ReadAll(&MPU9150_Data);
	vcali.a += MPU9150_Data.Gyroscope_X;
	vcali.b += MPU9150_Data.Gyroscope_Y;
	vcali.c += MPU9150_Data.Gyroscope_Z;

	g.a += MPU9150_Data.Accelerometer_X;
	g.b += MPU9150_Data.Accelerometer_Y;
	g.c += MPU9150_Data.Accelerometer_Z;

	n.a += MPU9150_Data.Magnetometer_X;
	n.b += MPU9150_Data.Magnetometer_Y;
	n.c += MPU9150_Data.Magnetometer_Z;
    }

    //calibration
    vcali.a = vcali.a/num_of_itr;
    vcali.b = vcali.b/num_of_itr;
    vcali.c = vcali.c/num_of_itr;

    //get two angles from g vector
    g.a = g.a/num_of_itr;
    g.b = g.b/num_of_itr;
    g.c = g.c/num_of_itr;
    float g_abs = sqrt(g.a*g.a + g.b*g.b + g.c*g.c);

    angles.b = asin(g.a/g_abs);
    angles.c = asin(-g.b/(g_abs*cos(angles.b)));

    //get the last angle
    n.a = n.a/num_of_itr;
    n.b = n.b/num_of_itr;
    n.c = n.c/num_of_itr;
    float n_abs = sqrt(n.a*n.a+n.b*n.b+n.c*n.c);

    angles.a = acos(n.a/(n_abs*cos(angles.b)));

    prev_t = TM_DELAY_Time()/1000.0;

    return 1;
}
/* Internal functions */
static void TM_BUTTON_INT_CheckButton(TM_BUTTON_t* ButtonStruct) {
	uint32_t now, status;
	
	/* Read values */
	now = TM_DELAY_Time();
	status = TM_GPIO_GetInputPinValue(ButtonStruct->GPIOx, ButtonStruct->GPIO_Pin);
	
	/* First stage */
	if (ButtonStruct->State == BUTTON_STATE_START) {
		/* Check if pressed */
		if (status == ButtonStruct->GPIO_State) {
			/* Button pressed, go to stage BUTTON_STATE_START */
			ButtonStruct->State = BUTTON_STATE_DEBOUNCE;
			
			/* Save pressed time */
			ButtonStruct->StartTime = now;
		}
	}

	if (ButtonStruct->State == BUTTON_STATE_DEBOUNCE) {
		/* Button still pressed */
		/* Check for debounce */
		if (status == ButtonStruct->GPIO_State) {
			if (now > (ButtonStruct->StartTime + ButtonStruct->PressDebounceTime)) {
				/* Button debounce OK, Goto Normal Press */
				ButtonStruct->State = BUTTON_STATE_PRESSED;

				/* Try to call user function */
				if (ButtonStruct->ButtonHandler) {
					/* Call function callback */
					ButtonStruct->ButtonHandler(ButtonStruct, TM_BUTTON_PressType_OnPressed);
				}
			}
		} else if (status != ButtonStruct->GPIO_State) {
			/* Not pressed */
			/* It was bounce, start over */
			/* Go to state BUTTON_STATE_START */
			ButtonStruct->State = BUTTON_STATE_START;
		}
	}
	
	if (ButtonStruct->State == BUTTON_STATE_PRESSED) {
		/* Button still pressed */
		/* Check for long press */
		if (status == ButtonStruct->GPIO_State) {
			if (now > (ButtonStruct->StartTime + ButtonStruct->PressLongTime)) {
				/* Button pressed OK, call function */
				if (ButtonStruct->ButtonHandler) {
					/* Call function callback */
					ButtonStruct->ButtonHandler(ButtonStruct, TM_BUTTON_PressType_Long);
				}
				
				/* Go to stage BUTTON_STATE_WAITRELEASE */
				ButtonStruct->State = BUTTON_STATE_WAITRELEASE;
			}
		} else if (status != ButtonStruct->GPIO_State) {
			/* Not pressed */
			if (now > (ButtonStruct->StartTime + ButtonStruct->PressNormalTime)) {
				/* Button pressed OK, call function */
				if (ButtonStruct->ButtonHandler) {
					/* Call function callback */
					ButtonStruct->ButtonHandler(ButtonStruct, TM_BUTTON_PressType_Normal);
				}
				
				/* Go to stage BUTTON_STATE_WAITRELEASE */
				ButtonStruct->State = BUTTON_STATE_WAITRELEASE;
			} else {
				/* Go to state BUTTON_STATE_START */
				ButtonStruct->State = BUTTON_STATE_START;
			}
		} else {
			/* Go to state BUTTON_STATE_START */
			ButtonStruct->State = BUTTON_STATE_START;
		}
	}
	
	if (ButtonStruct->State == BUTTON_STATE_WAITRELEASE) {
		/* Wait till button released */
		if (status != ButtonStruct->GPIO_State) {
			/* Go to stage 0 again */
			ButtonStruct->State = BUTTON_STATE_START;
		}
	}
	
	/* Save current status */
	ButtonStruct->LastStatus = status;
}
Пример #15
0
int main(void) {
	TM_MPU6050_t MPU6050_Data0;
	TM_MPU6050_t MPU6050_Data1;
	uint8_t sensor1 = 0, sensor2 = 0;
	char str[120];
	
	/* Initialize system */
	SystemInit();

	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize USART, TX: PB6 */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Initialize MPU6050 sensor 0, address = 0xD0, AD0 pin on sensor is low */
	if (TM_MPU6050_Init(&MPU6050_Data0, TM_MPU6050_Device_0, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_250s) == TM_MPU6050_Result_Ok) {
		/* Display message to user */
		TM_USART_Puts(USART1, "MPU6050 sensor 0 is ready to use!\n");
		
		/* Sensor 1 OK */
		sensor1 = 1;
	}
	
	/* Initialize MPU6050 sensor 1, address = 0xD2, AD0 pin on sensor is high */
	if (TM_MPU6050_Init(&MPU6050_Data1, TM_MPU6050_Device_1, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_250s) == TM_MPU6050_Result_Ok) {
		/* Display message to user */
		TM_USART_Puts(USART1, "MPU6050 sensor 1 is ready to use!\n");
		
		/* Sensor 2 OK */
		sensor2 = 1;
	}
	
	while (1) {
		/* Every 500ms */
		if (TM_DELAY_Time() >= 500) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* If sensor 1 is connected */
			if (sensor1) {
				/* Read all data from sensor 1 */
				TM_MPU6050_ReadAll(&MPU6050_Data0);
				
				/* Format data */
				sprintf(str, "1. Accelerometer\n- X:%d\n- Y:%d\n- Z:%d\nGyroscope\n- X:%d\n- Y:%d\n- Z:%d\nTemperature\n- %3.4f\n\n\n",
					MPU6050_Data0.Accelerometer_X,
					MPU6050_Data0.Accelerometer_Y,
					MPU6050_Data0.Accelerometer_Z,
					MPU6050_Data0.Gyroscope_X,
					MPU6050_Data0.Gyroscope_Y,
					MPU6050_Data0.Gyroscope_Z,
					MPU6050_Data0.Temperature
				);
				
				/* Show to usart */
				TM_USART_Puts(USART1, str);
			}
			
			/* If sensor 2 is connected */
			if (sensor2) {
				/* Read all data from sensor 1 */
				TM_MPU6050_ReadAll(&MPU6050_Data1);
				
				/* Format data */
				sprintf(str, "2. Accelerometer\n- X:%d\n- Y:%d\n- Z:%d\nGyroscope\n- X:%d\n- Y:%d\n- Z:%d\nTemperature\n- %3.4f\n\n\n",
					MPU6050_Data1.Accelerometer_X,
					MPU6050_Data1.Accelerometer_Y,
					MPU6050_Data1.Accelerometer_Z,
					MPU6050_Data1.Gyroscope_X,
					MPU6050_Data1.Gyroscope_Y,
					MPU6050_Data1.Gyroscope_Z,
					MPU6050_Data1.Temperature
				);
				
				/* Show to usart */
				TM_USART_Puts(USART1, str);
			}
		}
	}
}
Пример #16
0
int main(void) {
	/* Variables used */
	TM_GPS_Data_t GPS_Data;
	TM_GPS_Result_t result, current;
	TM_GPS_Float_t GPS_Float;
	TM_GPS_Distance_t GPS_Distance;
	char buffer[40];
	uint8_t i;
	float temp;
	uint8_t iOff;
	
	/* Initialize system */
	SystemInit();
	
	/* Delay init */
	TM_DELAY_Init();
	
	/* Initialize leds */
	TM_DISCO_LedInit();
	
	/* Initialize GPS on 115200 baudrate */
	TM_GPS_Init(&GPS_Data, 115200);
	
	/* Initialize ili9341 LCD on STM32F429-Discovery board */
	TM_ILI9341_Init();
	/* Rotate LCD */
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	/* Go to the begginning of LCD */
	iOff = 0;
	
	/* Version 1.1 added */
	/* Set two test coordinates */
	/* from Ljubljana */
	GPS_Distance.Latitude1 = 46.050513;
	GPS_Distance.Longitude1 = 14.512873;
	/* to New York */
	GPS_Distance.Latitude2 = 40.711096;
	GPS_Distance.Longitude2 = -74.007529;
	
	/* Display location */
	TM_ILI9341_Puts(10, START_Y + 11 * iOff++, "Ljubljana -> New York", &TM_Font_7x10, 0x0000, 0xFFFF);
	
	/* Calculate distance and bearing between 2 pointes */
	TM_GPS_DistanceBetween(&GPS_Distance);
	
	/* Convert float number */
	TM_GPS_ConvertFloat(GPS_Distance.Distance, &GPS_Float, 1);
	sprintf(buffer, " - Distance: %d.%1d meters", GPS_Float.Integer, GPS_Float.Decimal);
	TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
	TM_GPS_ConvertFloat(GPS_Distance.Bearing, &GPS_Float, 3);
	sprintf(buffer, " - Bearing: %d.%03d degrees", GPS_Float.Integer, GPS_Float.Decimal);
	TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
	
	/* Delay 5s */
	Delayms(5000);
	
	/* Clear screen */
	TM_ILI9341_Fill(0xFFFF);
	
	/* Go to the begginning of LCD */
	iOff = 0;
	
	/* Reset counter */
	TM_DELAY_SetTime(0);
	while (1) {
		/* Update GPR data */
		/* Call this as faster as possible */
		result = TM_GPS_Update(&GPS_Data);
		/* If we didn't receive any useful data in the start */
		if (result == TM_GPS_Result_FirstDataWaiting && TM_DELAY_Time() > 3000) {
			/* If we didn't receive nothing within 3 seconds */
			TM_DELAY_SetTime(0);
			/* Display data on LCD */
			TM_ILI9341_Puts(10, START_Y + 11 * iOff++, "Check your GPS receiver!", &TM_Font_7x10, 0x0000, 0xFFFF);
		}
		/* If we have any unread data */
		if (result == TM_GPS_Result_NewData) {
			/* We received new packet of useful data from GPS */
			current = TM_GPS_Result_NewData;
			
			/* Go to the begginning of LCD */
			iOff = 0;
			
			/* Is GPS signal valid? */
			if (GPS_Data.Validity) {
				/* If you want to make a GPS tracker, now is the time to save your data on SD card */
				
				/* Toggle GREEN LED */
				TM_DISCO_LedToggle(LED_GREEN);
				
				/* We have valid GPS signal */
#ifndef GPS_DISABLE_GPGGA		
				/* Latitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Latitude, &GPS_Float, 6);
				sprintf(buffer, " - Latitude: %d.%d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Longitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Longitude, &GPS_Float, 6);
				sprintf(buffer, " - Longitude: %d.%d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Satellites in use */
				sprintf(buffer, " - Sats in use: %02d", GPS_Data.Satellites);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);	
				
				/* Current time */
				sprintf(buffer, " - UTC Time: %02d.%02d.%02d:%02d", GPS_Data.Time.Hours, GPS_Data.Time.Minutes, GPS_Data.Time.Seconds, GPS_Data.Time.Hundredths);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Fix: 0 = invalid, 1 = GPS, 2 = DGPS */
				sprintf(buffer, " - Fix: %d", GPS_Data.Fix);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);				
				
				/* Altitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Altitude, &GPS_Float, 6);
				sprintf(buffer, " - Altitude: %3d.%06d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);				
#endif

#ifndef GPS_DISABLE_GPRMC
				/* Current date */
				sprintf(buffer, " - Date: %02d.%02d.%04d", GPS_Data.Date.Date, GPS_Data.Date.Month, GPS_Data.Date.Year + 2000);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Current speed in knots */
				TM_GPS_ConvertFloat(GPS_Data.Speed, &GPS_Float, 6);
				sprintf(buffer, " - Speed in knots: %2d.%06d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Current speed in km/h */
				temp = TM_GPS_ConvertSpeed(GPS_Data.Speed, TM_GPS_Speed_KilometerPerHour);
				TM_GPS_ConvertFloat(temp, &GPS_Float, 6);
				sprintf(buffer, " - Speed in km/h: %2d.%06d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				TM_GPS_ConvertFloat(GPS_Data.Direction, &GPS_Float, 3);
				sprintf(buffer, " - Direction: %3d.%03d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
#endif

#ifndef GPS_DISABLE_GPGSA				
				/* Horizontal dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.HDOP, &GPS_Float, 2);
				sprintf(buffer, " - HDOP: %2d.%02d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Vertical dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.VDOP, &GPS_Float, 2);
				sprintf(buffer, " - VDOP: %2d.%02d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Position dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.PDOP, &GPS_Float, 2);
				sprintf(buffer, " - PDOP: %2d.%02d", GPS_Float.Integer, GPS_Float.Decimal);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);	
				
				/* Current fix mode in use */ 
				sprintf(buffer, " - Fix mode: %d", GPS_Data.FixMode);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
				
				/* Display IDs of satellites in use */
				sprintf(buffer, "Sats ids: ");
				for (i = 0; i < GPS_Data.Satellites; i++) {
					if (i < (GPS_Data.Satellites - 1)) {
						sprintf(buffer, "%s%d,", buffer, GPS_Data.SatelliteIDs[i]);
					} else {
						sprintf(buffer, "%s%d", buffer, GPS_Data.SatelliteIDs[i]);
					}	
				}
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);		
#endif
				
#ifndef GPS_DISABLE_GPGSV
				/* Satellites in view */
				sprintf(buffer, " - Satellites in view: %02d", GPS_Data.SatellitesInView);
				TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF);
#endif
			} else {
				/* Clear screen */
				if (iOff > 0) {
					iOff = 0;
					TM_ILI9341_Fill(0xFFFF);
				}
				
				/* Go to the beginning of LCD */
				iOff = 0;
				
				/* Toggle RED LED */
				TM_DISCO_LedToggle(LED_RED);
				
				/* GPS signal is not valid */
				TM_ILI9341_Puts(10, START_Y + 11 * iOff, "New received data haven't valid GPS signal!", &TM_Font_7x10, 0x0000, 0xFFFF);
			}
		} else if (result == TM_GPS_Result_FirstDataWaiting && current != TM_GPS_Result_FirstDataWaiting) {
			current = TM_GPS_Result_FirstDataWaiting;
			TM_ILI9341_Puts(10, START_Y + 11 * iOff++, "Waiting first data from GPS!", &TM_Font_7x10, 0x0000, 0xFFFF);
		} else if (result == TM_GPS_Result_OldData && current != TM_GPS_Result_OldData) {
			current = TM_GPS_Result_OldData;
			/* We already read data, nothing new was received from GPS */
		}
	}
}
Пример #17
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* Checks if reset was because of wakeup from standby */
	if (TM_LOWPOWER_StandbyReset()) {
		for (i = 0; i < 10; i++) {
			/* Toggle LED red to indicate this */
			TM_DISCO_LedToggle(LED_RED);
			/* Delay */
			Delayms(100);
		}
	}
	
	/* Initialize RTC with internal clock */
	TM_RTC_Init(TM_RTC_ClockSource_Internal);
	
	/* Set RTC to generate wakeup interrupt every 10 seconds */
	TM_RTC_Interrupts(TM_RTC_Int_10s);
	
	/* Enable wakeup pin, PA0 */
	TM_LOWPOWER_EnableWakeUpPin();
	
	/* Set time to 0 */
	TM_DELAY_SetTime(0);
	
	while (1) {
		/* Toggle LEDs every 200ms */
		if (TM_DELAY_Time() >= 200) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_GREEN);
			
			/* Increase counter */
			i++;
			
			/* After 20 toggles, put STM32F4 into STANDBY mode */
			if (i == 20) {
				/* Reset counter */
				i = 0;
				
				
				/* Put STM32F4 into standby mode */
				/* You can wake up MCU with rising edge on PA0 pin */
				/* Or with some special interrupts, like RTC, etc */
				TM_LOWPOWER_Standby();
				
				/* Toggle RED LED to indicate wakeup from STANDBY mode */
				/* This should never happen, because STM32F4 will reset after wakeup from STANDBY */
				TM_DISCO_LedToggle(LED_RED);
			}
		}
	}
}
Пример #18
0
int main(void) {
	TM_NRF24L01_Transmit_Status_t transmissionStatus;
	char str[40];
	
	//Initialize system
	SystemInit();
	
	//Initialize system and Delay functions
	TM_DELAY_Init();
	
	//Initialize onboard leds
	TM_DISCO_LedInit();
	
	//Initialize USART, TX: PB6, RX: PB7
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	//Initialize NRF24L01+ on channel 15 and 32bytes of payload
	//By default 2Mbps data rate and 0dBm output power
	//NRF24L01 goes to RX mode by default
	TM_NRF24L01_Init(15, 32);
	
	//Set 2MBps data rate and -18dBm output power
	TM_NRF24L01_SetRF(TM_NRF24L01_DataRate_2M, TM_NRF24L01_OutputPower_M18dBm);
	
	//Set my address, 5 bytes
	TM_NRF24L01_SetMyAddress(MyAddress);
	//Set TX address, 5 bytes
	TM_NRF24L01_SetTxAddress(TxAddress);
	
	//Reset counter
	TM_DELAY_SetTime(0);
	while (1) {
		//Every 2 seconds
		if (TM_DELAY_Time() > 2000000) {
			//Fill data with something
			sprintf((char *)dataOut, "abcdefghijklmnoszxABCDEFCBDA");
			//Display on USART
			TM_USART_Puts(USART1, "pinging: ");
			//Reset time, start counting microseconds
			TM_DELAY_SetTime(0);
			//Transmit data, goes automatically to TX mode
			TM_NRF24L01_Transmit(dataOut);
			
			TM_DISCO_LedOn(LED_PIN);
			//Wait for data to be sent
			do {
				transmissionStatus = TM_NRF24L01_GetTransmissionStatus();
			} while (transmissionStatus == TM_NRF24L01_Transmit_Status_Sending);
			TM_DISCO_LedOff(LED_PIN);
			
			//Go back to RX mode
			TM_NRF24L01_PowerUpRx();
			
			//Wait received data, wait max 100ms, if time is larger, than data was probably lost
			while (!TM_NRF24L01_DataReady() && TM_DELAY_Time() < 100000);
			
			//Format time
			sprintf(str, "%d us", TM_DELAY_Time());
			//Show ping time
			TM_USART_Puts(USART1, str);
			
			//Get data from NRF2L01+
			TM_NRF24L01_GetData(dataIn);
			
			//Check transmit status
			if (transmissionStatus == TM_NRF24L01_Transmit_Status_Ok) {
				//Transmit went OK
				TM_USART_Puts(USART1, ": OK\n\r");
			} else if (transmissionStatus == TM_NRF24L01_Transmit_Status_Lost) {
				//Message was LOST
				TM_USART_Puts(USART1, ": LOST\n\r");
			} else {
				//This should never happen
				TM_USART_Puts(USART1, ": SENDING\n\r");
			}
		}
	}
}
Пример #19
0
void TM_SNAKE_Start(void) {
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Turn off all leds */
	TM_DISCO_LedOff(LED_ALL);
	
	/* Initialize True random number generator */
	TM_RNG_Init();
	
	/* Initialize ILI9341 LCD */
	TM_ILI9341_Init();
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	/* Initialize USB HID Host for keyboard */
	TM_USB_HIDHOST_Init();
	
	/* Set default options */
	TM_SNAKE_SetFirstOptions();
	
	/* Set default values */
	TM_SNAKE_SetDefaultSnake();
	
	/* Prepare display */
	TM_SNAKE_PrepareDisplay();
	
	/* Generate random target */
	TM_SNAKE_GenerateTarget();
	
	/* Set time to 0 */
	TM_DELAY_SetTime(0);
	while (1) {
		/* Process USB HID host */
		TM_USB_HIDHOST_Process();
		
		/* Check for timeout, move snake here */
		if (TM_DELAY_Time() >= Settings.Millis && !Settings.Pause && !GameOver) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Get new direction value */
			Snake.Direction = Snake1.Direction;
			
			/* Get last x/y value from snake array = snake head */
			Snake_Head[0] = Snake.Snake[Snake.LastIndex][0];
			Snake_Head[1] = Snake.Snake[Snake.LastIndex][1];
			
			/* Store last value before update */
			Snake_Head_Last[0] = Snake_Head[0];
			Snake_Head_Last[1] = Snake_Head[1];
			
			if (!Snake_FirstTime) {
				/* Move snake */
				switch (Snake.Direction) {
					case SNAKE_DIRECTION_LEFT:
						Snake_Head[0] -= 1;
						break;
					case SNAKE_DIRECTION_RIGHT:
						Snake_Head[0] += 1;
						break;
					case SNAKE_DIRECTION_UP:
						Snake_Head[1] -= 1;
						break;
					case SNAKE_DIRECTION_DOWN:
						Snake_Head[1] += 1;
						break;
					default:
						break;
				}
			}
			
			/* Overflow is activated */
			if (Settings.Overflow) {
				/* Check X */
				if (Snake_Head[0] == -1) {
					Snake_Head[0] = SNAKE_PIXELS - 1;
				} else if (Snake_Head[0] == SNAKE_PIXELS) {
					Snake_Head[0] = 0;
				}
				/* Check Y */
				if (Snake_Head[1] == -1) {
					Snake_Head[1] = SNAKE_PIXELS - 1;
				} else if (Snake_Head[1] == SNAKE_PIXELS) {
					Snake_Head[1] = 0;
				}
			} else {
				/* Check walls */
				if (
					Snake_Head[0] == -1 ||
					Snake_Head[0] == SNAKE_PIXELS ||
					Snake_Head[1] == -1 ||
					Snake_Head[1] == SNAKE_PIXELS
				) {
					/* We hit the wall somewhere */
					GameOver = 1;
				}
			}
					
			if (!Snake_FirstTime) {
				/* Clear first value from array = snake foot */
				TM_SNAKE_DeleteFromArray(0, Snake_Foot);
				
				/* Check if snake hit itself */
				if (TM_SNAKE_MatchesSnakeLocations(Snake_Head)) {
					/* Set gameover flag */
					GameOver = 1;
				}
			}
			
			/* Check if target is reached */
			if (
				!GameOver &&
				Snake_Head[0] == Snake_Food[0] &&
				Snake_Head[1] == Snake_Food[1]
			) {
				/* Add new value to the array, increase snake */
				TM_SNAKE_AddToArray(Snake_Head);
				
				/* Increase counter for snake hits */
				Snake.Hits++;
				
				/* Generate new target */
				TM_SNAKE_GenerateTarget();
			}
			
			if (!GameOver) {
				if (!Snake_FirstTime) {
					/* Add new value to the array = new snake head */
					TM_SNAKE_AddToArray(Snake_Head);
				}
				
				/* Clear pixel on LCD for foot */
				/* First clear foot, maybe is new head on the same position */
				TM_SNAKE_DrawPixel(Snake_Foot[0], Snake_Foot[1], 0);
				
				/* Draw pixel on LCD for new head position with head color */
				TM_SNAKE_DrawPixel(Snake_Head[0], Snake_Head[1], 3);
				/* Draw new pixel for the second pixel after head with new color to delete head color */
				TM_SNAKE_DrawPixel(Snake_Head_Last[0], Snake_Head_Last[1], 1);
			}
			
			
			/* Clear flag if needed */
			if (Snake_FirstTime) {
				Snake_FirstTime = 0;
			}
		}
		
		if (GameOver) {
			/* Check flag */
			if (!GameOverDisplay) {
				/* Set flag */
				GameOverDisplay = 1;
				
				/* Show content to user */
				TM_ILI9341_Puts(88, 120, "Game\nOVER", &TM_Font_16x26, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLACK);
				TM_ILI9341_Puts(28, 180, "Press 'r' to start again!!", &TM_Font_7x10, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLACK);
			}
		} else {
			/* Clear flag */
			GameOverDisplay = 0;
		}
		
		/* Check if connected device is keyboard */
		if (TM_USB_HIDHOST_Device() == TM_USB_HIDHOST_Result_KeyboardConnected) {
			/* Green LED ON */
			TM_DISCO_LedOn(LED_GREEN);
			
			/* Read keyboard data */
			TM_USB_HIDHOST_ReadKeyboard(&Keyboard);
			
			/* If any buttons active */
			if (Keyboard.ButtonStatus == TM_USB_HIDHOST_Button_Pressed) {
				/* Check pressed button and do actions */
				switch ((uint8_t)Keyboard.Button) {
					case SNAKE_KEY_LEFT:
						/* Change direction if possible */
						if (
							Snake.Direction == SNAKE_DIRECTION_UP ||
							Snake.Direction == SNAKE_DIRECTION_DOWN ||
							Snake.Direction == SNAKE_DIRECTION_LEFT
						) {
							/* Disable pause mode */
							Settings.Pause = 0;
							/* Set direction */
							Snake1.Direction = SNAKE_DIRECTION_LEFT;
						}
						break;
					case SNAKE_KEY_RIGHT:
						/* Change direction if possible */
						if (
							Snake.Direction == SNAKE_DIRECTION_UP ||
							Snake.Direction == SNAKE_DIRECTION_DOWN ||
							Snake.Direction == SNAKE_DIRECTION_RIGHT
						) {
							/* Disable pause mode */
							Settings.Pause = 0;
							/* Set direction */
							Snake1.Direction = SNAKE_DIRECTION_RIGHT;
						}
						break;
					case SNAKE_KEY_UP:
						/* Change direction if possible */
						if (
							Snake.Direction == SNAKE_DIRECTION_LEFT ||
							Snake.Direction == SNAKE_DIRECTION_RIGHT ||
							Snake.Direction == SNAKE_DIRECTION_UP
						) {
							/* Disable pause mode */
							Settings.Pause = 0;
							/* Set direction */
							Snake1.Direction = SNAKE_DIRECTION_UP;
						}
						break;
					case SNAKE_KEY_DOWN:
						/* Change direction if possible */
						if (
							Snake.Direction == SNAKE_DIRECTION_LEFT ||
							Snake.Direction == SNAKE_DIRECTION_RIGHT ||
							Snake.Direction == SNAKE_DIRECTION_DOWN
						) {
							/* Disable pause mode */
							Settings.Pause = 0;
							/* Set direction */
							Snake1.Direction = SNAKE_DIRECTION_DOWN;
						}
						break;
					case SNAKE_KEY_SPEED_UP:
						/* Increase speed if possible */
						TM_SNAKE_SpeedUp();
						break;
					case SNAKE_KEY_SPEED_DOWN:
						/* Decrease speed if possible */
						TM_SNAKE_SpeedDown();
						break;
					case SNAKE_KEY_PAUSE:
						/* Toggle pause */
						if (Settings.Pause) {
							Settings.Pause = 0;
						} else {
							Settings.Pause = 1;
						}
						break;
					case SNAKE_KEY_RESET:
						/* Draw snake area */
						TM_SNAKE_DrawArea();
						/* Set default snake, leave as it was before */
						TM_SNAKE_SetDefaultSnake();
						/* Generate random target */
						TM_SNAKE_GenerateTarget();
						/* Disable gameover */
						GameOver = 0;
						/* Reset first time flag */
						Snake_FirstTime = 1;
						break;
					case SNAKE_KEY_OVERFLOW:
						/* Toggle overflow mode */
						if (Settings.Overflow) {
							Settings.Overflow = 0;
						} else {
							Settings.Overflow = 1;
						}
						break;
					default:
						break;
				}
			}
		} else {
			/* Green LED OFF */
			TM_DISCO_LedOff(LED_GREEN);
		}
		
		/* Update LCD with changed settings */
		
		/* Check overflow */
		if (Settings1.Overflow != Settings.Overflow || Settings1.Speed != Settings.Speed) {
			/* Save new */
			Settings1.Overflow = Settings.Overflow;
			/* Save new */
			Settings1.Speed = Settings.Speed;
			
			/* Display game mode and speed */
			sprintf(Buffer, "Mode:%4d; Speed: %2d/%2d", Settings.Overflow, Settings.Speed, SNAKE_SPEED_MAX);
			TM_ILI9341_Puts(10, SNAKE_TEXT_LINE1, Buffer, &TM_Font_7x10, 0x0000, SNAKE_COLOR_MAIN_BCK);
		}
		/* Check snake hits */
		if (Snake1.Hits != Snake.Hits) {
			/* Save new */
			Snake1.Hits = Snake.Hits;
			
			/* Display Speed */
			sprintf(Buffer, "Hits:%4d; Score: %5d", Snake.Hits, (2 - Settings.Overflow) * Snake.Hits * Settings.Speed);
			TM_ILI9341_Puts(10, SNAKE_TEXT_LINE2, Buffer, &TM_Font_7x10, 0x0000, SNAKE_COLOR_MAIN_BCK);
		}
	}
}
Пример #20
0
GUI_TIMER_TIME GUI_X_GetTime(void) {
	/* Return current time */
	return TM_DELAY_Time();
}
Пример #21
0
int main(void) {
	/* Variables used */
	TM_GPS_Data_t GPS_Data;
	TM_GPS_Result_t result, current;
	TM_GPS_Float_t GPS_Float;
	TM_GPS_Distance_t GPS_Distance;
	char buffer[40];
	uint8_t i;
	float temp;
	
	/* Initialize system */
	SystemInit();
	
	/* Delay init */
	TM_DELAY_Init();
	
	/* Initialize GPS on 115200 baudrate */
	TM_GPS_Init(&GPS_Data, 115200);
	
	/* Initialize USART3 for debug */
	/* TX = PB10 */
	TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
	
	/* Version 1.1 added */
	/* Set two test coordinates */
	GPS_Distance.Latitude1 = 48.300215;
	GPS_Distance.Longitude1 = -122.285903;
	GPS_Distance.Latitude2 = 45.907813;
	GPS_Distance.Longitude2 = 56.659407;
	
	/* Calculate distance and bearing between 2 pointes */
	TM_GPS_DistanceBetween(&GPS_Distance);
	/* Convert float number */
	TM_GPS_ConvertFloat(GPS_Distance.Distance, &GPS_Float, 6);
	sprintf(buffer, "Distance is: %d.%06d meters\n", GPS_Float.Integer, GPS_Float.Decimal);
	TM_USART_Puts(USART3, buffer);
	TM_GPS_ConvertFloat(GPS_Distance.Bearing, &GPS_Float, 6);
	sprintf(buffer, "Bearing is: %d.%06d degrees\n\n", GPS_Float.Integer, GPS_Float.Decimal);
	TM_USART_Puts(USART3, buffer);
	
	/* Reset counter */
	TM_DELAY_SetTime(0);
	while (1) {
		/* Update GPR data */
		/* Call this as faster as possible */
		result = TM_GPS_Update(&GPS_Data);
		/* If we didn't receive any useful data in the start */
		if (result == TM_GPS_Result_FirstDataWaiting && TM_DELAY_Time() > 3000000) {
			/* If we didn't receive nothing within 3 seconds */
			TM_DELAY_SetTime(0);
			/* Display data on USART */
			TM_USART_Puts(USART3, "\nNothing received after 3 seconds. Is your GPS connected and baudrate set correct?\n");
			TM_USART_Puts(USART3, "Most GPS receivers has by default 9600 baudrate and 1Hz refresh rate. Check your settings!\n\n");
		}
		/* If we have any unread data */
		if (result == TM_GPS_Result_NewData) {
			/* We received new packet of useful data from GPS */
			current = TM_GPS_Result_NewData;
			
			/* Is GPS signal valid? */
			if (GPS_Data.Validity) {
				/* If you want to make a GPS tracker, not is the time to save your data on SD card */
				
				/* We have valid GPS signal */
				TM_USART_Puts(USART3, "New received data have valid GPS signal\n");
				TM_USART_Puts(USART3, "---------------------------------------\n");
#ifndef GPS_DISABLE_GPGGA
				/* GPGGA data */
				TM_USART_Puts(USART3, "GPGGA statement:\n");
				
				/* Latitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Latitude, &GPS_Float, 6);
				sprintf(buffer, " - Latitude: %d.%d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
				
				/* Longitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Longitude, &GPS_Float, 6);
				sprintf(buffer, " - Longitude: %d.%d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
				
				/* Satellites in use */
				sprintf(buffer, " - Sats in use: %02d\n", GPS_Data.Satellites);
				TM_USART_Puts(USART3, buffer);	
				
				/* Current time */
				sprintf(buffer, " - UTC Time: %02d.%02d.%02d:%02d\n", GPS_Data.Time.Hours, GPS_Data.Time.Minutes, GPS_Data.Time.Seconds, GPS_Data.Time.Hundredths);
				TM_USART_Puts(USART3, buffer);
				
				/* Fix: 0 = invalid, 1 = GPS, 2 = DGPS */
				sprintf(buffer, " - Fix: %d\n", GPS_Data.Fix);
				TM_USART_Puts(USART3, buffer);				
				
				/* Altitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Altitude, &GPS_Float, 6);
				sprintf(buffer, " - Altitude: %3d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);				
#endif
#ifndef GPS_DISABLE_GPRMC
				/* GPRMC data */
				TM_USART_Puts(USART3, "GPRMC statement:\n");
				
				/* Current date */
				sprintf(buffer, " - Date: %02d.%02d.%04d\n", GPS_Data.Date.Date, GPS_Data.Date.Month, GPS_Data.Date.Year + 2000);
				TM_USART_Puts(USART3, buffer);
				
				/* Current speed in knots */
				TM_GPS_ConvertFloat(GPS_Data.Speed, &GPS_Float, 6);
				sprintf(buffer, " - Speed in knots: %d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
				
				/* Current speed in km/h */
				temp = TM_GPS_ConvertSpeed(GPS_Data.Speed, TM_GPS_Speed_KilometerPerHour);
				TM_GPS_ConvertFloat(temp, &GPS_Float, 6);
				sprintf(buffer, " - Speed in km/h: %d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
				
				TM_GPS_ConvertFloat(GPS_Data.Direction, &GPS_Float, 3);
				sprintf(buffer, " - Direction: %3d.%03d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
#endif
#ifndef GPS_DISABLE_GPGSA
				/* GPGSA data */
				TM_USART_Puts(USART3, "GPGSA statement:\n");
				
				/* Horizontal dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.HDOP, &GPS_Float, 2);
				sprintf(buffer, " - HDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
				
				/* Vertical dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.VDOP, &GPS_Float, 2);
				sprintf(buffer, " - VDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);
				
				/* Position dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.PDOP, &GPS_Float, 2);
				sprintf(buffer, " - PDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				TM_USART_Puts(USART3, buffer);	
				
				/* Current fix mode in use */ 
				sprintf(buffer, " - Fix mode: %d\n", GPS_Data.FixMode);
				TM_USART_Puts(USART3, buffer);
				
				/* Display IDs of satellites in use */
				TM_USART_Puts(USART3, "- ID's of used satellites: ");
				for (i = 0; i < GPS_Data.Satellites; i++) {
					if (i < (GPS_Data.Satellites - 1)) {
						sprintf(buffer, "%d,", GPS_Data.SatelliteIDs[i]);
					} else {
						sprintf(buffer, "%d\n", GPS_Data.SatelliteIDs[i]);
					}
					TM_USART_Puts(USART3, buffer);
				}
				
#endif
#ifndef GPS_DISABLE_GPGSV
				/* GPGSV data */
				TM_USART_Puts(USART3, "GPGSV statement:\n");
				
				/* Satellites in view */
				sprintf(buffer, " - Satellites in view: %d\n", GPS_Data.SatellitesInView);
				TM_USART_Puts(USART3, buffer);	
#endif
				TM_USART_Puts(USART3, "---------------------------------------\n");
			} else {
				/* GPS signal is not valid */
				TM_USART_Puts(USART3, "New received data haven't valid GPS signal!\n");
			}
		} else if (result == TM_GPS_Result_FirstDataWaiting && current != TM_GPS_Result_FirstDataWaiting) {
			current = TM_GPS_Result_FirstDataWaiting;
			TM_USART_Puts(USART3, "Waiting first data from GPS!\n");
		} else if (result == TM_GPS_Result_OldData && current != TM_GPS_Result_OldData) {
			current = TM_GPS_Result_OldData;
			/* We already read data, nothing new was received from GPS */
		}
	}
}