// File: /workspace/github_cpp_makefile_star2_O1/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 0x7c46b
leaq 0x2c0649(%rip), %rbx    # 0x33f2e0
movq %rbx, %rdi
callq 0x9120
testl %eax, %eax
jle 0x7edc0
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 0x7ece6
testl %edx, %edx
je 0x7edbb
cmpl $0xa, %edx
jne 0x7ecf4
jmp 0x7edbb
cmpl $0xd, %edx
je 0x7edbb
cmpl $0x2e, %edx
je 0x7ed35
movsbl %dl, %ecx
addl $-0x30, %ecx
cmpl $0xa, %ecx
jb 0x7ed35
cmpb $0x2a, %dl
jne 0x7ed25
cmpl $0x7c, %r14d
jg 0x7edbb
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 0x7ecca
jmp 0x7edbb
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 0x7edc2
movq %rbx, %rax
cmpl %eax, %r13d
leaq 0x2c0572(%rip), %rbx    # 0x33f2e0
movabsq $0x42c8000042c80000, %rdi # imm = 0x42C8000042C80000
jge 0x7edb0
movq %r12, %r13
movb (%rbx,%r13), %cl
movzbl %cl, %edx
cmpl $0x2d, %edx
jle 0x7ed90
cmpl $0x2e, %edx
je 0x7eda6
jmp 0x7ed9e
testl %edx, %edx
je 0x7edc2
cmpl $0xa, %edx
je 0x7edc2
cmpl $0xd, %edx
je 0x7edc2
addb $-0x30, %cl
cmpb $0x9, %cl
ja 0x7edb0
cmpq %r15, %r13
jge 0x7edb0
incq %r13
jmp 0x7ed7d
cmpl %eax, %r13d
jl 0x7ecc0
jmp 0x7edc2
movl %r14d, %esi
jmp 0x7edc2
xorl %esi, %esi
cmpl $0x1, %esi
je 0x7eddc
testl %esi, %esi
jne 0x7edf1
leaq 0x28e040(%rip), %rax    # 0x30ce12
cmpw $0x0, (%rax)
je 0x7ee4b
xorl %eax, %eax
jmp 0x7ee54
movss -0x230(%rbp), %xmm2
movss 0x8e1e8(%rip), %xmm0    # 0x10cfd4
ucomiss %xmm2, %xmm0
jae 0x7ee3d
testl %esi, %esi
jle 0x7ee2b
movl %esi, %ebx
xorl %r14d, %r14d
movl %r14d, %eax
andl $0x1, %eax
negl %eax
movzwl %ax, %edi
callq 0x7c3fc
cvttss2si -0x230(%rbp,%r14,4), %edi
callq 0xaff7
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x7c3fc
incq %r14
cmpq %r14, %rbx
jne 0x7edfa
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jne 0x7ee77
jp 0x7ee77
xorl %edi, %edi
jmp 0x7eeb1
callq 0x348ad
movw $0xffff, %ax            # imm = 0xFFFF
movzwl %ax, %edi
callq 0x7c3fc
movl $0x1f4, %edi            # imm = 0x1F4
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xaff7
movss %xmm1, -0x2c(%rbp)
movss %xmm2, -0x30(%rbp)
callq 0x348ad
movss -0x30(%rbp), %xmm0
ucomiss 0x8e142(%rip), %xmm0    # 0x10cfd4
jne 0x7ee9d
jp 0x7ee9d
movl $0xffff, %edi           # imm = 0xFFFF
jmp 0x7eeb1
movss -0x2c(%rbp), %xmm0
mulss 0x9fafe(%rip), %xmm0    # 0x11e9a8
cvttss2si %xmm0, %eax
movzwl %ax, %edi
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7c3fc