mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Refactor buzzer sound handling in UITask; replace hardcoded RTTTL strings with class member variables for better maintainability.
This commit is contained in:
parent
0d8fa629ba
commit
0dde372ebf
3 changed files with 22 additions and 20 deletions
|
|
@ -603,14 +603,14 @@ void UITask::notify(UIEventType t) {
|
|||
#if defined(PIN_BUZZER)
|
||||
switch(t){
|
||||
case UIEventType::contactMessage:
|
||||
// gemini's pick
|
||||
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
|
||||
// Play message sound using class member
|
||||
buzzer.play(buzzer.message_song);
|
||||
break;
|
||||
case UIEventType::channelMessage:
|
||||
buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#");
|
||||
buzzer.play(buzzer.channel_song); // Play channel message sound
|
||||
break;
|
||||
case UIEventType::ack:
|
||||
buzzer.play("ack:d=32,o=8,b=120:c");
|
||||
buzzer.play(buzzer.ack_song); // Play ack sound
|
||||
break;
|
||||
case UIEventType::roomMessage:
|
||||
case UIEventType::newContactMessage:
|
||||
|
|
|
|||
|
|
@ -93,14 +93,14 @@ void UITask::notify(UIEventType t) {
|
|||
#if defined(PIN_BUZZER)
|
||||
switch(t){
|
||||
case UIEventType::contactMessage:
|
||||
// gemini's pick
|
||||
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
|
||||
// Play message sound using class member
|
||||
buzzer.play(buzzer.message_song);
|
||||
break;
|
||||
case UIEventType::channelMessage:
|
||||
buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#");
|
||||
buzzer.play(buzzer.channel_song); // Play channel message sound
|
||||
break;
|
||||
case UIEventType::ack:
|
||||
buzzer.play("ack:d=32,o=8,b=120:c");
|
||||
buzzer.play(buzzer.ack_song); // Play ack sound
|
||||
break;
|
||||
case UIEventType::roomMessage:
|
||||
case UIEventType::newContactMessage:
|
||||
|
|
|
|||
|
|
@ -5,14 +5,20 @@
|
|||
|
||||
/* class abstracts underlying RTTTL library
|
||||
|
||||
Just a simple imlementation to start. At the moment use same
|
||||
melody for message and discovery
|
||||
Suggest enum type for different sounds
|
||||
- on message
|
||||
- on discovery
|
||||
|
||||
|
||||
Just a simple implementation to start. Use RTTTL strings directly for different events.
|
||||
|
||||
Example usage:
|
||||
genericBuzzer buzzer;
|
||||
buzzer.begin();
|
||||
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); // Play message sound
|
||||
buzzer.play("Discovery:d=4,o=5,b=180:8e6,8d6,8c6"); // Play discovery sound
|
||||
|
||||
You can configure the melodies by changing the RTTTL strings in your code.
|
||||
|
||||
TODO
|
||||
- make message ring tone configurable
|
||||
- make message ring tone configurable at runtime
|
||||
|
||||
*/
|
||||
|
||||
|
|
@ -20,7 +26,7 @@ class genericBuzzer
|
|||
{
|
||||
public:
|
||||
void begin(); // set up buzzer port
|
||||
void play(const char *melody); // Generic play function
|
||||
void play(const char *melody); // Play RTTTL melody
|
||||
void loop(); // loop driven-nonblocking
|
||||
void startup(); // play startup sound
|
||||
void shutdown(); // play shutdown sound
|
||||
|
|
@ -28,7 +34,6 @@ class genericBuzzer
|
|||
void quiet(bool buzzer_state); // enables or disables the buzzer
|
||||
bool isQuiet(); // get buzzer state on/off
|
||||
|
||||
|
||||
// Example RTTTL melodies for startup/shutdown/message/discovery
|
||||
const char *startup_song = "Startup:d=4,o=5,b=160:16c6,16e6,8g6";
|
||||
const char *shutdown_song = "Shutdown:d=4,o=5,b=100:8g5,16e5,16c5";
|
||||
|
|
@ -36,10 +41,7 @@ class genericBuzzer
|
|||
const char *discovery_song = "Discovery:d=4,o=5,b=180:8e6,8d6,8c6";
|
||||
const char *channel_song = "kerplop:d=16,o=6,b=120:32g#,16c#"; // more of a "plop" sound for channel change
|
||||
const char *ack_song = "ack:d=16,o=8,b=120:c8,c6"; // Two beeps: first high (C8), then low (C6)
|
||||
private:
|
||||
// gemini's picks:
|
||||
const char *startup_song = "Startup:d=4,o=5,b=160:16c6,16e6,8g6";
|
||||
const char *shutdown_song = "Shutdown:d=4,o=5,b=100:8g5,16e5,16c5";
|
||||
|
||||
private:
|
||||
bool _is_quiet = true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue