From 1e7bbe93893167d2110842bcea5750cecd368c34 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Tue, 8 Aug 2023 22:35:47 -0400 Subject: [PATCH] maidenhead implemented in screen --- src/menu_utils.cpp | 19 ++++++++++++++----- src/utils.cpp | 35 +++++++++++++++++++++++++++++++++++ src/utils.h | 1 + 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/menu_utils.cpp b/src/menu_utils.cpp index cf4766c..0ab6e65 100644 --- a/src/menu_utils.cpp +++ b/src/menu_utils.cpp @@ -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 { diff --git a/src/utils.cpp b/src/utils.cpp index d6d76d5..7063ec6 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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. */ diff --git a/src/utils.h b/src/utils.h index b235069..af42c80 100644 --- a/src/utils.h +++ b/src/utils.h @@ -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);