// File: /workspace/github_cpp_makefile_star2_O2/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 $0x218, %rsp            # imm = 0x218
callq 0x7108f
leaq 0x2b5c70(%rip), %rdi    # 0x3292e0
callq 0x9120
movslq %eax, %r15
xorl %esi, %esi
movabsq $0x42c8000042c80000, %rdi # imm = 0x42C8000042C80000
xorl %ebx, %ebx
cmpl %eax, %esi
jge 0x7377e
movslq %esi, %r12
incl %esi
movl %esi, %r14d
leaq 0x2b5c43(%rip), %rdx    # 0x3292e0
cmpq %r15, %r12
jge 0x7377e
movzbl (%rdx,%r12), %esi
testl %esi, %esi
je 0x7377e
cmpl $0xa, %esi
je 0x7377e
cmpl $0xd, %esi
je 0x7377e
movslq %ebx, %r13
cmpl $0x2e, %esi
je 0x73703
movsbl %sil, %ecx
addl $-0x30, %ecx
cmpl $0xa, %ecx
jb 0x73703
cmpb $0x2a, %sil
jne 0x736fb
cmpl $0x7c, %ebx
jg 0x7377e
movq %rdi, -0x240(%rbp,%r13,4)
movq %rdi, -0x238(%rbp,%r13,4)
addl $0x4, %ebx
incq %r12
incl %r14d
jmp 0x7369d
movq %rax, -0x30(%rbp)
leaq (%r12,%rdx), %rdi
callq 0x9470
cvtsd2ss %xmm0, %xmm1
movss %xmm1, -0x240(%rbp,%r13,4)
leal 0x1(%rbx), %r13d
cmpl $0x7e, %ebx
jg 0x73781
movq -0x30(%rbp), %rax
cmpl %eax, %r12d
movl %eax, %esi
cmovgl %r12d, %esi
leaq 0x2b5ba5(%rip), %rdx    # 0x3292e0
movabsq $0x42c8000042c80000, %rdi # imm = 0x42C8000042C80000
cmpq %r15, %r12
jge 0x73776
movzbl 0x1(%rdx,%r12), %ecx
cmpl $0x2e, %ecx
je 0x7376b
testl %ecx, %ecx
je 0x73781
cmpl $0xa, %ecx
je 0x73781
cmpl $0xd, %ecx
je 0x73781
addb $-0x3a, %cl
cmpb $-0xa, %cl
jb 0x73773
incl %r14d
incq %r12
jmp 0x73745
movl %r14d, %esi
movl %r13d, %ebx
jmp 0x73686
movl %ebx, %r13d
cmpl $0x1, %r13d
je 0x7379d
testl %r13d, %r13d
jne 0x737b2
leaq 0x28367f(%rip), %rax    # 0x2f6e12
cmpw $0x0, (%rax)
je 0x7380c
xorl %eax, %eax
jmp 0x73815
movss -0x240(%rbp), %xmm2
movss 0x8393f(%rip), %xmm0    # 0xf70ec
ucomiss %xmm2, %xmm0
jae 0x737fe
xorl %ebx, %ebx
testl %r13d, %r13d
cmovlel %ebx, %r13d
cmpq %rbx, %r13
je 0x737ec
movl %ebx, %eax
andl $0x1, %eax
negl %eax
movzwl %ax, %edi
callq 0x71025
cvttss2si -0x240(%rbp,%rbx,4), %edi
callq 0xae83
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x71025
incq %rbx
jmp 0x737bb
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jne 0x73838
jp 0x73838
xorl %edi, %edi
jmp 0x73872
callq 0x31be3
movw $0xffff, %ax            # imm = 0xFFFF
movzwl %ax, %edi
callq 0x71025
movl $0x1f4, %edi            # imm = 0x1F4
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xae83
movss %xmm1, -0x34(%rbp)
movss %xmm2, -0x30(%rbp)
callq 0x31be3
movss -0x30(%rbp), %xmm0
ucomiss 0x83899(%rip), %xmm0    # 0xf70ec
jne 0x7385e
jp 0x7385e
movl $0xffff, %edi           # imm = 0xFFFF
jmp 0x73872
movss -0x34(%rbp), %xmm0
mulss 0x95165(%rip), %xmm0    # 0x1089d0
cvttss2si %xmm0, %eax
movzwl %ax, %edi
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x71025