zhyinch
2022-09-01 12c58931b1bf47cbe49dfdd40e3975502a7893c0
Src/main.c
@@ -136,7 +136,7 @@
//      g_com_map[MOTOR_ONTIME]--;
//      motor_state = 1;
//   }
if(g_com_map[MOTOR_ENABLE])
if(0)//g_com_map[MOTOR_ENABLE])
{
    
@@ -188,6 +188,7 @@
   if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
   {
      nomove_count = 0;
        bat_percent=Get_Battary();
      if(state5v==0)
      {
         state5v=1;
@@ -295,6 +296,7 @@
         break;
      }
}
u8 active_flag,nomovesleeptime;
void Program_Init(void)
{   float temp;
   uint16_t temp2;
@@ -305,23 +307,9 @@
   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] = 0x0119;
#ifdef DEBUG_MODE
//   g_com_map[DEV_ROLE]=1;
//      g_com_map[DEV_ID]=1;
   g_com_map[COM_INTERVAL]=100;
//   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;
   }
    if(module_power>67)
      {module_power=67;}
      if(module_power<0)
      {module_power=0;}
   module_power = g_com_map[POWER];
   g_com_map[VERSION] = (1<<8)|35;
    active_flag = g_com_map[ACTIVE_INDEX];
       module_power = g_com_map[POWER];
   imu_enable=g_com_map[IMU_ENABLE];
   motor_enable=g_com_map[MOTOR_ENABLE];
   
@@ -332,8 +320,30 @@
   tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime;   
   slot_startcount=tyncpoll_time*1000/LPTIMER_LSB;
   lastpoll_time=tyncpoll_time;
  tag_frequency = 1000/g_com_map[COM_INTERVAL];
    tag_frequency = 1000/g_com_map[COM_INTERVAL];
   total_slotnum = 1000/g_com_map[COM_INTERVAL];
    nomovesleeptime = g_com_map[NOMOVESLEEP_TIME];
   if(active_flag==0)
   {
      imu_enable=1;
      nomovesleeptime =10;
   }
#ifdef DEBUG_MODE
//   g_com_map[DEV_ROLE]=1;
//      g_com_map[DEV_ID]=1;
//   g_com_map[COM_INTERVAL]=100;
//   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;
   }
    if(module_power>67)
      {module_power=67;}
      if(module_power<0)
      {module_power=0;}
   current_slotnum=1;
   current_time=GetLPTime();
      if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
@@ -440,7 +450,7 @@
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
      if(g_start_send_flag)
      if(g_start_send_flag&&active_flag)
   { static uint16_t blink_count=0;
      SystemClock_Config();
      g_start_send_flag = 0;   
@@ -469,7 +479,7 @@
      {
         waitusart_timer--;
      }
         if(m_bEUARTTxEn==0&&waitusart_timer==0&&(motor_state==0||motor_state==3))
         if(m_bEUARTTxEn==0&&waitusart_timer==0)
         {   
#ifndef DEBUG_MODE   
if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))            
@@ -933,6 +943,10 @@
      key_keeptime+=(float)g_com_map[COM_INTERVAL]/1000;
      if(key_keeptime>=KEY_KEEPRESET_TIME)
      {
            g_com_map[ACTIVE_INDEX]=!active_flag;
            save_com_map_to_flash();
            MOTOR_ON;
            HAL_Delay(2000);
         SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; 
      }
   }else{
@@ -944,14 +958,14 @@
   }else{
      stationary_flag = 0;
   }
if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
   {
      tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
   }
   if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
   {
      mcu_sleep();
   }
//if(nomove_count>=nomovesleeptime-1&&imu_enable)
//   {
//      tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
//   }
//   if(nomove_count>nomovesleeptime&&imu_enable)
//   {
//      mcu_sleep();
//   }
}
/* USER CODE END 4 */