// File: /workspace/github_cpp_makefile_star2_O2/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 0xad3f
leaq 0x2370d9(%rip), %rbx    # 0x2f7768
movsd %xmm0, (%rbx)
leaq 0x269727(%rip), %rax    # 0x329dc1
cmpb $0x0, (%rax)
je 0xc0842
leaq 0x2370b6(%rip), %rax    # 0x2f7760
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xc06c4
andq $0x0, 0x37ef74(%rip)    # 0x43f630
andq $0x0, 0x37ef74(%rip)    # 0x43f638
movsd %xmm0, (%rax)
cmpb $0x0, 0x37ef32(%rip)    # 0x43f601
je 0xc070c
ucomisd 0x37ef5f(%rip), %xmm0   # 0x43f638
jbe 0xc070c
movsd 0x37ef5d(%rip), %xmm1   # 0x43f640
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xc06ef
jnp 0xc070c
callq 0xefffc
movsd (%rbx), %xmm0
movsd 0x37ef40(%rip), %xmm1   # 0x43f640
addsd %xmm0, %xmm1
movsd %xmm1, 0x37ef24(%rip)   # 0x43f630
cmpb $0x0, 0x37eeed(%rip)    # 0x43f600
movsd 0x37ef2d(%rip), %xmm1   # 0x43f648
je 0xc075e
xorl %eax, %eax
ucomisd 0x37ef09(%rip), %xmm0   # 0x43f630
jbe 0xc0760
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xc0735
jnp 0xc0760
callq 0xf0092
movsd 0x37ef06(%rip), %xmm1   # 0x43f648
movsd (%rbx), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x37eee6(%rip)   # 0x43f638
cmpb $0x0, 0x37eea7(%rip)    # 0x43f600
sete %al
jmp 0xc0760
movb $0x1, %al
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movsd 0x37eed0(%rip), %xmm0   # 0x43f640
jne 0xc07a7
jp 0xc07a7
ucomisd 0x54f7c(%rip), %xmm0    # 0x1156f8
jb 0xc07a7
testb %al, %al
je 0xc07a7
callq 0xefffc
movsd 0x37eeb1(%rip), %xmm0   # 0x43f640
movsd (%rbx), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x37ee91(%rip)   # 0x43f630
movsd 0x37eea1(%rip), %xmm1   # 0x43f648
movsd 0x54f49(%rip), %xmm2    # 0x1156f8
cmplepd %xmm1, %xmm2
xorpd %xmm1, %xmm1
cmpeqpd %xmm0, %xmm1
andpd %xmm2, %xmm1
movd %xmm1, %ecx
movb 0x37ee36(%rip), %al     # 0x43f601
testb %al, %al
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xc07f6
callq 0xf0092
movsd (%rbx), %xmm0
addsd 0x37ee60(%rip), %xmm0   # 0x43f648
movsd %xmm0, 0x37ee48(%rip)   # 0x43f638
movb 0x37ee0b(%rip), %al     # 0x43f601
orb 0x37ee04(%rip), %al     # 0x43f600
movb 0x37ee00(%rip), %cl     # 0x43f602
orb %cl, %al
jne 0xc0825
callq 0xf0092
movsd (%rbx), %xmm0
addsd 0x32849(%rip), %xmm0    # 0xf3060
movsd %xmm0, 0x37ee19(%rip)   # 0x43f638
movb 0x37eddd(%rip), %cl     # 0x43f602
testb %cl, %cl
je 0xc0842
callq 0xf0092
movsd (%rbx), %xmm0
addsd 0x32826(%rip), %xmm0    # 0xf3060
movsd %xmm0, 0x37edee(%rip)   # 0x43f630
addq $0x8, %rsp
popq %rbx
popq %rbp
retq