Преглед изворни кода

Consolidates Buzzer and Speaker into a single object

João Brázio пре 8 година
родитељ
комит
2b5faa61e2
4 измењених фајлова са 14 додато и 89 уклоњено
  1. 2
    7
      Marlin/Marlin.h
  2. 0
    4
      Marlin/Marlin_main.cpp
  3. 12
    4
      Marlin/buzzer.h
  4. 0
    74
      Marlin/speaker.h

+ 2
- 7
Marlin/Marlin.h Прегледај датотеку

@@ -386,13 +386,8 @@ void calculate_volumetric_multipliers();
386 386
 
387 387
 // Buzzer
388 388
 #if HAS_BUZZER
389
-  #if ENABLED(SPEAKER)
390
-    #include "speaker.h"
391
-    extern Speaker buzzer;
392
-  #else
393
-    #include "buzzer.h"
394
-    extern Buzzer buzzer;
395
-  #endif
389
+  #include "buzzer.h"
390
+  extern Buzzer buzzer;
396 391
 #endif
397 392
 
398 393
 /**

+ 0
- 4
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -375,11 +375,7 @@ static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL
375 375
 
376 376
 // Buzzer
377 377
 #if HAS_BUZZER
378
-  #if ENABLED(SPEAKER)
379
-    Speaker buzzer;
380
-  #else
381 378
     Buzzer buzzer;
382
-  #endif
383 379
 #endif
384 380
 
385 381
 static uint8_t target_extruder;

+ 12
- 4
Marlin/buzzer.h Прегледај датотеку

@@ -32,7 +32,6 @@
32 32
 /**
33 33
  * @brief Tone structure
34 34
  * @details Simple abstraction of a tone based on a duration and a frequency.
35
- *
36 35
  */
37 36
 struct tone_t {
38 37
   uint16_t duration;
@@ -116,14 +115,23 @@ class Buzzer {
116 115
      *          playing the tones in the queue.
117 116
      */
118 117
     virtual void tick() {
118
+      const millis_t now = millis();
119
+
119 120
       if (!this->state.endtime) {
120 121
         if (this->buffer.isEmpty()) return;
121 122
 
122 123
         this->state.tone = this->buffer.dequeue();
123
-        this->state.endtime = millis() + this->state.tone.duration;
124
-        if (this->state.tone.frequency > 0) this->on();
124
+        this->state.endtime = now + this->state.tone.duration;
125
+
126
+        if (this->state.tone.frequency > 0) {
127
+          #if ENABLED(SPEAKER)
128
+            ::tone(BEEPER_PIN, this->state.tone.frequency, this->state.tone.duration);
129
+          #else
130
+            this->on();
131
+          #endif
132
+        }
125 133
       }
126
-      else if (ELAPSED(millis(), this->state.endtime)) this->reset();
134
+      else if (ELAPSED(now, this->state.endtime)) this->reset();
127 135
     }
128 136
 };
129 137
 

+ 0
- 74
Marlin/speaker.h Прегледај датотеку

@@ -1,74 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
- *
8
- * This program is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-#ifndef __SPEAKER_H__
24
-#define __SPEAKER_H__
25
-
26
-#include "buzzer.h"
27
-
28
-class Speaker: public Buzzer {
29
-  private:
30
-    typedef Buzzer super;
31
-
32
-    struct state_t {
33
-      tone_t   tone;
34
-      millis_t next;
35
-    } state;
36
-
37
-  protected:
38
-    /**
39
-     * @brief Resets the state of the class
40
-     * @details Brings the class state to a known one.
41
-     */
42
-    void reset() {
43
-      super::reset();
44
-      this->state.next = 0;
45
-    }
46
-
47
-  public:
48
-    /**
49
-     * @brief Class constructor
50
-     */
51
-    Speaker() {
52
-      this->reset();
53
-    }
54
-
55
-    /**
56
-     * @brief Loop function
57
-     * @details This function should be called at loop, it will take care of
58
-     * playing the tones in the queue.
59
-     */
60
-    virtual void tick() {
61
-      const uint32_t now = millis();
62
-
63
-      if (now >= this->state.next) {
64
-        if (this->buffer.isEmpty()) return;
65
-
66
-        this->reset();
67
-        this->state.tone = this->buffer.dequeue();
68
-        this->state.next = now + this->state.tone.duration;
69
-        ::tone(BEEPER_PIN, this->state.tone.frequency, this->state.tone.duration);
70
-      }
71
-    }
72
-};
73
-
74
-#endif

Loading…
Откажи
Сачувај