// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: edit_temp_pid_value(char, char*, int)
u08 edit_temp_pid_value(char c, char *s, int kbd_cmd)
{
   if(s == 0) return 'k';

   c = toupper(c);

   if(c == 'A') {    // KA command - bang-bang autotune
      // ka0 = abort autotune
      // ka1 = do full tuneup with all settling delays
      // ka2 = don't wait for temp to get near setpoint
      // ka3 = don't wait for pid to stabilize
      if(bang_bang == 0) OLD_P_GAIN = P_GAIN;
      bang_bang = 1;
      sscanf(s, "%d", &bang_bang);
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;

      if(bang_bang > 4) bang_bang = 1;
      else if(bang_bang == 0) {       // abort autotune
         P_GAIN = OLD_P_GAIN;
         calc_k_factors();
         if(kbd_cmd) clear_pid_display();
         if(kbd_cmd) show_pid_values();
      }
   }
   else if(c == 'D') {  // KD command - derivitive time constant
      D_TC = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'F') {  // KF command - filter time constant
      FILTER_TC = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'G') {  // KG command - scale factor (loop gain correction)
      k7 = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'H') {  // KH command - PID debug (help) display
      pid_debug = toggle_value(pid_debug);
      if(pid_debug) osc_pid_debug = 0;
      if(kbd_cmd) clear_pid_display();
   }
   else if(c == 'I') {  // KI command - integral time constant
      I_TC = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'K') {  // KK command - all major PID values
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;
      FILTER_OFFSET = 0.0;

      #ifdef DOUBLE_DATA
         sscanf(s, "%lf%c%lf%c%lf%c%lf", &P_GAIN,&c, &D_TC,&c,  &FILTER_TC,&c, &I_TC);
      #else
         sscanf(s, "%f%c%f%c%f%c%f", &P_GAIN,&c, &D_TC,&c,  &FILTER_TC,&c, &I_TC);
      #endif

      calc_k_factors();
   }
   else if(c == 'L') {  // KL command - load distubance
      k6 = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'N') {  // KN command - mark's medium values
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;
      set_default_pid(1);
      if(0 && kbd_cmd) show_pid_values();
   }
   else if(c == 'O') {  // KO command - filter offset
      FILTER_OFFSET = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'P') {  // KP command - pid gain
      P_GAIN = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'R') {  // KR command - integrator reset
      k8 = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'S') {  // KS command - scale factor (loop gain correction)
      k7 = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == 'T') {  // KT command - pwm test
      #ifdef DOUBLE_DATA
         sscanf(s, "%lf%c%lf", &test_cool, &c, &test_heat);
      #else
         sscanf(s, "%f%c%f", &test_cool, &c, &test_heat);
      #endif

      if(test_heat || test_cool) {
         if(kbd_cmd) enable_temp_control();
         do_temp_control = 1;
      }
      if(++test_marker >= MAX_MARKER) test_marker = 1;
      if(test_marker < 0) test_marker = 1;
      mark_q_entry[test_marker] = plot_q_in;
   }
   else if(c == 'W') {  // KW command - Warren's slow values
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;
      set_default_pid(0);
      if(0 && kbd_cmd) show_pid_values();
   }
   else if(c == 'X') {  // KX command - fast PID values
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;
      set_default_pid(2);
      if(0 && kbd_cmd) show_pid_values();
   }
   else if(c == 'Y') {  // KY command - very fast PID values
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;
      set_default_pid(3);
      if(0 && kbd_cmd) show_pid_values();
   }
   else if(c == 'Z') {  // KZ command - reset PID
      integrator = 0.0F;
      if(kbd_cmd) enable_temp_control();
      do_temp_control = 1;
   }
   else if(c == '9') {  // K9 command - autotune step size
      KL_TUNE_STEP = (DATA_SIZE) atof(s);
      calc_k_factors();
   }
   else if(c == '0') {  // K0 command - make temperature crude
      crude_temp = toggle_value(crude_temp);
   }
   else return 1;

   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
testq %rsi, %rsi
je 0x30f4b
movl %edx, %r14d
movq %rsi, %r15
movsbl %dil, %edi
callq 0x9700
movb %al, -0x21(%rbp)
movzbl %al, %eax
movb $0x1, %bl
addl $-0x30, %eax
cmpl $0x2a, %eax
ja 0x3121b
leaq 0xc51fe(%rip), %rcx     # 0xf612c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x9470
leaq 0x40e81a(%rip), %rax    # 0x43f760
jmp 0x311f2
movb $0x6b, %bl
jmp 0x3121b
testl %r14d, %r14d
je 0x30f5c
callq 0xf01cf
leaq 0x2f8e5d(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
pushq $0x3
jmp 0x31213
movq %r15, %rdi
callq 0x9470
leaq 0x2f86cc(%rip), %rax    # 0x329648
jmp 0x311f2
movq %r15, %rdi
callq 0x9470
leaq 0x40e7c8(%rip), %rax    # 0x43f758
jmp 0x311f2
movq %r15, %rdi
callq 0x9470
leaq 0x2f86c4(%rip), %rax    # 0x329668
jmp 0x311f2
leaq 0x2f868c(%rip), %rbx    # 0x32963c
cmpl $0x0, (%rbx)
jne 0x30fcb
leaq 0x2f868c(%rip), %rax    # 0x329648
movsd (%rax), %xmm0
leaq 0x2f86b1(%rip), %rax    # 0x329678
movsd %xmm0, (%rax)
movl $0x1, (%rbx)
leaq 0xdcec4(%rip), %rsi     # 0x10de9c
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9350
testl %r14d, %r14d
je 0x30fef
callq 0xf01cf
leaq 0x2f8dca(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
movl (%rbx), %eax
cmpl $0x5, %eax
jl 0x31249
movl $0x1, (%rbx)
jmp 0x31219
leaq 0x40e71a(%rip), %rax    # 0x43f730
andq $0x0, (%rax)
testl %r14d, %r14d
je 0x31024
callq 0xf01cf
leaq 0x2f8d95(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
jmp 0x31219
testl %r14d, %r14d
je 0x3103d
callq 0xf01cf
leaq 0x2f8d7c(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
pushq $0x1
jmp 0x31213
leaq 0x2f85ef(%rip), %rbx    # 0x329644
movzbl (%rbx), %edi
callq 0x31279
movzbl %al, %eax
movl %eax, (%rbx)
jmp 0x31219
movq %r15, %rdi
callq 0x9470
leaq 0x2f85fa(%rip), %rax    # 0x329670
jmp 0x311f2
leaq 0x2f85be(%rip), %rbx    # 0x329640
movzbl (%rbx), %edi
callq 0x31279
movb %al, (%rbx)
testb %al, %al
je 0x3109a
leaq 0x2f8601(%rip), %rax    # 0x329698
movb $0x0, (%rax)
testl %r14d, %r14d
je 0x31219
callq 0x30ec4
jmp 0x31219
movq %r15, %rdi
callq 0x9470
leaq 0x2f8594(%rip), %rax    # 0x329650
jmp 0x311f2
movq %r15, %rdi
callq 0x9470
leaq 0x40e698(%rip), %rax    # 0x43f768
jmp 0x311f2
leaq 0xec249(%rip), %rsi     # 0x11d325
leaq 0x2f854d(%rip), %rbx    # 0x329630
leaq 0x2f853e(%rip), %r12    # 0x329628
leaq -0x21(%rbp), %rcx
movq %r15, %rdi
movq %rbx, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x9350
movsd (%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x3111c
jp 0x3111c
movsd (%rbx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x3111c
jnp 0x31130
testl %r14d, %r14d
je 0x31126
callq 0xf01cf
leaq 0x2f8c93(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
leaq 0x2f8501(%rip), %rax    # 0x329638
movl (%rax), %ecx
leal 0x1(%rcx), %edx
cmpl $0x9, %ecx
pushq $0x1
popq %rcx
cmovgel %ecx, %edx
testl %edx, %edx
cmovsl %ecx, %edx
movl %edx, (%rax)
leaq 0x1d41d5(%rip), %rax    # 0x205328
movq (%rax), %rax
movslq %edx, %rcx
leaq 0x1d4150(%rip), %rdx    # 0x2052b0
movq %rax, (%rdx,%rcx,8)
jmp 0x31219
movq %r15, %rdi
callq 0x9470
leaq 0x2f84e0(%rip), %rax    # 0x329658
jmp 0x311f2
testl %r14d, %r14d
je 0x31184
callq 0xf01cf
leaq 0x2f8c35(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
leaq 0x2f84d3(%rip), %rax    # 0x329668
andq $0x0, (%rax)
subq $0x8, %rsp
leaq 0x2f84bc(%rip), %r10    # 0x329660
leaq -0x21(%rbp), %rcx
leaq 0x2f84a9(%rip), %r11    # 0x329658
leaq 0xec165(%rip), %rsi     # 0x11d31b
leaq 0x2f848b(%rip), %rdx    # 0x329648
leaq 0x2f848c(%rip), %r8     # 0x329650
xorl %ebx, %ebx
movq %r15, %rdi
movq %rcx, %r9
xorl %eax, %eax
pushq %r10
pushq %rcx
pushq %r11
callq 0x9350
addq $0x20, %rsp
callq 0xef0e2
jmp 0x3121b
movq %r15, %rdi
callq 0x9470
leaq 0x2f846e(%rip), %rax    # 0x329660
movsd %xmm0, (%rax)
callq 0xef0e2
jmp 0x31219
testl %r14d, %r14d
je 0x31207
callq 0xf01cf
leaq 0x2f8bb2(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
pushq $0x2
popq %rdi
callq 0xef1f2
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
je 0x31234
callq 0xf01cf
leaq 0x2f8b85(%rip), %rax    # 0x329dc0
movb $0x1, (%rax)
xorl %ebx, %ebx
xorl %edi, %edi
callq 0xef1f2
jmp 0x3121b
testl %eax, %eax
jne 0x31219
leaq 0x2f8424(%rip), %rax    # 0x329678
movsd (%rax), %xmm0
leaq 0x2f83e9(%rip), %rax    # 0x329648
movsd %xmm0, (%rax)
callq 0xef0e2
testl %r14d, %r14d
je 0x31219
callq 0x30ec4
callq 0xef290
jmp 0x31219