// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: set_driver_mode()
void set_driver_mode()
{
int i, j;
int len;
int count;
float vals[128];
float val;

   // This routine sets the LED driver mode by pulsing the battery on and off.
   // It is also used to switch the battery on, off, or PWM it.

   end_sweep();
   count = 0;
   i = 0;
   len = strlen(edit_buffer);

   while(i < len) {   // get a list of numbers on the line
      for(j=i; j<len; j++) {   // find next number field
         if(edit_buffer[j] == 0) goto no_num;
         if(edit_buffer[j] == 0x0A) goto no_num;
         if(edit_buffer[j] == 0x0D) goto no_num;
         if(edit_buffer[j] == '.') goto got_num;
         if(isdigit(edit_buffer[j])) goto got_num;
         if(edit_buffer[j] == '*') {  // '*' is a double 100 msec pulse
            if(count >= 125) break;
            vals[count++] = 100;     // off
            vals[count++] = 100;     // on
            vals[count++] = 100;     // off
            vals[count++] = 100;     // on
         }
      }
      break;

      got_num:
      i = j;
      val = 0;
      val = (float) atof(&edit_buffer[i]);
      vals[count] = val;
      ++count;
      if(count >= 128) break;

      while(i < len) {  // skip over number
         ++i;
         if(edit_buffer[i] == 0) goto no_num;
         if(edit_buffer[i] == 0x0A) goto no_num;
         if(edit_buffer[i] == 0x0D) goto no_num;
         if(edit_buffer[i] == '.') continue;
         if(edit_buffer[i] < '0') break;
         if(edit_buffer[i] > '9') break;
         if(edit_buffer[i] == '*') break;
      }
   }

   no_num:
   if(count == 0) {  // no numbers on the line, toggle battery state
      if(batt_pwm) {
         set_batt_pwm(0);
      }
      else {
update_check();
         set_batt_pwm(65535);
      }
//    set_luxor_delay(CLICK_TIME);
      Sleep(CLICK_TIME);
   }
   else if((count == 1) && (vals[0] <= 1.0)) {  // single number
      if(vals[0] == 0.0F) {
         set_batt_pwm(0);
      }
      else {
update_check();
         if(vals[0] == 1.0F) set_batt_pwm(65535);
         else set_batt_pwm((u16) (val*65536.0F));
      }
   }
   else {  // pulse the battery
      for(i=0; i<count; i++) {
         if(i & 1) {  // an ON time
            set_batt_pwm(65535);
         }
         else {           // an OFF time
            set_batt_pwm(0);
         }
//       set_luxor_delay((u16) vals[i]);
         Sleep((DWORD) vals[i]);
         set_batt_pwm(65535);
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
callq 0x7c226
leaq 0x2c080b(%rip), %rbx    # 0x33f2e0
movq %rbx, %rdi
callq 0x9120
testl %eax, %eax
jle 0x7ec05
movl %eax, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %esi, %esi
movabsq $0x42c8000042c80000, %rdi # imm = 0x42C8000042C80000
xorl %r13d, %r13d
movslq %r13d, %r13
leaq 0x1(%r13), %r12
movl %esi, %r14d
movzbl (%rbx,%r13), %edx
cmpl $0xc, %edx
jg 0x7eb24
testl %edx, %edx
je 0x7ebf9
cmpl $0xa, %edx
jne 0x7eb32
jmp 0x7ebf9
cmpl $0xd, %edx
je 0x7ebf9
cmpl $0x2e, %edx
je 0x7eb73
movsbl %dl, %ecx
addl $-0x30, %ecx
cmpl $0xa, %ecx
jb 0x7eb73
cmpb $0x2a, %dl
jne 0x7eb63
cmpl $0x7c, %r14d
jg 0x7ebf9
movslq %r14d, %rcx
movq %rdi, -0x230(%rbp,%rcx,4)
movq %rdi, -0x228(%rbp,%rcx,4)
addl $0x4, %r14d
incq %r13
incq %r12
cmpq %r15, %r13
jl 0x7eb08
jmp 0x7ebf9
movq %rbx, %rcx
movq %rax, %rbx
leaq (%rcx,%r13), %rdi
callq 0x9470
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movslq %r14d, %rax
movss %xmm1, -0x230(%rbp,%rax,4)
leal 0x1(%r14), %esi
cmpl $0x7e, %r14d
jg 0x7ebfc
movq %rbx, %rax
cmpl %eax, %r13d
leaq 0x2c0734(%rip), %rbx    # 0x33f2e0
movabsq $0x42c8000042c80000, %rdi # imm = 0x42C8000042C80000
jge 0x7ebee
movq %r12, %r13
movb (%rbx,%r13), %cl
movzbl %cl, %edx
cmpl $0x2d, %edx
jle 0x7ebce
cmpl $0x2e, %edx
je 0x7ebe4
jmp 0x7ebdc
testl %edx, %edx
je 0x7ebfc
cmpl $0xa, %edx
je 0x7ebfc
cmpl $0xd, %edx
je 0x7ebfc
addb $-0x30, %cl
cmpb $0x9, %cl
ja 0x7ebee
cmpq %r15, %r13
jge 0x7ebee
incq %r13
jmp 0x7ebbb
cmpl %eax, %r13d
jl 0x7eafe
jmp 0x7ebfc
movl %r14d, %esi
cmpl $0x1, %esi
je 0x7ec42
testl %esi, %esi
jne 0x7ec68
leaq 0x28e206(%rip), %rax    # 0x30ce12
cmpw $0x0, (%rax)
je 0x7ec16
xorl %eax, %eax
jmp 0x7ec1f
callq 0x349ca
movw $0xffff, %ax            # imm = 0xFFFF
movzwl %ax, %edi
callq 0x7c189
movl $0x1f4, %edi            # imm = 0x1F4
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xafe8
movss -0x230(%rbp), %xmm2
movss 0x8e41a(%rip), %xmm0    # 0x10d06c
ucomiss %xmm2, %xmm0
jb 0x7ec6a
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jne 0x7ecb2
jp 0x7ecb2
xorl %edi, %edi
jmp 0x7ecec
jle 0x7eca0
movl %esi, %ebx
xorl %r14d, %r14d
movl %r14d, %eax
andl $0x1, %eax
negl %eax
movzwl %ax, %edi
callq 0x7c189
cvttss2si -0x230(%rbp,%r14,4), %edi
callq 0xafe8
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x7c189
incq %r14
cmpq %r14, %rbx
jne 0x7ec6f
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movss %xmm1, -0x2c(%rbp)
movss %xmm2, -0x30(%rbp)
callq 0x349ca
movss -0x30(%rbp), %xmm0
ucomiss 0x8e39f(%rip), %xmm0    # 0x10d06c
jne 0x7ecd8
jp 0x7ecd8
movl $0xffff, %edi           # imm = 0xFFFF
jmp 0x7ecec
movss -0x2c(%rbp), %xmm0
mulss 0x9fd73(%rip), %xmm0    # 0x11ea58
cvttss2si %xmm0, %eax
movzwl %ax, %edi
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7c189