diff --git a/.vscode/settings.json b/.vscode/settings.json
index c2bc7b28c..21bf462ee 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -51,7 +51,8 @@
"iterator": "cpp",
"shared_mutex": "cpp",
"iostream": "cpp",
- "esp_nimble_hci.h": "c"
+ "esp_nimble_hci.h": "c",
+ "map": "cpp"
},
"cSpell.words": [
"Blox",
diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py
index 4672dbc96..234b6ef05 100644
--- a/bin/platformio-custom.py
+++ b/bin/platformio-custom.py
@@ -17,7 +17,7 @@ Import("projenv")
prefsLoc = projenv["PROJECT_DIR"] + "/version.properties"
verObj = readProps(prefsLoc)
-print("Using meshtastic platform-custom.py, firmare version " + verObj['long'])
+print("Using meshtastic platformio-custom.py, firmare version " + verObj['long'])
# print("path is" + ','.join(sys.path))
# General options that are passed to the C and C++ compilers
diff --git a/platformio.ini b/platformio.ini
index 1ff5e92ce..6628cdb99 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -20,6 +20,7 @@ default_envs = tbeam
;default_envs = pca10059_diy_eink
;default_envs = meshtastic-diy-v1
;default_envs = meshtastic-diy-v1.1
+;default_envs = m5stack-coreink
extra_configs = variants/*/platformio.ini
@@ -83,7 +84,8 @@ lib_deps =
adafruit/Adafruit BME280 Library@^2.2.2
adafruit/Adafruit BME680 Library@^2.0.1
adafruit/Adafruit MCP9808 Library@^2.0.0
-
+ adafruit/Adafruit INA260 Library@^1.5.0
+ adafruit/Adafruit INA219@^1.2.0
; Common settings for ESP targes, mixin with extends = esp32_base
[esp32_base]
extends = arduino_base
diff --git a/protobufs b/protobufs
index 695b24211..e5b5adc19 160000
--- a/protobufs
+++ b/protobufs
@@ -1 +1 @@
-Subproject commit 695b2421130a6efd9ad7cdecfe2d4420404f0f97
+Subproject commit e5b5adc196d3593ab15c04101093443ab8b36c9c
diff --git a/src/Power.cpp b/src/Power.cpp
index feb7930ad..6d95e2e09 100644
--- a/src/Power.cpp
+++ b/src/Power.cpp
@@ -5,6 +5,7 @@
#include "main.h"
#include "sleep.h"
#include "utils.h"
+#include "buzz/buzz.h"
#ifdef TBEAM_V10
// FIXME. nasty hack cleanup how we load axp192
@@ -211,8 +212,12 @@ void Power::shutdown()
{
#ifdef TBEAM_V10
DEBUG_MSG("Shutting down\n");
+ axp.setChgLEDMode(AXP20X_LED_OFF);
axp.shutdown();
#elif NRF52_SERIES
+ playBeep();
+ ledOff(PIN_LED1);
+ ledOff(PIN_LED2);
doDeepSleep(DELAY_FOREVER);
#endif
}
diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp
index 1bfc58694..82f73147c 100644
--- a/src/PowerFSM.cpp
+++ b/src/PowerFSM.cpp
@@ -335,7 +335,7 @@ void PowerFSM_setup()
powerFSM.add_timed_transition(&stateON, &stateDARK,
config.display.screen_on_secs ? config.display.screen_on_secs
- : 60 * 1000,
+ : 60 * 1000 * 10,
NULL, "Screen-on timeout");
// On most boards we use light-sleep to be our main state, but on NRF52 we just stay in DARK
@@ -348,9 +348,6 @@ void PowerFSM_setup()
// See: https://github.com/meshtastic/Meshtastic-device/issues/1071
if (isRouter || config.power.is_power_saving) {
-
- // I don't think this transition is correct, turning off for now - @geeksville
- // powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout");
powerFSM.add_timed_transition(&stateNB, &stateLS,
config.power.min_wake_secs ? config.power.min_wake_secs
: default_min_wake_secs * 1000,
diff --git a/src/SerialConsole.cpp b/src/SerialConsole.cpp
index 76926bb4e..49e7e017a 100644
--- a/src/SerialConsole.cpp
+++ b/src/SerialConsole.cpp
@@ -4,6 +4,8 @@
#include "configuration.h"
#define Port Serial
+// Defaulting to the formerly removed phone_timeout_secs value of 15 minutes
+#define SERIAL_CONNECTION_TIMEOUT (15 * 60) * 1000UL
SerialConsole *console;
@@ -41,13 +43,12 @@ SerialConsole::SerialConsole() : StreamAPI(&Port), RedirectablePrint(&Port)
emitRebooted();
}
+
// For the serial port we can't really detect if any client is on the other side, so instead just look for recent messages
bool SerialConsole::checkIsConnected()
{
uint32_t now = millis();
- return (now - lastContactMsec) < config.power.phone_timeout_secs
- ? config.power.phone_timeout_secs
- : default_phone_timeout_secs * 1000UL;
+ return (now - lastContactMsec) < SERIAL_CONNECTION_TIMEOUT;
}
/**
diff --git a/src/configuration.h b/src/configuration.h
index 1f4864f8a..f0d44a3e9 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -25,6 +25,7 @@ along with this program. If not, see .
#pragma once
#include
+
#ifdef RV3028_RTC
#include "Melopero_RV3028.h"
#endif
@@ -144,7 +145,7 @@ along with this program. If not, see .
//#define DISABLE_NTP
// Disable the welcome screen and allow
-//#define DISABLE_WELCOME_UNSET
+#define DISABLE_WELCOME_UNSET
// -----------------------------------------------------------------------------
// OLED & Input
@@ -170,6 +171,15 @@ along with this program. If not, see .
// The older M5 Faces I2C Keyboard
#define FACESKB_ADDR 0x88
+// -----------------------------------------------------------------------------
+// SENSOR
+// -----------------------------------------------------------------------------
+#define BME_ADDR 0x76
+#define BME_ADDR_ALTERNATE 0x77
+#define MCP9808_ADDR 0x18
+#define INA_ADDR 0x40
+#define INA_ADDR_ALTERNATE 0x41
+
// -----------------------------------------------------------------------------
// GPS
// -----------------------------------------------------------------------------
diff --git a/src/debug/i2cScan.h b/src/debug/i2cScan.h
index ba5636ea9..29d7cdc95 100644
--- a/src/debug/i2cScan.h
+++ b/src/debug/i2cScan.h
@@ -1,8 +1,27 @@
#include "../configuration.h"
#include "../main.h"
#include
+#include "mesh/generated/telemetry.pb.h"
#ifndef NO_WIRE
+uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) {
+ uint16_t value = 0x00;
+ Wire.beginTransmission(address);
+ Wire.write(reg);
+ Wire.endTransmission();
+ delay(20);
+ Wire.requestFrom(address, length);
+ DEBUG_MSG("Wire.available() = %d\n", Wire.available());
+ if (Wire.available() == 2) {
+ // Read MSB, then LSB
+ value = (uint16_t)Wire.read() << 8;
+ value |= Wire.read();
+ } else if (Wire.available()) {
+ value = Wire.read();
+ }
+ return value;
+}
+
uint8_t oled_probe(byte addr)
{
uint8_t r = 0;
@@ -34,7 +53,7 @@ uint8_t oled_probe(byte addr)
void scanI2Cdevice(void)
{
byte err, addr;
- uint8_t r = 0x00;
+ uint16_t registerValue = 0x00;
int nDevices = 0;
for (addr = 1; addr < 127; addr++) {
Wire.beginTransmission(addr);
@@ -74,15 +93,8 @@ void scanI2Cdevice(void)
if (addr == CARDKB_ADDR) {
cardkb_found = addr;
// Do we have the RAK14006 instead?
- Wire.beginTransmission(addr);
- Wire.write(0x04); // SENSOR_GET_VERSION
- Wire.endTransmission();
- delay(20);
- Wire.requestFrom((int)addr, 1);
- if (Wire.available()) {
- r = Wire.read();
- }
- if (r == 0x02) { // KEYPAD_VERSION
+ registerValue = getRegisterValue(addr, 0x04, 1);
+ if (registerValue == 0x02) { // KEYPAD_VERSION
DEBUG_MSG("RAK14004 found\n");
kb_model = 0x02;
} else {
@@ -104,6 +116,31 @@ void scanI2Cdevice(void)
DEBUG_MSG("axp192 PMU found\n");
}
#endif
+ if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) {
+ registerValue = getRegisterValue(addr, 0xD0, 1); // GET_ID
+ if (registerValue == 0x61) {
+ DEBUG_MSG("BME-680 sensor found at address 0x%x\n", (uint8_t)addr);
+ nodeTelemetrySensorsMap[TelemetrySensorType_BME680] = addr;
+ } else if (registerValue == 0x60) {
+ DEBUG_MSG("BME-280 sensor found at address 0x%x\n", (uint8_t)addr);
+ nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = addr;
+ }
+ }
+ if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) {
+ registerValue = getRegisterValue(addr, 0xFE, 2);
+ DEBUG_MSG("Register MFG_UID: 0x%x\n", registerValue);
+ if (registerValue == 0x5449) {
+ DEBUG_MSG("INA260 sensor found at address 0x%x\n", (uint8_t)addr);
+ nodeTelemetrySensorsMap[TelemetrySensorType_INA260] = addr;
+ } else { // Assume INA219 if INA260 ID is not found
+ DEBUG_MSG("INA219 sensor found at address 0x%x\n", (uint8_t)addr);
+ nodeTelemetrySensorsMap[TelemetrySensorType_INA219] = addr;
+ }
+ }
+ if (addr == MCP9808_ADDR) {
+ nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr;
+ DEBUG_MSG("MCP9808 sensor found at address 0x%x\n", (uint8_t)addr);
+ }
} else if (err == 4) {
DEBUG_MSG("Unknow error at address 0x%x\n", addr);
}
diff --git a/src/esp32/ESP32CryptoEngine.cpp b/src/esp32/ESP32CryptoEngine.cpp
index d7eaa46bf..e80d59661 100644
--- a/src/esp32/ESP32CryptoEngine.cpp
+++ b/src/esp32/ESP32CryptoEngine.cpp
@@ -49,12 +49,13 @@ class ESP32CryptoEngine : public CryptoEngine
*/
virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
{
+ hexDump("before", bytes, numBytes, 16);
if (key.length > 0) {
uint8_t stream_block[16];
static uint8_t scratch[MAX_BLOCKSIZE];
size_t nc_off = 0;
- // DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
+ DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
initNonce(fromNode, packetId);
assert(numBytes <= MAX_BLOCKSIZE);
memcpy(scratch, bytes, numBytes);
@@ -64,12 +65,11 @@ class ESP32CryptoEngine : public CryptoEngine
auto res = mbedtls_aes_crypt_ctr(&aes, numBytes, &nc_off, nonce, stream_block, scratch, bytes);
assert(!res);
}
+ hexDump("after", bytes, numBytes, 16);
}
virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
{
- // DEBUG_MSG("ESP32 decrypt!\n");
-
// For CTR, the implementation is the same
encrypt(fromNode, packetId, numBytes, bytes);
}
diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp
index 073b313cd..7c002d928 100644
--- a/src/graphics/EInkDisplay2.cpp
+++ b/src/graphics/EInkDisplay2.cpp
@@ -31,6 +31,11 @@
//4.2 inch 300x400 - GxEPD2_420_M01
#define TECHO_DISPLAY_MODEL GxEPD2_420_M01
+#elif defined(M5_COREINK)
+//M5Stack CoreInk
+//1.54 inch 200x200 - GxEPD2_154_M09
+#define TECHO_DISPLAY_MODEL GxEPD2_154_M09
+
#endif
GxEPD2_BW *adafruitDisplay;
@@ -58,6 +63,12 @@ EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl)
//GxEPD2_420_M01
setGeometry(GEOMETRY_RAWMODE, 300, 400);
+ #elif defined(M5_COREINK)
+
+ //M5Stack_CoreInk 200x200
+ //1.54 inch 200x200 - GxEPD2_154_M09
+ setGeometry(GEOMETRY_RAWMODE, EPD_HEIGHT, EPD_WIDTH);
+
#endif
// setGeometry(GEOMETRY_RAWMODE, 128, 64); // old resolution
// setGeometry(GEOMETRY_128_64); // We originally used this because I wasn't sure if rawmode worked - it does
@@ -108,7 +119,7 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit)
// 4.2 inch 300x400 - GxEPD2_420_M01
//adafruitDisplay->nextPage();
- #elif defined(PCA10059)
+ #elif defined(PCA10059) || defined(M5_COREINK)
adafruitDisplay->nextPage();
#endif
@@ -180,35 +191,10 @@ bool EInkDisplay::connect()
adafruitDisplay->init(115200, true, 10, false, SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
//RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
- //RAK14000 2.13 inch b/w 250x122 does not support partial updates
adafruitDisplay->setRotation(3);
//For 1.54, 2.9 and 4.2
//adafruitDisplay->setRotation(1);
-
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
- adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
+ //adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
} else {
(void)adafruitDisplay;
}
@@ -221,6 +207,13 @@ bool EInkDisplay::connect()
adafruitDisplay->setRotation(3);
adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
}
+#elif defined(M5_COREINK)
+ auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY);
+ adafruitDisplay = new GxEPD2_BW(*lowLevel);
+ delay(100);
+ adafruitDisplay->init(115200, true, 20, false, SPI, SPISettings(4000000, MSBFIRST, SPI_MODE0));
+ adafruitDisplay->setRotation(0);
+ adafruitDisplay->setPartialWindow(0, 0, EPD_WIDTH, EPD_HEIGHT);
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 6e1ff9151..c709f90e2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -90,6 +90,9 @@ uint32_t serialSinceMsec;
bool axp192_found;
+// Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan
+uint8_t nodeTelemetrySensorsMap[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
Router *router = NULL; // Users of router don't care what sort of subclass implements that API
const char *getDeviceName()
diff --git a/src/main.h b/src/main.h
index bb262a58b..cc17adb09 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1,9 +1,11 @@
#pragma once
+#include