// File: /workspace/github_cpp_makefile_star2_O1/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 0x239138(%rip), %rax    # 0x33f6e0
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
leaq 0x2390fd(%rip), %rcx    # 0x33f6b8
movsd (%rcx), %xmm3
jne 0x1065c3
jnp 0x1065f6
ucomisd %xmm1, %xmm3
jne 0x1065cb
jnp 0x1065f6
ucomisd %xmm0, %xmm3
jbe 0x1065f6
movapd %xmm0, %xmm2
divsd %xmm3, %xmm2
mulsd %xmm2, %xmm3
leaq 0x2390cc(%rip), %rcx    # 0x33f6b0
mulsd (%rcx), %xmm2
addsd 0x2a80(%rip), %xmm0     # 0x109070
movsd %xmm0, (%rax)
jmp 0x106601
leaq 0x2390b3(%rip), %rcx    # 0x33f6b0
movsd (%rcx), %xmm2
movsd 0x2a67(%rip), %xmm0     # 0x109070
movapd %xmm0, %xmm4
divsd %xmm3, %xmm4
leaq 0x239088(%rip), %rcx    # 0x33f6a0
movsd (%rcx), %xmm1
mulsd %xmm1, %xmm4
xorpd %xmm5, %xmm5
cmpneqsd %xmm5, %xmm3
andpd %xmm4, %xmm3
movlpd %xmm3, 0x34f31b(%rip)   # 0x455950
ucomisd %xmm5, %xmm2
jbe 0x106674
addsd %xmm0, %xmm2
movapd %xmm0, %xmm3
divsd %xmm2, %xmm3
movapd %xmm0, %xmm4
subsd %xmm3, %xmm4
movsd %xmm4, 0x34f2f1(%rip)   # 0x455948
leaq 0x23904a(%rip), %rcx    # 0x33f6a8
movsd (%rcx), %xmm3
xorpd 0x2b36(%rip), %xmm3     # 0x1091a0
mulsd %xmm1, %xmm3
divsd %xmm2, %xmm3
jmp 0x10669e
leaq 0x239035(%rip), %rcx    # 0x33f6b0
movsd (%rcx), %xmm2
movsd %xmm2, 0x34f2c1(%rip)   # 0x455948
leaq 0x23901a(%rip), %rcx    # 0x33f6a8
movsd (%rcx), %xmm3
xorpd 0x2b06(%rip), %xmm3     # 0x1091a0
mulsd %xmm1, %xmm3
movsd %xmm3, 0x34f29a(%rip)   # 0x455940
subsd 0x34f29a(%rip), %xmm0   # 0x455948
mulsd %xmm0, %xmm1
subsd %xmm3, %xmm1
movsd %xmm1, 0x34f27a(%rip)   # 0x455938
leaq 0x238fd3(%rip), %rcx    # 0x33f698
movb (%rcx), %cl
testb %cl, %cl
je 0x106711
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x106711
jp 0x106711
leaq 0x238f56(%rip), %rax    # 0x33f638
movl (%rax), %edx
leal 0x1(%rdx), %esi
cmpl $0x9, %edx
movl $0x1, %edx
cmovgel %edx, %esi
testl %esi, %esi
cmovsl %edx, %esi
movl %esi, (%rax)
leaq 0x114c28(%rip), %rax    # 0x21b328
movq (%rax), %rax
movslq %esi, %rdx
leaq 0x114ba3(%rip), %rsi    # 0x21b2b0
movq %rax, (%rsi,%rdx,8)
testb %cl, %cl
je 0x10671b
popq %rbp
jmp 0x10671d
popq %rbp
retq