Ver código fonte

Merge pull request #4265 from thinkyhead/rc_buzzer_patchup

Two strategies to address a stuck buzzer
Scott Lahteine 8 anos atrás
pai
commit
6121c9018a
2 arquivos alterados com 10 adições e 8 exclusões
  1. 7
    7
      Marlin/buzzer.h
  2. 3
    1
      Marlin/ultralcd.cpp

+ 7
- 7
Marlin/buzzer.h Ver arquivo

@@ -46,7 +46,7 @@ class Buzzer {
46 46
   private:
47 47
     struct state_t {
48 48
       tone_t   tone;
49
-      uint32_t timestamp;
49
+      uint32_t endtime;
50 50
     } state;
51 51
 
52 52
   protected:
@@ -82,7 +82,7 @@ class Buzzer {
82 82
      */
83 83
     void reset() {
84 84
       this->off();
85
-      this->state.timestamp = 0;
85
+      this->state.endtime = 0;
86 86
     }
87 87
 
88 88
   public:
@@ -97,7 +97,7 @@ class Buzzer {
97 97
     /**
98 98
      * @brief Add a tone to the queue
99 99
      * @details Adds a tone_t structure to the ring buffer, will block IO if the
100
-     * queue is full waiting for one slot to get available.
100
+     *          queue is full waiting for one slot to get available.
101 101
      *
102 102
      * @param duration Duration of the tone in milliseconds
103 103
      * @param frequency Frequency of the tone in hertz
@@ -114,17 +114,17 @@ class Buzzer {
114 114
     /**
115 115
      * @brief Loop function
116 116
      * @details This function should be called at loop, it will take care of
117
-     * playing the tones in the queue.
117
+     *          playing the tones in the queue.
118 118
      */
119 119
     virtual void tick() {
120
-      if (!this->state.timestamp) {
120
+      if (!this->state.endtime) {
121 121
         if (this->buffer.isEmpty()) return;
122 122
 
123 123
         this->state.tone = this->buffer.dequeue();
124
-        this->state.timestamp = millis() + this->state.tone.duration;
124
+        this->state.endtime = millis() + this->state.tone.duration;
125 125
         if (this->state.tone.frequency > 0) this->on();
126 126
       }
127
-      else if (millis() >= this->state.timestamp) this->reset();
127
+      else if (ELAPSED(millis(), this->state.endtime)) this->reset();
128 128
     }
129 129
 };
130 130
 

+ 3
- 1
Marlin/ultralcd.cpp Ver arquivo

@@ -2334,12 +2334,14 @@ void kill_screen(const char* lcd_msg) {
2334 2334
     lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
2335 2335
     next_button_update_ms = millis() + 500;
2336 2336
 
2337
+    // Buzz and wait. The delay is needed for buttons to settle!
2337 2338
     #if ENABLED(LCD_USE_I2C_BUZZER)
2338 2339
       lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
2340
+      delay(10);
2339 2341
     #elif PIN_EXISTS(BEEPER)
2340 2342
       buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
2343
+      for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
2341 2344
     #endif
2342
-    delay(10); // needed for buttons to settle
2343 2345
   }
2344 2346
 
2345 2347
   /**

Carregando…
Cancelar
Salvar