examples : rename arduino examples

This commit is contained in:
Georgi Gerganov
2022-06-11 19:54:18 +03:00
parent d76316aecb
commit 5f555d9281
9 changed files with 205 additions and 205 deletions

View File

@@ -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)

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -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;
}
}
}

View File

@@ -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)

View File

@@ -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;
}
}
}