// File: /workspace/github_cpp_makefile_star2_O1/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 0xaea1
leaq 0x23bef1(%rip), %rbx    # 0x30d768
movsd %xmm0, (%rbx)
leaq 0x26e53f(%rip), %rax    # 0x33fdc1
cmpb $0x0, (%rax)
je 0xd1a1a
leaq 0x23bece(%rip), %rax    # 0x30d760
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xd18ac
xorl %ecx, %ecx
movq %rcx, 0x383e6b(%rip)    # 0x455710
movq %rcx, 0x383e6c(%rip)    # 0x455718
movsd %xmm0, (%rax)
cmpb $0x0, 0x383e2a(%rip)    # 0x4556e1
je 0xd18f0
ucomisd 0x383e57(%rip), %xmm0   # 0x455718
jbe 0xd18f0
movsd 0x383e55(%rip), %xmm0   # 0x455720
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd18d7
jnp 0xd18f0
callq 0x10628c
movsd (%rbx), %xmm0
addsd 0x383e38(%rip), %xmm0   # 0x455720
movsd %xmm0, 0x383e20(%rip)   # 0x455710
cmpb $0x0, 0x383de9(%rip)    # 0x4556e0
je 0xd1934
movsd (%rbx), %xmm0
ucomisd 0x383e0b(%rip), %xmm0   # 0x455710
jbe 0xd1934
movsd 0x383e19(%rip), %xmm0   # 0x455728
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd191b
jnp 0xd1934
callq 0x106322
movsd (%rbx), %xmm0
addsd 0x383dfc(%rip), %xmm0   # 0x455728
movsd %xmm0, 0x383de4(%rip)   # 0x455718
movsd 0x383dec(%rip), %xmm0   # 0x455728
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd1980
jp 0xd1980
movsd 0x383dd0(%rip), %xmm0   # 0x455720
ucomisd 0x59d78(%rip), %xmm0    # 0x12b6d0
jb 0xd1980
cmpb $0x0, 0x383d7f(%rip)    # 0x4556e0
jne 0xd1980
callq 0x10628c
xorpd %xmm1, %xmm1
movsd (%rbx), %xmm0
addsd 0x383da8(%rip), %xmm0   # 0x455720
movsd %xmm0, 0x383d90(%rip)   # 0x455710
movsd 0x383d98(%rip), %xmm0   # 0x455720
ucomisd %xmm1, %xmm0
jne 0xd19c4
jp 0xd19c4
movsd 0x383d90(%rip), %xmm0   # 0x455728
ucomisd 0x59d30(%rip), %xmm0    # 0x12b6d0
jb 0xd19c4
cmpb $0x0, 0x383d38(%rip)    # 0x4556e1
jne 0xd19c4
callq 0x106322
movsd (%rbx), %xmm0
addsd 0x383d6c(%rip), %xmm0   # 0x455728
movsd %xmm0, 0x383d54(%rip)   # 0x455718
cmpb $0x0, 0x383d15(%rip)    # 0x4556e0
jne 0xd19f8
cmpb $0x0, 0x383d0d(%rip)    # 0x4556e1
jne 0xd19f8
cmpb $0x0, 0x383d05(%rip)    # 0x4556e2
jne 0xd19f8
callq 0x106322
movsd (%rbx), %xmm0
addsd 0x37670(%rip), %xmm0    # 0x109060
movsd %xmm0, 0x383d20(%rip)   # 0x455718
cmpb $0x0, 0x383ce3(%rip)    # 0x4556e2
je 0xd1a1a
callq 0x106322
movsd (%rbx), %xmm0
addsd 0x3764e(%rip), %xmm0    # 0x109060
movsd %xmm0, 0x383cf6(%rip)   # 0x455710
addq $0x8, %rsp
popq %rbx
popq %rbp
retq