From 5f555d9281d89fa8c96d0904051957704f2550eb Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 11 Jun 2022 19:54:18 +0300 Subject: [PATCH] examples : rename arduino examples --- examples/CMakeLists.txt | 2 +- .../.gitignore | 0 examples/arduino-tx-obsolete/CMakeLists.txt | 0 examples/arduino-tx-obsolete/arduino-tx.ino | 87 +++++++++ .../ggwave.h | 0 examples/arduino-tx/CMakeLists.txt | 10 ++ examples/arduino-tx/arduino-tx.ino | 166 +++++++++++------- examples/arduino-tx2/CMakeLists.txt | 10 -- examples/arduino-tx2/arduino-tx2.ino | 135 -------------- 9 files changed, 205 insertions(+), 205 deletions(-) rename examples/{arduino-tx2 => arduino-tx-obsolete}/.gitignore (100%) create mode 100644 examples/arduino-tx-obsolete/CMakeLists.txt create mode 100644 examples/arduino-tx-obsolete/arduino-tx.ino rename examples/{arduino-tx => arduino-tx-obsolete}/ggwave.h (100%) delete mode 100644 examples/arduino-tx2/CMakeLists.txt delete mode 100644 examples/arduino-tx2/arduino-tx2.ino diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6964dd3..fa79075 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -89,7 +89,7 @@ else() add_subdirectory(arduino-rx) add_subdirectory(arduino-tx) - add_subdirectory(arduino-tx2) + add_subdirectory(arduino-tx-obsolete) endif() if (GGWAVE_SUPPORT_SDL2) diff --git a/examples/arduino-tx2/.gitignore b/examples/arduino-tx-obsolete/.gitignore similarity index 100% rename from examples/arduino-tx2/.gitignore rename to examples/arduino-tx-obsolete/.gitignore diff --git a/examples/arduino-tx-obsolete/CMakeLists.txt b/examples/arduino-tx-obsolete/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/arduino-tx-obsolete/arduino-tx.ino b/examples/arduino-tx-obsolete/arduino-tx.ino new file mode 100644 index 0000000..2e107b0 --- /dev/null +++ b/examples/arduino-tx-obsolete/arduino-tx.ino @@ -0,0 +1,87 @@ +// This example uses a custom ggwave imlpementation specifically for Arduino UNO. +// Since the Arduino UNO has only 2KB of RAM, the ggwave library is not able to +// to fit into the Arduino's memory (eventhough it is very close). +// If your microcontroller has more than 2KB of RAM, you should check the other Tx +// examples to see if you can use the original ggwave library. +#include "ggwave.h" + +const int kPinLed0 = 13; +const int kPinSpeaker = 10; +const int kPinButton0 = 2; +const int kPinButton1 = 4; + +void setup() { + Serial.begin(57600); + + pinMode(kPinLed0, OUTPUT); + pinMode(kPinSpeaker, OUTPUT); + pinMode(kPinButton0, INPUT); + pinMode(kPinButton1, INPUT); + + delay(3000); + + digitalWrite(kPinLed0, HIGH); + GGWave::send_text(kPinSpeaker, "Hello!", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(2000); + + digitalWrite(kPinLed0, HIGH); + GGWave::send_text(kPinSpeaker, "This is a", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + GGWave::send_text(kPinSpeaker, "ggwave demo", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(2000); + + digitalWrite(kPinLed0, HIGH); + GGWave::send_text(kPinSpeaker, "The arduino", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + GGWave::send_text(kPinSpeaker, "transmits data", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + GGWave::send_text(kPinSpeaker, "using sound", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + GGWave::send_text(kPinSpeaker, "through a buzzer", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(1000); + + digitalWrite(kPinLed0, HIGH); + GGWave::send_text(kPinSpeaker, "The sound is", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + GGWave::send_text(kPinSpeaker, "decoded in a", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + GGWave::send_text(kPinSpeaker, "web page.", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(1000); + + digitalWrite(kPinLed0, HIGH); + GGWave::send_text(kPinSpeaker, "Press the button!", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); +} + +char txt[16]; +int pressed = 0; +bool isDown = false; + +void loop() { + int but0 = digitalRead(kPinButton0); + int but1 = digitalRead(kPinButton1); + + if (but1 == LOW && isDown == false) { + delay(200); + ++pressed; + isDown = true; + } else if (but1 == HIGH) { + isDown = false; + } + + if (but0 == LOW) { + snprintf(txt, 16, "Pressed: %d", pressed); + + digitalWrite(kPinLed0, HIGH); + GGWave::send_text(kPinSpeaker, txt, GGWave::GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + pressed = 0; + } +} diff --git a/examples/arduino-tx/ggwave.h b/examples/arduino-tx-obsolete/ggwave.h similarity index 100% rename from examples/arduino-tx/ggwave.h rename to examples/arduino-tx-obsolete/ggwave.h diff --git a/examples/arduino-tx/CMakeLists.txt b/examples/arduino-tx/CMakeLists.txt index e69de29..bbf0d07 100644 --- a/examples/arduino-tx/CMakeLists.txt +++ b/examples/arduino-tx/CMakeLists.txt @@ -0,0 +1,10 @@ +# +# arduino-tx + +configure_file(${CMAKE_SOURCE_DIR}/include/ggwave/ggwave.h ${CMAKE_CURRENT_SOURCE_DIR}/ggwave/ggwave.h COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/src/ggwave.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ggwave.cpp COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/src/fft.h ${CMAKE_CURRENT_SOURCE_DIR}/fft.h COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/gf.hpp ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/gf.hpp COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/rs.hpp ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/rs.hpp COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/poly.hpp ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/poly.hpp COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/LICENSE COPYONLY) diff --git a/examples/arduino-tx/arduino-tx.ino b/examples/arduino-tx/arduino-tx.ino index 2e107b0..e5288c1 100644 --- a/examples/arduino-tx/arduino-tx.ino +++ b/examples/arduino-tx/arduino-tx.ino @@ -1,87 +1,135 @@ -// This example uses a custom ggwave imlpementation specifically for Arduino UNO. -// Since the Arduino UNO has only 2KB of RAM, the ggwave library is not able to -// to fit into the Arduino's memory (eventhough it is very close). -// If your microcontroller has more than 2KB of RAM, you should check the other Tx -// examples to see if you can use the original ggwave library. -#include "ggwave.h" +#include "ggwave/ggwave.h" const int kPinLed0 = 13; const int kPinSpeaker = 10; const int kPinButton0 = 2; const int kPinButton1 = 4; +const int samplesPerFrame = 128; +const int sampleRate = 6000; + +// global GGwave instance +GGWave ggwave; + +char txt[64]; +#define P(str) (strcpy_P(txt, PSTR(str)), txt) + +// helper function to output the generated GGWave waveform via a buzzer +void send_text(GGWave & ggwave, uint8_t pin, const char * text, GGWave::TxProtocolId protocolId) { + Serial.print(F("Sending text: ")); + Serial.println(text); + + ggwave.init(text, protocolId); + ggwave.encode(); + + const auto & protocol = GGWave::Protocols::tx()[protocolId]; + const auto tones = ggwave.txTones(); + const auto duration_ms = protocol.txDuration_ms(ggwave.samplesPerFrame(), ggwave.sampleRateOut()); + for (auto & curTone : tones) { + const auto freq_hz = (protocol.freqStart + curTone)*ggwave.hzPerSample(); + tone(pin, freq_hz); + delay(duration_ms); + } + + noTone(pin); + digitalWrite(pin, LOW); +} + void setup() { Serial.begin(57600); + while (!Serial); pinMode(kPinLed0, OUTPUT); pinMode(kPinSpeaker, OUTPUT); pinMode(kPinButton0, INPUT); pinMode(kPinButton1, INPUT); - delay(3000); + Serial.println(F("Trying to create ggwave instance")); - digitalWrite(kPinLed0, HIGH); - GGWave::send_text(kPinSpeaker, "Hello!", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); + auto p = GGWave::getDefaultParameters(); + p.payloadLength = 16; + p.sampleRateInp = sampleRate; + p.sampleRateOut = sampleRate; + p.sampleRate = sampleRate; + p.samplesPerFrame = samplesPerFrame; + p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16; + p.sampleFormatOut = GGWAVE_SAMPLE_FORMAT_U8; + p.operatingMode = (ggwave_OperatingMode) (GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES | GGWAVE_OPERATING_MODE_USE_DSS); - delay(2000); + GGWave::Protocols::tx().only(GGWAVE_PROTOCOL_MT_FASTEST); + ggwave.prepare(p); + ggwave.setLogFile(nullptr); + Serial.println(ggwave.heapSize()); - digitalWrite(kPinLed0, HIGH); - GGWave::send_text(kPinSpeaker, "This is a", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - GGWave::send_text(kPinSpeaker, "ggwave demo", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(2000); - - digitalWrite(kPinLed0, HIGH); - GGWave::send_text(kPinSpeaker, "The arduino", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - GGWave::send_text(kPinSpeaker, "transmits data", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - GGWave::send_text(kPinSpeaker, "using sound", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - GGWave::send_text(kPinSpeaker, "through a buzzer", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(1000); - - digitalWrite(kPinLed0, HIGH); - GGWave::send_text(kPinSpeaker, "The sound is", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - GGWave::send_text(kPinSpeaker, "decoded in a", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - GGWave::send_text(kPinSpeaker, "web page.", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(1000); - - digitalWrite(kPinLed0, HIGH); - GGWave::send_text(kPinSpeaker, "Press the button!", GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); + Serial.println(F("Instance initialized")); } -char txt[16]; int pressed = 0; bool isDown = false; void loop() { - int but0 = digitalRead(kPinButton0); - int but1 = digitalRead(kPinButton1); + delay(1000); - if (but1 == LOW && isDown == false) { - delay(200); - ++pressed; - isDown = true; - } else if (but1 == HIGH) { - isDown = false; - } + digitalWrite(kPinLed0, HIGH); + send_text(ggwave, kPinSpeaker, P("Hello!"), GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); - if (but0 == LOW) { - snprintf(txt, 16, "Pressed: %d", pressed); + delay(2000); - digitalWrite(kPinLed0, HIGH); - GGWave::send_text(kPinSpeaker, txt, GGWave::GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - pressed = 0; + digitalWrite(kPinLed0, HIGH); + send_text(ggwave, kPinSpeaker, P("This is a"), GGWAVE_PROTOCOL_MT_FASTEST); + send_text(ggwave, kPinSpeaker, P("ggwave demo"), GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(2000); + + digitalWrite(kPinLed0, HIGH); + send_text(ggwave, kPinSpeaker, P("The arduino"), GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + send_text(ggwave, kPinSpeaker, P("transmits data"), GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + send_text(ggwave, kPinSpeaker, P("using sound"), GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + send_text(ggwave, kPinSpeaker, P("through a buzzer"), GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(1000); + + digitalWrite(kPinLed0, HIGH); + send_text(ggwave, kPinSpeaker, P("The sound is"), GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + send_text(ggwave, kPinSpeaker, P("decoded in a"), GGWAVE_PROTOCOL_MT_FASTEST); + delay(200); + send_text(ggwave, kPinSpeaker, P("web page."), GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + delay(1000); + + digitalWrite(kPinLed0, HIGH); + send_text(ggwave, kPinSpeaker, P("Press the button!"), GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + + Serial.println(F("Starting main loop")); + + while (true) { + int but0 = digitalRead(kPinButton0); + int but1 = digitalRead(kPinButton1); + + if (but1 == LOW && isDown == false) { + delay(200); + ++pressed; + isDown = true; + } else if (but1 == HIGH) { + isDown = false; + } + + if (but0 == LOW) { + snprintf(txt, 16, "Pressed: %d", pressed); + + digitalWrite(kPinLed0, HIGH); + send_text(ggwave, kPinSpeaker, txt, GGWAVE_PROTOCOL_MT_FASTEST); + digitalWrite(kPinLed0, LOW); + pressed = 0; + } } } diff --git a/examples/arduino-tx2/CMakeLists.txt b/examples/arduino-tx2/CMakeLists.txt deleted file mode 100644 index 4778294..0000000 --- a/examples/arduino-tx2/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -# arduino-tx2 - -configure_file(${CMAKE_SOURCE_DIR}/include/ggwave/ggwave.h ${CMAKE_CURRENT_SOURCE_DIR}/ggwave/ggwave.h COPYONLY) -configure_file(${CMAKE_SOURCE_DIR}/src/ggwave.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ggwave.cpp COPYONLY) -configure_file(${CMAKE_SOURCE_DIR}/src/fft.h ${CMAKE_CURRENT_SOURCE_DIR}/fft.h COPYONLY) -configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/gf.hpp ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/gf.hpp COPYONLY) -configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/rs.hpp ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/rs.hpp COPYONLY) -configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/poly.hpp ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/poly.hpp COPYONLY) -configure_file(${CMAKE_SOURCE_DIR}/src/reed-solomon/LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/reed-solomon/LICENSE COPYONLY) diff --git a/examples/arduino-tx2/arduino-tx2.ino b/examples/arduino-tx2/arduino-tx2.ino deleted file mode 100644 index e5288c1..0000000 --- a/examples/arduino-tx2/arduino-tx2.ino +++ /dev/null @@ -1,135 +0,0 @@ -#include "ggwave/ggwave.h" - -const int kPinLed0 = 13; -const int kPinSpeaker = 10; -const int kPinButton0 = 2; -const int kPinButton1 = 4; - -const int samplesPerFrame = 128; -const int sampleRate = 6000; - -// global GGwave instance -GGWave ggwave; - -char txt[64]; -#define P(str) (strcpy_P(txt, PSTR(str)), txt) - -// helper function to output the generated GGWave waveform via a buzzer -void send_text(GGWave & ggwave, uint8_t pin, const char * text, GGWave::TxProtocolId protocolId) { - Serial.print(F("Sending text: ")); - Serial.println(text); - - ggwave.init(text, protocolId); - ggwave.encode(); - - const auto & protocol = GGWave::Protocols::tx()[protocolId]; - const auto tones = ggwave.txTones(); - const auto duration_ms = protocol.txDuration_ms(ggwave.samplesPerFrame(), ggwave.sampleRateOut()); - for (auto & curTone : tones) { - const auto freq_hz = (protocol.freqStart + curTone)*ggwave.hzPerSample(); - tone(pin, freq_hz); - delay(duration_ms); - } - - noTone(pin); - digitalWrite(pin, LOW); -} - -void setup() { - Serial.begin(57600); - while (!Serial); - - pinMode(kPinLed0, OUTPUT); - pinMode(kPinSpeaker, OUTPUT); - pinMode(kPinButton0, INPUT); - pinMode(kPinButton1, INPUT); - - Serial.println(F("Trying to create ggwave instance")); - - auto p = GGWave::getDefaultParameters(); - p.payloadLength = 16; - p.sampleRateInp = sampleRate; - p.sampleRateOut = sampleRate; - p.sampleRate = sampleRate; - p.samplesPerFrame = samplesPerFrame; - p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16; - p.sampleFormatOut = GGWAVE_SAMPLE_FORMAT_U8; - p.operatingMode = (ggwave_OperatingMode) (GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES | GGWAVE_OPERATING_MODE_USE_DSS); - - GGWave::Protocols::tx().only(GGWAVE_PROTOCOL_MT_FASTEST); - ggwave.prepare(p); - ggwave.setLogFile(nullptr); - Serial.println(ggwave.heapSize()); - - Serial.println(F("Instance initialized")); -} - -int pressed = 0; -bool isDown = false; - -void loop() { - delay(1000); - - digitalWrite(kPinLed0, HIGH); - send_text(ggwave, kPinSpeaker, P("Hello!"), GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(2000); - - digitalWrite(kPinLed0, HIGH); - send_text(ggwave, kPinSpeaker, P("This is a"), GGWAVE_PROTOCOL_MT_FASTEST); - send_text(ggwave, kPinSpeaker, P("ggwave demo"), GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(2000); - - digitalWrite(kPinLed0, HIGH); - send_text(ggwave, kPinSpeaker, P("The arduino"), GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - send_text(ggwave, kPinSpeaker, P("transmits data"), GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - send_text(ggwave, kPinSpeaker, P("using sound"), GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - send_text(ggwave, kPinSpeaker, P("through a buzzer"), GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(1000); - - digitalWrite(kPinLed0, HIGH); - send_text(ggwave, kPinSpeaker, P("The sound is"), GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - send_text(ggwave, kPinSpeaker, P("decoded in a"), GGWAVE_PROTOCOL_MT_FASTEST); - delay(200); - send_text(ggwave, kPinSpeaker, P("web page."), GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - delay(1000); - - digitalWrite(kPinLed0, HIGH); - send_text(ggwave, kPinSpeaker, P("Press the button!"), GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - - Serial.println(F("Starting main loop")); - - while (true) { - int but0 = digitalRead(kPinButton0); - int but1 = digitalRead(kPinButton1); - - if (but1 == LOW && isDown == false) { - delay(200); - ++pressed; - isDown = true; - } else if (but1 == HIGH) { - isDown = false; - } - - if (but0 == LOW) { - snprintf(txt, 16, "Pressed: %d", pressed); - - digitalWrite(kPinLed0, HIGH); - send_text(ggwave, kPinSpeaker, txt, GGWAVE_PROTOCOL_MT_FASTEST); - digitalWrite(kPinLed0, LOW); - pressed = 0; - } - } -}