diff --git a/.vscode/settings.json b/.vscode/settings.json index 455d58ffb..4a61ccd24 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -50,7 +50,8 @@ "cassert": "cpp", "iterator": "cpp", "shared_mutex": "cpp", - "iostream": "cpp" + "iostream": "cpp", + "esp_nimble_hci.h": "c" }, "cSpell.words": [ "Blox", diff --git a/bin/build-all.sh b/bin/build-all.sh index 9e0fcee71..922fd4b7d 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -9,7 +9,7 @@ BOARDS_ESP32="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v2.0 helt #BOARDS_ESP32=tbeam # FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine -BOARDS_NRF52="rak4631 t-echo" +BOARDS_NRF52="rak4631_5005 rak4631_19003 t-echo" #BOARDS_NRF52="" OUTDIR=release/latest diff --git a/platformio.ini b/platformio.ini index 7a908ffd9..8d4f3a883 100644 --- a/platformio.ini +++ b/platformio.ini @@ -113,9 +113,13 @@ lib_deps = adafruit/Adafruit Unified Sensor@^1.1.4 paulstoffregen/OneWire@^2.3.5 robtillaart/DS18B20@^0.1.11 + h2zero/NimBLE-Arduino@1.3.1 # Hmm - this doesn't work yet # board_build.ldscript = linker/esp32.extram.bss.ld -lib_ignore = segger_rtt +lib_ignore = + segger_rtt + ESP32 BLE Arduino + platform_packages = framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#4cde0f5d412d2695184f32e8a47e9bea57b45276 @@ -325,12 +329,21 @@ monitor_speed = 115200 # board_build.ldscript = linker/nrf52840_s140_sim832.ld ; The very slick RAK wireless RAK 4631 / 4630 board -[env:rak4631] +[env:rak4631_5005] extends = nrf52840_base board = wiscore_rak4631 # add our variants files to the include and src paths # define build flags for the TFT_eSPI library -build_flags = ${nrf52840_base.build_flags} -Ivariants/WisCore_RAK4631_Board +build_flags = ${nrf52840_base.build_flags} -Ivariants/WisCore_RAK4631_Board -D RAK_BASE_5005 +src_filter = ${nrf52_base.src_filter} +<../variants/WisCore_RAK4631_Board> +debug_tool = jlink + +[env:rak4631_19003] +extends = nrf52840_base +board = wiscore_rak4631 +# add our variants files to the include and src paths +# define build flags for the TFT_eSPI library +build_flags = ${nrf52840_base.build_flags} -Ivariants/WisCore_RAK4631_Board -D RAK_BASE_19003 src_filter = ${nrf52_base.src_filter} +<../variants/WisCore_RAK4631_Board> debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) diff --git a/proto b/proto index 10e6857b1..c52c8ef99 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 10e6857b1bd4a03ec16ec5cbaadf4f28293ab9a5 +Subproject commit c52c8ef99ead88a5edb73891b33247c54d37cb28 diff --git a/src/configuration.h b/src/configuration.h index 0d32e36fd..597f60094 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -243,6 +243,7 @@ along with this program. If not, see . //#define GPS_TX_PIN 12 // not connected #define BUTTON_PIN 39 // The middle button GPIO on the T-Beam +#define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Plugin (#975). #define LORA_DIO0 26 // a No connect on the SX1262/SX1268 module #define LORA_RESET 23 // RST for SX1276, and for SX1262/SX1268 @@ -330,8 +331,6 @@ along with this program. If not, see . #define GPS_RX_PIN 36 #define GPS_TX_PIN 37 -#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage - #define I2C_SDA 4 // I2C pins for this board #define I2C_SCL 15 diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 83880d9a5..702708c82 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -36,9 +36,11 @@ along with this program. If not, see . #include "target_specific.h" #include "utils.h" #include "gps/GeoCoord.h" +#include "sleep.h" #ifndef NO_ESP32 #include "mesh/http/WiFiAPClient.h" +#include "esp_task_wdt.h" #endif using namespace meshtastic; /** @todo remove */ @@ -154,8 +156,17 @@ static void drawSSLScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16 display->setFont(FONT_SMALL); display->drawString(64 + x, y, "Creating SSL certificate"); +#ifndef NO_ESP32 + yield(); + esp_task_wdt_reset(); +#endif + display->setFont(FONT_SMALL); - display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait..."); + if ((millis() / 1000) % 2) { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . ."); + } else { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . "); + } } #ifdef HAS_EINK @@ -215,7 +226,11 @@ static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, i display->drawString(64 + x, y, "Updating"); display->setFont(FONT_SMALL); - display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait..."); + if ((millis() / 1000) % 2) { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . ."); + } else { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . "); + } // display->setFont(FONT_LARGE); // display->drawString(64 + x, 26 + y, btPIN); @@ -413,7 +428,10 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const auto gpsFormat = radioConfig.preferences.gps_format; String displayLine = ""; - if (!gps->getIsConnected() && !radioConfig.preferences.fixed_position) { + if (radioConfig.preferences.fixed_position) { + displayLine = "Fixed GPS"; + display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine); + } else if (!gps->getIsConnected() && !radioConfig.preferences.fixed_position) { displayLine = "No GPS Module"; display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine); } else if (!gps->getHasLock() && !radioConfig.preferences.fixed_position) { @@ -688,6 +706,7 @@ void _screen_header() Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), ui(&dispdev) { + address_found = address; cmdQueue.setReader(this); } @@ -875,6 +894,11 @@ int32_t Screen::runOnce() // oldFrameState = ui.getUiState()->frameState; DEBUG_MSG("Setting idle framerate\n"); targetFramerate = IDLE_FRAMERATE; + +#ifndef NO_ESP32 + setCPUFast(false); // Turn up the CPU to improve screen animations +#endif + ui.setTargetFPS(targetFramerate); forceDisplay(); } @@ -920,10 +944,12 @@ void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiStat * it is expected that this will be used during the boot phase */ void Screen::setSSLFrames() { - DEBUG_MSG("showing SSL frames\n"); - static FrameCallback sslFrames[] = {drawSSLScreen}; - ui.setFrames(sslFrames, 1); - ui.update(); + if (address_found) { + // DEBUG_MSG("showing SSL frames\n"); + static FrameCallback sslFrames[] = {drawSSLScreen}; + ui.setFrames(sslFrames, 1); + ui.update(); + } } // restore our regular frame list @@ -1074,6 +1100,11 @@ void Screen::setFastFramerate() // We are about to start a transition so speed up fps targetFramerate = SCREEN_TRANSITION_FRAMERATE; + +#ifndef NO_ESP32 + setCPUFast(true); // Turn up the CPU to improve screen animations +#endif + ui.setTargetFPS(targetFramerate); setInterval(0); // redraw ASAP runASAP = true; @@ -1299,7 +1330,24 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat display->drawString(x, y, String("USB")); } - auto mode = "Mode " + String(channels.getPrimary().modem_config); + auto mode = ""; + + if (channels.getPrimary().modem_config == 0) { + mode = "ShrtSlow"; + } else if (channels.getPrimary().modem_config == 1) { + mode = "ShrtFast"; + } else if (channels.getPrimary().modem_config == 2) { + mode = "LngFast"; + } else if (channels.getPrimary().modem_config == 3) { + mode = "LngSlow"; + } else if (channels.getPrimary().modem_config == 4) { + mode = "MedSlow"; + } else if (channels.getPrimary().modem_config == 5) { + mode = "MedFast"; + } else { + mode = "Custom"; + } + display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode), y, mode); // Line 2 diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index e4b9044c7..9334fe43c 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -97,6 +97,8 @@ class Screen : public concurrency::OSThread Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; + uint8_t address_found; + /// Initializes the UI, turns on the display, starts showing boot screen. // // Not thread safe - must be called before any other methods are called. diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 6f1d26f6a..4ba4c14d1 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -245,6 +245,10 @@ void NodeDB::init() preferences.end(); DEBUG_MSG("Number of Device Reboots: %d\n", myNodeInfo.reboot_count); + /* The ESP32 has a wifi radio. This will need to be modified at some point so + * the test isn't so simplistic. + */ + myNodeInfo.has_wifi = true; #endif resetRadioConfig(); // If bogus settings got saved, then fix them @@ -429,7 +433,7 @@ uint32_t sinceLastSeen(const NodeInfo *n) return delta; } -#define NUM_ONLINE_SECS (60 * 2) // 2 hrs to consider someone offline +#define NUM_ONLINE_SECS (60 & 60 * 2) // 2 hrs to consider someone offline size_t NodeDB::getNumOnlineNodes() { diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index dd2fd9b2a..96aca5026 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -16,8 +16,13 @@ ErrorCode ReliableRouter::send(MeshPacket *p) // If someone asks for acks on broadcast, we need the hop limit to be at least one, so that first node that receives our // message will rebroadcast. But asking for hop_limit 0 in that context means the client app has no preference on hop counts // and we want this message to get through the whole mesh, so use the default. - if (p->to == NODENUM_BROADCAST && p->hop_limit == 0) - p->hop_limit = HOP_RELIABLE; + if (p->to == NODENUM_BROADCAST && p->hop_limit == 0) { + if (radioConfig.preferences.hop_limit && radioConfig.preferences.hop_limit <= HOP_MAX) { + p->hop_limit = (radioConfig.preferences.hop_limit >= HOP_MAX) ? HOP_MAX : radioConfig.preferences.hop_limit; + } else { + p->hop_limit = HOP_RELIABLE; + } + } auto copy = packetPool.allocCopy(*p); startRetransmission(copy); diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 053f36295..5c62b87ab 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -115,7 +115,11 @@ MeshPacket *Router::allocForSending() p->which_payloadVariant = MeshPacket_decoded_tag; // Assume payload is decoded at start. p->from = nodeDB.getNodeNum(); p->to = NODENUM_BROADCAST; - p->hop_limit = HOP_RELIABLE; + if (radioConfig.preferences.hop_limit && radioConfig.preferences.hop_limit <= HOP_MAX) { + p->hop_limit = (radioConfig.preferences.hop_limit >= HOP_MAX) ? HOP_MAX : radioConfig.preferences.hop_limit; + } else { + p->hop_limit = HOP_RELIABLE; + } p->id = generatePacketId(); p->rx_time = getValidTime(RTCQualityFromNet); // Just in case we process the packet locally - make sure it has a valid timestamp diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index 670978a0a..08c647aea 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -86,7 +86,7 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 454 +#define AdminMessage_size 461 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index ae13b867c..8fb70d39b 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -152,6 +152,7 @@ typedef struct _RadioConfig_UserPreferences { bool is_always_powered; uint32_t auto_screen_carousel_secs; uint32_t on_battery_shutdown_after_secs; + uint32_t hop_limit; } RadioConfig_UserPreferences; typedef struct _RadioConfig { @@ -196,9 +197,9 @@ extern "C" { /* Initializer values for message structs */ #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 @@ -266,6 +267,7 @@ extern "C" { #define RadioConfig_UserPreferences_is_always_powered_tag 151 #define RadioConfig_UserPreferences_auto_screen_carousel_secs_tag 152 #define RadioConfig_UserPreferences_on_battery_shutdown_after_secs_tag 153 +#define RadioConfig_UserPreferences_hop_limit_tag 154 #define RadioConfig_preferences_tag 1 /* Struct field encoding specification for nanopb */ @@ -340,7 +342,8 @@ X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_heartbeat, 149) \ X(a, STATIC, SINGULAR, UINT32, position_flags, 150) \ X(a, STATIC, SINGULAR, BOOL, is_always_powered, 151) \ X(a, STATIC, SINGULAR, UINT32, auto_screen_carousel_secs, 152) \ -X(a, STATIC, SINGULAR, UINT32, on_battery_shutdown_after_secs, 153) +X(a, STATIC, SINGULAR, UINT32, on_battery_shutdown_after_secs, 153) \ +X(a, STATIC, SINGULAR, UINT32, hop_limit, 154) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -352,8 +355,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg; #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg /* Maximum encoded size of messages (where known) */ -#define RadioConfig_size 451 -#define RadioConfig_UserPreferences_size 448 +#define RadioConfig_size 458 +#define RadioConfig_UserPreferences_size 455 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index f9e2e99dc..d073c16a0 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -5,6 +5,9 @@ #include #include #include +#include "sleep.h" +#include "graphics/Screen.h" + #include #include @@ -78,13 +81,15 @@ static void taskCreateCert(void *parameter) { prefs.begin("MeshtasticHTTPS", false); + +#if 0 // Delete the saved certs (used in debugging) - if (0) { - DEBUG_MSG("Deleting any saved SSL keys ...\n"); - // prefs.clear(); - prefs.remove("PK"); - prefs.remove("cert"); - } + DEBUG_MSG("Deleting any saved SSL keys ...\n"); + // prefs.clear(); + prefs.remove("PK"); + prefs.remove("cert"); +#endif + DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n"); @@ -103,16 +108,12 @@ static void taskCreateCert(void *parameter) cert = new SSLCert(certBuffer, certLen, pkBuffer, pkLen); DEBUG_MSG("Retrieved Private Key: %d Bytes\n", cert->getPKLength()); - // DEBUG_MSG("Retrieved Private Key: " + String(cert->getPKLength()) + " Bytes"); - // for (int i = 0; i < cert->getPKLength(); i++) - // Serial.print(cert->getPKData()[i], HEX); - // Serial.println(); - DEBUG_MSG("Retrieved Certificate: %d Bytes\n", cert->getCertLength()); - // for (int i = 0; i < cert->getCertLength(); i++) - // Serial.print(cert->getCertData()[i], HEX); - // Serial.println(); + } else { + + setCPUFast(true); + DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n"); yield(); cert = new SSLCert(); @@ -144,6 +145,9 @@ static void taskCreateCert(void *parameter) prefs.putBytes("PK", (uint8_t *)cert->getPKData(), cert->getPKLength()); prefs.putBytes("cert", (uint8_t *)cert->getCertData(), cert->getCertLength()); } + + setCPUFast(false); + } isCertReady = true; @@ -154,6 +158,7 @@ static void taskCreateCert(void *parameter) void createSSLCert() { + bool runLoop = false; if (isWifiAvailable() && !isCertReady) { // Create a new process just to handle creating the cert. @@ -161,21 +166,28 @@ void createSSLCert() // jm@casler.org (Oct 2020) xTaskCreate(taskCreateCert, /* Task function. */ "createCert", /* String with name of task. */ - 16384, /* Stack size in bytes. */ + //16384, /* Stack size in bytes. */ + 8192, /* Stack size in bytes. */ NULL, /* Parameter passed as input of the task */ 16, /* Priority of the task. */ NULL); /* Task handle. */ DEBUG_MSG("Waiting for SSL Cert to be generated.\n"); - int seconds = 0; while (!isCertReady) { - DEBUG_MSG("."); - delay(1000); - yield(); - esp_task_wdt_reset(); - seconds++; - if ((seconds == 3) && screen) { - screen->setSSLFrames(); + if ((millis() / 500) % 2) { + if (runLoop) { + DEBUG_MSG("."); + + yield(); + esp_task_wdt_reset(); + + if (millis() / 1000 >= 3) { + screen->setSSLFrames(); + } + } + runLoop = false; + } else { + runLoop = true; } } DEBUG_MSG("SSL Cert Ready!\n"); @@ -199,40 +211,6 @@ void initWebServer() { DEBUG_MSG("Initializing Web Server ...\n"); -#if 0 -// this seems to be a copypaste dup of taskCreateCert - prefs.begin("MeshtasticHTTPS", false); - - size_t pkLen = prefs.getBytesLength("PK"); - size_t certLen = prefs.getBytesLength("cert"); - - DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n"); - - if (pkLen && certLen) { - - uint8_t *pkBuffer = new uint8_t[pkLen]; - prefs.getBytes("PK", pkBuffer, pkLen); - - uint8_t *certBuffer = new uint8_t[certLen]; - prefs.getBytes("cert", certBuffer, certLen); - - cert = new SSLCert(certBuffer, certLen, pkBuffer, pkLen); - - DEBUG_MSG("Retrieved Private Key: %d Bytes\n", cert->getPKLength()); - // DEBUG_MSG("Retrieved Private Key: " + String(cert->getPKLength()) + " Bytes"); - // for (int i = 0; i < cert->getPKLength(); i++) - // Serial.print(cert->getPKData()[i], HEX); - // Serial.println(); - - DEBUG_MSG("Retrieved Certificate: %d Bytes\n", cert->getCertLength()); - // for (int i = 0; i < cert->getCertLength(); i++) - // Serial.print(cert->getCertData()[i], HEX); - // Serial.println(); - } else { - DEBUG_MSG("Web Server started without SSL keys! How did this happen?\n"); - } -#endif - // We can now use the new certificate to setup our server as usual. secureServer = new HTTPSServer(cert); insecureServer = new HTTPServer(); diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 2c69b0bcc..eae2a6db7 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -11,7 +11,6 @@ #include "services/gap/ble_svc_gap.h" #include "services/gatt/ble_svc_gatt.h" #include "sleep.h" -#include #include #ifndef NO_ESP32 diff --git a/src/nimble/BluetoothUtil.h b/src/nimble/BluetoothUtil.h index fe6d0e678..4e423769e 100644 --- a/src/nimble/BluetoothUtil.h +++ b/src/nimble/BluetoothUtil.h @@ -1,6 +1,5 @@ #pragma once -#include #include /// We only allow one BLE connection at a time diff --git a/src/nimble/NimbleBluetoothAPI.cpp b/src/nimble/NimbleBluetoothAPI.cpp index da2f80ea1..6b44e44d0 100644 --- a/src/nimble/NimbleBluetoothAPI.cpp +++ b/src/nimble/NimbleBluetoothAPI.cpp @@ -3,7 +3,6 @@ #include "configuration.h" #include "nimble/BluetoothUtil.h" #include "nimble/NimbleDefs.h" -#include // This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in // proccess at once diff --git a/src/nimble/NimbleDefs.h b/src/nimble/NimbleDefs.h index 6b1db22e5..7a2b0b46a 100644 --- a/src/nimble/NimbleDefs.h +++ b/src/nimble/NimbleDefs.h @@ -11,7 +11,6 @@ #include "host/ble_uuid.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" -#include #ifdef __cplusplus extern "C" { diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index e0503930c..e10f05d1e 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -148,14 +148,22 @@ int32_t PositionPlugin::runOnce() NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) { + // The minimum distance to travel before we are able to send a new position packet. + const uint32_t distanceTravelMinimum = 30; + + // The minimum time that would pass before we are able to send a new position packet. + const uint32_t timeTravelMinimum = 30; + + // Determine the distance in meters between two points on the globe float distance = GeoCoord::latLongToMeter(lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); - // 2500 is a magic number. 50 is the minumum distance we want to travel before sending another position packet. - uint32_t distanceTravel = ((2500 / myNodeInfo.bitrate) >= 50) ? (2500 / myNodeInfo.bitrate) : 50; + // Yes, this has a bunch of magic numbers. Sorry. This is to make the scale non-linear. + const float distanceTravelMath = 1203 / (sqrt( pow(myNodeInfo.bitrate, 1.5) / 1.1 ) ) ; + uint32_t distanceTravel = (distanceTravelMath >= distanceTravelMinimum) ? distanceTravelMath : distanceTravelMinimum; - // 1500 is a magic number. 30 is the minumum interval between position packets - uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= 30) ? (1500 / myNodeInfo.bitrate) : 30; + // Yes, this has a bunch of magic numbers. Sorry. + uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= timeTravelMinimum) ? (1500 / myNodeInfo.bitrate) : timeTravelMinimum; // If the distance traveled since the last update is greater than 100 meters // and it's been at least 60 seconds since the last update diff --git a/variants/WisCore_RAK4631_Board/variant.h b/variants/WisCore_RAK4631_Board/variant.h index bea410c3c..3058068c8 100644 --- a/variants/WisCore_RAK4631_Board/variant.h +++ b/variants/WisCore_RAK4631_Board/variant.h @@ -58,11 +58,16 @@ extern "C" { /* * Buttons */ -#define PIN_BUTTON1 11 + +#ifdef RAK_BASE_5005 +#define PIN_BUTTON1 9 // Pin for button on E-ink button module or IO expansion +#define BUTTON_NEED_PULLUP +#endif #define PIN_BUTTON2 12 #define PIN_BUTTON3 24 #define PIN_BUTTON4 25 + /* * Analog pins */ @@ -147,7 +152,7 @@ static const uint8_t SCK = PIN_SPI_SCK; SW1 <-> P0.01 (Arduino GPIO number 1) A0 <-> P0.04/AIN2 (Arduino Analog A2 A1 <-> P0.31/AIN7 (Arduino Analog A7 - SPI_CS <-> P0.26 (Arduino GPIO number 26) + SPI_CS <-> P0.26 (Arduino GPIO number 26) */ // RAK4630 LoRa module @@ -169,8 +174,11 @@ static const uint8_t SCK = PIN_SPI_SCK; // #define PIN_GPS_RESET (34) #define PIN_GPS_EN (34) #define PIN_GPS_PPS (17) // Pulse per second input from the GPS + +#ifdef RAK_BASE_5005 #define GPS_RX_PIN PIN_SERIAL1_RX #define GPS_TX_PIN PIN_SERIAL1_TX +#endif // Battery // The battery sense is hooked to pin A0 (5) diff --git a/version.properties b/version.properties index 5eae0b8b4..13eff275e 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 1 minor = 2 -build = 48 +build = 49