Skip to content

Commit

Permalink
Merge pull request #26 from etherkit/v1.3.1
Browse files Browse the repository at this point in the history
V1.3.1
  • Loading branch information
NT7S authored Jul 19, 2021
2 parents a787ff0 + f2c5f5c commit 555d7f8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ Public Methods
*/
```

### latlon_to_grid()
```
/*
* latlon_to_grid(float lat, float lon, char* ret_grid)
*
* Takes a station latitude and longitude provided in decimal degrees format and
* returns a string with the 6-digit Maidenhead grid designator.
*
* lat - Latitude in decimal degrees format.
* lon - Longitude in decimal degrees format.
* ret_grid - Derived Maidenhead grid square. A pointer to a character array of
* at least 7 bytes must be provided here for the function return value.
*
*/
```

Tokens
------
Here are the defines, structs, and enumerations you will find handy to use with the library.
Expand All @@ -277,6 +293,10 @@ Also, a big thank you to Murray Greenman, ZL1BPU for working allowing me to pick

Changelog
---------
* v1.3.1

* Added latitude/longitude to Maidenhead grid convenience function

* v1.3.0

* WSPR Type 2 and Type 3 message capability added
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Etherkit JTEncode
version=1.3.0
version=1.3.1
author=Jason Milldrum <[email protected]>
maintainer=Jason Milldrum <[email protected]>
sentence=Generate JT65, JT9, JT4, FT8, WSPR, and FSQ symbols on your Arduino.
Expand Down
54 changes: 54 additions & 0 deletions src/JTEncode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,60 @@ void JTEncode::ft8_encode(const char * msg, uint8_t * symbols)
ft8_merge_sync_vector(s, symbols);
}

/*
* latlon_to_grid(float lat, float lon, char* ret_grid)
*
* Takes a station latitude and longitude provided in decimal degrees format and
* returns a string with the 6-digit Maidenhead grid designator.
*
* lat - Latitude in decimal degrees format.
* lon - Longitude in decimal degrees format.
* ret_grid - Derived Maidenhead grid square. A pointer to a character array of
* at least 7 bytes must be provided here for the function return value.
*
*/
void JTEncode::latlon_to_grid(float lat, float lon, char* ret_grid)
{
char grid[7];
memset(grid, 0, 7);

// Bounds checks
if(lat < -90.0) {
lat = -90.0;
}
if(lat > 90.0) {
lat = 90.0;
}
if(lon < -180.0) {
lon = -180.0;
}
if(lon > 180.0) {
lon = 180.0;
}

// Normalize lat and lon
lon += 180.0;
lat += 90.0;

// Derive first coordinate pair
grid[0] = (char)((uint8_t)(lon / 20) + 'A');
grid[1] = (char)((uint8_t)(lat / 10) + 'A');

// Derive second coordinate pair
lon = lon - ((uint8_t)(lon / 20) * 20);
lat = lat - ((uint8_t)(lat / 10) * 10);
grid[2] = (char)((uint8_t)(lon / 2) + '0');
grid[3] = (char)((uint8_t)(lat) + '0');

// Derive third coordinate pair
lon = lon - ((uint8_t)(lon / 2) * 2);
lat = lat - ((uint8_t)(lat));
grid[4] = (char)((uint8_t)(lon * 12) + 'a');
grid[5] = (char)((uint8_t)(lat * 24) + 'a');

strncpy(ret_grid, grid, 6);
}

/* Private Class Members */

uint8_t JTEncode::jt_code(char c)
Expand Down
1 change: 1 addition & 0 deletions src/JTEncode.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class JTEncode
void fsq_encode(const char *, const char *, uint8_t *);
void fsq_dir_encode(const char *, const char *, const char, const char *, uint8_t *);
void ft8_encode(const char *, uint8_t *);
void latlon_to_grid(float, float, char*);
private:
uint8_t jt_code(char);
uint8_t ft_code(char);
Expand Down

0 comments on commit 555d7f8

Please sign in to comment.