2016-03-25 01:19:46 -05:00
|
|
|
/**
|
2016-03-24 13:01:20 -05:00
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-06-17 09:31:14 -05:00
|
|
|
#include "Marlin.h"
|
|
|
|
#if HAS_BUZZER
|
2015-08-11 11:38:26 -05:00
|
|
|
#include "buzzer.h"
|
|
|
|
#include "ultralcd.h"
|
|
|
|
|
2015-06-17 09:31:14 -05:00
|
|
|
void buzz(long duration, uint16_t freq) {
|
|
|
|
if (freq > 0) {
|
2015-07-31 00:21:18 -05:00
|
|
|
#if ENABLED(LCD_USE_I2C_BUZZER)
|
2015-06-17 09:31:14 -05:00
|
|
|
lcd_buzz(duration, freq);
|
2015-07-31 01:19:11 -05:00
|
|
|
#elif PIN_EXISTS(BEEPER) // on-board buzzers have no further condition
|
|
|
|
SET_OUTPUT(BEEPER_PIN);
|
2015-08-03 14:30:37 -05:00
|
|
|
#if ENABLED(SPEAKER) // a speaker needs a AC ore a pulsed DC
|
2015-07-31 01:19:11 -05:00
|
|
|
//tone(BEEPER_PIN, freq, duration); // needs a PWMable pin
|
2015-07-24 16:19:09 -05:00
|
|
|
unsigned int delay = 1000000 / freq / 2;
|
|
|
|
int i = duration * freq / 1000;
|
|
|
|
while (i--) {
|
2015-07-31 01:19:11 -05:00
|
|
|
WRITE(BEEPER_PIN, HIGH);
|
2015-07-24 16:19:09 -05:00
|
|
|
delayMicroseconds(delay);
|
2015-07-31 01:19:11 -05:00
|
|
|
WRITE(BEEPER_PIN, LOW);
|
2015-07-24 16:19:09 -05:00
|
|
|
delayMicroseconds(delay);
|
|
|
|
}
|
|
|
|
#else // buzzer has its own resonator - needs a DC
|
2015-07-31 01:19:11 -05:00
|
|
|
WRITE(BEEPER_PIN, HIGH);
|
2015-07-24 16:19:09 -05:00
|
|
|
delay(duration);
|
2015-07-31 01:19:11 -05:00
|
|
|
WRITE(BEEPER_PIN, LOW);
|
2015-07-24 16:19:09 -05:00
|
|
|
#endif
|
2015-06-17 09:31:14 -05:00
|
|
|
#else
|
|
|
|
delay(duration);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delay(duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|