zhyinch
2020-06-17 4864dd7a1bf69e16045c18bc19220b3ce9f55c72
Ô´Âë/ºËÐİå/Src/application/beep_logic_app.c
@@ -8,11 +8,11 @@
#define OFFTIME1 0  // 100ms
#define ONTIME2 1   // 100ms
#define OFFTIME2 1  // 100ms
#define OFFTIME2 0  // 100ms
#define ONTIME3 1   // 500ms
#define ONTIME3 5   // 500ms
#define OFFTIME3 5  // 500ms
u8 distoffset1=0,distoffset2=0;
void main_logic(void)   //主逻辑在这里执行
{
   static uint8_t beep_state,timer_state,beep_timer,beep_ontime,beep_offtime;
@@ -25,61 +25,43 @@
      min_dist=0xffff;
      for(i = 0; i < 255;i++)
      {
         if(g_Tagdist[i] < min_dist)
         if(g_Tagdist[i] < min_dist&&g_Tagdist[i]>g_com_map[ALARM_DISTANCE1])
         {
            min_dist=g_Tagdist[i];
         }
            
      }
      
      if(min_dist <= g_com_map[ALARM_DISTANCE1])
      {
         beep_ontime = ONTIME1;
         beep_offtime = OFFTIME1;
         beep_state=1;
      }else if (min_dist <= g_com_map[ALARM_DISTANCE2])
 if (min_dist <= g_com_map[ALARM_DISTANCE2]+distoffset1)
      {
         beep_ontime = ONTIME2;
         beep_offtime = OFFTIME2;
         beep_state=1;
      }else if (min_dist <= g_com_map[ALARM_DISTANCE3])
         beep_state=2;
         distoffset1=20;
         distoffset2=0;
      }
 else if (min_dist <= g_com_map[ALARM_DISTANCE3]+distoffset2)
      {
         beep_ontime = ONTIME3;
         beep_offtime = OFFTIME3;
         beep_state=1;
      }else{
         distoffset1=0;
         distoffset2=20;
      }
      else{
         beep_state=0;
         distoffset1=0;
         distoffset2=0;
      }
      
      if(beep_state==1)
      if(beep_state!=0)
      {
         if(timer_state==1)
         {
            if(beep_timer++ < beep_ontime)
            {
               switch(g_com_map[ALARM_DEV])
                     {
                        case 0:
                           BEEP2_ON;
                           BEEP_OFF;
                           OUT2_OFF;
                           break;
                        case 1:
                           BEEP_ON;
                           BEEP2_OFF;
                           OUT2_OFF;
                           break;
                        case 2:
                           OUT2_ON;
                           BEEP_OFF;
                           BEEP2_OFF;
                           break;
                        default:
                           BEEP2_ON;
                           BEEP_ON;
                           OUT2_ON;
                           break;
                     }
               RELAY1_ON;
               RELAY2_ON;
            }else{
               timer_state=0;
               beep_timer=0;
@@ -87,23 +69,8 @@
         }else{
             if(beep_timer++ < beep_offtime)
               {
                  switch(g_com_map[ALARM_DEV])
                     {
                        case 0:
                           BEEP2_OFF;
                           break;
                        case 1:
                           BEEP_OFF;
                           break;
                        case 2:
                           OUT2_OFF;
                           break;
                        default:
                           BEEP2_OFF;
                           BEEP_OFF;
                           OUT2_OFF;
                           break;
                     }
                  RELAY1_OFF;
                  RELAY2_OFF;
               }else{
                     timer_state=1;
                     beep_timer=0;
@@ -112,23 +79,8 @@
         }
      
      }   else {
         switch(g_com_map[ALARM_DEV])
         {
            case 0:
               BEEP2_OFF;
               break;
            case 1:
               BEEP_OFF;
               break;
            case 2:
               OUT2_OFF;
               break;
            default:
               BEEP2_OFF;
               BEEP_OFF;
               OUT2_OFF;
               break;
         }
         RELAY1_OFF;
          RELAY2_OFF;
      }
   }
}