Browse Source

Merge pull request #4265 from thinkyhead/rc_buzzer_patchup

Two strategies to address a stuck buzzer
Scott Lahteine 9 years ago
parent
commit
6121c9018a
2 changed files with 10 additions and 8 deletions
  1. 7
    7
      Marlin/buzzer.h
  2. 3
    1
      Marlin/ultralcd.cpp

+ 7
- 7
Marlin/buzzer.h View File

46
   private:
46
   private:
47
     struct state_t {
47
     struct state_t {
48
       tone_t   tone;
48
       tone_t   tone;
49
-      uint32_t timestamp;
49
+      uint32_t endtime;
50
     } state;
50
     } state;
51
 
51
 
52
   protected:
52
   protected:
82
      */
82
      */
83
     void reset() {
83
     void reset() {
84
       this->off();
84
       this->off();
85
-      this->state.timestamp = 0;
85
+      this->state.endtime = 0;
86
     }
86
     }
87
 
87
 
88
   public:
88
   public:
97
     /**
97
     /**
98
      * @brief Add a tone to the queue
98
      * @brief Add a tone to the queue
99
      * @details Adds a tone_t structure to the ring buffer, will block IO if the
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
      * @param duration Duration of the tone in milliseconds
102
      * @param duration Duration of the tone in milliseconds
103
      * @param frequency Frequency of the tone in hertz
103
      * @param frequency Frequency of the tone in hertz
114
     /**
114
     /**
115
      * @brief Loop function
115
      * @brief Loop function
116
      * @details This function should be called at loop, it will take care of
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
     virtual void tick() {
119
     virtual void tick() {
120
-      if (!this->state.timestamp) {
120
+      if (!this->state.endtime) {
121
         if (this->buffer.isEmpty()) return;
121
         if (this->buffer.isEmpty()) return;
122
 
122
 
123
         this->state.tone = this->buffer.dequeue();
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
         if (this->state.tone.frequency > 0) this->on();
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 View File

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

Loading…
Cancel
Save