// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: filter_spikes()
void filter_spikes()
{
// This routine helps filter out false temperature sensor reading spikes.
// It sends the last valid temperature reading to the PID until the reading  
// either increases in value,  falls below the starting value, or times out.

//temperature += KL_TUNE_STEP;    // simulate a temperature spike
//if(KL_TUNE_STEP > 0.0F) KL_TUNE_STEP -= 0.01F;
//else KL_TUNE_STEP = 0.0F;

   if(enviro_temp_pid || ((have_temperature == 0) && enviro_mode())) {  // receiver does not send temperature
      this_temperature = tc1;
      return;
   }
   else {  // use receiver temperature sensor
      this_temperature = temperature;
   }

   if(spike_mode == 0) {
      spike_delay = 0;
      return;  // not filtering spikes
   }

   if(spike_threshold && last_temp) { // filter out temperature spikes
      if(spike_delay > 0) {  // hold temperature while spike settles out
         if(this_temperature < spike_temp) {  // temp has fallen below where the spike started
            spike_delay = 0; 
         }
         else if((this_temperature > last_temp_val) && (spike_mode < 2)) {  // temp is now rising
            spike_delay = 0; 
         }
         else {  // countdown max spike filter time
            --spike_delay;
            this_temperature = spike_temp;
         }
      }
      else if((this_temperature - last_temp) > spike_threshold) {  // temp spike seen
         if(undo_fw_temp_filter) spike_delay = 3;                  // de-filtered temps cause one second spikes
         else                    spike_delay = SPIKE_FILTER_TIME;  // filtered temps cause 30 second spikes
         spike_temp = last_temp;
         this_temperature = spike_temp;
      }
   }

   if(spike_mode > 1) temperature = this_temperature;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x11217c(%rip), %rax    # 0x21891c
cmpl $0x0, (%rax)
je 0x1067ba
leaq 0x206404(%rip), %rax    # 0x30cbb0
movsd (%rax), %xmm0
movsd %xmm0, 0x34ee50(%rip)   # 0x455608
popq %rbp
retq
leaq 0x206a8b(%rip), %rax    # 0x30d24c
cmpl $0x0, (%rax)
je 0x106840
leaq 0x20624b(%rip), %rax    # 0x30ca18
movsd (%rax), %xmm0
movsd %xmm0, 0x34ee2f(%rip)   # 0x455608
leaq 0x2067c4(%rip), %rcx    # 0x30cfa4
movb (%rcx), %cl
testb %cl, %cl
je 0x106852
leaq 0x2067ab(%rip), %rdx    # 0x30cf98
movsd (%rdx), %xmm1
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm1
jne 0x1067fd
jnp 0x10682e
movsd 0x34ee0b(%rip), %xmm2   # 0x455610
ucomisd %xmm3, %xmm2
jne 0x10680d
jnp 0x10682e
leaq 0x20678c(%rip), %rdx    # 0x30cfa0
movl (%rdx), %esi
testl %esi, %esi
jle 0x106864
movsd 0x34ee06(%rip), %xmm1   # 0x455628
ucomisd %xmm0, %xmm1
jbe 0x1068a5
movl $0x0, (%rdx)
movapd %xmm0, %xmm1
cmpb $0x1, %cl
je 0x1067b8
movsd %xmm1, (%rax)
jmp 0x1067b8
callq 0x5f6cb
testl %eax, %eax
jne 0x1067a5
jmp 0x1067c6
leaq 0x206747(%rip), %rax    # 0x30cfa0
movl $0x0, (%rax)
jmp 0x1067b8
movapd %xmm0, %xmm3
subsd %xmm2, %xmm3
ucomisd %xmm1, %xmm3
movapd %xmm0, %xmm1
jbe 0x106832
leaq 0x114a8f(%rip), %rsi    # 0x21b30c
cmpb $0x0, (%rsi)
movl $0x2d, %esi
movl $0x3, %edi
cmovel %esi, %edi
movl %edi, (%rdx)
movsd %xmm2, 0x34ed91(%rip)   # 0x455628
movsd %xmm2, 0x34ed69(%rip)   # 0x455608
movapd %xmm2, %xmm1
jmp 0x106832
cmpb $0x1, %cl
jne 0x1068c2
leaq 0x2066cf(%rip), %rdi    # 0x30cf80
ucomisd (%rdi), %xmm0
jbe 0x1068c2
movl $0x0, (%rdx)
jmp 0x1067b8
decl %esi
movl %esi, (%rdx)
movsd %xmm1, 0x34ed3a(%rip)   # 0x455608
jmp 0x106832