zhyinch
2021-04-19 8f55070fefc9edde12a09fe00e2e8d512e8ddd34
Src/main.c
@@ -87,6 +87,7 @@
uint16_t slottime,max_slotpos;
uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
extern uint8_t module_power;
extern float nomove_count;
uint8_t imu_enable,motor_enable;   
u16 GetLPTime(void)
{
@@ -122,17 +123,19 @@
//   LED_TR_OFF;
   current_time=GetLPTime();
   //motor_state=2;
      if(g_com_map[MOTOR_ONTIME]>0)
   {
      g_com_map[MOTOR_ONTIME]--;
      motor_state = 1;
   }
//      if(g_com_map[MOTOR_ONTIME]>0)
//   {
//      g_com_map[MOTOR_ONTIME]--;
//      motor_state = 1;
//   }
if(motor_enable)
{
   switch(motor_state)
      {case 0:
         MOTOR_OFF;
         break;
      case 1:
         if(current_time<MOTOR_ONTIME)
         if(current_time<WARNING_MOTORONTIME)
         {
            MOTOR_ON;      
         }else{
@@ -147,8 +150,12 @@
         MOTOR_OFF;
         break;   
   }
}else{
   MOTOR_OFF;
}
   if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
   {
      nomove_count = 0;
      if(state5v==0)
      {
         state5v=1;
@@ -239,7 +246,7 @@
   Usart1ParseDataCallback = UsartParseDataHandler;
   parameter_init();
   //deca_sleep(1000);
   g_com_map[VERSION] = 0x0110;
   g_com_map[VERSION] = 0x0115;
#ifdef DEBUG_MODE
//   g_com_map[DEV_ROLE]=1;
//      g_com_map[DEV_ID]=1;
@@ -247,7 +254,6 @@
//   g_com_map[MAX_REPORT_ANC_NUM]=1;
   g_com_map[NOMOVESLEEP_TIME]=10;
#endif
      if(g_com_map[COM_INTERVAL]==0)
   {
     g_com_map[COM_INTERVAL]=100;
@@ -341,7 +347,7 @@
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_LPTIM1_Init();
    MX_DMA_Init();
   MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_SPI1_Init();
  MX_ADC_Init();
@@ -353,7 +359,7 @@
   Dw1000_App_Init();
   
   dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
   //dwt_entersleep();
   dwt_entersleep();
   waitusart_timer=tag_frequency*USART_KEEPWAKE_TIME;;
   DW_DISABLE;
    if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
@@ -403,9 +409,10 @@
      {
         waitusart_timer--;
      }
         if(m_bEUARTTxEn==0&&waitusart_timer==0)
         if(m_bEUARTTxEn==0&&waitusart_timer==0&&(motor_state==0||motor_state==3))
         {   
#ifndef DEBUG_MODE
#ifndef DEBUG_MODE
if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
            HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
#endif
         }
@@ -686,7 +693,7 @@
  HAL_GPIO_WritePin(GPIOA, SCL_Pin|SDA_Pin|SPI_CS_Pin, GPIO_PIN_SET);
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|MOTOR_Pin, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|MOTOR_Pin|PWR_CTL_Pin, GPIO_PIN_SET);
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, LED1_G_Pin|LED1_R_Pin|LED2_R_Pin, GPIO_PIN_RESET);
@@ -733,8 +740,10 @@
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(USER_KEY_GPIO_Port, &GPIO_InitStruct);
  /*Configure GPIO pins : MOTOR_Pin LED1_G_Pin LED1_R_Pin LED2_R_Pin */
  GPIO_InitStruct.Pin = MOTOR_Pin|LED1_G_Pin|LED1_R_Pin|LED2_R_Pin;
  /*Configure GPIO pins : MOTOR_Pin LED1_G_Pin LED1_R_Pin LED2_R_Pin
                           PWR_CTL_Pin */
  GPIO_InitStruct.Pin = MOTOR_Pin|LED1_G_Pin|LED1_R_Pin|LED2_R_Pin
                          |PWR_CTL_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
@@ -791,7 +800,6 @@
  HAL_PWR_EnterSTANDBYMode();   
}
extern uint8_t tx_near_msg[80],stationary_flag;
extern float nomove_count;
float key_keeptime;
void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
{