add gps for techo
This commit is contained in:
@@ -25,6 +25,9 @@ build_src_filter = ${nrf52840_techo.build_src_filter}
|
|||||||
+<helpers/*.cpp>
|
+<helpers/*.cpp>
|
||||||
+<helpers/nrf52/TechoBoard.cpp>
|
+<helpers/nrf52/TechoBoard.cpp>
|
||||||
+<../variants/techo>
|
+<../variants/techo>
|
||||||
|
lib_deps =
|
||||||
|
${nrf52840_techo.lib_deps}
|
||||||
|
stevemarple/MicroNMEA @ ^2.0.6
|
||||||
debug_tool = jlink
|
debug_tool = jlink
|
||||||
upload_protocol = nrfutil
|
upload_protocol = nrfutil
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include <helpers/ArduinoHelpers.h>
|
#include <helpers/ArduinoHelpers.h>
|
||||||
|
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||||
|
|
||||||
TechoBoard board;
|
TechoBoard board;
|
||||||
|
|
||||||
@@ -10,7 +11,8 @@ WRAPPER_CLASS radio_driver(radio, board);
|
|||||||
|
|
||||||
VolatileRTCClock fallback_clock;
|
VolatileRTCClock fallback_clock;
|
||||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||||
SensorManager sensors;
|
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
|
||||||
|
TechoSensorManager sensors = TechoSensorManager(nmea);
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
DISPLAY_CLASS display;
|
DISPLAY_CLASS display;
|
||||||
@@ -72,3 +74,80 @@ mesh::LocalIdentity radio_new_identity() {
|
|||||||
RadioNoiseListener rng(radio);
|
RadioNoiseListener rng(radio);
|
||||||
return mesh::LocalIdentity(&rng); // create new random identity
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TechoSensorManager::start_gps() {
|
||||||
|
if (!gps_active) {
|
||||||
|
gps_active = true;
|
||||||
|
_location->begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TechoSensorManager::stop_gps() {
|
||||||
|
if (gps_active) {
|
||||||
|
gps_active = false;
|
||||||
|
_location->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TechoSensorManager::begin() {
|
||||||
|
Serial1.begin(9600);
|
||||||
|
|
||||||
|
// GPS enabled pin
|
||||||
|
pinMode(GPS_EN, OUTPUT);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TechoSensorManager::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, node_altitude);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TechoSensorManager::loop() {
|
||||||
|
static long next_gps_update = 0;
|
||||||
|
|
||||||
|
if (!gps_active) {
|
||||||
|
return; // GPS is not active, skip further processing
|
||||||
|
}
|
||||||
|
|
||||||
|
_location->loop();
|
||||||
|
|
||||||
|
if (millis() > next_gps_update) {
|
||||||
|
if (_location->isValid()) {
|
||||||
|
node_lat = ((double)_location->getLatitude())/1000000.;
|
||||||
|
node_lon = ((double)_location->getLongitude())/1000000.;
|
||||||
|
node_altitude = ((double)_location->getAltitude()) / 1000.0;
|
||||||
|
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
|
||||||
|
}
|
||||||
|
next_gps_update = millis() + 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int TechoSensorManager::getNumSettings() const {
|
||||||
|
return 1; // always show GPS setting
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* TechoSensorManager::getSettingName(int i) const {
|
||||||
|
return (i == 0) ? "gps" : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* TechoSensorManager::getSettingValue(int i) const {
|
||||||
|
if (i == 0) {
|
||||||
|
return gps_active ? "1" : "0";
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TechoSensorManager::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
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,15 +7,32 @@
|
|||||||
#include <helpers/CustomSX1262Wrapper.h>
|
#include <helpers/CustomSX1262Wrapper.h>
|
||||||
#include <helpers/AutoDiscoverRTCClock.h>
|
#include <helpers/AutoDiscoverRTCClock.h>
|
||||||
#include <helpers/SensorManager.h>
|
#include <helpers/SensorManager.h>
|
||||||
|
#include <helpers/sensors/LocationProvider.h>
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
#include <helpers/ui/GxEPDDisplay.h>
|
#include <helpers/ui/GxEPDDisplay.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class TechoSensorManager : public SensorManager {
|
||||||
|
bool gps_active = false;
|
||||||
|
LocationProvider* _location;
|
||||||
|
|
||||||
|
void start_gps();
|
||||||
|
void stop_gps();
|
||||||
|
public:
|
||||||
|
TechoSensorManager(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 TechoBoard board;
|
extern TechoBoard board;
|
||||||
extern WRAPPER_CLASS radio_driver;
|
extern WRAPPER_CLASS radio_driver;
|
||||||
extern AutoDiscoverRTCClock rtc_clock;
|
extern AutoDiscoverRTCClock rtc_clock;
|
||||||
extern SensorManager sensors;
|
extern TechoSensorManager sensors;
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
extern DISPLAY_CLASS display;
|
extern DISPLAY_CLASS display;
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ void initVariant() {
|
|||||||
digitalWrite(PIN_TXCO, HIGH);
|
digitalWrite(PIN_TXCO, HIGH);
|
||||||
|
|
||||||
// shutdown gps
|
// shutdown gps
|
||||||
pinMode(PIN_GPS_STANDBY, OUTPUT);
|
pinMode(GPS_EN, OUTPUT);
|
||||||
digitalWrite(PIN_GPS_STANDBY, LOW);
|
digitalWrite(GPS_EN, LOW);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// UART pin definition
|
// UART pin definition
|
||||||
|
|
||||||
#define PIN_SERIAL1_RX (41) // GPS TX
|
#define PIN_SERIAL1_RX PIN_GPS_TX
|
||||||
#define PIN_SERIAL1_TX (40) // GPS RX
|
#define PIN_SERIAL1_TX PIN_GPS_RX
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// I2C pin definition
|
// I2C pin definition
|
||||||
|
|
||||||
@@ -127,7 +127,6 @@ extern const int SCK;
|
|||||||
|
|
||||||
#define PIN_GPS_RX (41)
|
#define PIN_GPS_RX (41)
|
||||||
#define PIN_GPS_TX (40)
|
#define PIN_GPS_TX (40)
|
||||||
#define PIN_GPS_WAKEUP (34)
|
#define GPS_EN (34)
|
||||||
#define PIN_GPS_RESET (37)
|
#define PIN_GPS_RESET (37)
|
||||||
#define PIN_GPS_PPS (36)
|
#define PIN_GPS_PPS (36)
|
||||||
#define PIN_GPS_STANDBY (34)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user