zhyinch
2021-11-15 f7c0b32abbf454e9adef4454ade15bd5940873e5
Src/main.c
@@ -110,7 +110,7 @@
   }
}
uint16_t hardware_version,hardware_pici,hardware_type;
u16 current_time;
u16 current_time,currentcount,beepcount;
uint8_t state5v;
void IdleTask(void)
{
@@ -128,63 +128,63 @@
//   LED_TB_OFF;
//}else{
//   LED_TR_OFF;
   current_time=GetLPTime();
   //motor_state=2;
if(g_com_map[MOTOR_ENABLE])
{
    
      if(motor_keeptime>0)
      {
         motor_state = 2;
      }else{
         motor_state = 0;
      }
      //motor_state=2;
   switch(motor_state)
      {case 0:
         if(hardware_type==NSH1)
         {MOTOR_OFF;
         }else if(hardware_type==GP)
         {
         HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
         }
         break;
      case 1:
         if(current_time<MOTOR_ONTIME)
         {
            if(hardware_type==NSH1)
            {MOTOR_ON;
            }else if(hardware_type==GP)
            {
            HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
            }
         }else{
            if(hardware_type==NSH1)
            {MOTOR_OFF;
            }else if(hardware_type==GP)
            {
            HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
            }
         }
         break;
      case 2:
         if(hardware_type==NSH1)
            {MOTOR_ON;
            }else if(hardware_type==GP)
            {
            HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
            }
         break;
      case 3:
         if(hardware_type==NSH1)
            {MOTOR_OFF;
            }else if(hardware_type==GP)
            {
            HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
            }
         break;
   }
}
//if(g_com_map[MOTOR_ENABLE])
//{
//
//      if(motor_keeptime>0)
//      {
//         motor_state = 2;
//      }else{
//         motor_state = 0;
//      }
//      //motor_state=2;
//   switch(motor_state)
//      {case 0:
//         if(hardware_type==NSH1)
//         {MOTOR_OFF;
//         }else if(hardware_type==GP)
//         {
//         HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
//         }
//         break;
//      case 1:
//         if(current_time<MOTOR_ONTIME)
//         {
//            if(hardware_type==NSH1)
//            {MOTOR_ON;
//            }else if(hardware_type==GP)
//            {
//            HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
//            }
//         }else{
//            if(hardware_type==NSH1)
//            {MOTOR_OFF;
//            }else if(hardware_type==GP)
//            {
//            HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
//            }
//         }
//         break;
//      case 2:
//         if(hardware_type==NSH1)
//            {MOTOR_ON;
//            }else if(hardware_type==GP)
//            {
//            HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
//            }
//         break;
//      case 3:
//         if(hardware_type==NSH1)
//            {MOTOR_OFF;
//            }else if(hardware_type==GP)
//            {
//            HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
//            }
//         break;
//   }
//}
    bat_percent=Get_Battary();
   if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
   {
@@ -281,14 +281,14 @@
   hardware_pici= STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2);
   hardware_type= STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4);
   //deca_sleep(1000);
   g_com_map[VERSION] = 0x022b;
   g_com_map[VERSION] = 0x022d;
    
//   g_com_map[DEV_ID]=0x7;
#ifdef DEBUG_MODE
//   g_com_map[DEV_ROLE]=1;
//      g_com_map[DEV_ID]=0x4009;
//    g_com_map[ACTIVE_INDEX]=1;
   g_com_map[COM_INTERVAL]=50;
//   g_com_map[COM_INTERVAL]=50;
//   g_com_map[MAX_REPORT_ANC_NUM]=1;
//   g_com_map[NOMOVESLEEP_TIME]=10;
//         g_com_map[IMU_ENABLE]=0;
@@ -353,20 +353,21 @@
void HardWareTypeDiffConfig(void)
{
   GPIO_InitTypeDef GPIO_InitStruct = {0};
   if(g_com_map[MOTORBEEPER_INDEX]!=1&&g_com_map[MOTORBEEPER_INDEX]!=2)
   {
         g_com_map[MOTORBEEPER_INDEX] = 2;
   }
//   if(g_com_map[MOTORBEEPER_INDEX]!=1&&g_com_map[MOTORBEEPER_INDEX]!=2)
//   {
         g_com_map[MOTORBEEPER_INDEX] = 1;
//   }
   hardware_type   = g_com_map[MOTORBEEPER_INDEX];
   switch(hardware_type)
      {
        case 1:     
            HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET);
            GPIO_InitStruct.Pin = MOTOR_Pin;
            HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);
            GPIO_InitStruct.Pin = GPIO_PIN_11;
            GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
            GPIO_InitStruct.Pull = GPIO_NOPULL;
            GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
            HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
            HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
                  //motor_keeptime = 10;
         break;
      case 2:
         MX_TIM2_Init();
@@ -377,6 +378,27 @@
{
      //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
}
void BeeperTask(void)
{   if(g_com_map[MOTOR_ENABLE])
{
   if(motor_keeptime>0)
      {
         motor_state = 2;
      }else{
         motor_state = 0;
      }
   current_time=GetLPTime();
   while(motor_keeptime>0)
   {
   currentcount=HAL_LPTIM_ReadCounter(&hlptim1);
   if(currentcount-beepcount>3||beepcount>currentcount)
   {
      beepcount = currentcount;
      LED_BLINK(GPIOA, GPIO_PIN_11);
   }
   }
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);
}}
/* USER CODE END 0 */
/**
@@ -479,6 +501,7 @@
         __enable_irq();
      //LED0_BLINK;      
      IdleTask();   
      BeeperTask();
      if(waitusart_timer>0)
      {
         waitusart_timer--;
@@ -935,7 +958,7 @@
   nomove_count+=1/(float)tag_frequency;
   if(motor_keeptime>0)
   {   
   motor_keeptime-=1/(float)tag_frequency;
   motor_keeptime-=1/(float)tag_frequency*2;
   }
    if(motor_keeptime<0)
    {motor_keeptime = 0;}