acid-drop

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README | LICENSE

commit 847963c2ab346e69b63512a478850497f5d05080
parent e697bf679052e8edb8332185a3afc9d2ae5f957f
Author: acidvegas <acid.vegas@acid.vegas>
Date: Wed, 5 Jun 2024 23:23:18 -0400

update.... 2 hie 4 commit message

Diffstat:
Msrc/Speaker.h | 8+++++---
Dsrc/apps/LoRa.cpp | 77-----------------------------------------------------------------------------
Asrc/apps/lora.cpp | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/main.ino | 14+++++++++-----

4 files changed, 117 insertions(+), 85 deletions(-)

diff --git 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
@@ -1,76 +0,0 @@
-#include <RadioLib.h>
-#include "pins.h"
-
-
-SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
-
-
-bool setupRadio() {
-    digitalWrite(BOARD_SDCARD_CS, HIGH);
-    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 {
-        Serial.print("Start Radio failed,code:");
-        Serial.println(state);
-        return false;
-    }
-
-    if (radio.setFrequency(RADIO_FREQ) == RADIOLIB_ERR_INVALID_FREQUENCY) {
-        Serial.println(F("Selected frequency is invalid for this module!"));
-        return false;
-    }
-
-    if (radio.setBandwidth(125.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
-        Serial.println(F("Selected bandwidth is invalid for this module!"));
-        return false;
-    }
-
-    if (radio.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
-        Serial.println(F("Selected spreading factor is invalid for this module!"));
-        return false;
-    }
-
-    if (radio.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
-        Serial.println(F("Selected coding rate is invalid for this module!"));
-        return false;
-    }
-
-    if (radio.setSyncWord(0xAB) != RADIOLIB_ERR_NONE) {
-        Serial.println(F("Unable to set sync word!"));
-        return false;
-    }
-
-    // set output power to 10 dBm (accepted range is -17 - 22 dBm)
-    if (radio.setOutputPower(17) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
-        Serial.println(F("Selected output power is invalid for this module!"));
-        return false;
-    }
-
-    // set over current protection limit to 140 mA (accepted range is 45 - 140 mA) (set value to 0 to disable overcurrent protection)
-    if (radio.setCurrentLimit(140) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) {
-        Serial.println(F("Selected current limit is invalid for this module!"));
-        return false;
-    }
-
-    // set LoRa preamble length to 15 symbols (accepted range is 0 - 65535)
-    if (radio.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
-        Serial.println(F("Selected preamble length is invalid for this module!"));
-        return false;
-    }
-
-    if (radio.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
-        Serial.println(F("Selected CRC is invalid for this module!"));
-        return false;
-    }
-
-    // set the function that will be called when new packet is received
-    //radio.setDio1Action(setFlag);
-
-    return true;
-}
-\ No newline at end of file
diff --git a/src/apps/lora.cpp b/src/apps/lora.cpp
@@ -0,0 +1,102 @@
+#include <RadioLib.h>
+#include "pins.h"
+
+
+SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
+
+
+bool setupRadio() {
+    pinMode(RADIO_CS_PIN, OUTPUT);
+    digitalWrite(RADIO_CS_PIN, HIGH);
+
+    int state = radio.begin(RADIO_FREQ);
+    
+    if (state == RADIOLIB_ERR_NONE) {
+        Serial.println("Start Radio success!");
+    } else {
+        Serial.print("Start Radio failed,code:");
+        Serial.println(state);
+        return false;
+    }
+
+    if (radio.setFrequency(RADIO_FREQ) == RADIOLIB_ERR_INVALID_FREQUENCY) {
+        Serial.println(F("Selected frequency is invalid for this module!"));
+        return false;
+    }
+
+    if (radio.setBandwidth(125.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
+        Serial.println(F("Selected bandwidth is invalid for this module!"));
+        return false;
+    }
+
+    if (radio.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
+        Serial.println(F("Selected spreading factor is invalid for this module!"));
+        return false;
+    }
+
+    if (radio.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
+        Serial.println(F("Selected coding rate is invalid for this module!"));
+        return false;
+    }
+
+    if (radio.setSyncWord(0xAB) != RADIOLIB_ERR_NONE) {
+        Serial.println(F("Unable to set sync word!"));
+        return false;
+    }
+
+    // set output power to 10 dBm (accepted range is -17 - 22 dBm)
+    if (radio.setOutputPower(17) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
+        Serial.println(F("Selected output power is invalid for this module!"));
+        return false;
+    }
+
+    // set over current protection limit to 140 mA (accepted range is 45 - 140 mA) (set value to 0 to disable overcurrent protection)
+    if (radio.setCurrentLimit(140) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) {
+        Serial.println(F("Selected current limit is invalid for this module!"));
+        return false;
+    }
+
+    // set LoRa preamble length to 15 symbols (accepted range is 0 - 65535)
+    if (radio.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
+        Serial.println(F("Selected preamble length is invalid for this module!"));
+        return false;
+    }
+
+    if (radio.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
+        Serial.println(F("Selected CRC is invalid for this module!"));
+        return false;
+    }
+
+    // set the function that will be called when new packet is received
+    //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
@@ -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