maidenhead implemented in screen

This commit is contained in:
richonguzman 2023-08-08 22:35:47 -04:00
parent bb6f4715fa
commit 1e7bbe9389
3 changed files with 50 additions and 5 deletions

View File

@ -68,8 +68,20 @@ namespace MENU_Utils {
}
}
secondRowMainMenu = utils::createDateString(now()) + " " + utils::createTimeString(now());
const auto time_now = now();
secondRowMainMenu = utils::createDateString(time_now) + " " + utils::createTimeString(time_now);
if (time_now % 10 < 5) {
thirdRowMainMenu = String(gps.location.lat(), 4) + " " + String(gps.location.lng(), 4);
}
else {
thirdRowMainMenu = String(utils::getMaidenheadLocator(gps.location.lat(), gps.location.lng(), 8));
}
for(int i = thirdRowMainMenu.length(); i < 18; i++) {
thirdRowMainMenu += " ";
}
if (gps.hdop.hdop() > 5) {
hdopState = "X";
} else if (gps.hdop.hdop() > 2 && gps.hdop.hdop() < 5) {
@ -77,10 +89,7 @@ namespace MENU_Utils {
} else if (gps.hdop.hdop() <= 2) {
hdopState = "+";
}
thirdRowMainMenu = String(gps.location.lat(), 4) + " " + String(gps.location.lng(), 4);
for(int i = thirdRowMainMenu.length(); i < 18; i++) {
thirdRowMainMenu += " ";
}
if (gps.satellites.value() > 9) {
thirdRowMainMenu += String(gps.satellites.value()) + hdopState;
} else {

View File

@ -14,6 +14,41 @@ extern String versionDate;
namespace utils {
static char locator[11];
// The letterize and getMaidenheadLocator functions are
// Copyright (c) 2021 Mateusz Salwach
// MIT License
static char letterize(int x) {
return (char) x + 65;
}
char *getMaidenheadLocator(double lat, double lon, int size) {
double LON_F[]={20,2.0,0.083333,0.008333,0.0003472083333333333};
double LAT_F[]={10,1.0,0.0416665,0.004166,0.0001735833333333333};
int i;
lon += 180;
lat += 90;
if (size <= 0 || size > 10) size = 6;
size/=2; size*=2;
for (i = 0; i < size/2; i++){
if (i % 2 == 1) {
locator[i*2] = (char) (lon/LON_F[i] + '0');
locator[i*2+1] = (char) (lat/LAT_F[i] + '0');
} else {
locator[i*2] = letterize((int) (lon/LON_F[i]));
locator[i*2+1] = letterize((int) (lat/LAT_F[i]));
}
lon = fmod(lon, LON_F[i]);
lat = fmod(lat, LAT_F[i]);
}
locator[i*2]=0;
return locator;
}
char *ax25_base91enc(char *s, uint8_t n, uint32_t v) {
/* Creates a Base-91 representation of the value in v in the string */
/* pointed to by s, n-characters long. String length should be n+1. */

View File

@ -6,6 +6,7 @@
namespace utils {
char *getMaidenheadLocator(double lat, double lon, int size);
char *ax25_base91enc(char *s, uint8_t n, uint32_t v);
String createDateString(time_t t);
String createTimeString(time_t t);