Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ static Adafruit_VL53L0X VL53L0X;
#define RAK_WISBLOCK_GPS
#endif

#if ENV_INCLUDE_GPS && defined(T1000_E)
#define T1000_E_GPS
#define GPS_RX_PIN PIN_GPS_RX
#define GPS_RX_PIN PIN_GPS_TX
#include "t1000e_sensors.h"
#endif

#ifdef RAK_WISBLOCK_GPS
static uint32_t gpsResetPin = 0;
static bool i2cGPSFlag = false;
Expand Down Expand Up @@ -483,6 +490,12 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
}
#endif

#ifdef T1000_E_GPS
// Firmware reports light as a 0-100 % scale, but expose it via Luminosity so app labels it "Luminosity".
telemetry.addLuminosity(TELEM_CHANNEL_SELF, t1000e_get_light());
telemetry.addTemperature(TELEM_CHANNEL_SELF, t1000e_get_temperature());
#endif

}

return true;
Expand Down Expand Up @@ -680,6 +693,27 @@ void EnvironmentSensorManager::start_gps() {
return;
#endif

#ifdef T1000_E_GPS
pinMode(GPS_EN, OUTPUT);
digitalWrite(GPS_EN, HIGH);
delay(10);
pinMode(GPS_VRTC_EN, OUTPUT);
digitalWrite(GPS_VRTC_EN, HIGH);
delay(10);

pinMode(GPS_RESET, OUTPUT);
digitalWrite(GPS_RESET, HIGH);
delay(10);
digitalWrite(GPS_RESET, LOW);

pinMode(GPS_SLEEP_INT, OUTPUT);
digitalWrite(GPS_SLEEP_INT, HIGH);
pinMode(GPS_RTC_INT, OUTPUT);
digitalWrite(GPS_RTC_INT, LOW);
pinMode(GPS_RESETB, INPUT_PULLUP);
return;
#endif

_location->begin();
_location->reset();

Expand All @@ -696,6 +730,17 @@ void EnvironmentSensorManager::stop_gps() {
return;
#endif

#ifdef T1000_E_GPS
digitalWrite(GPS_VRTC_EN, LOW);
digitalWrite(GPS_EN, LOW);
digitalWrite(GPS_RESET, HIGH);
digitalWrite(GPS_SLEEP_INT, HIGH);
digitalWrite(GPS_RTC_INT, LOW);
pinMode(GPS_RESETB, OUTPUT);
digitalWrite(GPS_RESETB, LOW);
return;
#endif

_location->stop();

#ifndef PIN_GPS_EN
Expand Down
8 changes: 7 additions & 1 deletion variants/t1000-e/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends = nrf52_base
board = tracker-t1000-e
board_build.ldscript = boards/nrf52840_s140_v7.ld
build_flags = ${nrf52_base.build_flags}
${sensor_base.build_flags}
-I src/helpers/nrf52
-I lib/nrf52/s140_nrf52_7.3.0_API/include
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
Expand All @@ -24,13 +25,18 @@ build_flags = ${nrf52_base.build_flags}
-D P_LORA_MISO=40 ; P1.8
-D P_LORA_MOSI=41 ; P0.9
-D P_LORA_RESET=42 ; P1.10
-D GPS_BAUD_RATE=115200
-D LR11X0_DIO_AS_RF_SWITCH=true
-D LR11X0_DIO3_TCXO_VOLTAGE=1.6
-D ENV_INCLUDE_GPS=1
-D ENV_INCLUDE_BME680=0
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<helpers/nrf52/T1000eBoard.cpp>
+<helpers/sensors/EnvironmentSensorManager.cpp>
+<../variants/t1000-e>
lib_deps =
${nrf52_base.lib_deps}
stevemarple/MicroNMEA @ ^2.0.6
debug_tool = jlink
upload_protocol = nrfutil

Expand Down
116 changes: 8 additions & 108 deletions variants/t1000-e/target.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <Arduino.h>
#include "t1000e_sensors.h"
#include "target.h"
#include <helpers/sensors/MicroNMEALocationProvider.h>

T1000eBoard board;

Expand All @@ -10,8 +9,14 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU
WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock rtc_clock;
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
T1000SensorManager sensors = T1000SensorManager(nmea);

#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#else
EnvironmentSensorManager sensors;
#endif

#ifdef DISPLAY_CLASS
NullDisplayDriver display;
Expand Down Expand Up @@ -94,108 +99,3 @@ mesh::LocalIdentity radio_new_identity() {
return mesh::LocalIdentity(&rng); // create new random identity
}

void T1000SensorManager::start_gps() {
gps_active = true;
//_nmea->begin();
// this init sequence should be better
// comes from seeed examples and deals with all gps pins
pinMode(GPS_EN, OUTPUT);
digitalWrite(GPS_EN, HIGH);
delay(10);
pinMode(GPS_VRTC_EN, OUTPUT);
digitalWrite(GPS_VRTC_EN, HIGH);
delay(10);

pinMode(GPS_RESET, OUTPUT);
digitalWrite(GPS_RESET, HIGH);
delay(10);
digitalWrite(GPS_RESET, LOW);

pinMode(GPS_SLEEP_INT, OUTPUT);
digitalWrite(GPS_SLEEP_INT, HIGH);
pinMode(GPS_RTC_INT, OUTPUT);
digitalWrite(GPS_RTC_INT, LOW);
pinMode(GPS_RESETB, INPUT_PULLUP);
}

void T1000SensorManager::sleep_gps() {
gps_active = false;
digitalWrite(GPS_VRTC_EN, HIGH);
digitalWrite(GPS_EN, LOW);
digitalWrite(GPS_RESET, HIGH);
digitalWrite(GPS_SLEEP_INT, HIGH);
digitalWrite(GPS_RTC_INT, LOW);
pinMode(GPS_RESETB, OUTPUT);
digitalWrite(GPS_RESETB, LOW);
//_nmea->stop();
}

void T1000SensorManager::stop_gps() {
gps_active = false;
digitalWrite(GPS_VRTC_EN, LOW);
digitalWrite(GPS_EN, LOW);
digitalWrite(GPS_RESET, HIGH);
digitalWrite(GPS_SLEEP_INT, HIGH);
digitalWrite(GPS_RTC_INT, LOW);
pinMode(GPS_RESETB, OUTPUT);
digitalWrite(GPS_RESETB, LOW);
//_nmea->stop();
}


bool T1000SensorManager::begin() {
// init GPS
Serial1.begin(115200);
return true;
}

bool T1000SensorManager::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);
}
if (requester_permissions & TELEM_PERM_ENVIRONMENT) {
// Firmware reports light as a 0-100 % scale, but expose it via Luminosity so app labels it "Luminosity".
telemetry.addLuminosity(TELEM_CHANNEL_SELF, t1000e_get_light());
telemetry.addTemperature(TELEM_CHANNEL_SELF, t1000e_get_temperature());
}
return true;
}

void T1000SensorManager::loop() {
static long next_gps_update = 0;

_nmea->loop();

if (millis() > next_gps_update) {
if (gps_active && _nmea->isValid()) {
node_lat = ((double)_nmea->getLatitude())/1000000.;
node_lon = ((double)_nmea->getLongitude())/1000000.;
node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
//Serial.printf("lat %f lon %f\r\n", _lat, _lon);
}
next_gps_update = millis() + 1000;
}
}

int T1000SensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch)

const char* T1000SensorManager::getSettingName(int i) const {
return i == 0 ? "gps" : NULL;
}
const char* T1000SensorManager::getSettingValue(int i) const {
if (i == 0) {
return gps_active ? "1" : "0";
}
return NULL;
}
bool T1000SensorManager::setSettingValue(const char* name, const char* value) {
if (strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
sleep_gps(); // sleep for faster fix !
} else {
start_gps();
}
return true;
}
return false; // not supported
}
22 changes: 2 additions & 20 deletions variants/t1000-e/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,19 @@
#include <helpers/ArduinoHelpers.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/LocationProvider.h>
#include <helpers/sensors/EnvironmentSensorManager.h>
#ifdef DISPLAY_CLASS
#include "NullDisplayDriver.h"
#endif

class T1000SensorManager: public SensorManager {
bool gps_active = false;
LocationProvider * _nmea;

void start_gps();
void sleep_gps();
void stop_gps();
public:
T1000SensorManager(LocationProvider &nmea): _nmea(&nmea) { }
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;
LocationProvider* getLocationProvider() { return _nmea; }
};

#ifdef DISPLAY_CLASS
extern NullDisplayDriver display;
#endif

extern T1000eBoard board;
extern WRAPPER_CLASS radio_driver;
extern VolatileRTCClock rtc_clock;
extern T1000SensorManager sensors;
extern EnvironmentSensorManager sensors;

bool radio_init();
uint32_t radio_get_rng_seed();
Expand Down