mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
initial support for generic RTTTL notifier
This commit is contained in:
parent
f9c0056955
commit
be88bea42d
4 changed files with 112 additions and 1 deletions
54
examples/companion_radio/buzzer.cpp
Normal file
54
examples/companion_radio/buzzer.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#ifdef PIN_BUZZER
|
||||||
|
#include "buzzer.h"
|
||||||
|
|
||||||
|
void genericBuzzer::begin() {
|
||||||
|
Serial.print("DBG: Setting up buzzer on pin ");
|
||||||
|
Serial.println(PIN_BUZZER);
|
||||||
|
#ifdef PIN_BUZZER_EN
|
||||||
|
pinMode(PIN_BUZZER_EN, OUTPUT);
|
||||||
|
digitalWrite(PIN_BUZZER_EN, HIGH);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
quiet(false);
|
||||||
|
pinMode(PIN_BUZZER, OUTPUT);
|
||||||
|
startup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void genericBuzzer::play(const char *melody) {
|
||||||
|
if (isPlaying()) // interrupt existing
|
||||||
|
{
|
||||||
|
rtttl::stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_is_quiet) return;
|
||||||
|
|
||||||
|
rtttl::begin(PIN_BUZZER,melody);
|
||||||
|
// Serial.print("DBG: Playing melody - isQuiet: ");
|
||||||
|
// Serial.println(isQuiet());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool genericBuzzer::isPlaying() {
|
||||||
|
return rtttl::isPlaying();
|
||||||
|
}
|
||||||
|
|
||||||
|
void genericBuzzer::loop() {
|
||||||
|
if (!rtttl::done()) rtttl::play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void genericBuzzer::startup() {
|
||||||
|
play(startup_song);
|
||||||
|
}
|
||||||
|
|
||||||
|
void genericBuzzer::shutdown() {
|
||||||
|
play(shutdown_song);
|
||||||
|
}
|
||||||
|
|
||||||
|
void genericBuzzer::quiet(bool buzzer_state) {
|
||||||
|
_is_quiet = buzzer_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool genericBuzzer::isQuiet() {
|
||||||
|
return _is_quiet;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ifdef PIN_BUZZER
|
||||||
36
examples/companion_radio/buzzer.h
Normal file
36
examples/companion_radio/buzzer.h
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <NonBlockingRtttl.h>
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
|
||||||
|
TODO
|
||||||
|
- make message ring tone configurable
|
||||||
|
|
||||||
|
*/
|
||||||
|
class genericBuzzer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void begin(); // set up buzzer port
|
||||||
|
void play(const char *melody); // Generic play function
|
||||||
|
void loop(); // loop driven-nonblocking
|
||||||
|
void startup(); // play startup sound
|
||||||
|
void shutdown(); // play shutdown sound
|
||||||
|
bool isPlaying(); // returns true if a sound is still playing else false
|
||||||
|
void quiet(bool buzzer_state); // enables or disables the buzzer
|
||||||
|
bool isQuiet(); // get buzzer state on/off
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
bool _is_quiet = true;
|
||||||
|
};
|
||||||
|
|
@ -66,6 +66,11 @@
|
||||||
static UITask ui_task(&board);
|
static UITask ui_task(&board);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PIN_BUZZER
|
||||||
|
#include "buzzer.h"
|
||||||
|
genericBuzzer buzzer;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Believe it or not, this std C function is busted on some platforms!
|
// Believe it or not, this std C function is busted on some platforms!
|
||||||
static uint32_t _atoi(const char* sp) {
|
static uint32_t _atoi(const char* sp) {
|
||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
|
|
@ -484,7 +489,12 @@ class MyMesh : public BaseChatMesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
void soundBuzzer() {
|
void soundBuzzer() {
|
||||||
// TODO
|
#if defined(PIN_BUZZER)
|
||||||
|
// gemini's pick
|
||||||
|
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
|
||||||
|
//Serial.println("DBG: Buzzzzzz");
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -1553,6 +1563,10 @@ public:
|
||||||
ui_task.setHasConnection(_serial->isConnected());
|
ui_task.setHasConnection(_serial->isConnected());
|
||||||
ui_task.loop();
|
ui_task.loop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PIN_BUZZER
|
||||||
|
if (buzzer.isPlaying()) buzzer.loop();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1620,6 +1634,10 @@ void setup() {
|
||||||
|
|
||||||
board.begin();
|
board.begin();
|
||||||
|
|
||||||
|
#ifdef PIN_BUZZER
|
||||||
|
buzzer.begin();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
DisplayDriver* disp = NULL;
|
DisplayDriver* disp = NULL;
|
||||||
if (display.begin()) {
|
if (display.begin()) {
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,12 @@ build_flags = ${t1000-e.build_flags}
|
||||||
-D RX_BOOSTED_GAIN=true
|
-D RX_BOOSTED_GAIN=true
|
||||||
-D RF_SWITCH_TABLE
|
-D RF_SWITCH_TABLE
|
||||||
-D DISPLAY_CLASS=NullDisplayDriver
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
|
-D PIN_BUZZER=25
|
||||||
|
-D PIN_BUZZER_EN=37 ; P1/5 - required for T1000-E
|
||||||
build_src_filter = ${t1000-e.build_src_filter}
|
build_src_filter = ${t1000-e.build_src_filter}
|
||||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||||
+<../examples/companion_radio/*.cpp>
|
+<../examples/companion_radio/*.cpp>
|
||||||
lib_deps = ${t1000-e.lib_deps}
|
lib_deps = ${t1000-e.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
stevemarple/MicroNMEA @ ^2.0.6
|
stevemarple/MicroNMEA @ ^2.0.6
|
||||||
|
end2endzone/NonBlockingRTTTL@^1.3.0
|
||||||
Loading…
Add table
Add a link
Reference in a new issue