// File: 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
callq 0xb630
leaq 0x24dad8(%rip), %rax    # 0x36c948
movsd %xmm0, (%rax)
leaq 0x280126(%rip), %rax    # 0x39efa1
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x11ee88
jmp 0x11f095
leaq 0x24dab9(%rip), %rax    # 0x36c948
movsd (%rax), %xmm1
leaq 0x24daa6(%rip), %rax    # 0x36c940
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x11eeba
xorps %xmm0, %xmm0
movsd %xmm0, 0x395d71(%rip)   # 0x4b4c20
xorps %xmm0, %xmm0
movsd %xmm0, 0x395d6e(%rip)   # 0x4b4c28
leaq 0x24da87(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
leaq 0x24da74(%rip), %rax    # 0x36c940
movsd %xmm0, (%rax)
cmpb $0x0, 0x395d1a(%rip)    # 0x4b4bf1
je 0x11ef27
leaq 0x24da68(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
ucomisd 0x395d3c(%rip), %xmm0   # 0x4b4c28
jbe 0x11ef25
movsd 0x395d3a(%rip), %xmm0   # 0x4b4c30
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x11ef03
jp 0x11ef03
jmp 0x11ef23
callq 0x16aaf0
leaq 0x24da39(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
addsd 0x395d15(%rip), %xmm0   # 0x4b4c30
movsd %xmm0, 0x395cfd(%rip)   # 0x4b4c20
jmp 0x11ef25
jmp 0x11ef27
cmpb $0x0, 0x395cc2(%rip)    # 0x4b4bf0
je 0x11ef7e
leaq 0x24da11(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
ucomisd 0x395cdd(%rip), %xmm0   # 0x4b4c20
jbe 0x11ef7c
movsd 0x395ceb(%rip), %xmm0   # 0x4b4c38
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x11ef5a
jp 0x11ef5a
jmp 0x11ef7a
callq 0x16abc0
leaq 0x24d9e2(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
addsd 0x395cc6(%rip), %xmm0   # 0x4b4c38
movsd %xmm0, 0x395cae(%rip)   # 0x4b4c28
jmp 0x11ef7c
jmp 0x11ef7e
movsd 0x395cb2(%rip), %xmm0   # 0x4b4c38
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x11efd3
jp 0x11efd3
movsd 0x395c97(%rip), %xmm0   # 0x4b4c30
movsd 0x6f367(%rip), %xmm1    # 0x18e308
ucomisd %xmm1, %xmm0
jb 0x11efd3
movzbl 0x395c42(%rip), %eax    # 0x4b4bf0
cmpl $0x0, %eax
jne 0x11efd3
callq 0x16aaf0
leaq 0x24d989(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
addsd 0x395c65(%rip), %xmm0   # 0x4b4c30
movsd %xmm0, 0x395c4d(%rip)   # 0x4b4c20
movsd 0x395c55(%rip), %xmm0   # 0x4b4c30
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x11f028
jp 0x11f028
movsd 0x395c4a(%rip), %xmm0   # 0x4b4c38
movsd 0x6f312(%rip), %xmm1    # 0x18e308
ucomisd %xmm1, %xmm0
jb 0x11f028
movzbl 0x395bee(%rip), %eax    # 0x4b4bf1
cmpl $0x0, %eax
jne 0x11f028
callq 0x16abc0
leaq 0x24d934(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
addsd 0x395c18(%rip), %xmm0   # 0x4b4c38
movsd %xmm0, 0x395c00(%rip)   # 0x4b4c28
movzbl 0x395bc1(%rip), %eax    # 0x4b4bf0
cmpl $0x0, %eax
jne 0x11f06c
movzbl 0x395bb6(%rip), %eax    # 0x4b4bf1
cmpl $0x0, %eax
jne 0x11f06c
movzbl 0x395bab(%rip), %eax    # 0x4b4bf2
cmpl $0x0, %eax
jne 0x11f06c
callq 0x16abc0
movsd 0x4fff7(%rip), %xmm0    # 0x16f050
leaq 0x24d8e8(%rip), %rax    # 0x36c948
addsd (%rax), %xmm0
movsd %xmm0, 0x395bbc(%rip)   # 0x4b4c28
cmpb $0x0, 0x395b7f(%rip)    # 0x4b4bf2
je 0x11f095
callq 0x16abc0
movsd 0x4ffce(%rip), %xmm0    # 0x16f050
leaq 0x24d8bf(%rip), %rax    # 0x36c948
addsd (%rax), %xmm0
movsd %xmm0, 0x395b8b(%rip)   # 0x4b4c20
popq %rbp
retq
nopw (%rax,%rax)