In my work for #11 I accidentially created a serious bug on Heltec...

devices.  It caused bogus i2c transactions when device would go to sleep.
Fixed now, also, I now treat GPS usage uniformly between TBEAM and HELTEC
we always probe for and use the GPS if we find it.

Which means for the extra nerds
(someone requested this, I'm sorry - I don't remember who) you can now
optionally attach an external GPS to HELTECs if you want.  The pins are:

 #define GPS_RX_PIN 34
 #define GPS_TX_PIN 12

(@girtsf, sorry about including formatting changes in this PR, apparently
I had my IDE set to not autoreformat until just now
1.2-legacy
geeksville 2020-03-15 16:46:28 -07:00
rodzic 74f7b7b622
commit d0b8adab75
2 zmienionych plików z 57 dodań i 56 usunięć

Wyświetl plik

@ -137,72 +137,75 @@ bool GPS::canSleep()
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs /// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
void GPS::prepareSleep() void GPS::prepareSleep()
{ {
ublox.powerOff(); if (isConnected)
ublox.powerOff();
} }
void GPS::doTask() void GPS::doTask()
{ {
#ifdef GPS_RX_PIN #ifdef GPS_RX_PIN
// Consume all characters that have arrived if (isConnected)
// getPVT automatically calls checkUblox
ublox.checkUblox(); //See if new data is available. Process bytes as they come in.
// DEBUG_MSG("sec %d\n", ublox.getSecond());
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
// If we don't have a fix (a quick check), don't try waiting for a solution)
uint8_t fixtype = ublox.getFixType();
DEBUG_MSG("fix type %d\n", fixtype);
// any fix that has time
if ((fixtype >= 2 && fixtype <= 5) && !timeSetFromGPS && ublox.getT())
{ {
struct timeval tv; // Consume all characters that have arrived
isConnected = true; // We just received a packet, so we must have a GPS // getPVT automatically calls checkUblox
ublox.checkUblox(); //See if new data is available. Process bytes as they come in.
/* Convert to unix time // DEBUG_MSG("sec %d\n", ublox.getSecond());
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
// If we don't have a fix (a quick check), don't try waiting for a solution)
uint8_t fixtype = ublox.getFixType();
DEBUG_MSG("fix type %d\n", fixtype);
// any fix that has time
if ((fixtype >= 2 && fixtype <= 5) && !timeSetFromGPS && ublox.getT())
{
struct timeval tv;
isConnected = true; // We just received a packet, so we must have a GPS
/* Convert to unix time
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
*/ */
struct tm t; struct tm t;
t.tm_sec = ublox.getSecond(); t.tm_sec = ublox.getSecond();
t.tm_min = ublox.getMinute(); t.tm_min = ublox.getMinute();
t.tm_hour = ublox.getHour(); t.tm_hour = ublox.getHour();
t.tm_mday = ublox.getDay(); t.tm_mday = ublox.getDay();
t.tm_mon = ublox.getMonth() - 1; t.tm_mon = ublox.getMonth() - 1;
t.tm_year = ublox.getYear() - 1900; t.tm_year = ublox.getYear() - 1900;
t.tm_isdst = false; t.tm_isdst = false;
time_t res = mktime(&t); time_t res = mktime(&t);
tv.tv_sec = res; tv.tv_sec = res;
tv.tv_usec = 0; // time.centisecond() * (10 / 1000); tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec); DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec);
perhapsSetRTC(&tv); perhapsSetRTC(&tv);
}
if ((fixtype >= 3 && fixtype <= 4) && ublox.getP()) // rd fixes only
{
// we only notify if position has changed
isConnected = true; // We just received a packet, so we must have a GPS
latitude = ublox.getLatitude() * 1e-7;
longitude = ublox.getLongitude() * 1e-7;
altitude = ublox.getAltitude() / 1000; // in mm convert to meters
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d\n", latitude, longitude, altitude);
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
if (hasValidLocation)
{
wantNewLocation = false;
notifyObservers();
//ublox.powerOff();
} }
}
else // we didn't get a location update, go back to sleep and hope the characters show up
wantNewLocation = true;
if ((fixtype >= 3 && fixtype <= 4) && ublox.getP()) // rd fixes only
{
// we only notify if position has changed
isConnected = true; // We just received a packet, so we must have a GPS
latitude = ublox.getLatitude() * 1e-7;
longitude = ublox.getLongitude() * 1e-7;
altitude = ublox.getAltitude() / 1000; // in mm convert to meters
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d\n", latitude, longitude, altitude);
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
if (hasValidLocation)
{
wantNewLocation = false;
notifyObservers();
//ublox.powerOff();
}
}
else // we didn't get a location update, go back to sleep and hope the characters show up
wantNewLocation = true;
}
#endif #endif
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 1s until we have something over the serial // Once we have sent a location once we only poll the GPS rarely, otherwise check back every 1s until we have something over the serial

Wyświetl plik

@ -41,8 +41,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Select which board is being used. If the outside build environment has sent a choice, just use that // Select which board is being used. If the outside build environment has sent a choice, just use that
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32) #if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
#define T_BEAM_V10 // AKA Rev1 (second board released) // #define T_BEAM_V10 // AKA Rev1 (second board released)
// #define HELTEC_LORA32 #define HELTEC_LORA32
#define HW_VERSION_US // We encode the hardware freq range in the hw version string, so sw update can eventually install the correct build #define HW_VERSION_US // We encode the hardware freq range in the hw version string, so sw update can eventually install the correct build
#endif #endif
@ -84,14 +84,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define GPS_SERIAL_NUM 1 #define GPS_SERIAL_NUM 1
#define GPS_BAUDRATE 9600 #define GPS_BAUDRATE 9600
#if defined(T_BEAM_V10)
#define GPS_RX_PIN 34 #define GPS_RX_PIN 34
#ifdef USE_JTAG #ifdef USE_JTAG
#define GPS_TX_PIN -1 #define GPS_TX_PIN -1
#else #else
#define GPS_TX_PIN 12 #define GPS_TX_PIN 12
#endif #endif
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// LoRa SPI // LoRa SPI