// File: /workspace/github_cpp_makefile_star2_O1/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 0x112892(%rip), %rax    # 0x21891c
cmpl $0x0, (%rax)
je 0x1060a4
leaq 0x206b1a(%rip), %rax    # 0x30cbb0
movsd (%rax), %xmm0
movsd %xmm0, 0x34f646(%rip)   # 0x4556e8
popq %rbp
retq
leaq 0x2071a1(%rip), %rax    # 0x30d24c
cmpl $0x0, (%rax)
je 0x106138
leaq 0x20695d(%rip), %rax    # 0x30ca18
movsd (%rax), %xmm0
movsd %xmm0, 0x34f621(%rip)   # 0x4556e8
leaq 0x206ed6(%rip), %rcx    # 0x30cfa4
movb (%rcx), %cl
testb %cl, %cl
je 0x10614a
leaq 0x206ebd(%rip), %rdx    # 0x30cf98
movsd (%rdx), %xmm2
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jne 0x1060ef
jnp 0x106195
movsd 0x34f5f9(%rip), %xmm1   # 0x4556f0
ucomisd %xmm3, %xmm1
jne 0x106103
jnp 0x106195
leaq 0x206e96(%rip), %rdx    # 0x30cfa0
movl (%rdx), %esi
testl %esi, %esi
jle 0x10615c
movsd 0x34f5f0(%rip), %xmm1   # 0x455708
ucomisd %xmm0, %xmm1
ja 0x106130
cmpb $0x1, %cl
jne 0x106189
leaq 0x206e56(%rip), %rdi    # 0x30cf80
ucomisd (%rdi), %xmm0
jbe 0x106189
movl $0x0, (%rdx)
jmp 0x106195
callq 0x5f743
testl %eax, %eax
jne 0x10608f
jmp 0x1060b4
leaq 0x206e4f(%rip), %rax    # 0x30cfa0
movl $0x0, (%rax)
jmp 0x1060a2
subsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jbe 0x106195
leaq 0x11519f(%rip), %rsi    # 0x21b30c
cmpb $0x0, (%rsi)
movl $0x2d, %esi
movl $0x3, %edi
cmovel %esi, %edi
movl %edi, (%rdx)
movsd %xmm1, 0x34f581(%rip)   # 0x455708
jmp 0x10618d
decl %esi
movl %esi, (%rdx)
movsd %xmm1, 0x34f553(%rip)   # 0x4556e8
cmpb $0x1, %cl
je 0x1060a2
movsd 0x34f542(%rip), %xmm0   # 0x4556e8
movsd %xmm0, (%rax)
jmp 0x1060a2