LSM303 Example Software Question
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
My Flora is connected to a GPS. I can't use the GPS to set DST if the Flora isn't running. As far as I know, there's no GPS output string that includes a DST flag, or local time for that matter.
-
- Posts: 564
- Joined: Wed Jun 19, 2013 3:35 am
Re: LSM303 Example Software Question
Barry914 wrote:My Flora is connected to a GPS. I can't use the GPS to set DST if the Flora isn't running. As far as I know, there's no GPS output string that includes a DST flag, or local time for that matter.
Actually, according to the Command Packet, the Ultimate GPS does support the following sentences -
Supported NMEA Sentences
0 NMEA_SEN_GLL, // GPGLL interval ‐ Geographic Position ‐ Latitude longitude
1 NMEA_SEN_RMC, // GPRMC interval ‐ Recommended Minimum Specific GNSS Sentence
2 NMEA_SEN_VTG, // GPVTG interval ‐ Course over Ground and Ground Speed
3 NMEA_SEN_GGA, // GPGGA interval ‐ GPS Fix Data
4 NMEA_SEN_GSA, // GPGSA interval ‐ GNSS DOPS and Active Satellites
5 NMEA_SEN_GSV, // GPGSV interval ‐ GNSS Satellites in View
6 //Reserved
7 //Reserved
13 //Reserved
14 //Reserved
15 //Reserved
16 //Reserved
17 NMEA_SEN_ZDA, // GPZDA interval – Time & Date
18 NMEA_SEN_MCHN, // PMTKCHN interval – GPS channel status
The ZDA sentence includes the following data -
I haven't explored that at all.....yet!ZDA - Data and Time
$GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
$GPZDA,201530.00,04,07,2002,00,00*60
where:
hhmmss HrMinSec(UTC)
dd,mm,yyy Day,Month,Year
xx local zone hours -13..13
yy local zone minutes 0..59
*CC checksum
So, I really don't know the specifics about local hours and DST.
And...the library does not yet support parsing of that sentence. But, if it works....I could throw something together this weekend?
What's your current code look like so far? Any room for trimming other bits down to make room?
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
I guess I missed that data. I have the command doc and I'll take another look. My code looks surprisingly similar to the NeoGeo Watch project code. It uses the Time library to convert UTC to local time with a call to adjustTime(), which applies an offset. As for trimming code, I've already picked the low hanging fruit like data types and trimming unused code (it no longer supports the serial console, for instance). I suppose if I took out the clock mode code I'd have plenty of memory for a decent DST routine, but I think there's something wrong with that idea. My biggest problem right now is not knowing when to stop. I have been told I lack that skill. I could just recompile the code twice a year, but no ...
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: LSM303 Example Software Question
The clockMode() code looks like a good candidate for optimization. Especially this stuff:My code looks surprisingly similar to the NeoGeo Watch project code.
Code: Select all
float gpsMin = (minute() + (second()/60.0));
unsigned int ledMin = 0;
int minTemp = 0;
if (gpsMin <= 1.875) minTemp = topLED;
if ((gpsMin > 1.875) && (gpsMin <= 5.625)) minTemp = topLED - 1;
if ((gpsMin > 5.625) && (gpsMin <= 9.375)) minTemp = topLED - 2;
if ((gpsMin > 9.375) && (gpsMin <= 13.125)) minTemp = topLED - 3;
if ((gpsMin > 13.125) && (gpsMin <= 16.875)) minTemp = topLED - 4;
if ((gpsMin > 16.875) && (gpsMin <= 20.625)) minTemp = topLED - 5;
if ((gpsMin > 20.625) && (gpsMin <= 24.375)) minTemp = topLED - 6;
if ((gpsMin > 24.375) && (gpsMin <= 28.125)) minTemp = topLED - 7;
if ((gpsMin > 28.125) && (gpsMin <= 31.875)) minTemp = topLED - 8;
if ((gpsMin > 31.875) && (gpsMin <= 35.625)) minTemp = topLED - 9;
if ((gpsMin > 35.625) && (gpsMin <= 39.375)) minTemp = topLED - 10;
if ((gpsMin > 39.375) && (gpsMin <= 43.125)) minTemp = topLED - 11;
if ((gpsMin > 43.125) && (gpsMin <= 46.875)) minTemp = topLED - 12;
if ((gpsMin > 46.875) && (gpsMin <= 50.625)) minTemp = topLED - 13;
if ((gpsMin > 50.625) && (gpsMin <= 54.375)) minTemp = topLED - 14;
if ((gpsMin > 54.375) && (gpsMin <= 58.125)) minTemp = topLED - 15;
if (gpsMin > 58.125) minTemp = topLED - 16;
Code: Select all
int gpsSeconds = (minute() * 60 + (second()));
headingDistance() and compassDirection() are also pretty ripe for optimization.
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
Those if statements are truly a waste of memory and definitely something to tackle first. I had thought of using map() but had not thought of using int seconds, and if done in hours and minutes it doesn't work. Without thinking too hard, won't I still have the "half pixel" problem you get with minutes and hours? I am not sure if map() rounds up or down or both, but I think it's down. What do you get when you map 60 minutes to 16 pixels and the input is 57? Is it different than mapping 60*60 minutes to 16 pixels? I guess I have to find out. The compass functions are so ... um ... distributed I hesitate to wade into them, but I have gone through those pieces of code and commented the flow so if I decide to do it I will have a little head start. I can certainly do for the compass display what I do for the clock display and get rid of those if statements too. To paraphrase Click and Clack, the Tappet Brothers, I am about to waste a perfectly good weekend writing code, and even though my wife cringes when I say it, I am pleased to owe it all to Adafruit.
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: LSM303 Example Software Question
The map function does truncate. But it is not hard to tweak the inputs to get the output you want: http://www.jetmore.org/john/blog/2011/0 ... tribution/I am not sure if map() rounds up or down or both, but I think it's down.
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
I think I did what was suggested (code below) but it does not provide the output I am looking for. Here's the output for mapping 0 - 59 to 0 - 15:
And here's the code that generated this output:
Code: Select all
input = 0 outValS = 0
input = 1 outValS = 0
input = 2 outValS = 0
input = 3 outValS = 0
input = 4 outValS = 1
input = 5 outValS = 1
input = 6 outValS = 1
input = 7 outValS = 1
input = 8 outValS = 2
input = 9 outValS = 2
input = 10 outValS = 2
input = 11 outValS = 2
input = 12 outValS = 3
input = 13 outValS = 3
input = 14 outValS = 3
input = 15 outValS = 4
input = 16 outValS = 4
input = 17 outValS = 4
input = 18 outValS = 4
input = 19 outValS = 5
input = 20 outValS = 5
input = 21 outValS = 5
input = 22 outValS = 5
input = 23 outValS = 6
input = 24 outValS = 6
input = 25 outValS = 6
input = 26 outValS = 7
input = 27 outValS = 7
input = 28 outValS = 7
input = 29 outValS = 7
input = 30 outValS = 8
input = 31 outValS = 8
input = 32 outValS = 8
input = 33 outValS = 8
input = 34 outValS = 9
input = 35 outValS = 9
input = 36 outValS = 9
input = 37 outValS = 10
input = 38 outValS = 10
input = 39 outValS = 10
input = 40 outValS = 10
input = 41 outValS = 11
input = 42 outValS = 11
input = 43 outValS = 11
input = 44 outValS = 11
input = 45 outValS = 12
input = 46 outValS = 12
input = 47 outValS = 12
input = 48 outValS = 13
input = 49 outValS = 13
input = 50 outValS = 13
input = 51 outValS = 13
input = 52 outValS = 14
input = 53 outValS = 14
input = 54 outValS = 14
input = 55 outValS = 14
input = 56 outValS = 15
input = 57 outValS = 15
input = 58 outValS = 15
input = 59 outValS = 15
Code: Select all
void setup()
{
Serial.begin(9600);
}
void loop()
{
int i;
int outValS;
if (Serial.available())
{
Serial.read();
for (i = 0; i < 60; i++)
{
int inSecs = i * 60;
outValS = constrain(map(inSecs, 0, 3541, 0, 16), 0, 15);
Serial.print("input = ");
Serial.print(i);
Serial.print("\toutValS = ");
Serial.println(outValS);
}
}
}
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: LSM303 Example Software Question
What exactly is the output you are looking for? You may need to add (or subtract) an offset to your input value.
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
Yes, I think an output offset might do it. I'm looking for the same outputs i get from the existing clock display. It maps pretty symmetrically around 12, 3, 6 & 9, which is not happening with straight mapping.
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
I think this is the way to do it:
It produces this output:
So this:
can be replaced with:
Code: Select all
void setup()
{
Serial.begin(9600);
}
void loop()
{
int min;
float outValS;
if (Serial.available())
{
Serial.read();
for (min = 0; min < 60; min++)
{
outValS = (int)((min + 2) / 3.75);
if (outValS > 15)
{
outValS -= 16;
}
Serial.print("minute = ");
Serial.print(min);
Serial.print("\tLED = ");
Serial.println(outValS);
}
}
}
Code: Select all
minute = 0 LED = 0.00
minute = 1 LED = 0.00
minute = 2 LED = 1.00
minute = 3 LED = 1.00
minute = 4 LED = 1.00
minute = 5 LED = 1.00
minute = 6 LED = 2.00
minute = 7 LED = 2.00
minute = 8 LED = 2.00
minute = 9 LED = 2.00
minute = 10 LED = 3.00
minute = 11 LED = 3.00
minute = 12 LED = 3.00
minute = 13 LED = 4.00
minute = 14 LED = 4.00
minute = 15 LED = 4.00
minute = 16 LED = 4.00
minute = 17 LED = 5.00
minute = 18 LED = 5.00
minute = 19 LED = 5.00
minute = 20 LED = 5.00
minute = 21 LED = 6.00
minute = 22 LED = 6.00
minute = 23 LED = 6.00
minute = 24 LED = 6.00
minute = 25 LED = 7.00
minute = 26 LED = 7.00
minute = 27 LED = 7.00
minute = 28 LED = 8.00
minute = 29 LED = 8.00
minute = 30 LED = 8.00
minute = 31 LED = 8.00
minute = 32 LED = 9.00
minute = 33 LED = 9.00
minute = 34 LED = 9.00
minute = 35 LED = 9.00
minute = 36 LED = 10.00
minute = 37 LED = 10.00
minute = 38 LED = 10.00
minute = 39 LED = 10.00
minute = 40 LED = 11.00
minute = 41 LED = 11.00
minute = 42 LED = 11.00
minute = 43 LED = 12.00
minute = 44 LED = 12.00
minute = 45 LED = 12.00
minute = 46 LED = 12.00
minute = 47 LED = 13.00
minute = 48 LED = 13.00
minute = 49 LED = 13.00
minute = 50 LED = 13.00
minute = 51 LED = 14.00
minute = 52 LED = 14.00
minute = 53 LED = 14.00
minute = 54 LED = 14.00
minute = 55 LED = 15.00
minute = 56 LED = 15.00
minute = 57 LED = 15.00
minute = 58 LED = 0.00
minute = 59 LED = 0.00
Code: Select all
if (gpsMin <= 1.875) minTemp = topLED;
if ((gpsMin > 1.875) && (gpsMin <= 5.625)) minTemp = topLED - 1;
if ((gpsMin > 5.625) && (gpsMin <= 9.375)) minTemp = topLED - 2;
if ((gpsMin > 9.375) && (gpsMin <= 13.125)) minTemp = topLED - 3;
if ((gpsMin > 13.125) && (gpsMin <= 16.875)) minTemp = topLED - 4;
if ((gpsMin > 16.875) && (gpsMin <= 20.625)) minTemp = topLED - 5;
if ((gpsMin > 20.625) && (gpsMin <= 24.375)) minTemp = topLED - 6;
if ((gpsMin > 24.375) && (gpsMin <= 28.125)) minTemp = topLED - 7;
if ((gpsMin > 28.125) && (gpsMin <= 31.875)) minTemp = topLED - 8;
if ((gpsMin > 31.875) && (gpsMin <= 35.625)) minTemp = topLED - 9;
if ((gpsMin > 35.625) && (gpsMin <= 39.375)) minTemp = topLED - 10;
if ((gpsMin > 39.375) && (gpsMin <= 43.125)) minTemp = topLED - 11;
if ((gpsMin > 43.125) && (gpsMin <= 46.875)) minTemp = topLED - 12;
if ((gpsMin > 46.875) && (gpsMin <= 50.625)) minTemp = topLED - 13;
if ((gpsMin > 50.625) && (gpsMin <= 54.375)) minTemp = topLED - 14;
if ((gpsMin > 54.375) && (gpsMin <= 58.125)) minTemp = topLED - 15;
if (gpsMin > 58.125) minTemp = topLED - 16;
if (minTemp < 0)
{
ledMin = minTemp + 16;
}
else
{
ledMin = minTemp;
}
Code: Select all
minTemp = (int)((gpsMin + 2) / 3.75) % 16;
ledMin = (16 - minTemp + topLED) % 16;
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: LSM303 Example Software Question
That should save a byte or two. Now get to work filling up all that extra space!
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
Here's the complete clockMode() code with all the comparisons for hours and minutes replaced by an algorithmic method. It saves about 1500 bytes. I guess I might as well do the compass code too. I'll post that too. It's been less than 24 hours since I started running this code in the watch so I guess it's not fully tested, but I think it works.
Code: Select all
void clockMode()
{
if (start == 1)
{ // we have gotten a GPS fix and set the time
ring.setPixelColor(startLEDlast, ring.Color(0, 0, 0));
// hour, minute, second, are defined in the Time library. Updated in the main loop with periodic calls to setTime()
float gpsMin = (minute() + (second()/60.0));
unsigned int ledMin = 0;
int minTemp = 0;
minTemp = (int)((gpsMin + 2) / 3.75) % 16;
ledMin = (16 - minTemp + topLED) % 16;
float gpsHour = (hour() + (minute()/60.0));
if (gpsHour > 12)
{
gpsHour = gpsHour - 12;
}
unsigned int ledHour = 0;
int hourTemp = 0;
hourTemp = (int)((gpsHour + .333) * 1.333) % 16;
ledHour = (16 - hourTemp + topLED) % 16;
if ((ledHour == ledMin) && (lastCombined == 0))
{
ring.setPixelColor(lastHour, ring.Color(0, 0, 0));
ring.setPixelColor(lastMin, ring.Color(0, 0, 0));
ring.setPixelColor(ledHour, ring.Color(255, 0, 255));
ring.show();
lastCombined = 1;
lastHour = ledHour;
lastMin = ledMin;
}
else
{
if (lastHour != ledHour)
{
ring.setPixelColor(lastHour, ring.Color(0, 0, 0));
ring.setPixelColor(ledHour, ring.Color(255, 50, 0));
ring.show();
lastHour = ledHour;
}
if (lastMin != ledMin)
{
ring.setPixelColor(lastMin, ring.Color(0, 0, 0));
ring.setPixelColor(ledMin, ring.Color(200, 200, 0));
if (lastCombined == 1)
{
ring.setPixelColor(ledHour, ring.Color(255, 0, 0));
lastCombined = 0;
}
ring.show();
lastMin = ledMin;
}
}
}
else // never got a GPS fix, so chase a blue pixel around the ring until we do
{
// if millis() or timer wraps around, we'll just reset it
if (startupTimer > millis()) startupTimer = millis();
// approximately every 10 seconds or so, update time
if (millis() - startupTimer > 200)
{
startupTimer = millis(); // reset the timer
if (startLED == 16)
{
startLED = 0;
}
ring.setPixelColor(startLEDlast, ring.Color(0, 0, 0)); // do this until GPS fix
ring.setPixelColor(startLED, ring.Color(0, 255, 0));
ring.show();
startLEDlast = startLED;
startLED++;
//delay(200);
}
}
}
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: LSM303 Example Software Question
And here's the updated compassDirection() from the same project. There's also code that displays the compass as 4 rotating points, making it easier for me to determine my actual heading. Any beta testers out there? This stuff could use a good shake.
I seem to remember that this started as a quest to automatically set DST. These changes have recovered about 2.5 Kb but I still haven't begun working on the original problem.
I seem to remember that this started as a quest to automatically set DST. These changes have recovered about 2.5 Kb but I still haven't begun working on the original problem.
Code: Select all
// computes the LED that points in the desired direction. Used in compass and nav modes
// Remember: this is not the direction you are heading. It points to north or to the
// destination.
void compassDirection(int compassHeading)
{
uint8_t ledDir = 16;
int tempDir = 16;
tempDir = (int)((compassHeading + 11.25) / 22.5) % 16;
if (mode == 1) // nav mode
{
ledDir = (int)(16 - tempDir + topLED + BANNED) %16;
}
else
{
ledDir = (int)(tempDir + topLED + BANNED) %16;
}
if (lastDir != ledDir) // if there has been a direction change
{
ring.setPixelColor(lastDir, ring.Color(0, 0, 0));
// This displays a simulated compass card in compass mode
// or a single LED in nav mode
if (mode == 2) // compass mode
{
compassCard(ledDir);
}
else
{
ring.show();
}
lastDir = ledDir;
}
// the LED color may change even if the direction does not
ring.setPixelColor(ledDir, ring.Color(dirLED_r, dirLED_g, dirLED_b));
}
/*
Implments a compass card display with 4 cardinal points.
North is blue, south is violet, east and west are yellow.
Takes the LED number of north as a parameter.
*/
void compassCard(uint8_t n)
{
uint8_t ledE;
uint8_t ledS;
uint8_t ledW;
static uint8_t lastLedE;
static uint8_t lastLedS;
static uint8_t lastLedW;
ring.setPixelColor(lastLedE, 0);
ring.setPixelColor(lastLedS, 0);
ring.setPixelColor(lastLedW, 0);
ledE = (n + 4) % 16;
ledS = (n + 8) % 16;
ledW = (n + 12) % 16;
ring.setPixelColor(n, 0x0000ff); // north is blue
ring.setPixelColor(ledE, 0xf8a000); // east is yellow
ring.setPixelColor(ledS, 0xff68ff); // south is violet
ring.setPixelColor(ledW, 0xf8a000); // west is yellow
ring.show();
lastLedE = ledE;
lastLedS = ledS;
lastLedW = ledW;
}
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: LSM303 Example Software Question
That's a pretty good payback.I seem to remember that this started as a quest to automatically set DST. These changes have recovered about 2.5 Kb ...
That's the way all my projects seem to go too... but I still haven't begun working on the original problem.
-
- Posts: 564
- Joined: Wed Jun 19, 2013 3:35 am
Re: LSM303 Example Software Question
There are so many ways to do the same thing ---
Sorry.... I think this is what I was originally considering when I mentioned the GPS idea. I just completely spaced on it during my last response.
(Need to stop posting when I'm sleepy..)
If the ZDA sentence doesn't 'automatically' calculate local DST, this might be a simpler way to go than using months and days.
There is a thing called "GPS Weeks".
From Wikipedia (emphasis added) -
http://en.wikipedia.org/wiki/GPS_enhanc ... imekeeping
You can find a calendar of GPS Weeks and Days here -
https://www.ngs.noaa.gov/CORS/Gpscal.shtml
To get the current GPS Week from the GPS Module, send this command -
Packet Type: 607 PMTK_Q_EPO_INFO
The GPS should respond with a sentence which looks similar to this -
Packet Type: 707 PMTK_DT_EPO_INFO
The values in that sentence breakdown as follows (copied from PMTK Command Packet) -
http://www.adafruit.com/datasheets/PMTK ... 39-A01.pdf
GPS weeks begin on Sundays...end on Saturdays.
Since DST starts at 2am on a Sunday and ends at 2am on a Sunday.... as long as you're not too concerned about changing the time exactly at 2am...you can simply check to see if the current week falls between the week just prior to DST in the spring and the week containing the Sunday of time change in the fall. If so...add one hour to your timezone offset used to calculate local time from the GPS' UTC time. (That's "+1", so an offset of -6 hrs would become -5)
For example - This year's DST begins on first day of GPS week 1782 and ends on first day of GPS week 1817.
So, code could look something like this (after getting the current GPS week from GPS) -
Much simpler code. At least, after the GPS Week data is parsed. And, depending on how you want to code it and a few variables only you can answer...the GPS week could conceivably only need to be checked once/day...once/week.... only during March and November....? It seems unnecessary and wasteful to have that included in every loop.
Make sense? ....I hope
(*The following added primarily for future readers of this thread)
In the U.S., timezone offsets are negative -- Subtracting hours from UTC to get local time.
Timezone // Normal Offset // DST Offset
Eastern // UTC - 5h // UTC - 4h
Central // UTC - 6h // UTC - 5h
Mountain // UTC - 7h // UTC - 6h *n/a for Arizona
Pacific // UTC - 8h // UTC - 7h
Alaska // UTC - 9h // UTC - 8h
** Hawaii does not observe DST
Sorry.... I think this is what I was originally considering when I mentioned the GPS idea. I just completely spaced on it during my last response.
(Need to stop posting when I'm sleepy..)
If the ZDA sentence doesn't 'automatically' calculate local DST, this might be a simpler way to go than using months and days.
There is a thing called "GPS Weeks".
From Wikipedia (emphasis added) -
http://en.wikipedia.org/wiki/GPS_enhanc ... imekeeping
(So...you might be able to design an algorithm to calculate the important weeks....or just store a table for a few years worth of key week numbers?)As opposed to the year, month, and day format of the Gregorian calendar, the GPS date is expressed as a week number and a seconds-into-week number. The week number was transmitted as a ten-bit field in the C/A and P(Y) navigation messages, and so it became zero again every 1,024 weeks (19.6 years). GPS week zero started at 00:00:00 UTC (00:00:19 TAI) on January 6, 1980, and the week number became zero again for the first time at 23:59:47 UTC on August 21, 1999 (00:00:19 TAI on August 22, 1999). To determine the current Gregorian date, a GPS receiver must be provided with the approximate date (to within 3,584 days) to correctly translate the GPS date signal. To address this concern the modernized GPS navigation message uses a 13-bit field, which only repeats every 8,192 weeks (157 years), thus lasting until the year 2137 (157 years after GPS week zero).
You can find a calendar of GPS Weeks and Days here -
https://www.ngs.noaa.gov/CORS/Gpscal.shtml
To get the current GPS Week from the GPS Module, send this command -
Code: Select all
$PMTK607*33<CR><LF>
The GPS should respond with a sentence which looks similar to this -
Code: Select all
$PMTK707,28,1680,259200,1681,237600,1680,345600,1680,345600*19
The values in that sentence breakdown as follows (copied from PMTK Command Packet) -
http://www.adafruit.com/datasheets/PMTK ... 39-A01.pdf
The LCWN field value should be the current GPS Week. (Might want to experiment and verify this...)Data Field:
PMTK707,Set,FWN,FTOW,LWN,LTOW,FCWN,FCTOW,LCWN,LCTOW
Set: Total number sets of EPO data stored in the GPS chip
FWN & FTOW : GPS week number and TOW of the first set of EPO data stored in chip respectively
LWN & LTOW : GPS week number and TOW of the last set of EPO data stored in chip respectively
FCWN & FCTOW : GPS week number and TOW of the first set of EPO data that are currently used
respectively
LCWN & LCTOW : GPS week number and TOW of the last set of EPO data that are currently used
respectively
GPS weeks begin on Sundays...end on Saturdays.
Since DST starts at 2am on a Sunday and ends at 2am on a Sunday.... as long as you're not too concerned about changing the time exactly at 2am...you can simply check to see if the current week falls between the week just prior to DST in the spring and the week containing the Sunday of time change in the fall. If so...add one hour to your timezone offset used to calculate local time from the GPS' UTC time. (That's "+1", so an offset of -6 hrs would become -5)
For example - This year's DST begins on first day of GPS week 1782 and ends on first day of GPS week 1817.
So, code could look something like this (after getting the current GPS week from GPS) -
Code: Select all
if (GPSweek > 1781 && GPSweek < 1817)
{
use DST Timezone Offset; // Normal offset + 1 hour
}
else
{
use 'normal' Timezone Offset;
}
Make sense? ....I hope
(*The following added primarily for future readers of this thread)
In the U.S., timezone offsets are negative -- Subtracting hours from UTC to get local time.
Timezone // Normal Offset // DST Offset
Eastern // UTC - 5h // UTC - 4h
Central // UTC - 6h // UTC - 5h
Mountain // UTC - 7h // UTC - 6h *n/a for Arizona
Pacific // UTC - 8h // UTC - 7h
Alaska // UTC - 9h // UTC - 8h
** Hawaii does not observe DST
Please be positive and constructive with your questions and comments.