From 847963c2ab346e69b63512a478850497f5d05080 Mon Sep 17 00:00:00 2001 From: acidvegas Date: Wed, 5 Jun 2024 23:23:18 -0400 Subject: [PATCH] update.... 2 hie 4 commit message --- src/Speaker.h | 8 +++++--- src/apps/{LoRa.cpp => lora.cpp} | 34 +++++++++++++++++++++++++++++---- src/main.ino | 14 +++++++++----- 3 files changed, 44 insertions(+), 12 deletions(-) rename src/apps/{LoRa.cpp => lora.cpp} (71%) diff --git a/src/Speaker.h b/src/Speaker.h index afe4f79..e0d8c3b 100644 --- a/src/Speaker.h +++ b/src/Speaker.h @@ -77,9 +77,11 @@ void playRTTTL(const char* rtttl) { void playNotificationSound() { - playTone(1000, 200); + playTone(1000, 150); delay(100); - playTone(1500, 200); + playTone(1500, 150); delay(100); - playTone(2000, 200); + playTone(2000, 150); + delay(100); + playTone(500, 150); } diff --git a/src/apps/LoRa.cpp b/src/apps/lora.cpp similarity index 71% rename from src/apps/LoRa.cpp rename to src/apps/lora.cpp index 0349a34..f0ffa13 100644 --- a/src/apps/LoRa.cpp +++ b/src/apps/lora.cpp @@ -6,13 +6,11 @@ SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUS bool setupRadio() { - digitalWrite(BOARD_SDCARD_CS, HIGH); + pinMode(RADIO_CS_PIN, OUTPUT); digitalWrite(RADIO_CS_PIN, HIGH); - digitalWrite(BOARD_TFT_CS, HIGH); - SPI.end(); - SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD int state = radio.begin(RADIO_FREQ); + if (state == RADIOLIB_ERR_NONE) { Serial.println("Start Radio success!"); } else { @@ -73,4 +71,32 @@ bool setupRadio() { //radio.setDio1Action(setFlag); return true; +} + +bool transmit() { + int state = radio.transmit("Hello World!"); + + // you can also transmit byte array up to 256 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; + int state = radio.transmit(byteArr, 8); + */ + + if (state == RADIOLIB_ERR_NONE) { + Serial.println(F("Radio tramsmittion successful!")); + Serial.print(F("[SX1262] Datarate:\t")); + Serial.print(radio.getDataRate()); + Serial.println(F(" bps")); + return true; + } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) { + Serial.println(F("Radio packet too long")); // 256 bytes is the maximum packet length + return false; + } else if (state == RADIOLIB_ERR_TX_TIMEOUT) { + Serial.println(F("Radio timeout")); + return false; + } else { + Serial.print(F("Radio error failed, code ")); + Serial.println(state); + return false; + } } \ No newline at end of file diff --git a/src/main.ino b/src/main.ino index 3e90668..798911e 100644 --- a/src/main.ino +++ b/src/main.ino @@ -125,22 +125,26 @@ void wgConnect(const IPAddress& localIp, const char* privateKey, const char* end void setup() { // Initialize serial communication Serial.begin(115200); + + // Wait for the serial monitor to open + //while (!Serial); + Serial.println("Booting device..."); - // Turn on the power to the board + // Give power to the board peripherals pinMode(BOARD_POWERON, OUTPUT); digitalWrite(BOARD_POWERON, HIGH); - // Turn on power to the screen + // Give power to the screen pinMode(TFT_BL, OUTPUT); digitalWrite(TFT_BL, HIGH); - setBrightness(8); // Set the screen brightness to 50% + setBrightness(8); // Set the screen brightness to 50%) // Give power to the SD card pinMode(BOARD_SDCARD_CS, OUTPUT); digitalWrite(BOARD_SDCARD_CS, HIGH); pinMode(BOARD_SPI_MISO, INPUT_PULLUP); - SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD + SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); // Turn on power to the radio pinMode(RADIO_CS_PIN, OUTPUT); @@ -163,7 +167,7 @@ void setup() { // Initialize the speaker setupI2S(); // Do we want to keep this open or uninstall after each use to keep resources free? - const char* rtttl_boot = "TakeOnMe:d=4,o=4,b=450:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5"; + const char* rtttl_boot = "TakeOnMe:d=4,o=4,b=500:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5"; playRTTTL(rtttl_boot); // Setup the WiFi