@@ -445,14 +445,26 @@ void vEFuses(ULONG thread_input) {
445445 /* Determine pump1 eFuse state. */
446446 static const uint16_t PUMP1_UPPERBOUND = 45 ;
447447 static const uint16_t PUMP1_LOWERBOUND = 35 ;
448+ static const int PUMP1_SWITCHING_TIMEOUT = 5000 ;
449+ static nertimer_t pump1_switching_timer = { 0 };
448450 switch (data .control_state [EFUSE_PUMP1 ]) {
449451 case EF_ON : efuse_enable (EFUSE_PUMP1 ); break ;
450452 case EF_OFF : efuse_disable (EFUSE_PUMP1 ); break ;
451453 case EF_AUTO :
452- if (motor_temp >= PUMP1_UPPERBOUND ) {
454+ if (controller_temp >= PUMP1_UPPERBOUND ) {
455+ /* If timer is still active, break early. */
456+ if (!is_timer_expired (& pump1_switching_timer ) && is_timer_active (& pump1_switching_timer )) { break ; }
457+
458+ /* Otherwise, make the state change but restart the timer. */
453459 efuse_enable (EFUSE_PUMP1 );
454- } else if (motor_temp <= PUMP1_LOWERBOUND ) {
460+ start_timer (& pump1_switching_timer , PUMP1_SWITCHING_TIMEOUT );
461+ } else if (controller_temp <= PUMP1_LOWERBOUND ) {
462+ /* If timer is still active, break early. */
463+ if (!is_timer_expired (& pump1_switching_timer ) && is_timer_active (& pump1_switching_timer )) { break ; }
464+
465+ /* Otherwise, make the state change but restart the timer. */
455466 efuse_disable (EFUSE_PUMP1 );
467+ start_timer (& pump1_switching_timer , PUMP1_SWITCHING_TIMEOUT );
456468 }
457469 break ;
458470 default : efuse_enable (EFUSE_PUMP1 ); break ;
@@ -461,14 +473,26 @@ void vEFuses(ULONG thread_input) {
461473 /* Determine pump2 eFuse state. */
462474 static const uint16_t PUMP2_UPPERBOUND = 45 ;
463475 static const uint16_t PUMP2_LOWERBOUND = 35 ;
476+ static const int PUMP2_SWITCHING_TIMEOUT = 5000 ;
477+ static nertimer_t pump2_switching_timer = { 0 };
464478 switch (data .control_state [EFUSE_PUMP2 ]) {
465479 case EF_ON : efuse_enable (EFUSE_PUMP2 ); break ;
466480 case EF_OFF : efuse_disable (EFUSE_PUMP2 ); break ;
467481 case EF_AUTO :
468- if (controller_temp >= PUMP2_UPPERBOUND ) {
482+ if (motor_temp >= PUMP2_UPPERBOUND ) {
483+ /* If timer is still active, break early. */
484+ if (!is_timer_expired (& pump2_switching_timer ) && is_timer_active (& pump2_switching_timer )) { break ; }
485+
486+ /* Otherwise, make the state change but restart the timer. */
469487 efuse_enable (EFUSE_PUMP2 );
470- } else if (controller_temp <= PUMP2_LOWERBOUND ) {
488+ start_timer (& pump2_switching_timer , PUMP2_SWITCHING_TIMEOUT );
489+ } else if (motor_temp <= PUMP2_LOWERBOUND ) {
490+ /* If timer is still active, break early. */
491+ if (!is_timer_expired (& pump2_switching_timer ) && is_timer_active (& pump2_switching_timer )) { break ; }
492+
493+ /* Otherwise, make the state change but restart the timer. */
471494 efuse_disable (EFUSE_PUMP2 );
495+ start_timer (& pump2_switching_timer , PUMP2_SWITCHING_TIMEOUT );
472496 }
473497 break ;
474498 default : efuse_enable (EFUSE_PUMP2 ); break ;
@@ -700,6 +724,7 @@ void vEFuses(ULONG thread_input) {
700724 }
701725}
702726
727+
703728/* Mux Thread (for the ADC multiplexer). */
704729static thread_t mux_thread = {
705730 .name = "Mux Thread" , /* Name */
0 commit comments