Skip to content

Commit

Permalink
Merge pull request #454 from justcallmekoko/nmea2
Browse files Browse the repository at this point in the history
Nmea2
  • Loading branch information
justcallmekoko authored Jan 1, 2024
2 parents f98e41d + 6ee3a66 commit 5909158
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 39 deletions.
34 changes: 24 additions & 10 deletions esp32_marauder/GpsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void GpsInterface::enqueue(MicroNMEA& nmea){
if(this->text_in){
int size=text_in->size();
if(size){
#ifdef GPS_TEXT_MAXCOPIES
if(this->text_cycles>=GPS_TEXT_MAXCOPIES){
#ifdef GPS_TEXT_MAXCYCLES
if(this->text_cycles>=GPS_TEXT_MAXCYCLES){
#else
if(this->text_cycles){
#endif
Expand Down Expand Up @@ -158,8 +158,8 @@ void GpsInterface::enqueue(MicroNMEA& nmea){
#else
if(size>=5){
#endif
#ifdef GPS_TEXT_MAXCOPIES
if(this->text_cycles>=GPS_TEXT_MAXCOPIES){
#ifdef GPS_TEXT_MAXCYCLES
if(this->text_cycles>=GPS_TEXT_MAXCYCLES){
#else
if(this->text_cycles){
#endif
Expand Down Expand Up @@ -196,11 +196,25 @@ void GpsInterface::enqueue(MicroNMEA& nmea){
this->notparsed_nmea_sentence = nmea_sentence.c_str();

if(this->queue_enabled_flag){
if(!this->queue) this->new_queue();
if(enqueue){
String enqueue_me=nmea_sentence.c_str();
this->queue->add(enqueue_me);
nmea_sentence_t line = { unparsed, msg_id, nmea_sentence.c_str() };

if(this->queue){
#ifdef GPS_NMEA_MAXQUEUE
if(this->queue->size()>=GPS_NMEA_MAXQUEUE)
#else
if(this->queue->size()>=30)
#endif
this->flush_queue();
}
else
this->new_queue();

this->queue->add(line);
}
else
if(!this->queue)
this->new_queue();
}
else
this->flush_queue();
Expand Down Expand Up @@ -234,12 +248,12 @@ bool GpsInterface::queue_enabled(){
return this->queue_enabled_flag;
}

LinkedList<String>* GpsInterface::get_queue(){
LinkedList<nmea_sentence_t>* GpsInterface::get_queue(){
return this->queue;
}

void GpsInterface::new_queue(){
this->queue=new LinkedList<String>;
this->queue=new LinkedList<nmea_sentence_t>;
}

void GpsInterface::flush_queue(){
Expand All @@ -250,7 +264,7 @@ void GpsInterface::flush_queue(){
void GpsInterface::flush_queue_nmea(){
if(this->queue){
if(this->queue->size()){
LinkedList<String> *delme=this->queue;
LinkedList<nmea_sentence_t> *delme=this->queue;
this->new_queue();
delete delme;
}
Expand Down
28 changes: 24 additions & 4 deletions esp32_marauder/GpsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@
#include "configs.h"

//#define GPS_TEXT_MAXLINES 5 //default:5 lines in the buffer maximum
//#define GPS_TEXT_MAXCOPIES 1 //default:any nonzero number resets, i.e. one copy
//#define GPS_TEXT_MAXCYCLES 1 //default:1

//#define GPS_NMEA_SCRNLINES TEXT_HEIGHT //default: defined TEXT_HEIGHT from configs.h
//#define GPS_NMEA_SCRNWRAP true //default:true, except on MARAUDER_MINI where false
//#define GPS_NMEA_MAXQUEUE 30 //default:30 messages max in queue

#ifdef MARAUDER_MINI
#ifndef GPS_NMEA_SCRNWRAP
#define GPS_NMEA_SCRNWRAP false
#endif
#else
#ifndef GPS_NMEA_SCRNWRAP
#define GPS_NMEA_SCRNWRAP true
#endif
#endif

struct nmea_sentence_t {
bool unparsed;
String type;
String sentence;
};

void gps_nmea_notimp(MicroNMEA& nmea);

Expand Down Expand Up @@ -38,7 +58,7 @@ class GpsInterface {
void setType(String t);

void enqueue(MicroNMEA& nmea);
LinkedList<String>* get_queue();
LinkedList<nmea_sentence_t>* get_queue();
void flush_queue();
void flush_text();
void new_queue();
Expand Down Expand Up @@ -84,9 +104,9 @@ class GpsInterface {
type_t type_flag = GPSTYPE_NATIVE;

bool queue_enabled_flag=0;
LinkedList<String> *queue=NULL;
LinkedList<nmea_sentence_t> *queue=NULL;

int text_cycles=0;
unsigned int text_cycles=0;
LinkedList<String> *text_in=NULL;
LinkedList<String> *text=NULL;

Expand Down
1 change: 1 addition & 0 deletions esp32_marauder/MenuFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,7 @@ void MenuFunctions::RunSetup()
gpsInfoMenu.parentMenu = &deviceMenu;
this->addNodes(&gpsInfoMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
this->changeMenu(gpsInfoMenu.parentMenu);
});
}
Expand Down
110 changes: 85 additions & 25 deletions esp32_marauder/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,55 +1204,103 @@ void WiFiScan::RunGPSInfo() {

void WiFiScan::RunGPSNmea() {
#ifdef HAS_GPS
LinkedList<String> *buffer=gps_obj.get_queue();
LinkedList<nmea_sentence_t> *buffer=gps_obj.get_queue();
bool queue_enabled=gps_obj.queue_enabled();

String gxgga = gps_obj.generateGXgga();
String gxrmc = gps_obj.generateGXrmc();

if(!buffer||!queue_enabled)
gps_obj.flush_queue();
#ifndef HAS_SCREEN
else
gps_obj.flush_text();
#else
// Get screen position ready
display_obj.tft.setTextWrap(true);
int offset=100;
if((SCREEN_HEIGHT / 3)<offset)
offset=SCREEN_HEIGHT/3; //for smaller screens
if(offset<(TOP_FIXED_AREA+6))
offset=TOP_FIXED_AREA+6; //absolute minimium
display_obj.tft.setTextWrap(false);
display_obj.tft.setFreeFont(NULL);
display_obj.tft.setCursor(0, SCREEN_HEIGHT / 3);
display_obj.tft.setCursor(0, offset);
display_obj.tft.setTextSize(1);
display_obj.tft.setTextColor(TFT_CYAN);
display_obj.tft.setTextColor(TFT_GREEN);

// Clean up screen first
display_obj.tft.fillRect(0, (SCREEN_HEIGHT / 3) - 6, SCREEN_WIDTH, SCREEN_HEIGHT - ((SCREEN_HEIGHT / 3) - 6), TFT_BLACK);
display_obj.tft.fillRect(0, offset-6, SCREEN_WIDTH, SCREEN_HEIGHT - (offset-6), TFT_BLACK);

display_obj.tft.setCursor(0, SCREEN_HEIGHT / 3);
#ifdef GPS_NMEA_SCRNLINES
int lines=GPS_NMEA_SCRNLINES;
#else
int lines=TEXT_HEIGHT;
if(lines>((TFT_HEIGHT-offset-BOT_FIXED_AREA)/10))
lines=(TFT_HEIGHT-offset-BOT_FIXED_AREA)/10;
#endif

String text=gps_obj.getText();
if(queue_enabled){
if(gps_obj.getTextQueueSize()>0)
display_obj.tft.print(gps_obj.getTextQueue());
int queue=gps_obj.getTextQueueSize();
if(queue>0){
display_obj.tft.println(gps_obj.getTextQueue());
lines-=queue; //used lines for text display
}
else
if(text != "") display_obj.tft.print(text);
if(text != ""){
display_obj.tft.println(text);
lines--;
}
}
else
if(text != "") display_obj.tft.print(text);
if(text != ""){
display_obj.tft.println(text);
lines--;
}

//This one doesn't contain self-genned GxGGA or GxRMC, nor does it contain GxTXT, processed above
String display_nmea_sentence=gps_obj.getNmeaNotparsed();
#if GPS_NMEA_SCRNWRAP
lines-=((gxgga.length()-1)/STANDARD_FONT_CHAR_LIMIT) + 1;
lines-=((gxrmc.length()-1)/STANDARD_FONT_CHAR_LIMIT) + 1;
display_obj.tft.setTextWrap(GPS_NMEA_SCRNWRAP);
#else
lines-=2; //two self-genned messages
#endif
#endif

if(buffer && queue_enabled){
int size=buffer->size();
if(size){
gps_obj.new_queue();
for(int i=0;i<size;i++){
Serial.println(buffer->get(i));
nmea_sentence_t line=buffer->get(i);
Serial.println(line.sentence);

#ifdef HAS_SCREEN
if(lines>0){
if(line.unparsed){
if(line.type != "" && line.type != "TXT" && line.type != "GGA" && line.type != "RMC"){
int length=line.sentence.length();
if(length){
#if GPS_NMEA_SCRNWRAP
if((((length-1)/STANDARD_FONT_CHAR_LIMIT) + 1)<=lines){
#endif
display_obj.tft.println(line.sentence);
#if GPS_NMEA_SCRNWRAP
lines-=((length-1)/STANDARD_FONT_CHAR_LIMIT) + 1;
#else
lines--;
#endif
#if GPS_NMEA_SCRNWRAP
}
#endif
}
}
}
}
#endif
}
delete buffer;
}

#ifdef HAS_SCREEN
//This matches the else block, but could later display more of the queue...
display_obj.tft.print(display_nmea_sentence);
#endif
} else {
static String old_nmea_sentence="";
String nmea_sentence=gps_obj.getNmeaNotimp();
Expand All @@ -1263,17 +1311,24 @@ void WiFiScan::RunGPSNmea() {
}

#ifdef HAS_SCREEN
display_obj.tft.print(display_nmea_sentence);
if(lines>0){
String display_nmea_sentence=gps_obj.getNmeaNotparsed();
int length=display_nmea_sentence.length();
if(length)
#if GPS_NMEA_SCRNWRAP
if((((length-1)/STANDARD_FONT_CHAR_LIMIT) + 1)<=lines)
#endif
display_obj.tft.println(display_nmea_sentence);
}
#endif
}

String gxgga = gps_obj.generateGXgga();
String gxrmc = gps_obj.generateGXrmc();

#ifdef HAS_SCREEN
display_obj.tft.print(gxgga);
display_obj.tft.print(gxrmc);
display_obj.tft.setTextWrap(false);
display_obj.tft.println(gxgga);
display_obj.tft.println(gxrmc);
#if GPS_NMEA_SCRNWRAP
display_obj.tft.setTextWrap(false);
#endif
#endif

gps_obj.sendSentence(Serial, gxgga.c_str());
Expand Down Expand Up @@ -4770,4 +4825,9 @@ void WiFiScan::main(uint32_t currentTime)
packets_sent = 0;
}
}
#ifdef HAS_GPS
else if ((currentScanMode == WIFI_SCAN_OFF))
if(gps_obj.queue_enabled())
gps_obj.disable_queue();
#endif
}

0 comments on commit 5909158

Please sign in to comment.