SOUND_ON_DEFAULT option (#24102)

This commit is contained in:
Pauli Jokela
2022-05-12 05:23:16 +03:00
committed by Scott Lahteine
parent b2b5b85045
commit 3443a9e18b
23 changed files with 79 additions and 91 deletions

View File

@ -121,7 +121,7 @@ static void createChar_P(const char c, const byte * const ptr) {
#if ENABLED(LCD_USE_I2C_BUZZER)
void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!buzzer_enabled) return;
if (!sound_on) return;
lcd.buzz(duration, freq);
}
#endif

View File

@ -301,7 +301,7 @@ uint8_t MarlinUI::read_slow_buttons() {
// Duration in ms, freq in Hz
void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!PanelDetected) return;
if (!buzzer_enabled) return;
if (!sound_on) return;
#if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW);
SPI_SEND_ONE(BUZZER);

View File

@ -51,11 +51,7 @@ ENCODER_Rate EncoderRate;
// TODO: Replace with ui.quick_feedback
void Encoder_tick() {
#if PIN_EXISTS(BEEPER)
if (ui.buzzer_enabled) {
WRITE(BEEPER_PIN, HIGH);
delay(10);
WRITE(BEEPER_PIN, LOW);
}
if (ui.sound_on) buzzer.click(10);
#endif
}

View File

@ -2585,11 +2585,11 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case ADVANCED_BEEPER:
if (draw) {
Draw_Menu_Item(row, ICON_Version, F("LCD Beeper"));
Draw_Checkbox(row, ui.buzzer_enabled);
Draw_Checkbox(row, ui.sound_on);
}
else {
ui.buzzer_enabled = !ui.buzzer_enabled;
Draw_Checkbox(row, ui.buzzer_enabled);
ui.sound_on = !ui.sound_on;
Draw_Checkbox(row, ui.sound_on);
}
break;
#endif
@ -4600,7 +4600,7 @@ void CrealityDWINClass::Screen_Update() {
}
void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
if (ui.buzzer_enabled)
if (ui.sound_on)
DONE_BUZZ(success);
else
Update_Status(success ? "Success" : "Failed");
@ -4644,7 +4644,7 @@ void CrealityDWINClass::Reset_Settings() {
eeprom_settings.coordinates_split_line = 0;
TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
corner_pos = eeprom_settings.corner_pos / 10.0f;
TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = true);
TERN_(SOUND_MENU_ITEM, ui.sound_on = ENABLED(SOUND_ON_DEFAULT));
Redraw_Screen();
}

View File

@ -2155,8 +2155,8 @@ void SetPID(celsius_t t, heater_id_t h) {
#if ENABLED(SOUND_MENU_ITEM)
void SetEnableSound() {
ui.buzzer_enabled = !ui.buzzer_enabled;
Draw_Chkb_Line(CurrentMenu->line(), ui.buzzer_enabled);
ui.sound_on = !ui.sound_on;
Draw_Chkb_Line(CurrentMenu->line(), ui.sound_on);
DWIN_UpdateLCD();
}
#endif

View File

@ -35,6 +35,8 @@
#include "../../../inc/MarlinConfigPre.h"
// TODO: Use Marlin's built-in tone player instead.
#if ENABLED(ANYCUBIC_LCD_CHIRON)
#include "Tunes.h"
@ -44,15 +46,12 @@ namespace Anycubic {
void PlayTune(uint8_t beeperPin, const uint16_t *tune, uint8_t speed=1) {
uint8_t pos = 1;
uint16_t wholenotelen = tune[0] / speed;
const uint16_t wholenotelen = tune[0] / speed;
do {
uint16_t freq = tune[pos];
uint16_t notelen = wholenotelen / tune[pos + 1];
const uint16_t freq = tune[pos], notelen = wholenotelen / tune[pos + 1];
::tone(beeperPin, freq, notelen);
ExtUI::delay_ms(notelen);
pos += 2;
if (pos >= MAX_TUNE_LENGTH) break;
} while (tune[pos] != n_END);
}

View File

@ -42,9 +42,7 @@ namespace ExtUI {
void onMediaError() { AnycubicTFT.OnSDCardError(); }
void onMediaRemoved() { AnycubicTFT.OnSDCardStateChange(false); }
void onPlayTone(const uint16_t frequency, const uint16_t duration) {
#if ENABLED(SPEAKER)
::tone(BEEPER_PIN, frequency, duration);
#endif
TERN_(SPEAKER, ::tone(BEEPER_PIN, frequency, duration));
}
void onPrintTimerStarted() { AnycubicTFT.OnPrintTimerStarted(); }
void onPrintTimerPaused() { AnycubicTFT.OnPrintTimerPaused(); }

View File

@ -160,6 +160,8 @@
#endif
}
#include "../../../libs/buzzer.h"
void init_test_gpio() {
endstops.init();
@ -201,12 +203,7 @@
#endif
}
void mks_test_beeper() {
WRITE(BEEPER_PIN, HIGH);
delay(100);
WRITE(BEEPER_PIN, LOW);
delay(100);
}
void mks_test_beeper() { buzzer.click(100); }
#if ENABLED(SDSUPPORT)

View File

@ -118,19 +118,18 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif
#if ENABLED(SOUND_MENU_ITEM)
bool MarlinUI::buzzer_enabled = true;
bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
#endif
#if EITHER(PCA9632_BUZZER, USE_BEEPER)
#include "../libs/buzzer.h" // for BUZZ() macro
#if EITHER(PCA9632_BUZZER, HAS_BEEPER)
#if ENABLED(PCA9632_BUZZER)
#include "../feature/leds/pca9632.h"
#endif
void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!buzzer_enabled) return;
if (!sound_on) return;
#if ENABLED(PCA9632_BUZZER)
PCA9632_buzz(duration, freq);
#elif USE_BEEPER
#elif HAS_BEEPER
buzzer.tone(duration, freq);
#endif
}
@ -685,7 +684,7 @@ void MarlinUI::init() {
const millis_t ms = millis();
#endif
if (ELAPSED(ms, next_beep)) {
buzz(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
BUZZ(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
next_beep = ms + 500UL;
}
#endif
@ -739,7 +738,7 @@ void MarlinUI::init() {
#if HAS_CHIRP
chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
#if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);
@ -1632,7 +1631,7 @@ void MarlinUI::init() {
void MarlinUI::flow_fault() {
LCD_ALERTMESSAGE(MSG_FLOWMETER_FAULT);
TERN_(HAS_BUZZER, buzz(1000, 440));
BUZZ(1000, 440);
TERN_(HAS_MARLINUI_MENU, return_to_status());
}

View File

@ -21,16 +21,13 @@
*/
#pragma once
#include "../inc/MarlinConfig.h"
#include "../sd/cardreader.h"
#include "../module/motion.h"
#include "../libs/buzzer.h"
#include "buttons.h"
#include "../inc/MarlinConfig.h"
#if HAS_BUZZER
#include "../libs/buzzer.h"
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "tft_io/touch_calibration.h"
#endif
@ -192,6 +189,9 @@ typedef bool (*statusResetFunc_t)();
//////////// MarlinUI Singleton ////////////
////////////////////////////////////////////
class MarlinUI;
extern MarlinUI ui;
class MarlinUI {
public:
@ -225,9 +225,9 @@ public:
#endif
#if ENABLED(SOUND_MENU_ITEM)
static bool buzzer_enabled; // Initialized by settings.load()
static bool sound_on; // Initialized by settings.load()
#else
static constexpr bool buzzer_enabled = true;
static constexpr bool sound_on = true;
#endif
#if HAS_BUZZER
@ -235,7 +235,7 @@ public:
#endif
FORCE_INLINE static void chirp() {
TERN_(HAS_CHIRP, buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
TERN_(HAS_CHIRP, TERN(HAS_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
}
#if ENABLED(LCD_HAS_STATUS_INDICATORS)
@ -778,8 +778,6 @@ private:
#endif
};
extern MarlinUI ui;
#define LCD_MESSAGE_F(S) ui.set_status(F(S))
#define LCD_MESSAGE(M) ui.set_status(GET_TEXT_F(M))
#define LCD_ALERTMESSAGE_F(S) ui.set_alert_status(F(S))

View File

@ -247,7 +247,7 @@ static void _lcd_level_bed_corners_get_next_position() {
probe_triggered = PROBE_TRIGGERED();
if (probe_triggered) {
endstops.hit_on_purpose();
TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, ui.buzz(200, 600));
TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, BUZZ(200, 600));
}
idle();
}

View File

@ -574,7 +574,7 @@ void menu_configuration() {
#endif
#if ENABLED(SOUND_MENU_ITEM)
EDIT_ITEM(bool, MSG_SOUND, &ui.buzzer_enabled, []{ ui.chirp(); });
EDIT_ITEM(bool, MSG_SOUND, &ui.sound_on, []{ ui.chirp(); });
#endif
#if ENABLED(EEPROM_SETTINGS)

View File

@ -596,7 +596,7 @@ MotionAxisState motionAxisState;
static void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
#if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);

View File

@ -578,7 +578,7 @@ MotionAxisState motionAxisState;
static void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
#if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);

View File

@ -583,7 +583,7 @@ MotionAxisState motionAxisState;
static void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
#if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);