t114 gps support

This commit is contained in:
JQ 2025-05-09 20:30:11 -07:00
parent d072e7b575
commit ae5052fec7
4 changed files with 99 additions and 5 deletions

View file

@ -71,7 +71,8 @@ build_flags =
; -D ENABLE_PRIVATE_KEY_IMPORT=1
; -D ENABLE_PRIVATE_KEY_EXPORT=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
-D MESH_DEBUG=1
; -D GPS_NMEA_DEBUG=1
build_src_filter = ${Heltec_t114.build_src_filter}
+<helpers/nrf52/T114Board.cpp>
+<helpers/nrf52/SerialBLEInterface.cpp>
@ -84,6 +85,7 @@ lib_deps =
adafruit/Adafruit GFX Library @ ^1.12.1
${Heltec_t114.lib_deps}
densaugeo/base64 @ ~1.4.0
stevemarple/MicroNMEA @ ^2.0.6
[env:Heltec_t114_companion_radio_usb]
extends = Heltec_t114

View file

@ -1,6 +1,7 @@
#include <Arduino.h>
#include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h>
T114Board board;
@ -10,7 +11,8 @@ WRAPPER_CLASS radio_driver(radio, board);
VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
SensorManager sensors;
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
T114SensorManager sensors = T114SensorManager(nmea);
#ifndef LORA_CR
#define LORA_CR 5
@ -68,3 +70,69 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
void T114SensorManager::start_gps() {
if (!gps_active) {
gps_active = true;
_location->begin();
}
}
void T114SensorManager::stop_gps() {
if (gps_active) {
gps_active = false;
_location->stop();
}
}
bool T114SensorManager::begin() {
Serial1.begin(9600);
return true;
}
bool T114SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, 0.0f);
}
return true;
}
void T114SensorManager::loop() {
static long next_gps_update = 0;
_location->loop();
if (millis() > next_gps_update) {
if (_location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
}
next_gps_update = millis() + 1000;
}
}
int T114SensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch)
const char* T114SensorManager::getSettingName(int i) const {
return i == 0 ? "gps" : NULL;
}
const char* T114SensorManager::getSettingValue(int i) const {
if (i == 0) {
return gps_active ? "1" : "0";
}
return NULL;
}
bool T114SensorManager::setSettingValue(const char* name, const char* value) {
if (strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
stop_gps();
} else {
start_gps();
}
return true;
}
return false; // not supported
}

View file

@ -7,11 +7,29 @@
#include <helpers/CustomSX1262Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/LocationProvider.h>
class T114SensorManager : public SensorManager {
bool gps_active = false;
LocationProvider* _location;
void start_gps();
void stop_gps();
public:
T114SensorManager(LocationProvider &location): _location(&location) { }
bool begin() override;
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
void loop() override;
int getNumSettings() const override;
const char* getSettingName(int i) const override;
const char* getSettingValue(int i) const override;
bool setSettingValue(const char* name, const char* value) override;
};
extern T114Board board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
extern SensorManager sensors;
extern T114SensorManager sensors;
bool radio_init();
uint32_t radio_get_rng_seed();

View file

@ -41,8 +41,8 @@
////////////////////////////////////////////////////////////////////////////////
// UART pin definition
#define PIN_SERIAL1_RX (39)
#define PIN_SERIAL1_TX (37)
#define PIN_SERIAL1_RX (37)
#define PIN_SERIAL1_TX (39)
#define PIN_SERIAL2_RX (9)
#define PIN_SERIAL2_TX (10)
@ -112,6 +112,12 @@
#define PIN_BUZZER (46)
////////////////////////////////////////////////////////////////////////////////
// GPS
#define GPS_EN (21)
#define GPS_RESET (38)
////////////////////////////////////////////////////////////////////////////////
// TFT
#define PIN_TFT_SCL (40)