GPS time - format of values

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
billf
 
Posts: 51
Joined: Mon Jun 20, 2011 9:58 am

GPS time - format of values

Post by billf »

I'm working with the Ultimate GPS breakout board and I am using the 'parsing' sketch that came with the GPS library. Well, I started with that and I'm modifying it so I can display the 'local' time on a 7-segment LED display connected via I2C.

I have a 'throw me a fish' / 'teach me to fish' type of question. When I invoke a function like GPS.minute, how do I know what that function returns (that is, it an integer, a character string, etc. ?)

I looked in the parsing sketch, but I did not find a hint there. I'm assuming that this might be defined in the Adafruit_GPS library definition, but when I go there, I see two files: Adafruit.cpp and Adafruit.h

I'm not sure how to browse these types of files.

So please throw me a fish and tell me what is the 'return type' of GPS.minute OR teach me to fish and tell me how I can look that up for myself.

I thank you in advance for your assistance.

User avatar
billf
 
Posts: 51
Joined: Mon Jun 20, 2011 9:58 am

Re: GPS time - format of values

Post by billf »

I was able to get my code to work. It now displays the time (I'm using military or 24-hour display) adjusted for the 4 hour difference in time zones, so I accomplished that, but I still have the broader question of how to I dig deeper (i.e., browse) into library files to learn how they do things?
Attachments
GPSclock.jpg
GPSclock.jpg (397.81 KiB) Viewed 213 times

User avatar
billf
 
Posts: 51
Joined: Mon Jun 20, 2011 9:58 am

Re: GPS time - format of values

Post by billf »

I still have a question: If I see a function like GPS.minute() in a sketch and that function is not defined in the sketch, how do I find where that function is defined? In this case, I'm guessing it might be defined in the Adafruit_GPS library, but I don't know how to view a .cpp or a .h file. In this specific case, I would like to browse the file Adafruit_GPS.cpp or Adafruit_GPS.h

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPS time - format of values

Post by adafruit_support_mike »

In C, you have to do two things to make a function work: declare it, and define it.

A declaration tells the compiler how the function looks from the outside:

Code: Select all

int power( int, int );
That's everything external code needs to know to use the function: its name, what kind of parameters it takes, and the type of value it returns. You can also add hints about what the parameters mean by declaring parameter names:

Code: Select all

int power( int base, int exponent );
but they aren't strictly necessary.

A definition tells the compiler what the function looks like on the inside.. how it processes the input parameters to produce the return value:

Code: Select all

int power( int base, int exponent ) {
	int result = 1;
	
	for ( int i=1 ; i <= exponent ; i++ ) {
		result *= base;
	}
	return( result );
}
In a function definition, the parameter names are mandatory. They tell the compiler where to use which values.

Generally speaking, it's a good idea to put all the declarations in a header (.h) file, and all the definitions in a source (.c, .cpp) file. The compiler doesn't really enforce that though, and there are cases where it makes sense to put some function definitions into a .h file.

Most of the Adafruit libraries are very well behaved in terms of declaration/definition breakdown though. You should be able to see all the declarations for functions a library offers in the .h file, and the definitions that tell the compiler how each function behaves in the .cpp file.

Both kinds of file are plaintext, so you should be able to open and read them with any text editor.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”