// File: /workspace/github_cpp_makefile_star2_O2/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 0x2393e2(%rip), %rax    # 0x3296e0
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
leaq 0x2393a7(%rip), %rcx    # 0x3296b8
movsd (%rcx), %xmm2
jne 0xf0319
jnp 0xf0350
ucomisd %xmm1, %xmm2
jne 0xf0321
jnp 0xf0350
ucomisd %xmm0, %xmm2
jbe 0xf0350
movapd %xmm0, %xmm3
divsd %xmm2, %xmm3
mulsd %xmm3, %xmm2
leaq 0x239376(%rip), %rcx    # 0x3296b0
movsd (%rcx), %xmm1
mulsd %xmm1, %xmm3
addsd 0x2d26(%rip), %xmm0     # 0xf3070
movsd %xmm0, (%rax)
jmp 0xf035f
leaq 0x239359(%rip), %rax    # 0x3296b0
movsd (%rax), %xmm1
movapd %xmm1, %xmm3
movsd 0x2d09(%rip), %xmm4     # 0xf3070
movapd %xmm4, %xmm6
divsd %xmm2, %xmm6
leaq 0x23932a(%rip), %rax    # 0x3296a0
movsd (%rax), %xmm5
mulsd %xmm5, %xmm6
xorpd %xmm7, %xmm7
cmpneqsd %xmm7, %xmm2
andpd %xmm6, %xmm2
movlpd %xmm2, 0x34f4dd(%rip)   # 0x43f870
ucomisd %xmm7, %xmm3
jbe 0xf03ca
addsd %xmm4, %xmm3
movapd %xmm4, %xmm2
divsd %xmm3, %xmm2
movapd %xmm4, %xmm1
subsd %xmm2, %xmm1
leaq 0x2392f4(%rip), %rax    # 0x3296a8
movsd (%rax), %xmm2
xorpd 0x2df0(%rip), %xmm2     # 0xf31b0
mulsd %xmm5, %xmm2
divsd %xmm3, %xmm2
jmp 0xf03e1
leaq 0x2392d7(%rip), %rax    # 0x3296a8
movsd (%rax), %xmm2
xorpd 0x2dd3(%rip), %xmm2     # 0xf31b0
mulsd %xmm5, %xmm2
movsd %xmm1, 0x34f47f(%rip)   # 0x43f868
movsd %xmm2, 0x34f46f(%rip)   # 0x43f860
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm5
subsd %xmm2, %xmm5
movsd %xmm5, 0x34f453(%rip)   # 0x43f858
leaq 0x23928c(%rip), %rax    # 0x329698
movb (%rax), %al
testb %al, %al
je 0xf0456
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xf0456
jp 0xf0456
leaq 0x239213(%rip), %rax    # 0x329638
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 0x114ee5(%rip), %rax    # 0x205328
movq (%rax), %rax
movslq %edx, %rcx
leaq 0x114e60(%rip), %rdx    # 0x2052b0
movq %rax, (%rdx,%rcx,8)
jmp 0xf045a
testb %al, %al
je 0xf0460
popq %rbp
jmp 0xf0462
popq %rbp
retq