// File: 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
subq $0x30, %rsp
movb %dil, %al
movb %al, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x48ce5
movb $0x6b, -0x1(%rbp)
jmp 0x49213
movsbl -0x2(%rbp), %edi
callq 0x96e0
movb %al, -0x2(%rbp)
movsbl -0x2(%rbp), %eax
cmpl $0x41, %eax
jne 0x48dbc
leaq 0x355b17(%rip), %rax    # 0x39e81c
cmpl $0x0, (%rax)
jne 0x48d20
leaq 0x355b17(%rip), %rax    # 0x39e828
movsd (%rax), %xmm0
leaq 0x355b3c(%rip), %rax    # 0x39e858
movsd %xmm0, (%rax)
leaq 0x355af5(%rip), %rax    # 0x39e81c
movl $0x1, (%rax)
movq -0x10(%rbp), %rdi
leaq 0x13e509(%rip), %rsi    # 0x187241
leaq 0x355add(%rip), %rdx    # 0x39e81c
movb $0x0, %al
callq 0x9370
cmpl $0x0, -0x14(%rbp)
je 0x48d51
callq 0x16ad70
leaq 0x356248(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
leaq 0x355aba(%rip), %rax    # 0x39e81c
cmpl $0x4, (%rax)
jle 0x48d76
leaq 0x355aae(%rip), %rax    # 0x39e81c
movl $0x1, (%rax)
jmp 0x48db7
leaq 0x355a9f(%rip), %rax    # 0x39e81c
cmpl $0x0, (%rax)
jne 0x48db5
leaq 0x355acf(%rip), %rax    # 0x39e858
movsd (%rax), %xmm0
leaq 0x355a94(%rip), %rax    # 0x39e828
movsd %xmm0, (%rax)
callq 0x169430
cmpl $0x0, -0x14(%rbp)
je 0x48da8
callq 0x48c90
cmpl $0x0, -0x14(%rbp)
je 0x48db3
callq 0x1697c0
jmp 0x48db5
jmp 0x48db7
jmp 0x4920f
movsbl -0x2(%rbp), %eax
cmpl $0x44, %eax
jne 0x48de3
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x355a5b(%rip), %rax    # 0x39e830
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x4920d
movsbl -0x2(%rbp), %eax
cmpl $0x46, %eax
jne 0x48e0a
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x355a3c(%rip), %rax    # 0x39e838
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x4920b
movsbl -0x2(%rbp), %eax
cmpl $0x47, %eax
jne 0x48e31
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x46bf2d(%rip), %rax    # 0x4b4d50
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x49209
movsbl -0x2(%rbp), %eax
cmpl $0x48, %eax
jne 0x48e7a
leaq 0x3559df(%rip), %rax    # 0x39e820
movzbl (%rax), %edi
callq 0x49220
movb %al, %cl
leaq 0x3559ce(%rip), %rax    # 0x39e820
movb %cl, (%rax)
leaq 0x3559c5(%rip), %rax    # 0x39e820
cmpb $0x0, (%rax)
je 0x48e6a
leaq 0x355a11(%rip), %rax    # 0x39e878
movb $0x0, (%rax)
cmpl $0x0, -0x14(%rbp)
je 0x48e75
callq 0x48c90
jmp 0x49207
movsbl -0x2(%rbp), %eax
cmpl $0x49, %eax
jne 0x48ea1
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x3559ad(%rip), %rax    # 0x39e840
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x49205
movsbl -0x2(%rbp), %eax
cmpl $0x4b, %eax
jne 0x48f1d
cmpl $0x0, -0x14(%rbp)
je 0x48eb5
callq 0x16ad70
leaq 0x3560e4(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
leaq 0x355982(%rip), %rax    # 0x39e848
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rdi
leaq 0x14d08b(%rip), %rsi    # 0x195f63
leaq 0x355949(%rip), %rdx    # 0x39e828
leaq -0x2(%rbp), %r10
leaq 0x355946(%rip), %r8     # 0x39e830
leaq 0x355947(%rip), %r11    # 0x39e838
leaq 0x355948(%rip), %rax    # 0x39e840
movq %r10, %rcx
movq %r10, %r9
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x9370
callq 0x169430
jmp 0x49203
movsbl -0x2(%rbp), %eax
cmpl $0x4c, %eax
jne 0x48f44
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x46be12(%rip), %rax    # 0x4b4d48
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x49201
movsbl -0x2(%rbp), %eax
cmpl $0x4e, %eax
jne 0x48f71
cmpl $0x0, -0x14(%rbp)
je 0x48f58
callq 0x16ad70
leaq 0x356041(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
movl $0x1, %edi
callq 0x169640
jmp 0x491ff
movsbl -0x2(%rbp), %eax
cmpl $0x4f, %eax
jne 0x48f98
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x3558be(%rip), %rax    # 0x39e848
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x491fd
movsbl -0x2(%rbp), %eax
cmpl $0x50, %eax
jne 0x48fbf
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x355877(%rip), %rax    # 0x39e828
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x491fb
movsbl -0x2(%rbp), %eax
cmpl $0x52, %eax
jne 0x48fe6
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x46bd80(%rip), %rax    # 0x4b4d58
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x491f9
movsbl -0x2(%rbp), %eax
cmpl $0x53, %eax
jne 0x4900d
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x46bd51(%rip), %rax    # 0x4b4d50
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x491f7
movsbl -0x2(%rbp), %eax
cmpl $0x54, %eax
jne 0x490e5
movq -0x10(%rbp), %rdi
leaq 0x14cf48(%rip), %rsi    # 0x195f6d
leaq 0x3557e4(%rip), %rdx    # 0x39e810
leaq -0x2(%rbp), %rcx
leaq 0x3557d1(%rip), %r8     # 0x39e808
movb $0x0, %al
callq 0x9370
leaq 0x3557c3(%rip), %rax    # 0x39e808
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4906c
jp 0x4906c
leaq 0x3557b5(%rip), %rax    # 0x39e810
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4906c
jp 0x4906c
jmp 0x49081
cmpl $0x0, -0x14(%rbp)
je 0x49077
callq 0x16ad70
leaq 0x355f22(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
leaq 0x355790(%rip), %rax    # 0x39e818
movl (%rax), %eax
addl $0x1, %eax
leaq 0x355784(%rip), %rcx    # 0x39e818
movl %eax, (%rcx)
cmpl $0xa, %eax
jl 0x490a8
leaq 0x355776(%rip), %rax    # 0x39e818
movl $0x1, (%rax)
leaq 0x355769(%rip), %rax    # 0x39e818
cmpl $0x0, (%rax)
jge 0x490c1
leaq 0x35575d(%rip), %rax    # 0x39e818
movl $0x1, (%rax)
leaq 0x231440(%rip), %rax    # 0x27a508
movq (%rax), %rdx
leaq 0x355746(%rip), %rax    # 0x39e818
movslq (%rax), %rcx
leaq 0x2313b4(%rip), %rax    # 0x27a490
movq %rdx, (%rax,%rcx,8)
jmp 0x491f5
movsbl -0x2(%rbp), %eax
cmpl $0x57, %eax
jne 0x4910f
cmpl $0x0, -0x14(%rbp)
je 0x490f9
callq 0x16ad70
leaq 0x355ea0(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
xorl %edi, %edi
callq 0x169640
jmp 0x491f3
movsbl -0x2(%rbp), %eax
cmpl $0x58, %eax
jne 0x4913c
cmpl $0x0, -0x14(%rbp)
je 0x49123
callq 0x16ad70
leaq 0x355e76(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
movl $0x2, %edi
callq 0x169640
jmp 0x491f1
movsbl -0x2(%rbp), %eax
cmpl $0x59, %eax
jne 0x49169
cmpl $0x0, -0x14(%rbp)
je 0x49150
callq 0x16ad70
leaq 0x355e49(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
movl $0x3, %edi
callq 0x169640
jmp 0x491ef
movsbl -0x2(%rbp), %eax
cmpl $0x5a, %eax
jne 0x49197
leaq 0x46bba7(%rip), %rax    # 0x4b4d20
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
cmpl $0x0, -0x14(%rbp)
je 0x4918b
callq 0x16ad70
leaq 0x355e0e(%rip), %rax    # 0x39efa0
movb $0x1, (%rax)
jmp 0x491ed
movsbl -0x2(%rbp), %eax
cmpl $0x39, %eax
jne 0x491bb
movq -0x10(%rbp), %rdi
callq 0x9480
leaq 0x3556a0(%rip), %rax    # 0x39e850
movsd %xmm0, (%rax)
callq 0x169430
jmp 0x491eb
movsbl -0x2(%rbp), %eax
cmpl $0x30, %eax
jne 0x491e3
leaq 0x355659(%rip), %rax    # 0x39e824
movl (%rax), %eax
movzbl %al, %edi
callq 0x49220
movzbl %al, %ecx
leaq 0x355645(%rip), %rax    # 0x39e824
movl %ecx, (%rax)
jmp 0x491e9
movb $0x1, -0x1(%rbp)
jmp 0x49213
jmp 0x491eb
jmp 0x491ed
jmp 0x491ef
jmp 0x491f1
jmp 0x491f3
jmp 0x491f5
jmp 0x491f7
jmp 0x491f9
jmp 0x491fb
jmp 0x491fd
jmp 0x491ff
jmp 0x49201
jmp 0x49203
jmp 0x49205
jmp 0x49207
jmp 0x49209
jmp 0x4920b
jmp 0x4920d
jmp 0x4920f
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)