Ejemplo n.º 1
0
Archivo: led.c Proyecto: 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

} 
Ejemplo n.º 2
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 */
	}
}
Ejemplo n.º 3
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);
			}
		}
	}
}
Ejemplo n.º 4
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);
			}
		}
	}
}
Ejemplo n.º 5
0
int main(void)
{
  SystemInit();						// initialize MCU clocks and registers
  TM_DELAY_Init();					// initialize Delay library
  TM_DELAY_SetTime(0);				// Reset couter for systime
  Laser_GPIO_Conf();				// configure GPIO for laser control (to be able to enable/disable lasers via software
  TM_BKPSRAM_Init();				// initialize BKP RAM access library
  Laser_Update();			// load laser statuses saved in BKP RAM
  TM_USART_Init(OUTPUT_USART, OUTPUT_USART_PINS, OUTPUT_USART_SPEED);		// initialize UART used for collected Data output
  TM_USART_Init(MENU_USART, MENU_USART_PINS, MENU_USART_SPEED);				// initialize UART used for configuration
  TM_RTC_Init(TM_RTC_ClockSource_External);									// initialize RTC library
  TM_GPIO_Init(GPIOD, GPIO_Pin_8, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low); // configure GPIO for GSM status indication (RED LED)
  TM_GPIO_Init(GPIOD, GPIO_Pin_9, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low); // configure GPIO for GSM status indication (GREEN LED)
  Laser_ADC_Init();					// initialize ADC peripherals
  Menu_Init();						// initialize CLI library
  sfpInit();						// configure GPIO for SFP modules
  gsm_Init();						// initialize GSM module


  /* configure and initialize Ethernet hardware and LwIP stack */

  ETH_BSP_Config();					// configure ETH GPIOs
  printf("Ethernet MAC and PHY configured successfully!\n");
  LwIP_Init();						// start LwIP stack
  printf("LwIP stack initialized successfully!\n");
  UDP_Server_Init();				// start UDP Server
  printf("UDP Server initialized successfully!\n");

  //start periodic tasks

  /* GSM Status update "task" */
  GSM_Status_Update_Timer = TM_DELAY_TimerCreate(GSM_CHECK_INTERVAL, 1, 1, GSM_Status_Update_Timer_Task, NULL);
  printf("GSM status check task created!\n");
  /* Print results from remote devices "task" */
  Print_Results_Timer = TM_DELAY_TimerCreate(DATA_OUT_INTERVAL, 1, 1, Print_Results_Timer_Task, NULL);
  printf("Print collected data task created!\n");
  /* LaserLock status update "task" */
  LaserLock_Timer = TM_DELAY_TimerCreate(1000, 1, 1, LaserLock_Timer_Task, NULL);
  printf("Laser lock check task created!\n");

  while (1) {
	  /* CLI menu update */
	  Menu_Update();
      /* check if any packet received */
	  if (ETH_CheckFrameReceived())
	  {
		  /* process received ethernet packet */
		  LwIP_Pkt_Handle();
	  }
    /* handle periodic timers for LwIP */
    LwIP_Periodic_Handle(LocalTime);
    /* update laser statuses */
    Laser_Update();
    /* remove SMS messages which were read by system */
    delete_read_gsm_messages();
  }
} 
Ejemplo n.º 6
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 */
	}
}
Ejemplo n.º 7
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);
		}
	}
}
Ejemplo n.º 8
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Delay init */
	TM_DELAY_Init();
	
	/* Initialize GPS on 115200 baudrate */
	TM_GPS_Init(&GPS_Data, 115200);
	
	/* Initialize USART2 for debug */
	/* TX = PA2 */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Register custom GPGxx statements */
	
	/* $GPRMC statement, term number 7 = Speed over ground in knots */
	GPRMC = TM_GPS_AddCustom(&GPS_Data, "$GPRMC", 7);
	/* $GPGLL statement, term number 1 = Current latitude */
	GPGLL = TM_GPS_AddCustom(&GPS_Data, "$GPGLL", 1);
	/* $GPGSA statement, term number 1 = M = Manual, forced to operate in 2D or 3D A=Automatic, 3D/2D */
	GPGSA = TM_GPS_AddCustom(&GPS_Data, "$GPGSA", 1);
	/* Add here more custom tags you want */
	/* ... */
	
	/* 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 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, now is the time to save your data on SD card */
				
				/* We have valid GPS signal */
				printf("New received data have valid GPS signal\n");
				printf("---------------------------------------\n");

				/* We have all data from GPS_Data structure valid, you can do here what you want */
				/* We will in this example show only custom data to user */
			
				/* Print custom statements */
				printf("Custom statements defined by user:\n");
				
				/* Go through all custom statements */
				for (i = 0; i < GPS_Data.CustomStatementsCount; i++) {
					printf(" - Statement: %s; TermNumber: %d; Value: %s\n",
						GPS_Data.CustomStatements[i]->Statement,  /*!< Statement value */
						GPS_Data.CustomStatements[i]->TermNumber, /*!< Term number */
						GPS_Data.CustomStatements[i]->Value       /*!< Value from GPS receiver */
					);
				}
				
				/* You can do it this way too for all your custom statements separatelly */
				printf(" - Statement2: %s; TermNumber: %d; Value: %s\n",
					GPRMC->Statement, GPRMC->TermNumber, GPRMC->Value
				);
				
				printf("---------------------------------------\n");
			} else {
				/* GPS signal is not valid */
				printf("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;
			printf("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 */
		}
	}
}
Ejemplo n.º 9
0
int main(void) {
		char str[100];

//		char buffer1[100];
		
//	/* Free and total space */
//	uint32_t total, free;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delays */
	TM_DELAY_Init();
	/* Enable watchdog, 4 seconds before timeout */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_8s)) {
		/* Report to user */
		//printf("Reset occured because of Watchdog\n");
	}	
	/* Reset counter to 0 */
	TM_DELAY_SetTime(0);
	/* init DTMF*/
	TM_GPIO_Init(DTMF_BIT0_PORT, DTMF_BIT0_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	TM_GPIO_Init(DTMF_BIT1_PORT, DTMF_BIT1_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	TM_GPIO_Init(DTMF_BIT2_PORT, DTMF_BIT2_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	TM_GPIO_Init(DTMF_BIT3_PORT, DTMF_BIT3_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	/* DTMF*/
		if (TM_EXTI_Attach(DFMF_BIT4_PORT, DTMF_BIT4_PIN, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat DFMF_BIT4\n");
	}
	
	/*init interrup INPUT*/
		if (TM_EXTI_Attach(W1_D0_PORT, W1_D0_PIN, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W1_D0\n");
	}
		if (TM_EXTI_Attach(W1_D1_PORT, W1_D1_PIN, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W1_D1\n");
	}
		if (TM_EXTI_Attach(W2_D1_PORT, W2_D1_PIN, TM_EXTI_Trigger_Falling) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W2_D1\n");
	}
		if (TM_EXTI_Attach(W2_D0_PORT, W2_D0_PIN, TM_EXTI_Trigger_Falling) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W2_D0\n"); // W2D0
	}
	/*init SWADD*/
	TM_GPIO_Init(ADD_BIT0_PORT, ADD_BIT0_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);	
	TM_GPIO_Init(ADD_BIT1_PORT, ADD_BIT1_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT2_PORT, ADD_BIT2_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT3_PORT, ADD_BIT3_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT4_PORT, ADD_BIT4_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT5_PORT, ADD_BIT5_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT6_PORT, ADD_BIT6_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT7_PORT, ADD_BIT7_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	/* init OUTPUT*/
	TM_GPIO_Init(RELAY_DK1_PORT, RELAY_DK1_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
	TM_GPIO_Init(RELAY_DK2_PORT, RELAY_DK2_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
	TM_GPIO_Init(RELAY_DK3_PORT, RELAY_DK3_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
	TM_GPIO_Init(RELAY_DK4_PORT, RELAY_DK4_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
/* Initialize USART6 at 115200 baud, TX: PC6, RX: PC7 , COM 1 - RFID1 gan cong tac nguon*/ 
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);
/* Initialize USART3 at 115200 baud, TX: PD8, RX: PD9 ,	COM 2 -RFID 2 gan ethernet*/
	TM_USART_Init(USART3, TM_USART_PinsPack_3, 115200);
/* Initialize USART1 at 115200 baud, TX: PA9, RX: PA10, CONG 485 */
	TM_USART_Init(USART1, TM_USART_PinsPack_1, 9600);
	/* Initialize USART2, with custom pins */					// COM 3 extension PC
	//TM_USART_Init(USART2, TM_USART_PinsPack_Custom,9600);
	TM_USART_Init(USART2, TM_USART_PinsPack_2,9600);
	
/* int DIR 485 set = send , reset = recvice*/ 
	TM_GPIO_Init(CCU_DIR_PORT, CCU_DIR_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_High);
	TM_GPIO_SetPinHigh(CCU_DIR_PORT,CCU_DIR_PIN);
/* Init 2 custom timers */
/* Timer1 has reload value each 500ms, enabled auto reload feature and timer is enabled */
	CustomTimer1 = TM_DELAY_TimerCreate(500, 1, 1, CustomTIMER1_Task, NULL);
	/* Timer1 has reload value each 1000ms, enabled auto reload feature and timer is enabled */
	CustomTimer2 = TM_DELAY_TimerCreate(100, 1, 1, CustomTIMER2_Task, NULL);
/* Init LCD*/
		TM_GPIO_Init(HD44780_RW_PORT, HD44780_RW_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
		TM_GPIO_SetPinLow(HD44780_RW_PORT,HD44780_RW_PIN);

		read_sw_add();
		timeout = value_dip;
		memset(str,'\0',0);
    //Initialize LCD 20 cols x 4 rows
    TM_HD44780_Init(16, 4);
    //Save custom character on location 0 in LCD
    TM_HD44780_CreateChar(0, &customChar[0]);    
    //Put string to LCD
    TM_HD44780_Puts(0, 0, "STM32F407VET\n\rCreartbyR&D-TIS"); /* 0 dong 1, 1 dong 2*/
    TM_HD44780_Puts(0, 2, "Welcome");
		Delayms(1000);
		TM_HD44780_Clear();
		sprintf(str,"Timer out %d", timeout);
		TM_HD44780_Puts(0, 0,str);
		Delayms(1000);
		TM_HD44780_Clear();
		TM_HD44780_Puts(0, 0,"----TIS8 PRO----");
		//TM_USART_Puts(USART3, "Welcome2");

	/*creat by duc*/
		TM_WATCHDOG_Reset();

//		TM_USART_BufferEmpty(USART3);
//		TM_USART_BufferEmpty(USART6);
		flag_RFID2=0;	
		flag_RFID1=0;
	/*end by duc*/
	while (1) {
/*process 485*/
	if(flag_485){
	flag_485=0;
	if(LEDStatus==0) TM_USART_Puts(USART1, "/LED000>\r\n");
	if(LEDStatus==1) TM_USART_Puts(USART1, "/LED001>\r\n");
	if(LEDStatus==2) TM_USART_Puts(USART1, "/LED002>\r\n");
	}	

/* xu li W1D0 - dk1*/
	if(flag_W1D0){
		turn_on_dk1();
		//flag_W1D0=0;
	}
/* xu li W1D1 - dk2*/
	if(flag_W1D1){
		turn_on_dk2();
		//flag_W1D1=0;
	}
	//TM_WATCHDOG_Reset();
//		/*end*/


if(Process!=1)
		TM_HD44780_Puts(0, 2,"Wait for Card"); /* 0 dong 1, 1 dong 2*/
if(flag_RFID1==1)
		{	
		
		Process=1;
		IDCAR1[0]=BufferCom1[4];
		IDCAR1[1]=BufferCom1[5];
		IDCAR1[2]=BufferCom1[6];
		IDCAR1[3]=BufferCom1[7];
		IDCAR1[4]=BufferCom1[8];
		IDCAR1[5]=BufferCom1[9];
		IDCAR1[6]=BufferCom1[10];
		
		if(BufferCom1[1]==0x08)	
			{
			sprintf(UID1,"%02x %02x %02x %02x,1",IDCAR1[0],IDCAR1[1],IDCAR1[2],IDCAR1[3]);
			}
		if(BufferCom1[1]==0x0B) 
			{
			sprintf(UID1,"%02x %02x %02x %02x %02x %02x %02x,1",IDCAR1[0],IDCAR1[1],IDCAR1[2],IDCAR1[3],IDCAR1[4],IDCAR1[5],IDCAR1[6]);
			}
		TM_HD44780_Puts(0, 2,"Waiting PC..."); /* 0 dong 1, 1 dong 2*/
				if(check_vip(UID1)){
			flag_PC=1;
			flag_R11=1;
			timerdk1 =0;
			Process=0;
		}
		else{
		if(Process)TM_USART_Puts(USART2,UID1);
		}
		WaitPC(200);
		flag_RFID1=0;
		if(flag_PC)
		{
			TM_HD44780_Puts(0, 2,"Door opened.."); /* 0 dong 1, 1 dong 2*/
			flag_PC=0;
			ProcessAction();
		}
		else Process=0;
		flag_RFID1=0;
	}
if(flag_RFID2==1)
		{	
		
		Process=1;
		IDCAR2[0]=BufferCom2[4];
		IDCAR2[1]=BufferCom2[5];
		IDCAR2[2]=BufferCom2[6];
		IDCAR2[3]=BufferCom2[7];
		IDCAR2[4]=BufferCom2[8];
		IDCAR2[5]=BufferCom2[9];
		IDCAR2[6]=BufferCom2[10];
		
		if(BufferCom2[1]==0x08)	
			{
			sprintf(UID2,"%02x %02x %02x %02x ,2",IDCAR2[0],IDCAR2[1],IDCAR2[2],IDCAR2[3]);
			}
		if(BufferCom2[1]==0x0B) 
			{
			sprintf(UID2,"%02x %02x %02x %02x %02x %02x %02x ,2",IDCAR2[0],IDCAR2[1],IDCAR2[2],IDCAR2[3],IDCAR2[4],IDCAR2[5],IDCAR2[6]);
			}
		TM_HD44780_Puts(0, 2,"Waiting PC..."); /* 0 dong 1, 1 dong 2*/
			if(check_vip(UID2)){
			flag_PC=1;
			flag_R31=1;
			timerdk2 =0;
			Process=0;
		}
		else{
		if(Process)TM_USART_Puts(USART2,UID2);}
		WaitPC(200);
		flag_RFID2=0;
		if(flag_PC)
		{
			TM_HD44780_Puts(0, 2,"Door opened.."); /* 0 dong 1, 1 dong 2*/
			flag_PC=0;
			ProcessAction();
		}
		else Process=0;
		flag_RFID2=0;
	}
		
/**/
timer_dk1 = timerdk1/2;	
if (timer_dk1 >= timeout){
			turn_off_dk1();
			flag_R11 =0;
			flag_W1D0=0;
			timerdk1=0;
			timer_dk1=0;
			flag_RFID1=0;
			flag_RFID2=0;
			Process=0;
//			if(LEDStatus==0) TM_USART_Puts(USART3, "/LED000>\r\n");
		}
timer_dk2 = timerdk2/2;
if (timer_dk2 >= timeout){
			turn_off_dk2();
			//flag_R21 =0;
			flag_R31 =0;
			flag_W1D1=0;
			timerdk2=0;
			timer_dk2=0;
			//flag_RFID1=0;
			Process=0;
//			if(LEDStatus==0) TM_USART_Puts(USART3, "/LED000>\r\n");
		}
timer_dk3 = timerdk3;
if (timer_dk3 >= 1){
			turn_off_dk3();
			flag_R12 =0;
			timerdk3=0;
			timer_dk3=0;
		}
timer_dk4 = timerdk4;
if (timer_dk4 >= 1){
			turn_off_dk4();
			flag_R22 =0;
			timer_dk4=0;
			timerdk4=0;
		}


		TM_WATCHDOG_Reset();
}
}
Ejemplo n.º 10
0
int main(void) {
	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 USART2 for debug */
	/* TX = PA2 */
	TM_USART_Init(USART2, 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 points */
	TM_GPS_DistanceBetween(&GPS_Distance);
	
	/* Convert float number */
	TM_GPS_ConvertFloat(GPS_Distance.Distance, &GPS_Float, 6);
	printf("Distance is: %d.%06d meters\n", GPS_Float.Integer, GPS_Float.Decimal);
	
	TM_GPS_ConvertFloat(GPS_Distance.Bearing, &GPS_Float, 6);
	printf("Bearing is: %d.%06d degrees\n\n", GPS_Float.Integer, GPS_Float.Decimal);
	
	/* 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 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, now is the time to save your data on SD card */
				
				/* We have valid GPS signal */
				printf("New received data have valid GPS signal\n");
				printf("---------------------------------------\n");
#ifndef GPS_DISABLE_GPGGA
				/* GPGGA data */
				printf("GPGGA statement:\n");
				
				/* Latitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Latitude, &GPS_Float, 6);
				printf(" - Latitude: %d.%d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Longitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Longitude, &GPS_Float, 6);
				printf(" - Longitude: %d.%d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Satellites in use */
				printf(" - Sats in use: %02d\n", GPS_Data.Satellites);
				
				/* Current time */
				printf(" - UTC Time: %02d.%02d.%02d:%02d\n", GPS_Data.Time.Hours, GPS_Data.Time.Minutes, GPS_Data.Time.Seconds, GPS_Data.Time.Hundredths);
				
				/* Fix: 0 = invalid, 1 = GPS, 2 = DGPS */
				printf(" - Fix: %d\n", GPS_Data.Fix);
				
				/* Altitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Altitude, &GPS_Float, 6);
				printf(" - Altitude: %3d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
#endif
#ifndef GPS_DISABLE_GPRMC
				/* GPRMC data */
				printf("GPRMC statement:\n");
				
				/* Current date */
				printf(" - Date: %02d.%02d.%04d\n", GPS_Data.Date.Date, GPS_Data.Date.Month, GPS_Data.Date.Year + 2000);
				
				/* Current speed in knots */
				TM_GPS_ConvertFloat(GPS_Data.Speed, &GPS_Float, 6);
				printf(" - Speed in knots: %d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Current speed in km/h */
				temp = TM_GPS_ConvertSpeed(GPS_Data.Speed, TM_GPS_Speed_KilometerPerHour);
				TM_GPS_ConvertFloat(temp, &GPS_Float, 6);
				printf(" - Speed in km/h: %d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				TM_GPS_ConvertFloat(GPS_Data.Direction, &GPS_Float, 3);
				printf(" - Direction: %3d.%03d\n", GPS_Float.Integer, GPS_Float.Decimal);
#endif
#ifndef GPS_DISABLE_GPGSA
				/* GPGSA data */
				printf("GPGSA statement:\n");
				
				/* Horizontal dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.HDOP, &GPS_Float, 2);
				printf(" - HDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Vertical dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.VDOP, &GPS_Float, 2);
				printf(" - VDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Position dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.PDOP, &GPS_Float, 2);
				printf(" - PDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Current fix mode in use */ 
				printf(" - Fix mode: %d\n", GPS_Data.FixMode);
				
				/* Display IDs of satellites in use */
				printf(" - ID's of used satellites: ");
				for (i = 0; i < GPS_Data.Satellites; i++) {
					printf("%d,", GPS_Data.SatelliteIDs[i]);
				}
				printf("\n");
				
#endif
#ifndef GPS_DISABLE_GPGSV
				/* GPGSV data */
				printf("GPGSV statement:\n");
				
				/* Satellites in view */
				printf(" - Satellites in view: %d\n", GPS_Data.SatellitesInView);
				
				/* Print satellites description */
				for (i = 0; i < GPS_Data.SatellitesInView; i++) {
					printf(" - S: %02d, A: %03d, E: %02d, SNR: %02d\n", 
						GPS_Data.SatDesc[i].ID, 
						GPS_Data.SatDesc[i].Azimuth, 
						GPS_Data.SatDesc[i].Elevation, 
						GPS_Data.SatDesc[i].SNR
					);
				}
#endif
				printf("---------------------------------------\n");
			} else {
				/* GPS signal is not valid */
				printf("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;
			printf("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 */
		}
	}
}
Ejemplo n.º 11
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);
			}
		}
	}
}
Ejemplo n.º 12
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");
			}
		}
	}
}
Ejemplo n.º 13
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);
		}
	}
}
Ejemplo n.º 14
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 */
		}
	}
}
Ejemplo n.º 15
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 */
		}
	}
}
Ejemplo n.º 16
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);
			}
		}
	}
}