// File: /workspace/github_cpp_makefile_star2_O3/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 0x33c98
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 0x33f6e
leaq 0xd8439(%rip), %rcx     # 0x10c0b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x9470
leaq 0x421acd(%rip), %rax    # 0x455760
jmp 0x33f43
movb $0x6b, %bl
jmp 0x33f6e
testl %r14d, %r14d
je 0x33ca9
callq 0x106b87
leaq 0x30c110(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
movl $0x3, %edi
jmp 0x33f67
movq %r15, %rdi
callq 0x9470
leaq 0x30b97c(%rip), %rax    # 0x33f648
jmp 0x33f43
movq %r15, %rdi
callq 0x9470
leaq 0x421a78(%rip), %rax    # 0x455758
jmp 0x33f43
movq %r15, %rdi
callq 0x9470
leaq 0x30b974(%rip), %rax    # 0x33f668
jmp 0x33f43
leaq 0x30b93c(%rip), %rbx    # 0x33f63c
cmpl $0x0, (%rbx)
jne 0x33d1b
leaq 0x30b93c(%rip), %rax    # 0x33f648
movsd (%rax), %xmm0
leaq 0x30b961(%rip), %rax    # 0x33f678
movsd %xmm0, (%rax)
movl $0x1, (%rbx)
leaq 0xf022c(%rip), %rsi     # 0x123f54
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9360
testl %r14d, %r14d
je 0x33d3f
callq 0x106b87
leaq 0x30c07a(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
movl (%rbx), %eax
cmpl $0x5, %eax
jl 0x33f9c
movl $0x1, (%rbx)
jmp 0x33f6c
leaq 0x4219ca(%rip), %rax    # 0x455730
movq $0x0, (%rax)
testl %r14d, %r14d
je 0x33d77
callq 0x106b87
leaq 0x30c042(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
jmp 0x33f6c
testl %r14d, %r14d
je 0x33d90
callq 0x106b87
leaq 0x30c029(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
movl $0x1, %edi
jmp 0x33f67
leaq 0x30b899(%rip), %rbx    # 0x33f644
movzbl (%rbx), %edi
callq 0x34013
movzbl %al, %eax
movl %eax, (%rbx)
jmp 0x33f6c
movq %r15, %rdi
callq 0x9470
leaq 0x30b8a4(%rip), %rax    # 0x33f670
jmp 0x33f43
leaq 0x30b868(%rip), %rbx    # 0x33f640
movzbl (%rbx), %edi
callq 0x34013
movb %al, (%rbx)
testb %al, %al
je 0x33fec
leaq 0x30b8a7(%rip), %rax    # 0x33f698
movb $0x0, (%rax)
jmp 0x33f6c
movq %r15, %rdi
callq 0x9470
leaq 0x30b848(%rip), %rax    # 0x33f650
jmp 0x33f43
movq %r15, %rdi
callq 0x9470
leaq 0x42194c(%rip), %rax    # 0x455768
jmp 0x33f43
leaq 0xff5dd(%rip), %rsi     # 0x133405
leaq 0x30b801(%rip), %rbx    # 0x33f630
leaq 0x30b7f2(%rip), %r12    # 0x33f628
leaq -0x21(%rbp), %rcx
movq %r15, %rdi
movq %rbx, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x9360
movsd (%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x33e68
jp 0x33e68
movsd (%rbx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x33e68
jnp 0x33e7c
testl %r14d, %r14d
je 0x33e72
callq 0x106b87
leaq 0x30bf47(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
leaq 0x30b7b5(%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 0x1e7487(%rip), %rax    # 0x21b328
movq (%rax), %rax
movslq %edx, %rcx
leaq 0x1e7402(%rip), %rdx    # 0x21b2b0
movq %rax, (%rdx,%rcx,8)
jmp 0x33f6c
movq %r15, %rdi
callq 0x9470
leaq 0x30b792(%rip), %rax    # 0x33f658
jmp 0x33f43
testl %r14d, %r14d
je 0x33ed2
callq 0x106b87
leaq 0x30bee7(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
leaq 0x30b785(%rip), %rax    # 0x33f668
movq $0x0, (%rax)
subq $0x8, %rsp
leaq 0x30b76b(%rip), %r10    # 0x33f660
leaq -0x21(%rbp), %rcx
leaq 0x30b758(%rip), %r11    # 0x33f658
leaq 0xff4f4(%rip), %rsi     # 0x1333fb
leaq 0x30b73a(%rip), %rdx    # 0x33f648
leaq 0x30b73b(%rip), %r8     # 0x33f650
xorl %ebx, %ebx
movq %r15, %rdi
movq %rcx, %r9
xorl %eax, %eax
pushq %r10
pushq %rcx
pushq %r11
callq 0x9360
addq $0x20, %rsp
callq 0x1059fd
jmp 0x33f6e
movq %r15, %rdi
callq 0x9470
leaq 0x30b71d(%rip), %rax    # 0x33f660
movsd %xmm0, (%rax)
callq 0x1059fd
jmp 0x33f6c
testl %r14d, %r14d
je 0x33f58
callq 0x106b87
leaq 0x30be61(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
movl $0x2, %edi
callq 0x105b0d
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
je 0x33f87
callq 0x106b87
leaq 0x30be32(%rip), %rax    # 0x33fdc0
movb $0x1, (%rax)
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x105b0d
jmp 0x33f6e
testl %eax, %eax
jne 0x33f6c
leaq 0x30b6d1(%rip), %rax    # 0x33f678
movsd (%rax), %xmm0
leaq 0x30b696(%rip), %rax    # 0x33f648
movsd %xmm0, (%rax)
callq 0x1059fd
testl %r14d, %r14d
je 0x33f6c
leaq 0x30b679(%rip), %rax    # 0x33f640
cmpb $0x0, (%rax)
jne 0x33fe5
leaq 0x30a9cd(%rip), %rax    # 0x33e9a0
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x30ab12(%rip), %rax    # 0x33eaf0
movb %cl, (%rax)
callq 0xfa97
callq 0x105ba9
jmp 0x33f6c
testl %r14d, %r14d
je 0x33f6c
leaq 0x30a9a4(%rip), %rax    # 0x33e9a0
xorl %ebx, %ebx
movb %bl, (%rax)
leaq 0x30aae9(%rip), %rax    # 0x33eaf0
movb %bl, (%rax)
callq 0xfa97
jmp 0x33f6e