t-beam supreme: fixes and consolidation

Made changes requested by Scott
Simplified gps init sequence and removed unnecessary code
Reverted SensorManager change
Updated PMU flow to enable header outputs
This commit is contained in:
cod3doomy 2025-05-25 21:23:31 -07:00
parent 64f30e82a4
commit 4b103ca0de
4 changed files with 44 additions and 105 deletions

View file

@ -13,7 +13,7 @@ public:
double node_lat, node_lon; // modify these, if you want to affect Advert location double node_lat, node_lon; // modify these, if you want to affect Advert location
double node_altitude; // altitude in meters double node_altitude; // altitude in meters
SensorManager() { node_lat = 0; node_lon = 0; node_altitude = 0;} SensorManager() { node_lat = 0; node_lon = 0; node_altitude = 0; }
virtual bool begin() { return false; } virtual bool begin() { return false; }
virtual bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { return false; } virtual bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { return false; }
virtual void loop() { } virtual void loop() { }

View file

@ -61,10 +61,10 @@ public:
void begin() { void begin() {
power_init();
ESP32Board::begin(); ESP32Board::begin();
power_init();
esp_reset_reason_t reason = esp_reset_reason(); esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) { if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status(); long wakeup_source = esp_sleep_get_ext1_wakeup_status();

View file

@ -143,9 +143,9 @@ bool TBeamS3SupremeBoard::power_init()
PMU.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG); PMU.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
// Set up PMU interrupts // Set up PMU interrupts
// MESH_DEBUG_PRINTLN("Setting up PMU interrupts"); MESH_DEBUG_PRINTLN("Setting up PMU interrupts");
// pinMode(PIN_PMU_IRQ, INPUT_PULLUP); pinMode(PIN_PMU_IRQ, INPUT_PULLUP);
// attachInterrupt(PIN_PMU_IRQ, setPMUIntFlag, FALLING); attachInterrupt(PIN_PMU_IRQ, setPMUIntFlag, FALLING);
// GPS // GPS
MESH_DEBUG_PRINTLN("Setting and enabling a-ldo4 for GPS"); MESH_DEBUG_PRINTLN("Setting and enabling a-ldo4 for GPS");
@ -188,22 +188,22 @@ bool TBeamS3SupremeBoard::power_init()
PMU.enableBLDO1(); PMU.enableBLDO1();
// Out to header pins // Out to header pins
// MESH_DEBUG_PRINTLN("Setting and enabling b-ldo2 for output to header"); MESH_DEBUG_PRINTLN("Setting and enabling b-ldo2 for output to header");
// PMU.setBLDO2Voltage(3300); PMU.setBLDO2Voltage(3300);
// PMU.enableBLDO2(); PMU.enableBLDO2();
// MESH_DEBUG_PRINTLN("Setting and enabling dcdc4 for output to header"); MESH_DEBUG_PRINTLN("Setting and enabling dcdc4 for output to header");
// PMU.setDC4Voltage(XPOWERS_AXP2101_DCDC4_VOL2_MAX); // 1.8V PMU.setDC4Voltage(XPOWERS_AXP2101_DCDC4_VOL2_MAX); // 1.8V
// PMU.enableDC4(); PMU.enableDC4();
// MESH_DEBUG_PRINTLN("Setting and enabling dcdc5 for output to header"); MESH_DEBUG_PRINTLN("Setting and enabling dcdc5 for output to header");
// PMU.setDC5Voltage(3300); PMU.setDC5Voltage(3300);
// PMU.enableDC5(); PMU.enableDC5();
// Unused power rails // Unused power rails
MESH_DEBUG_PRINTLN("Disabling unused supplies dcdc2, dldo1 and dldo2"); MESH_DEBUG_PRINTLN("Disabling unused supplies dcdc2, dcdc5, dldo1 and dldo2");
PMU.disableDC2(); PMU.disableDC2();
PMU.disableDC5(); //PMU.disableDC5();
PMU.disableDLDO1(); PMU.disableDLDO1();
PMU.disableDLDO2(); PMU.disableDLDO2();
@ -223,18 +223,18 @@ bool TBeamS3SupremeBoard::power_init()
PMU.enableVbusVoltageMeasure(); PMU.enableVbusVoltageMeasure();
// Reset and re-enable PMU interrupts // Reset and re-enable PMU interrupts
// MESH_DEBUG_PRINTLN("Re-enable interrupts"); MESH_DEBUG_PRINTLN("Re-enable interrupts");
// PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
// PMU.clearIrqStatus(); PMU.clearIrqStatus();
// PMU.enableIRQ( PMU.enableIRQ(
// XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | // Battery interrupts XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | // Battery interrupts
// XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | // VBUS interrupts XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | // VBUS interrupts
// XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | // Power Key interrupts XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | // Power Key interrupts
// XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ // Charging interrupts XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ // Charging interrupts
// ); );
#ifdef MESH_DEBUG #ifdef MESH_DEBUG
// scanDevices(&Wire); scanDevices(&Wire);
// scanDevices(&Wire1); scanDevices(&Wire1);
printPMU(); printPMU();
#endif #endif
@ -259,56 +259,6 @@ static bool readStringUntil(Stream& s, char dest[], size_t max_len, char term, u
return millis() < timeout; // false, if timed out return millis() < timeout; // false, if timed out
} }
static bool l76kProbe()
{
bool result = false;
uint32_t startTimeout ;
Serial1.write("$PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n");
delay(5);
// Get version information
startTimeout = millis() + 3000;
MESH_DEBUG_PRINTLN("Trying to init L76K GPS");
// Serial1.flush();
while (Serial1.available()) {
int c = Serial1.read();
// Serial.write(c);
// Serial.print(".");
// Serial.flush();
// Serial1.flush();
if (millis() > startTimeout) {
MESH_DEBUG_PRINTLN("L76K NMEA timeout!");
return false;
}
};
Serial1.flush();
delay(200);
Serial1.write("$PCAS06,0*1B\r\n");
char ver[100];
if (!readStringUntil(Serial1, ver, sizeof(ver), '\n', 500)) {
MESH_DEBUG_PRINTLN("Get L76K timeout!");
return false;
}
if (memcmp(ver, "$GPTXT,01,01,02", 15) == 0) {
MESH_DEBUG_PRINTLN("L76K GNSS init succeeded, using L76K GNSS Module\n");
result = true;
}
delay(500);
// Initialize the L76K Chip, use GPS + GLONASS
Serial1.write("$PCAS04,5*1C\r\n");
delay(250);
// only ask for RMC and GGA
Serial1.write("$PCAS03,1,0,0,0,1,0,0,0,0,0,,,0,0*02\r\n");
delay(250);
// Switch to Vehicle Mode, since SoftRF enables Aviation < 2g
Serial1.write("$PCAS11,3*1E\r\n");
return result;
}
bool radio_init() { bool radio_init() {
fallback_clock.begin(); fallback_clock.begin();
@ -380,25 +330,16 @@ bool TbeamSupSensorManager::begin() {
// init GPS port // init GPS port
Serial1.begin(GPS_BAUD_RATE, SERIAL_8N1, P_GPS_RX, P_GPS_TX); Serial1.begin(GPS_BAUD_RATE, SERIAL_8N1, P_GPS_RX, P_GPS_TX);
bool gps_alive = false; MESH_DEBUG_PRINTLN("Sleeping GPS for initial state");
for ( int i = 0; i < 3; ++i) { sleep_gps();
gps_alive = l76kProbe(); return true;
if (gps_alive) {
MESH_DEBUG_PRINTLN("GPS is init and active. Shutting down for initial state.");
sleep_gps();
return gps_alive;
}
}
gps_active = gps_alive;
MESH_DEBUG_PRINTLN("GPS init failed and GPS is not active");
return gps_alive;
} }
bool TbeamSupSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { bool TbeamSupSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission? if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
} }
if (requester_permissions & TELEM_PERM_ENVIRONMENT) { // does requester have permission? if (requester_permissions & TELEM_PERM_ENVIRONMENT && bme_active) { // does requester have permission?
telemetry.addTemperature(TELEM_CHANNEL_SELF, node_temp); telemetry.addTemperature(TELEM_CHANNEL_SELF, node_temp);
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, node_hum); telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, node_hum);
telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, node_pres); telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, node_pres);
@ -413,20 +354,21 @@ void TbeamSupSensorManager::loop() {
_nmea->loop(); _nmea->loop();
if (millis() > next_update) { if (millis() > next_update) {
if (_nmea->isValid()) { if (_nmea->isValid() && gps_active) {
node_lat = ((double)_nmea->getLatitude())/1000000.; node_lat = ((double)_nmea->getLatitude())/1000000.;
node_lon = ((double)_nmea->getLongitude())/1000000.; node_lon = ((double)_nmea->getLongitude())/1000000.;
node_altitude = ((double)_nmea->getAltitude()) / 1000.0; node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
//Serial.printf("lat %f lon %f\r\n", _lat, _lon); MESH_DEBUG_PRINT("lat %f lon %f alt %f\r\n", node_lat, node_lon, node_altitude);
} }
//read BME280 values //read BME280 values
//node_alt = bme.readAltitude(SEALEVELPRESSURE_HPA); if(bme_active){
node_temp = bme.readTemperature(); //node_alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
node_hum = bme.readHumidity(); node_temp = bme.readTemperature();
node_pres = (bme.readPressure() / 100.0F); node_hum = bme.readHumidity();
node_pres = (bme.readPressure() / 100.0F);
#ifdef MESH_DEBUG
#ifdef MESH_DEBUG
// Serial.print("Temperature = "); // Serial.print("Temperature = ");
// Serial.print(node_temp); // Serial.print(node_temp);
// Serial.println(" *C"); // Serial.println(" *C");
@ -442,7 +384,8 @@ void TbeamSupSensorManager::loop() {
// Serial.print("Approx. Altitude = "); // Serial.print("Approx. Altitude = ");
// Serial.print(node_alt); // Serial.print(node_alt);
// Serial.println(" m"); // Serial.println(" m");
#endif #endif
}
next_update = millis() + 1000; next_update = millis() + 1000;
} }
@ -455,7 +398,6 @@ int TbeamSupSensorManager::getNumSettings() const {
const char* TbeamSupSensorManager::getSettingName(int i) const { const char* TbeamSupSensorManager::getSettingName(int i) const {
switch(i){ switch(i){
case 0: return "gps"; case 0: return "gps";
case 1: return "bme280";
default: NULL; default: NULL;
} }
} }
@ -463,7 +405,6 @@ const char* TbeamSupSensorManager::getSettingName(int i) const {
const char* TbeamSupSensorManager::getSettingValue(int i) const { const char* TbeamSupSensorManager::getSettingValue(int i) const {
switch(i){ switch(i){
case 0: return gps_active == true ? "1" : "0"; case 0: return gps_active == true ? "1" : "0";
case 1: return bme_active == true ? "1" : "0";
default: NULL; default: NULL;
} }
} }

View file

@ -16,7 +16,7 @@ class TbeamSupSensorManager: public SensorManager {
LocationProvider * _nmea; LocationProvider * _nmea;
Adafruit_BME280 bme; Adafruit_BME280 bme;
double node_temp, node_hum, node_pres; double node_temp, node_hum, node_pres;
int sensorNum = 2; int sensorNum = 1;
#define SEALEVELPRESSURE_HPA (1013.25) #define SEALEVELPRESSURE_HPA (1013.25)
@ -65,8 +65,6 @@ enum {
OSC32768_ONLINE = _BV(13), OSC32768_ONLINE = _BV(13),
}; };
void scanDevices(TwoWire *w);
static bool l76kProbe();
bool radio_init(); bool radio_init();
uint32_t radio_get_rng_seed(); uint32_t radio_get_rng_seed();
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);