Skip to content

Commit

Permalink
In my work for meshtastic#11 I accidentially created a serious bug on…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
geeksville committed Mar 15, 2020
1 parent 22e4382 commit 9d78f56
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
99 changes: 51 additions & 48 deletions src/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
void GPS::prepareSleep()
{
ublox.powerOff();
if (isConnected)
ublox.powerOff();
}

void GPS::doTask()
{
#ifdef GPS_RX_PIN
// Consume all characters that have arrived
if (isConnected)
{
// Consume all characters that have arrived

// getPVT automatically calls checkUblox
ublox.checkUblox(); //See if new data is available. Process bytes as they come in.
// 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());
// 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);
// 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;
// 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
isConnected = true; // We just received a packet, so we must have a GPS

/* Convert to unix time
/* 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).
*/
struct tm t;
t.tm_sec = ublox.getSecond();
t.tm_min = ublox.getMinute();
t.tm_hour = ublox.getHour();
t.tm_mday = ublox.getDay();
t.tm_mon = ublox.getMonth() - 1;
t.tm_year = ublox.getYear() - 1900;
t.tm_isdst = false;
time_t res = mktime(&t);
tv.tv_sec = res;
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);

perhapsSetRTC(&tv);
}
struct tm t;
t.tm_sec = ublox.getSecond();
t.tm_min = ublox.getMinute();
t.tm_hour = ublox.getHour();
t.tm_mday = ublox.getDay();
t.tm_mon = ublox.getMonth() - 1;
t.tm_year = ublox.getYear() - 1900;
t.tm_isdst = false;
time_t res = mktime(&t);
tv.tv_sec = res;
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);

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
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);
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();
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;
}
else // we didn't get a location update, go back to sleep and hope the characters show up
wantNewLocation = true;

#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
Expand Down
6 changes: 2 additions & 4 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
#define T_BEAM_V10 // AKA Rev1 (second board released)
// #define HELTEC_LORA32
// #define T_BEAM_V10 // AKA Rev1 (second board released)
#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
#endif
Expand Down Expand Up @@ -84,14 +84,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define GPS_SERIAL_NUM 1
#define GPS_BAUDRATE 9600

#if defined(T_BEAM_V10)
#define GPS_RX_PIN 34
#ifdef USE_JTAG
#define GPS_TX_PIN -1
#else
#define GPS_TX_PIN 12
#endif
#endif

// -----------------------------------------------------------------------------
// LoRa SPI
Expand Down

0 comments on commit 9d78f56

Please sign in to comment.