Esempio n. 1
0
/**
  * @brief  Returns the selected Button state.
  * @param  Button: Specifies the Button to be checked.
  *   This parameter can be one of following parameters:    
  *     @arg Button_WAKEUP: Wakeup Push Button
  *     @arg Button_TAMPER: Tamper Push Button  
  *     @arg Button_KEY: Key Push Button 
  *     @arg Button_RIGHT: Joystick Right Push Button 
  *     @arg Button_LEFT: Joystick Left Push Button 
  *     @arg Button_UP: Joystick Up Push Button 
  *     @arg Button_DOWN: Joystick Down Push Button
  *     @arg Button_SEL: Joystick Sel Push Button    
  * @retval The Button GPIO pin value.
  */
uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
{
  return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}
int GetDigitalInput(int inputNumber)
{
    assert_param(IS_INPUT_ID_VALID(inputNumber));
    
    uint8_t inputState;
    
    switch(inputNumber)
    {
    case INPUT_1:
        inputState = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13);
        break;
    case INPUT_2:
        inputState = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_5);
        break;
    case INPUT_3:
        inputState = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8);
        break;
    case INPUT_4:
        inputState = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_4);
        break;
    case INPUT_5:
        inputState = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_7);
        break;
    case INPUT_6:
        inputState = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3);
        break;
    case INPUT_7:
        inputState = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_1);
        break;
    case INPUT_8:
        inputState = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10);
        break;
    case INPUT_9:
        inputState = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_6);
        break;
    case INPUT_10:
        inputState = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_4);
        break;
    case INPUT_11:
        inputState = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_2);
        break;
    case INPUT_12:
        inputState = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_6);
        break;
    case INPUT_13:
        inputState = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5);
        break;
    case INPUT_14:
        inputState = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6);
        break;
    case INPUT_15:
        inputState = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4);
        break;
    case INPUT_16:
        inputState = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_12);
        break;
    }
    
    if(inputState != 0)
    {
        return ON;
    }
    else
    {
        return OFF;
    }
}
Esempio n. 3
0
int main(void)
{
	 /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	SystemInit();

	GPIO_InitTypeDef  GPIO_InitStructure;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_11;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOF, &GPIO_InitStructure);

	NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

#ifdef USB_MS_ENABLED
	RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	delay(1000);										//wait for pin initialisation to take effect ~125ms

	if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8))			//if USB is plugged in
	{
		uint32_t i = 0;

		RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);		//Activate USB line-pull up

	    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
		GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
		GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
		GPIO_Init(GPIOB, &GPIO_InitStructure);
		GPIO_ResetBits(GPIOB, GPIO_Pin_2);

	    USBD_Init(&USB_OTG_dev,
	  #ifdef USE_USB_OTG_HS
	              USB_OTG_HS_CORE_ID,
	  #else
	              USB_OTG_FS_CORE_ID,
	  #endif
	              &USR_desc,
	              &USBD_MSC_cb,
	              &USR_cb);

	    while(1)													//stay in infinite loop, datalogger is not operational in USB mode
	    {
	        if (i++ == 0x100000)
	        {
	        	GPIOF->ODR ^= GPIO_Pin_11;
	        	GPIOF->ODR ^= GPIO_Pin_12;
	        	GPIOF->ODR ^= GPIO_Pin_13;
	        	i = 0;
	        }
	    }
	}
#endif

//////////////////////////****************************//////////////////////////////

	IWDT_config();		//Comment the watchdog timer when debugging

//////////////////////////****************************//////////////////////////////

	DBGMCU_Config(DBGMCU_IWDG_STOP, ENABLE);
	DBGMCU_Config(DBGMCU_I2C1_SMBUS_TIMEOUT, ENABLE);
	restore_offsets();
    if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
    {
        GPIO_WriteBit(GPIOF, GPIO_Pin_11, Bit_SET);
        RCC_ClearFlag();
    }

	xTaskCreate( vmisc_tasks, (const signed char*)"Manage misc tasks",
		STACK_SIZE_MIN, NULL, tskIDLE_PRIORITY, NULL );

	xTaskCreate( vIMU_tasks, (const signed char*)"Manage IMU tasks",
		STACK_SIZE_MIN*5, NULL, 2, NULL );

	vTaskStartScheduler();

  while(1)
  {
	  GPIOD->ODR ^= GPIO_Pin_12;
  }
}
Esempio n. 4
0
int gpio_get(unsigned nr)
{
	return GPIO_ReadInputDataBit(port_to_pointer(GPIO_PORT(nr)), 1 << GPIO_PIN(nr));
}
Esempio n. 5
0
/**
  * @brief  Read the port pin (connected to the push button) level.
  * @param  None
  * @retval : The port pin level (SET or RESET).
  */
uint8_t Push_Button_Read (void)
{
    /* Returns the status of the Button pin = "Key" button on the Evaluation board */
    return GPIO_ReadInputDataBit(GPIO_KEY_BUTTON, GPIO_PIN_KEY_BUTTON);
}
Esempio n. 6
0
/**
 * Reads the specified GPI and retrieves its digital logic level.
 *
 * @param gpi GPI_TypeDef The GPI input to read.
 * @retval DigitalLevel_t The digital logic level of the input pin.
 */
static DigitalLevel_t ReadGPI_Pin(GPI_TypeDef gpi) {
	uint8_t state = 0;
	switch (gpi) {
	case GPI0:
		state = GPIO_ReadInputDataBit(GPI0_GPIO_PORT, GPI0_PIN );
		break;
	case GPI1:
		state = GPIO_ReadInputDataBit(GPI1_GPIO_PORT, GPI1_PIN );
		break;
	case GPI2:
		state = GPIO_ReadInputDataBit(GPI2_GPIO_PORT, GPI2_PIN );
		break;
	case GPI3:
		state = GPIO_ReadInputDataBit(GPI3_GPIO_PORT, GPI3_PIN );
		break;
	case GPI4:
		state = GPIO_ReadInputDataBit(GPI4_GPIO_PORT, GPI4_PIN );
		break;
	case GPI5:
		state = GPIO_ReadInputDataBit(GPI5_GPIO_PORT, GPI5_PIN );
		break;
	case GPI6:
		state = GPIO_ReadInputDataBit(GPI6_GPIO_PORT, GPI6_PIN );
		break;
	case GPI7:
		state = GPIO_ReadInputDataBit(GPI7_GPIO_PORT, GPI7_PIN );
		break;
	case GPI8:
		state = GPIO_ReadInputDataBit(GPI8_GPIO_PORT, GPI8_PIN );
		break;
	case GPI9:
		state = GPIO_ReadInputDataBit(GPI9_GPIO_PORT, GPI9_PIN );
		break;
	case GPI10:
		state = GPIO_ReadInputDataBit(GPI10_GPIO_PORT, GPI10_PIN );
		break;
	case GPI11:
		state = GPIO_ReadInputDataBit(GPI11_GPIO_PORT, GPI11_PIN );
		break;
	case GPI12:
		state = GPIO_ReadInputDataBit(GPI12_GPIO_PORT, GPI12_PIN );
		break;
	case GPI13:
		state = GPIO_ReadInputDataBit(GPI13_GPIO_PORT, GPI13_PIN );
		break;
	case GPI14:
		state = GPIO_ReadInputDataBit(GPI14_GPIO_PORT, GPI14_PIN );
		break;
	case GPI15:
		state = GPIO_ReadInputDataBit(GPI15_GPIO_PORT, GPI15_PIN );
		break;
	case GPI16:
		state = GPIO_ReadInputDataBit(GPI16_GPIO_PORT, GPI16_PIN );
		break;
	case GPI17:
		state = GPIO_ReadInputDataBit(GPI17_GPIO_PORT, GPI17_PIN );
		break;
	case GPI18:
		state = GPIO_ReadInputDataBit(GPI18_GPIO_PORT, GPI18_PIN );
		break;
	case GPI19:
		state = GPIO_ReadInputDataBit(GPI19_GPIO_PORT, GPI19_PIN );
		break;
	case GPI20:
		state = GPIO_ReadInputDataBit(GPI20_GPIO_PORT, GPI20_PIN );
		break;
	case GPI21:
		state = GPIO_ReadInputDataBit(GPI21_GPIO_PORT, GPI21_PIN );
		break;
	case GPI22:
		state = GPIO_ReadInputDataBit(GPI22_GPIO_PORT, GPI22_PIN );
		break;
	case GPI23:
		state = GPIO_ReadInputDataBit(GPI23_GPIO_PORT, GPI23_PIN );
		break;
	default:
		/* TODO: Throw an error */
		break;
	}
	if (state) {
		return LOGIC_HIGH;
	} else {
		return LOGIC_LOW;
	}
}
Esempio n. 7
0
/**
  * @brief  Returns the selected Button state.
  * @param  Button: Specifies the Button to be checked.
  *   This parameter should be: BUTTON_USER  
  * @retval The Button GPIO pin value.
  */
uint32_t STM32F4_Discovery_PBGetState(Button_TypeDef Button)
{
  return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}
Esempio n. 8
0
//------------------------------------------------------------------
void  GPS_ANTENNA_status(void)     //  天线开短路状态检测 
{
    // 2013-4-20    更改PCB   用PD4 : GPS 天线开路      PB6 : GPS  天线短路
   	if(GPIO_ReadOutputDataBit(GPS_PWR_PORT, GPS_PWR_PIN )) // 在GPS 有电时有效   
		{
			if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4))//开路检测	1:天线开路
			{
				 if(OutGPS_Flag==0)
				 {
					   if((Warn_Status[3]&0x20)==0)
					         rt_kprintf("\r\n	检测到	天线开路"); 
					   Warn_Status[3]|=0x20;
					   Warn_Status[3]&=~0x40; 	 
					   GpsStatus.Antenna_Flag=1;
					   Gps_Exception.GPS_circuit_short_couter=0;
			 	}  
			}
			else if(!GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6))//短路检测  0:天线短路 
			{
			         if(( Warn_Status[3]&0x40)==0)   
				     {
                        Gps_Exception.GPS_short_keepTimer++;
						if( Gps_Exception.GPS_short_keepTimer>200)     
					    {
					       Gps_Exception.GPS_short_keepTimer=0;  // clear 
					       rt_kprintf("\r\n	检测到	天线短路");     
						   rt_kprintf("\r\n	发现短路,立即断开GPS电源");      
						   GPIO_ResetBits( GPS_PWR_PORT, GPS_PWR_PIN ); 


						      //------------------------------------------ 
							  Gps_Exception.GPS_circuit_short_couter++;
							  if(Gps_Exception.GPS_circuit_short_couter>=4)  
							   {
									Gps_Exception.GPS_short_checkFlag=2;
									Gps_Exception.GPS_short_timer=0; // clear  
									rt_kprintf("\r\n   短路检测大于3次 ,一直断开GPS 电源\r\n");   
									
									//	断开 GPS 电源后,得启动 本地定时 ,否则人家说丢包.NND
									/*
							  
									   */ 
							   }	
							  else
							   {
									  Gps_Exception.GPS_short_checkFlag=1; 
							   } 
			                   //-----------------------------------------------------
                             
							   // set  flag 	
							   Warn_Status[3]&=~0x20;
							   Warn_Status[3]|=0x40;	 
							   //------------------------------------------
					     }
			         } 		
				   

			}
			else
			{
				  if(Warn_Status[3]&0x20)
				  	      rt_kprintf("\r\n	检测到	天线恢复正常");   
	              Warn_Status[3]&=~0x20;
				  Warn_Status[3]&=~0x40;   
				  GpsStatus.Antenna_Flag=0;
				  Gps_Exception.GPS_circuit_short_couter=0;
			} 
			
		}
}
Esempio n. 9
0
int main3(void)
{
	//test_lcd();
	//return 0;
	//test_adc();

	/* Initialize system */
	//SystemInit();

	//TM_RCC_InitSystem();
	//HAL_Init();
	TM_DELAY_Init();

	//GPIO_setup();

	int i = 0;

#ifdef DISCOVERY
//    GPIO_SetBits(GPIOD, GPIO_Pin_12); //Подаем «1» на PD12
	//main2();	//return 0;
    //GPIO_SetBits(GPIOD, GPIO_Pin_13); //Подаем «1» на PD12

	while(1)
	{
	//Если кнопка нажата, то…
	    if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)
	    {
	    	char sz[32];
	    	sprintf(sz, "%d", i);
	    	lcd_print(sz, 0);
	    	//delay(1000);

	    	int tm = 500;
	        GPIO_SetBits(GPIOD, GPIO_Pin_12); //Подаем «1» на PD12
	        delay(tm); //Функция задержки
	        GPIO_SetBits(GPIOD, GPIO_Pin_13); //Подаем «1» на PD13
	        delay(tm);
	        GPIO_SetBits(GPIOD, GPIO_Pin_14); //Подаем «1» на PD14
	        delay(tm);
	        //GPIO_SetBits(GPIOD, GPIO_Pin_15); //Подаем «1» на PD15
	        delay(tm);
	        GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14/*|GPIO_Pin_15*/); //Сбрасываем все пины в «0»
	        delay(tm);
	    }
        //delay(1000); // ~3sec
        delay(100); // ~.3sec

        if(i % 2 == 0)
        	GPIO_SetBits(GPIOD, GPIO_Pin_15); //Подаем «1» на PD15
        else
        	GPIO_ResetBits(GPIOD, GPIO_Pin_15); //Подаем «1» на PD15

        i++;

	}

	return 0;

#endif

	//Если кнопка нажата, то…

	/*
	GPIO_setup();
	button_setup();
	GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 );

	initTimer();

	startTimer(1000);

	while(1)
	{

	}
	*/
	set_port(GPIOA,GPIO_Pin_5); // shotin
	set_port(GPIOC, GPIO_Pin_5); // shotout
	set_port(GPIOA, GPIO_Pin_3); // switch 1

	reset_port(GPIOC, GPIO_Pin_13); // left
	reset_port(GPIOC, GPIO_Pin_14); // right
	reset_port(GPIOA, GPIO_Pin_4); // switch 2

	while(1)
	{
	    if (get_port(GPIOC,GPIO_Pin_13)==1) // left
	    {
	    	lcd_print("left", 0);
	    	set_port(GPIOA,GPIO_Pin_3); // sw1
	    }
	    else
	    	reset_port(GPIOA,GPIO_Pin_3);

	    if (get_port(GPIOC,GPIO_Pin_14)==1) // right
	    {
	    	set_port(GPIOA, GPIO_Pin_4); // switch 2
	    	lcd_print("right", 0);

	    }
	    else
	    	reset_port(GPIOA, GPIO_Pin_4);

        if(i % 2 == 0)
        	set_port(GPIOC, GPIO_Pin_5); // shotout
        else
        	reset_port(GPIOC, GPIO_Pin_5);

	    Delayms(3);
        i++;

	}
	return 0;
}
Esempio n. 10
0
int get_port(PortType port, int id)
{
    uint8_t c = GPIO_ReadInputDataBit(port, id);
    return c;
}
Esempio n. 11
0
void CheckICInsert(void)
{
    unsigned char write_flag=0;
    u8 result0=0,result1=0,result2=0,result3=0,result4=0,result5=0;//i=0;
    u8 FLagx=0;//,len=0;
    unsigned char reg_record[32];
    u32 DriveCode32=0;

//===================测试IC卡读写==================================================
    if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7))
    {
        IC_Check_Count++;
        if(IC_Check_Count>=10)
        {
            IC_Check_Count=0;
            //带卡上电开8024的电
            if(flag_8024off==1)
            {
                R_Flag|=b_CardEdge;
                Init8024Flag=2;
                flag_8024off=0;
            }
            //8024的off从低变高
            if(Init8024Flag==1)
            {
                Init8024Flag=2;
                R_Flag|=b_CardEdge;
                //rt_kprintf("pc7  为 高,R_Flag=1\r\n");
            }
            //检测到卡后初始化ic卡
            if((R_Flag&b_CardEdge)&&(Init8024Flag==2))
            {
                Init8024Flag=3;
                _CardCMDVCC_LOW;
                for(DelayCheckIc=0; DelayCheckIc<500; DelayCheckIc++)
                    DELAY5us();
                _CardSetPower_HIGH;
                _CardSetRST_LOW;
                for(DelayCheckIc=0; DelayCheckIc<15; DelayCheckIc++)
                {
                    _CardSetCLK_LOW;
                    DELAY5us();
                    DELAY5us();
                    DELAY5us();
                    _CardSetCLK_HIGH;
                    DELAY5us();
                    DELAY5us();
                    DELAY5us();
                    _CardSetCLK_LOW;
                }
                R_Flag&=~b_CardEdge;
                write_flag=1;
                //rt_kprintf("只执行1次\r\n");
            }
        }
    }
    else
    {
        IC_Check_Count=0;
        _CardSetRST_HIGH;
        _CardSetPower_LOW;
        _CardCMDVCC_HIGH;
        if(Init8024Flag==0)
        {
            Init8024Flag=1;
            //rt_kprintf("pc7  为 低\r\n");
        }
    }
    if(write_flag==1)
    {
        write_flag=0;
        Rx_4442(241,13,reg_record);	//管理员卡
        if(strncmp((char *)reg_record,"administrator",13)==0)
        {
            rt_kprintf("\r\n管理员卡");
            administrator_card=1;
        }
        else
        {
            memset(DriverCardNUM,0,sizeof(DriverCardNUM));
            memset(DriverName,0,sizeof(DriverName));
            //memset(JT808Conf_struct.Driver_Info,0,sizeof(JT808Conf_struct.Driver_Info));

            result0=Rx_4442(70,10,(unsigned char *)DriverName);	//读驾驶员姓名
            rt_kprintf("\r\n驾驶员姓名:%s,result0=%d",DriverName,result0);


            result1=Rx_4442(52,18,(unsigned char *)DriverCardNUM);	//读驾驶证号码
            rt_kprintf("\r\n驾驶证代码:%s,result1=%d",DriverCardNUM,result1);

            memset(JT808Conf_struct.Driver_Info.DriveCode,0,sizeof(JT808Conf_struct.Driver_Info.DriveCode));
            result2=Rx_4442(49,3,(unsigned char *)JT808Conf_struct.Driver_Info.DriveCode);	//读驾驶员代码
            DriveCode32=(JT808Conf_struct.Driver_Info.DriveCode[0]<<16)+(JT808Conf_struct.Driver_Info.DriveCode[1]<<8)+JT808Conf_struct.Driver_Info.DriveCode[2];
            rt_kprintf("\r\n驾驶员代码:%d,result2=%d",DriveCode32,result2);

            memset(JT808Conf_struct.Driver_Info.Driver_ID,0,sizeof(JT808Conf_struct.Driver_Info.Driver_ID));
            result3=Rx_4442(80,20,(unsigned char *)JT808Conf_struct.Driver_Info.Driver_ID);	//身份证号码
            rt_kprintf("\r\n身份证号码:%s,result3=%d",JT808Conf_struct.Driver_Info.Driver_ID,result3);

            memset(JT808Conf_struct.Driver_Info.Drv_CareerID,0,sizeof(JT808Conf_struct.Driver_Info.Drv_CareerID));
            result4=Rx_4442(100,40,(unsigned char *)JT808Conf_struct.Driver_Info.Drv_CareerID);	//从业资格证
            rt_kprintf("\r\n从业资格证:%s,result4=%d",JT808Conf_struct.Driver_Info.Drv_CareerID,result4);

            memset(JT808Conf_struct.Driver_Info.Comfirm_agentID,0,sizeof(JT808Conf_struct.Driver_Info.Comfirm_agentID));
            result5=Rx_4442(140,41,(unsigned char *)institution);	//发证机构
            memcpy(JT808Conf_struct.Driver_Info.Comfirm_agentID,&institution[1],40);
            rt_kprintf("\r\n发证机构:%s,result5=%d",JT808Conf_struct.Driver_Info.Comfirm_agentID,result5);

            if((result0==0)&&(result1==0)&&(result2==0)&&(result3==0)&&(result4==0)&&(result5==0))//读结果正确
            {
                IC_CardInsert=1;//IC	卡插入正确
                FLagx=0;

                //前18位为驾驶证号码-------------疲劳驾驶相关------看是否更换了卡 --------------
                if(strncmp((char*)DriverCardNUM,(char*)JT808Conf_struct.Driver_Info.DriverCard_ID,18)!=0)
                {
                    memset(JT808Conf_struct.Driver_Info.DriverCard_ID,0,sizeof(JT808Conf_struct.Driver_Info.DriverCard_ID));
                    memcpy(JT808Conf_struct.Driver_Info.DriverCard_ID,DriverCardNUM,18);
                    FLagx=1;
                }
                //后20位为驾驶员姓名-------------疲劳驾驶相关------看是否更换了卡 --------------
                if(strncmp((char*)DriverName,(char*)JT808Conf_struct.Driver_Info.DriveName,20)!=0)
                {
                    memset(JT808Conf_struct.Driver_Info.DriveName,0,sizeof(JT808Conf_struct.Driver_Info.DriveName));
                    memcpy((u8*)JT808Conf_struct.Driver_Info.DriveName,DriverName,strlen((const char*)DriverName));
                    FLagx=2;
                }
                if(FLagx)//更换了IC 卡    清除疲劳驾驶相关
                {
                    TIRED_Drive_Init();  //清除疲劳驾驶的状态
                    GPIO_ResetBits(Buzzer_IO_Group,Buzzer_Group_Num); // 关闭蜂鸣器
                    Api_Config_Recwrite_Large(jt808,0,(u8*)&JT808Conf_struct,sizeof(JT808Conf_struct));
                    FLagx=0;//clear
                }
                BuzzerFlag=1;//响一声提示
                pMenuItem=&Menu_2_5_DriverInfor;
                pMenuItem->show();
            }
            else
            {
                BuzzerFlag=11;//响一声提示
                IC_CardInsert=2;//IC	卡插入错误
            }
        }
        Init8024Flag=0;
        GpsIo_Init();
    }

//===================测试IC卡读写完成==================================================

}
Esempio n. 12
0
//-------------------------------------------------------------------------------------------
void din2_read(void)
{
  GPIO_ReadInputDataBit(TTL_DIN2_PORT, TTL_DIN2_PORT_PIN);
}
Esempio n. 13
0
void trace_single_line()
{
 if((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3) == Bit_SET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4) == Bit_RESET))
 {
  turn_count=0; 
  left_count(10);
 }
 else if((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3) == Bit_RESET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4) == Bit_SET))
 {
  turn_count=0; 
  right_count(10);
 }
 else if((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3) == Bit_SET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4) == Bit_SET)
 &&(!((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_2) == Bit_SET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_5) == Bit_SET))))
 {
  turn_count=0; 
  forward();
 }
 else if((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3) == Bit_RESET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4) == Bit_RESET))
 {
  if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_2) == Bit_SET)
  {
   turn_count=0; 
   left_count(20);
  }
  else if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_5) == Bit_SET)
  {
   turn_count=0; 
   right_count(20);
  }
 }
 else if((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_2) == Bit_RESET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3) == Bit_RESET)
 &&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4) == Bit_RESET)&&(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_5) == Bit_RESET))
 {
  forward();
 }
}
Esempio n. 14
0
int main(void)
{
	int 			fd_client = -1;
	char 			*buf;
	int 			con = -1;
	int 			opt = 0;
	fd_set 			readfds, exceptfds;
	struct 			timeval_t t;
	struct 			sockaddr_t addr;
	lib_config_t 	libConfig;
	volatile int	setval;
	volatile int	readval;

	buf = (char*)malloc(3*1024);

	libConfig.tcp_buf_dynamic = mxEnable;
	libConfig.tcp_max_connection_num = 12;
	libConfig.tcp_rx_size = 2048;
	libConfig.tcp_tx_size = 2048;
	libConfig.hw_watchdog = 0;
	libConfig.wifi_channel = WIFI_CHANNEL_1_13;
	lib_config(&libConfig);
  
	mxchipInit();
	UART_Init();


	printf("\r\n%s\r\n mxchipWNet library version: %s\r\n", APP_INFO, system_lib_version());
	printf(menu);
	printf ("\nMXCHIP> ");
	
	//init http
	set_tcp_keepalive(3, 60);
	setSslMaxlen(6*1024);
	t.tv_sec = 0;
  	t.tv_usec = 100;
	
//	void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

	while(1)
	{
		mxchipTick();	
		if(menu_enable)
			Main_Menu();
		if(configSuccess)
		{
			wNetConfig.wifi_mode = Station;
			wNetConfig.dhcpMode = DHCP_Client;
			StartNetwork(&wNetConfig);
			printf("connect to %s.....\r\n", wNetConfig.wifi_ssid);
			configSuccess = 0;
			menu_enable = 1;

			sysTick_configuration();
			config_gpio_pc6();
			config_gpio_pb8();

			while(1) 
			{
				readval= GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_6);
				mxchipTick();
				//If wifi is established, connect to WEBSERVER, and send a http request
				if(https_server_addr == 0 && dns_pending == 0)
				{  
					//DNS function
					https_server_addr = dns_request(WEB_SERVER);
					if(https_server_addr == -1)
						printf("DNS test: %s failed. \r\n", WEB_SERVER); 
					else if (https_server_addr == 0) //DNS pending, waiting for callback
					{
						dns_pending = 1;
						printf("2DNS test: %s success. \r\n", WEB_SERVER); 
						printf("21http server addr=%x\n",https_server_addr);
					}
				}
				
				if( fd_client == -1 && (u32)https_server_addr>0)
				{
					fd_client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
					setsockopt(fd_client,0,SO_BLOCKMODE,&opt,4);
					addr.s_ip = https_server_addr; 
					addr.s_port = 443;
					if (connect(fd_client, &addr, sizeof(addr))!=0) 
						printf("Connect to %s failed.\r\n", WEB_SERVER); 
					else   
						printf("Connect to %s success.\r\n", WEB_SERVER); 	
				}

				if(serverConnectted&&sslConnectted==0)
				{
					printf("Connect to web server success! Setup SSL ecryption...\r\n");
					if (setSSLmode(1, fd_client)!= MXCHIP_SUCCESS)
					{
						printf("SSL connect fail\r\n");
						close(fd_client);
						fd_client = -1;
						serverConnectted = 0;
					} 
					else 
					{
						printf("SSL connect\r\n");
						sslConnectted = 1;
					}
				}	
		
				if(readval==1&&sslConnectted)
				{
					printf("read value is 1\n");
					send(fd_client, sendhttpRequest, strlen(sendhttpRequest), 0);
				//	return 0;
				}
				if(check_responce&&sslConnectted)
				{
					printf("readval=%d\n",readval);
					check_responce=0;
					send(fd_client, responcehttpRequest, strlen(responcehttpRequest), 0);
					//Check status on erery sockets 
					FD_ZERO(&readfds);

					if(sslConnectted)
						FD_SET(fd_client, &readfds);
		
					select(1, &readfds, NULL, &exceptfds, &t);
		
					//Read html data from WEBSERVER
					if(sslConnectted)
					{
						if(FD_ISSET(fd_client, &readfds))
						{
							con = recv(fd_client, buf, 2*1024, 0);
							if(con > 0)
							{
								printf("Get %s data successful! data length: %d bytes data\r\n", WEB_SERVER, con);
								setval=r_http(buf);
								printf("read from http  is %d\n",setval);
					
								if(setval==1)
									GPIO_SetBits(GPIOB,GPIO_Pin_8);
								 else
								  	GPIO_ResetBits(GPIOB,GPIO_Pin_8);
							}
							else
							{
								close(fd_client);
								serverConnectted = 0;
								sslConnectted = 0;
								fd_client = -1;
								printf("Web connection closed.\r\n");
							}
						}
					}
				}
			}
		}
		
		if(easylink)
		{
			OpenEasylink2(60);	
			easylink = 0;
		}
	}
}
Esempio n. 15
0
static uint8 ButtonPHY_getPORTA(uint16 channel)
{
  return GPIO_ReadInputDataBit(GPIOA,channel);
}
Esempio n. 16
0
void TIM3_IRQHandler(void)
{
  TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
  
  if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11)==0)
  {
    if(tp_flag<4)
    {
      tp_x[tp_flag]=TP_MeasureX();
      tp_y[tp_flag]=TP_MeasureY();
//      printf("%d\t%d\r\n",tp_x[tp_flag],tp_y[tp_flag]);
      if((-10<(tp_x[tp_flag]-tp_x[tp_flag-1])<10)&&(-10<(tp_y[tp_flag]-tp_y[tp_flag-1])<10))
      {tp_flag+=1;}
      else
      {tp_flag=0;}
    }
    else
    {
      tp_flag=0;
      TIM_Cmd(TIM3, DISABLE);
     
      u16 j=0,i=0;
      uint16_t temp=0;
      for(j=0;j<=4;j++)
      {
        for (i=0;i<4-j;i++)
        {
          if (tp_x[i]>tp_x[i+1])
          {
            temp=tp_x[i];
            tp_x[i]=tp_x[i+1];
            tp_x[i+1]=temp;
          }
        }
      }
      for(j=0;j<=4;j++)
      {
        for (i=0;i<4-j;i++)
        {
          if (tp_y[i]>tp_y[i+1])
          {
            temp=tp_y[i];
            tp_y[i]=tp_y[i+1];
            tp_y[i+1]=temp;
          }
        }
      }
      x=(tp_x[1]+tp_x[2]+tp_x[3])/3;
      y=(tp_y[1]+tp_y[2]+tp_y[3])/3;
      x=800-x;
      //y=480-y;
      printf("%d\t%d\r\n",x,y);
     if((x<800)&&(y<479))
     {
       
      LCD_DrawFullCircle(x,y,5,0xaaaa,1);
       if(x>24&&x<320&&y>320&&y<424)
       {
         APP_PROGRAM_FLAG=1;
       }
       
       if(x>480&&x<776&&y>320&&y<424)
       {
         Jump_To_App_flag=1;
       }
       
     }
    }
  }
}
Esempio n. 17
0
void AppTaskJoyControl(void *p_arg)
{
    OS_ERR os_err;
    (void)p_arg;

    AppTaskJoyControlInit();
    OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_PERIODIC, &os_err);

    while(1) {
        //printf("ADC: %d | %d\n\r", ADCConvertedValue[0], ADCConvertedValue[1]);
        opQueueElem_t opQueueElem   = {0};
        lcdQueueElem_t lcdQueueElem = {0};
        uint16_t vertMovementFactor = 100U*ADCConvertedValue[0]/MAX_ADC_RES_VALUE;
        uint16_t horiMovementFactor = 100U*ADCConvertedValue[1]/MAX_ADC_RES_VALUE;

        opQueueElem.ctrl = RADIO_CTRL_JOYSTICK;
        if(vertMovementFactor < 45U) {
            uint8_t speedFwd = MAX_VELOCITY_VALUE - (100U * ADCConvertedValue[0] / HALF_ADC_RES_VALUE);

            opQueueElem.operation = RADIO_OP_DRIVE;
            opQueueElem.opAction  = RADIO_DRVOP_JOY_FORWARD;
            opQueueElem.val_0 = speedFwd;
            opQueueElem.val_1 = speedFwd;

            lcdQueueElem.operation = LCD_OP_MOVE;
            lcdQueueElem.move.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.move.dir  = LCD_MV_FORWARD;
            lcdQueueElem.move.speed = speedFwd;
        }
        else if(vertMovementFactor > 50U) {
            uint8_t speedBwd = (100U * ADCConvertedValue[0] / HALF_ADC_RES_VALUE) - MAX_VELOCITY_VALUE;

            opQueueElem.operation = RADIO_OP_DRIVE;
            opQueueElem.opAction  = RADIO_DRVOP_JOY_BACKWARD;
            opQueueElem.val_0 = speedBwd;
            opQueueElem.val_1 = speedBwd;

            lcdQueueElem.operation = LCD_OP_MOVE;
            lcdQueueElem.move.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.move.dir = LCD_MV_BACKWARD;
            lcdQueueElem.move.speed = speedBwd;
        }

        if(horiMovementFactor < 45U) {
            if(opQueueElem.operation == RADIO_OP_NONE) {
                opQueueElem.operation = RADIO_OP_DRIVE;
                opQueueElem.opAction  = RADIO_DRVOP_JOY_RIGHT;
            }

            opQueueElem.val_0 = 0;
            opQueueElem.val_1 = MAX_VELOCITY_VALUE;

            lcdQueueElem.operation = LCD_OP_MOVE;
            lcdQueueElem.move.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.move.dir = LCD_MV_RIGHT;
            lcdQueueElem.move.speed = MAX_VELOCITY_VALUE;
        }
        else if(horiMovementFactor > 50U) {
            if(opQueueElem.operation == RADIO_OP_NONE) {
                opQueueElem.operation = RADIO_OP_DRIVE;
                opQueueElem.opAction  = RADIO_DRVOP_JOY_LEFT;
            }

            opQueueElem.val_0 = MAX_VELOCITY_VALUE;
            opQueueElem.val_1 = 0;

            lcdQueueElem.operation = LCD_OP_MOVE;
            lcdQueueElem.move.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.move.dir = LCD_MV_LEFT;
            lcdQueueElem.move.speed = MAX_VELOCITY_VALUE;
        }

        if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == Bit_RESET) {
            opQueueElem.operation = RADIO_OP_SOUND_SIG;
            opQueueElem.opAction  = RADIO_SIGOP_ON;

            lcdQueueElem.operation = LCD_OP_HORN;
            lcdQueueElem.horn.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.horn.state = LCD_HRN_ON;
        }
        else if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5) == Bit_RESET) {
            do {
                OSTimeDlyHMSM(0, 0, 0, 25, OS_OPT_TIME_PERIODIC, &os_err);
            }while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5) == Bit_RESET);

            opQueueElem.operation = RADIO_OP_LIGHTING;
            opQueueElem.opAction  = RADIO_LIGHTOP_LEFT;
            if(lightCurrentState.lightLeftCurrState == RADIO_LIGHTST_DISABLE) {
                opQueueElem.val_0 = RADIO_LIGHTST_ENABLE;
                lightCurrentState.lightLeftCurrState = RADIO_LIGHTST_ENABLE;
            }
            else {
                opQueueElem.val_0 = RADIO_LIGHTST_DISABLE;
                lightCurrentState.lightLeftCurrState = RADIO_LIGHTST_DISABLE;
            }

            lcdQueueElem.operation  = LCD_OP_LIGHT;
            lcdQueueElem.light.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.light.type = LCD_LIG_LEFT;
            lcdQueueElem.light.state = (LcdLightState_t)opQueueElem.val_0;
        }
        else if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7) == Bit_RESET) {
            do {
                OSTimeDlyHMSM(0, 0, 0, 25, OS_OPT_TIME_PERIODIC, &os_err);
            }while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7) == Bit_RESET);

            opQueueElem.operation = RADIO_OP_LIGHTING;
            opQueueElem.opAction  = RADIO_LIGHTOP_RIGHT;
            if(lightCurrentState.lightRightCurrState == RADIO_LIGHTST_DISABLE) {
                opQueueElem.val_0 = RADIO_LIGHTST_ENABLE;
                lightCurrentState.lightRightCurrState = RADIO_LIGHTST_ENABLE;
            }
            else {
                opQueueElem.val_0 = RADIO_LIGHTST_DISABLE;
                lightCurrentState.lightRightCurrState = RADIO_LIGHTST_DISABLE;
            }
            
            lcdQueueElem.operation  = LCD_OP_LIGHT;
            lcdQueueElem.light.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.light.type = LCD_LIG_RIGHT;
            lcdQueueElem.light.state = (LcdLightState_t)opQueueElem.val_0;
        }
        else if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4) == Bit_RESET) {
            do {
                OSTimeDlyHMSM(0, 0, 0, 25, OS_OPT_TIME_PERIODIC, &os_err);
            }while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4) == Bit_RESET);

            opQueueElem.operation = RADIO_OP_LIGHTING;
            opQueueElem.opAction  = RADIO_LIGHTOP_INNER;
            if(lightCurrentState.lightInnerCurrState == RADIO_LIGHTST_DISABLE) {
                opQueueElem.val_0 = RADIO_LIGHTST_ENABLE;
                lightCurrentState.lightInnerCurrState = RADIO_LIGHTST_ENABLE;
            }
            else {
                opQueueElem.val_0 = RADIO_LIGHTST_DISABLE;
                lightCurrentState.lightInnerCurrState = RADIO_LIGHTST_DISABLE;
            }

            lcdQueueElem.operation  = LCD_OP_LIGHT;
            lcdQueueElem.light.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.light.type = LCD_LIG_INNER;
            lcdQueueElem.light.state = (LcdLightState_t)opQueueElem.val_0;
        }
        else if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5) == Bit_RESET) {
            do {
                OSTimeDlyHMSM(0, 0, 0, 25, OS_OPT_TIME_PERIODIC, &os_err);
            }while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5) == Bit_RESET);

            opQueueElem.operation = RADIO_OP_LIGHTING;
            opQueueElem.opAction  = RADIO_LIGHTOP_OUTER;
            if(lightCurrentState.lightOuterCurrState == RADIO_LIGHTST_DISABLE) {
                opQueueElem.val_0 = RADIO_LIGHTST_ENABLE;
                lightCurrentState.lightOuterCurrState = RADIO_LIGHTST_ENABLE;
            }
            else {
                opQueueElem.val_0 = RADIO_LIGHTST_DISABLE;
                lightCurrentState.lightOuterCurrState = RADIO_LIGHTST_DISABLE;
            }

            lcdQueueElem.operation  = LCD_OP_LIGHT;
            lcdQueueElem.light.ctrl = LCD_CTRL_JOYSTICK;
            lcdQueueElem.light.type = LCD_LIG_OUTER;
            lcdQueueElem.light.state = (LcdLightState_t)opQueueElem.val_0;
        }
        else {
            // no action defined
        }

        send_to_radio_queue(&opQueueElem);
        send_to_lcd_queue(&lcdQueueElem);

        //printf("testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest ");
        OSTimeDlyHMSM(0, 0, 0, 20, OS_OPT_TIME_PERIODIC, &os_err);
    }
}