// File: /workspace/github_cpp_makefile_star2_O2/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 0x112b23(%rip), %rax    # 0x20291c
cmpl $0x0, (%rax)
je 0xefe13
leaq 0x206dab(%rip), %rax    # 0x2f6bb0
movsd (%rax), %xmm0
movsd %xmm0, 0x34f7f7(%rip)   # 0x43f608
popq %rbp
retq
leaq 0x207432(%rip), %rax    # 0x2f724c
cmpl $0x0, (%rax)
je 0xefe96
leaq 0x206bf2(%rip), %rax    # 0x2f6a18
movsd (%rax), %xmm0
movsd %xmm0, 0x34f7d6(%rip)   # 0x43f608
leaq 0x20716b(%rip), %rcx    # 0x2f6fa4
movb (%rcx), %cl
testb %cl, %cl
je 0xefea8
leaq 0x207152(%rip), %rdx    # 0x2f6f98
movsd (%rdx), %xmm1
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm1
jne 0xefe56
jnp 0xefe84
movsd 0x34f7b2(%rip), %xmm2   # 0x43f610
ucomisd %xmm3, %xmm2
jne 0xefe66
jnp 0xefe84
leaq 0x207133(%rip), %rdx    # 0x2f6fa0
movl (%rdx), %esi
testl %esi, %esi
jle 0xefeb7
movsd 0x34f7ad(%rip), %xmm1   # 0x43f628
ucomisd %xmm0, %xmm1
jbe 0xefef4
andl $0x0, (%rdx)
movapd %xmm0, %xmm1
cmpb $0x1, %cl
je 0xefe11
movsd %xmm1, (%rax)
jmp 0xefe11
callq 0x57eca
testl %eax, %eax
jne 0xefdfe
jmp 0xefe1f
leaq 0x2070f1(%rip), %rax    # 0x2f6fa0
andl $0x0, (%rax)
jmp 0xefe11
movapd %xmm0, %xmm3
subsd %xmm2, %xmm3
ucomisd %xmm1, %xmm3
movapd %xmm0, %xmm1
jbe 0xefe88
leaq 0x11543c(%rip), %rsi    # 0x20530c
cmpb $0x0, (%rsi)
pushq $0x2d
popq %rsi
pushq $0x3
popq %rdi
cmovel %esi, %edi
movl %edi, (%rdx)
movsd %xmm2, 0x34f742(%rip)   # 0x43f628
movsd %xmm2, 0x34f71a(%rip)   # 0x43f608
movapd %xmm2, %xmm1
jmp 0xefe88
cmpb $0x1, %cl
jne 0xeff0e
leaq 0x207080(%rip), %rdi    # 0x2f6f80
ucomisd (%rdi), %xmm0
jbe 0xeff0e
andl $0x0, (%rdx)
jmp 0xefe11
decl %esi
movl %esi, (%rdx)
movsd %xmm1, 0x34f6ee(%rip)   # 0x43f608
jmp 0xefe88