// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: update_pwm()
void update_pwm(void)
{
   // This routine is called whenever the system is idle or waiting in a loop.
   // It checks to see if it is time to change the temperature contoller PWM
   // output.
   this_msec = GetMsecs();
   if(temp_control_on == 0) return;

   if(this_msec < last_msec) {  // millisecond clock has wrapped
      cool_off_time = heat_off_time = 0.0F;
   }
   last_msec = this_msec;

   if(a_cooling) {   // we are currently cooling
      if(this_msec > cool_off_time) {  // it's time to stop cooling
         if(heat_time) {               // so turn on the heat
            apply_heat();
            heat_off_time = this_msec + (double) heat_time;  // set when to stop heating
         }
      }
   }
   if(a_heating) {  // we are currently heating
      if(this_msec > heat_off_time) {   // it's time to stop heating
         if(cool_time) {                // so turn on the cooler
            apply_cool();
            cool_off_time = this_msec + (double) cool_time;  // set when to stop cooling
         }
      }
   }

   // failsafe code to make sure controller does not lock up!!!!
   if((cool_time == 0.0) && (heat_time >= (PWM_CYCLE_TIME*2.0)) && (a_heating == 0)) {
      apply_heat();
      heat_off_time = this_msec + (double) heat_time;  // set when to stop heating
   }
   if((heat_time == 0.0) && (cool_time >= (PWM_CYCLE_TIME*2.0)) && (a_cooling == 0)) {
      apply_cool();
      cool_off_time = this_msec + (double) cool_time;  // set when to stop heating
   }
   if((a_heating == 0) && (a_cooling == 0) && (a_holding == 0)) {
      apply_cool();
      cool_off_time = this_msec + 100.0;
   }
   if(a_holding) {  // we are currently holding !!!!
      apply_cool();
      heat_off_time = this_msec + 100.0;  // set when to stop heating
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
callq 0xae92
leaq 0x23b858(%rip), %rbx    # 0x30d768
movsd %xmm0, (%rbx)
leaq 0x26dea6(%rip), %rax    # 0x33fdc1
cmpb $0x0, (%rax)
je 0xd20cf
leaq 0x23b835(%rip), %rax    # 0x30d760
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xd1f45
xorl %ecx, %ecx
movq %rcx, 0x3836f2(%rip)    # 0x455630
movq %rcx, 0x3836f3(%rip)    # 0x455638
movsd %xmm0, (%rax)
cmpb $0x0, 0x3836b1(%rip)    # 0x455601
je 0xd1f8d
ucomisd 0x3836de(%rip), %xmm0   # 0x455638
jbe 0xd1f8d
movsd 0x3836dc(%rip), %xmm1   # 0x455640
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xd1f70
jnp 0xd1f8d
callq 0x1069b0
movsd (%rbx), %xmm0
movsd 0x3836bf(%rip), %xmm1   # 0x455640
addsd %xmm0, %xmm1
movsd %xmm1, 0x3836a3(%rip)   # 0x455630
cmpb $0x0, 0x38366c(%rip)    # 0x455600
movsd 0x3836ac(%rip), %xmm1   # 0x455648
je 0xd1fe1
ucomisd 0x38368a(%rip), %xmm0   # 0x455630
jbe 0xd202c
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xd1fb8
jnp 0xd202c
callq 0x106a46
movsd 0x383683(%rip), %xmm1   # 0x455648
movsd (%rbx), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x383663(%rip)   # 0x455638
cmpb $0x0, 0x383624(%rip)    # 0x455600
sete %al
jmp 0xd1fe3
movb $0x1, %al
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movsd 0x38364d(%rip), %xmm0   # 0x455640
jne 0xd2034
jp 0xd2034
ucomisd 0x597b1(%rip), %xmm0    # 0x12b7b0
jb 0xd2034
testb %al, %al
je 0xd2034
callq 0x1069b0
movsd 0x38362e(%rip), %xmm0   # 0x455640
movsd (%rbx), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38360e(%rip)   # 0x455630
movsd 0x38361e(%rip), %xmm1   # 0x455648
jmp 0xd2034
movsd 0x38360c(%rip), %xmm0   # 0x455640
movsd 0x59774(%rip), %xmm2    # 0x12b7b0
cmplepd %xmm1, %xmm2
xorpd %xmm1, %xmm1
cmpeqpd %xmm0, %xmm1
andpd %xmm2, %xmm1
movd %xmm1, %ecx
movb 0x3835a9(%rip), %al     # 0x455601
testb %al, %al
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xd2083
callq 0x106a46
movsd (%rbx), %xmm0
addsd 0x3835d3(%rip), %xmm0   # 0x455648
movsd %xmm0, 0x3835bb(%rip)   # 0x455638
movb 0x38357e(%rip), %al     # 0x455601
orb 0x383577(%rip), %al     # 0x455600
movb 0x383573(%rip), %cl     # 0x455602
orb %cl, %al
jne 0xd20b2
callq 0x106a46
movsd (%rbx), %xmm0
addsd 0x36fbc(%rip), %xmm0    # 0x109060
movsd %xmm0, 0x38358c(%rip)   # 0x455638
movb 0x383550(%rip), %cl     # 0x455602
testb %cl, %cl
je 0xd20cf
callq 0x106a46
movsd (%rbx), %xmm0
addsd 0x36f99(%rip), %xmm0    # 0x109060
movsd %xmm0, 0x383561(%rip)   # 0x455630
addq $0x8, %rsp
popq %rbx
popq %rbp
retq