From cac83243269f06f67949373fd6662905c423e1bb Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 3 Jul 2022 17:59:41 +0300 Subject: [PATCH] tmp --- examples/esp32-rx/esp32-rx.ino | 73 +++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/examples/esp32-rx/esp32-rx.ino b/examples/esp32-rx/esp32-rx.ino index 5c8b6a0..2f7a248 100644 --- a/examples/esp32-rx/esp32-rx.ino +++ b/examples/esp32-rx/esp32-rx.ino @@ -1,15 +1,34 @@ #include "ggwave/ggwave.h" +#include #include +#include +#include +#include +#include + +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 32 // OLED display height, in pixels + +// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) +// The pins for I2C are defined by the Wire-library. +// On an arduino UNO: A4(SDA), A5(SCL) +// On an arduino MEGA 2560: 20(SDA), 21(SCL) +// On an arduino LEONARDO: 2(SDA), 3(SCL), ... +#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) +#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + + // global GGwave instance GGWave ggwave; using TSample = int16_t; const size_t kSampleSize_bytes = sizeof(TSample); -const int sampleRate = 12000; -const int samplesPerFrame = 256; +const int sampleRate = 24000; +const int samplesPerFrame = 512; TSample sampleBuffer[samplesPerFrame]; @@ -37,6 +56,28 @@ void setup() { while (!Serial); Serial.println(F("GGWave test for ESP32")); + // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally + if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { + Serial.println(F("SSD1306 allocation failed")); + for(;;); // Don't proceed, loop forever + } + + // Show initial display buffer contents on the screen -- + // the library initializes this with an Adafruit splash screen. + display.display(); + delay(2000); // Pause for 2 seconds + + // Clear the buffer + display.clearDisplay(); + + display.setTextSize(2); // Normal 1:1 pixel scale + display.setTextColor(SSD1306_WHITE); // Draw white text + display.setCursor(0, 0); // Start at top-left corner + display.cp437(true); // Use full 256 char 'Code Page 437' font + display.println(F("GGWave!")); + + display.display(); + { Serial.println(F("Trying to create ggwave instance")); @@ -57,16 +98,16 @@ void setup() { //GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_DT_NORMAL, true); //GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_DT_FAST, true); //GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_DT_FASTEST, true); - GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_MT_NORMAL, true); - GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_MT_FAST, true); + //GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_MT_NORMAL, true); + //GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_MT_FAST, true); GGWave::Protocols::tx().toggle(GGWAVE_PROTOCOL_MT_FASTEST, true); GGWave::Protocols::rx().disableAll(); //GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_DT_NORMAL, true); //GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_DT_FAST, true); - //GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_DT_FASTEST, true); - GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_NORMAL, true); - GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_FAST, true); + GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_DT_FASTEST, true); + //GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_NORMAL, true); + //GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_FAST, true); GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_FASTEST, true); ggwave.prepare(p); @@ -122,6 +163,10 @@ void loop() { s1 = s0 ^ s1; s0 = s0 ^ s1; } + + //for (int i = 0; i < samples_read; i++) { + // Serial.println(sampleBuffer[i]); + //} } auto tStart = millis(); @@ -148,9 +193,15 @@ void loop() { Serial.println(F(" bytes:")); Serial.println((char *) result.data()); - } - //for (int i = 0; i < samples_read; i++) { - // Serial.println(samples[i]); - //} + display.clearDisplay(); + + display.setTextSize(2); // Normal 1:1 pixel scale + display.setTextColor(SSD1306_WHITE); // Draw white text + display.setCursor(0, 0); // Start at top-left corner + display.cp437(true); // Use full 256 char 'Code Page 437' font + display.println((char *) result.data()); + + display.display(); + } }