// File: 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 0x10d2e1(%rip), %rax    # 0x277afc
cmpl $0x0, (%rax)
jne 0x16a836
leaq 0x201c05(%rip), %rax    # 0x36c42c
cmpl $0x0, (%rax)
jne 0x16a84e
callq 0x83ad0
cmpl $0x0, %eax
je 0x16a84e
leaq 0x201553(%rip), %rax    # 0x36bd90
movsd (%rax), %xmm0
movsd %xmm0, 0x34a3af(%rip)   # 0x4b4bf8
jmp 0x16a9d1
leaq 0x2013a3(%rip), %rax    # 0x36bbf8
movsd (%rax), %xmm0
movsd %xmm0, 0x34a397(%rip)   # 0x4b4bf8
leaq 0x20191c(%rip), %rax    # 0x36c184
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x16a882
leaq 0x201909(%rip), %rax    # 0x36c180
movl $0x0, (%rax)
jmp 0x16a9d1
leaq 0x2018ef(%rip), %rax    # 0x36c178
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16a89d
jp 0x16a89d
jmp 0x16a9af
movsd 0x34a35b(%rip), %xmm0   # 0x4b4c00
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16a8b5
jp 0x16a8b5
jmp 0x16a9af
leaq 0x2018c4(%rip), %rax    # 0x36c180
cmpl $0x0, (%rax)
jle 0x16a946
movsd 0x34a32b(%rip), %xmm1   # 0x4b4bf8
movsd 0x34a343(%rip), %xmm0   # 0x4b4c18
ucomisd %xmm1, %xmm0
jbe 0x16a8ea
leaq 0x20189e(%rip), %rax    # 0x36c180
movl $0x0, (%rax)
jmp 0x16a944
movsd 0x34a306(%rip), %xmm0   # 0x4b4bf8
leaq 0x201867(%rip), %rax    # 0x36c160
ucomisd (%rax), %xmm0
jbe 0x16a91d
leaq 0x20187e(%rip), %rax    # 0x36c184
movzbl (%rax), %eax
cmpl $0x2, %eax
jge 0x16a91d
leaq 0x20186b(%rip), %rax    # 0x36c180
movl $0x0, (%rax)
jmp 0x16a942
leaq 0x20185c(%rip), %rax    # 0x36c180
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x201850(%rip), %rax    # 0x36c180
movl %ecx, (%rax)
movsd 0x34a2de(%rip), %xmm0   # 0x4b4c18
movsd %xmm0, 0x34a2b6(%rip)   # 0x4b4bf8
jmp 0x16a944
jmp 0x16a9ad
movsd 0x34a2aa(%rip), %xmm0   # 0x4b4bf8
subsd 0x34a2aa(%rip), %xmm0   # 0x4b4c00
leaq 0x20181b(%rip), %rax    # 0x36c178
ucomisd (%rax), %xmm0
jbe 0x16a9ab
leaq 0x10fb82(%rip), %rax    # 0x27a4ec
cmpb $0x0, (%rax)
je 0x16a97e
leaq 0x20180a(%rip), %rax    # 0x36c180
movl $0x3, (%rax)
jmp 0x16a98b
leaq 0x2017fb(%rip), %rax    # 0x36c180
movl $0x2d, (%rax)
movsd 0x34a26d(%rip), %xmm0   # 0x4b4c00
movsd %xmm0, 0x34a27d(%rip)   # 0x4b4c18
movsd 0x34a275(%rip), %xmm0   # 0x4b4c18
movsd %xmm0, 0x34a24d(%rip)   # 0x4b4bf8
jmp 0x16a9ad
jmp 0x16a9af
leaq 0x2017ce(%rip), %rax    # 0x36c184
movzbl (%rax), %eax
cmpl $0x1, %eax
jle 0x16a9d1
movsd 0x34a232(%rip), %xmm0   # 0x4b4bf8
leaq 0x20122b(%rip), %rax    # 0x36bbf8
movsd %xmm0, (%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)