// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: calc_osc_k_factors()
void calc_osc_k_factors()
{
double i_tc;
double f_tc;

   // This routine converts the user friendly input PID constants into the
   // "k" values used by the PID filter algorithm.  It is called whenever
   // a PID filter constant is changed by the user.
   //
   // OSC_P_GAIN        -> osc_k1   (PID gain)
   // OSC_D_TC          -> osc_k2   (derivative time constant)
   // OSC_FILTER_TC     -> osc_k3   (filter time constant)
   // OSC_I_TC          -> osc_k4   (integrator time constant)
   // OSC_FILTER_OFFSET             (osc setpoint offset)

   if(osc_rampup && OSC_I_TC && (osc_rampup < OSC_I_TC)) {
      i_tc = OSC_I_TC      * (osc_rampup / OSC_I_TC);
      f_tc = OSC_FILTER_TC * (osc_rampup / OSC_I_TC);
      osc_rampup += 1.0;
   }
   else {
      i_tc = OSC_I_TC;
      f_tc = OSC_FILTER_TC;
   }

   if(i_tc) osc_k4 = (1.0/i_tc) / OSC_PID_UPDATE_RATE * OSC_P_GAIN;
   else     osc_k4 = 0.0;

   if(f_tc > 0.0) {
      osc_k3 = 1.0 - (1.0/((f_tc*OSC_PID_UPDATE_RATE)+1.0));
      osc_k2 = (-1.0 * OSC_D_TC * OSC_P_GAIN) / (f_tc*OSC_PID_UPDATE_RATE+1.0) * (OSC_PID_UPDATE_RATE/OSC_SCALE_FACTOR);
   }
   else {
      osc_k3 = OSC_FILTER_TC;
      osc_k2 = (-1.0 * OSC_D_TC * OSC_P_GAIN) * (OSC_PID_UPDATE_RATE/OSC_SCALE_FACTOR);
   }

   osc_k1 = ((OSC_P_GAIN/OSC_SCALE_FACTOR) * (1.0-osc_k3)) - osc_k2;

   if(osc_pid_debug && (osc_rampup == 0.0)) {  // set a marker each time a PID value changes
      if(++test_marker >= MAX_MARKER) test_marker = 1;
      if(test_marker < 0) test_marker = 1;
      mark_q_entry[test_marker] = plot_q_in;
   }

   if(osc_pid_debug) {
      show_osc_pid_values();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x238a22(%rip), %rax    # 0x33f6e0
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
leaq 0x2389e7(%rip), %rcx    # 0x33f6b8
movsd (%rcx), %xmm2
jne 0x106cd9
jnp 0x106d10
ucomisd %xmm1, %xmm2
jne 0x106ce1
jnp 0x106d10
ucomisd %xmm0, %xmm2
jbe 0x106d10
movapd %xmm0, %xmm3
divsd %xmm2, %xmm3
mulsd %xmm3, %xmm2
leaq 0x2389b6(%rip), %rcx    # 0x33f6b0
movsd (%rcx), %xmm1
mulsd %xmm1, %xmm3
addsd 0x2366(%rip), %xmm0     # 0x109070
movsd %xmm0, (%rax)
jmp 0x106d1f
leaq 0x238999(%rip), %rax    # 0x33f6b0
movsd (%rax), %xmm1
movapd %xmm1, %xmm3
movsd 0x2349(%rip), %xmm4     # 0x109070
movapd %xmm4, %xmm6
divsd %xmm2, %xmm6
leaq 0x23896a(%rip), %rax    # 0x33f6a0
movsd (%rax), %xmm5
mulsd %xmm5, %xmm6
xorpd %xmm7, %xmm7
cmpneqsd %xmm7, %xmm2
andpd %xmm6, %xmm2
movlpd %xmm2, 0x34eb1d(%rip)   # 0x455870
ucomisd %xmm7, %xmm3
jbe 0x106d8a
addsd %xmm4, %xmm3
movapd %xmm4, %xmm2
divsd %xmm3, %xmm2
movapd %xmm4, %xmm1
subsd %xmm2, %xmm1
leaq 0x238934(%rip), %rax    # 0x33f6a8
movsd (%rax), %xmm2
xorpd 0x2430(%rip), %xmm2     # 0x1091b0
mulsd %xmm5, %xmm2
divsd %xmm3, %xmm2
jmp 0x106da1
leaq 0x238917(%rip), %rax    # 0x33f6a8
movsd (%rax), %xmm2
xorpd 0x2413(%rip), %xmm2     # 0x1091b0
mulsd %xmm5, %xmm2
movsd %xmm1, 0x34eabf(%rip)   # 0x455868
movsd %xmm2, 0x34eaaf(%rip)   # 0x455860
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm5
subsd %xmm2, %xmm5
movsd %xmm5, 0x34ea93(%rip)   # 0x455858
leaq 0x2388cc(%rip), %rax    # 0x33f698
movb (%rax), %al
testb %al, %al
je 0x106e16
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x106e16
jp 0x106e16
leaq 0x238853(%rip), %rax    # 0x33f638
movl (%rax), %ecx
leal 0x1(%rcx), %edx
cmpl $0x9, %ecx
movl $0x1, %ecx
cmovgel %ecx, %edx
testl %edx, %edx
cmovsl %ecx, %edx
movl %edx, (%rax)
leaq 0x114525(%rip), %rax    # 0x21b328
movq (%rax), %rax
movslq %edx, %rcx
leaq 0x1144a0(%rip), %rdx    # 0x21b2b0
movq %rax, (%rdx,%rcx,8)
jmp 0x106e1a
testb %al, %al
je 0x106e20
popq %rbp
jmp 0x106e22
popq %rbp
retq