diff --git a/Makefile b/Makefile index cb47954..41e0aea 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\" endif CFLAGS=-O2 -g -Wall -W -LIBS=-lm -lSDL2 -lSDL2_ttf -lSDL2_gfx +LIBS=-lm -lSDL2 -lSDL2_ttf -lSDL2_gfx CC=gcc all: view1090 @@ -19,8 +19,8 @@ all: view1090 %.o: %.c $(CC) $(CFLAGS) $(EXTRACFLAGS) -c $< -view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o planeObj.o input.o draw.o font.o init.o mapdata.o status.o list.o parula.o monokai.o allstates.o - $(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o planeObj.o input.o draw.o font.o init.o mapdata.o status.o list.o parula.o monokai.o allstates.o $(LIBS) $(LDFLAGS) +view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o planeObj.o input.o draw.o font.o init.o mapdata.o status.o list.o parula.o monokai.o + $(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o planeObj.o input.o draw.o font.o init.o mapdata.o status.o list.o parula.o monokai.o $(LIBS) $(LDFLAGS) clean: rm -f *.o view1090 diff --git a/README.md b/README.md index a1eacc5..a36c562 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ cd spidr ###HARDWARE +Right now, Pixel 2 is $109 on Amazon (https://www.amazon.com/Google-Pixel-64-Black-Refurbished/dp/B0787V183F). +This significantly outperforms a rpi4. + + best option seems to be pi4 + pijuice zero (w/ rewired i2c) + hyperpixel 4. RTLSDR (stratux) sticks down or needs u shaped adapter. For future tuner, need to test audio phat w/ little speaker, i2c knob, etc. diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..77c2b56 --- /dev/null +++ b/TODO.md @@ -0,0 +1,37 @@ +todo + + + + +UI stuff + +tap on plane sets plane to active + +animated recenter to active + +toggle follow and orient (and other popup info?) +double tap to zoom +animated label show and hide + +draw map to texture and only redraw on move +color themes (requires settings load) +settings (button popups or panes, sliders, etc) +battery level (need separate linux/win/android) + + +Utility stuff +zipped map load (and write from python) --> start by reducing lat/lon precision to 4 or 5 decimal places and change storage to float instead of double +libconfig load settings + +Platforms +migrate Android project into main repo +SDL_AndroidGetJNIEnv() to access parameters, system info, etc +windows + + + + + + + +naming + +viz1090 +map1090 +sdl1090 \ No newline at end of file diff --git a/allstates.c.REMOVED.git-id b/allstates.c.REMOVED.git-id deleted file mode 100644 index 9bbece1..0000000 --- a/allstates.c.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -e1983f2439326aba30a2576504aac03b2f3cd2fc \ No newline at end of file diff --git a/allstates.o.REMOVED.git-id b/allstates.o.REMOVED.git-id deleted file mode 100644 index 76f110e..0000000 --- a/allstates.o.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9bee8f55a87c0c25e624b913e8e728619074d9ee \ No newline at end of file diff --git a/android_notes b/android_notes new file mode 100644 index 0000000..6778a50 --- /dev/null +++ b/android_notes @@ -0,0 +1,21 @@ +Android build notes + +This example works: +https://github.com/pvallet/hello-sdl2-android + +the only JDK that seems to work is oracle-java8-installer, discontinued but available as of 2/18/2020 from +sudo add-apt-repository ppa:ts.sch.gr/ppa +sudo apt-get update +sudo apt-get install oracle-java8-installer +per https://askubuntu.com/questions/1139387/update-to-latest-version-of-java-after-ppa-is-discontinued + +SDL2, SDL2_gfx, SDL2_ttf official need to go in external + +SDL2_gfx official doesn't have Android.mk, but this one does: + +https://github.com/keera-studios/SDL2_gfx + + +App parameters are in android/app/src/main/java/[pvallet/com/github/hellosdl2/helloSDL2Activity.java] (network access, fullscreen immersive mode" +Resources (fonts etc) need to go in android/app/src/main/res +build settings (arch, android version) are in android/AndroidManifest.xml AND android/SDL2/src/main/AndroidManifest.xml (not sure if the second one needs to be changed) \ No newline at end of file diff --git a/draw.c b/draw.c index 5c4f38f..e5a9da0 100644 --- a/draw.c +++ b/draw.c @@ -21,7 +21,7 @@ float sign(float x) { return (x > 0) - (x < 0); } -void CROSSVP(double *v, double *u, double *w) +void CROSSVP(float *v, float *u, float *w) { v[0] = u[1]*w[2] - u[2]*(w)[1]; v[1] = u[2]*w[0] - u[0]*(w)[2]; @@ -69,9 +69,9 @@ SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) { return out; } -SDL_Color hsv2SDLColor(double h, double s, double v) +SDL_Color hsv2SDLColor(float h, float s, float v) { - double hh, p, q, t, ff; + float hh, p, q, t, ff; long i; SDL_Color out; @@ -127,9 +127,9 @@ SDL_Color hsv2SDLColor(double h, double s, double v) return out; } -int screenDist(double d) { +int screenDist(float d) { - double scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; + float scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; if(appData.mapLogDist) { return round(0.95 * scale_factor * 0.5 * log(1.0+fabs(d)) / log(1.0+appData.maxDist)); @@ -138,7 +138,7 @@ int screenDist(double d) { } } -void pxFromLonLat(double *dx, double *dy, double lon, double lat) { +void pxFromLonLat(float *dx, float *dy, float lon, float lat) { if(!lon || !lat) { *dx = 0; *dy = 0; @@ -149,18 +149,18 @@ void pxFromLonLat(double *dx, double *dy, double lon, double lat) { *dy = 6371.0 * (lat - appData.centerLat) * M_PI / 180.0f; } -void latLonFromScreenCoords(double *lat, double *lon, int x, int y) { - double scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; +void latLonFromScreenCoords(float *lat, float *lon, int x, int y) { + float scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; - double dx = appData.maxDist * (x - (appData.screen_width>>1)) / (0.95 * scale_factor * 0.5 ); - double dy = appData.maxDist * (y - (appData.screen_height * CENTEROFFSET)) / (0.95 * scale_factor * 0.5 ); + float dx = appData.maxDist * (x - (appData.screen_width>>1)) / (0.95 * scale_factor * 0.5 ); + float dy = appData.maxDist * (y - (appData.screen_height * CENTEROFFSET)) / (0.95 * scale_factor * 0.5 ); *lat = 180.0f * dy / (6371.0 * M_PI) + appData.centerLat; *lon = 180.0 * dx / (cos(((*lat + appData.centerLat)/2.0f) * M_PI / 180.0f) * 6371.0 * M_PI) + appData.centerLon; } -void screenCoords(int *outX, int *outY, double dx, double dy) { +void screenCoords(int *outX, int *outY, float dx, float dy) { *outX = (appData.screen_width>>1) + ((dx>0) ? 1 : -1) * screenDist(dx); *outY = (appData.screen_height * CENTEROFFSET) + ((dy>0) ? -1 : 1) * screenDist(dy); } @@ -175,7 +175,7 @@ int outOfBounds(int x, int y) { void drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color planeColor) { - double arrowWidth = 6.0 * appData.screen_uiscale; + float arrowWidth = 6.0 * appData.screen_uiscale; float inx = x - (appData.screen_width>>1); float iny = y - appData.screen_height * CENTEROFFSET; @@ -195,15 +195,15 @@ void drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color planeCo // circleRGBA (appData.renderer,(appData.screen_width>>1) + outx, appData.screen_height * CENTEROFFSET + outy,50,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); // thickLineRGBA(appData.renderer,appData.screen_width>>1,appData.screen_height * CENTEROFFSET, (appData.screen_width>>1) + outx, appData.screen_height * CENTEROFFSET + outy,arrowWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); - double inmag = sqrt(inx *inx + iny*iny); - double vec[3]; + float inmag = sqrt(inx *inx + iny*iny); + float vec[3]; vec[0] = inx / inmag; vec[1] = iny /inmag; vec[2] = 0; - double up[] = {0,0,1}; + float up[] = {0,0,1}; - double out[3]; + float out[3]; CROSSVP(out,vec,up); @@ -231,21 +231,21 @@ void drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color planeCo *returny = y3; } -void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor) +void drawPlaneHeading(int x, int y, float heading, SDL_Color planeColor) { - double body = 8.0 * appData.screen_uiscale; - double wing = 6.0 * appData.screen_uiscale; - double tail = 3.0 * appData.screen_uiscale; - double bodyWidth = 2.0 * appData.screen_uiscale; + float body = 8.0 * appData.screen_uiscale; + float wing = 6.0 * appData.screen_uiscale; + float tail = 3.0 * appData.screen_uiscale; + float bodyWidth = 2.0 * appData.screen_uiscale; - double vec[3]; + float vec[3]; vec[0] = sin(heading * M_PI / 180); vec[1] = -cos(heading * M_PI / 180); vec[2] = 0; - double up[] = {0,0,1}; + float up[] = {0,0,1}; - double out[3]; + float out[3]; CROSSVP(out,vec,up); @@ -291,7 +291,7 @@ void drawPlane(int x, int y, SDL_Color planeColor) } -void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSeen, int idx) { +void drawTrail(float *oldDx, float *oldDy, float *oldHeading, time_t * oldSeen, int idx) { int currentIdx, prevIdx; @@ -313,7 +313,7 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee continue; } - double dx, dy; + float dx, dy; pxFromLonLat(&dx, &dy, oldDx[currentIdx], oldDy[currentIdx]); @@ -331,7 +331,7 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee continue; } - double age = pow(1.0 - (double)(now - oldSeen[currentIdx]) / TRAIL_TTL, 2.2); + float age = pow(1.0 - (float)(now - oldSeen[currentIdx]) / TRAIL_TTL, 2.2); if(age < 0) { age = 0; @@ -343,17 +343,17 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee //tick marks - age = 1.0 - (double) 4.0 * (now - oldSeen[currentIdx]) / TRAIL_TTL; + age = 1.0 - (float) 4.0 * (now - oldSeen[currentIdx]) / TRAIL_TTL; colorVal = (uint8_t)floor(255.0 * age); - double vec[3]; + float vec[3]; vec[0] = sin(oldHeading[currentIdx] * M_PI / 180); vec[1] = -cos(oldHeading[currentIdx] * M_PI / 180); vec[2] = 0; - double up[] = {0,0,1}; + float up[] = {0,0,1}; - double out[3]; + float out[3]; CROSSVP(out,vec,up); @@ -425,7 +425,7 @@ void drawScaleBars() // drawString("100km", (appData.screen_width>>1) + (0.707 * p100km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p100km) + 5, appData.mapFont, pink); } -void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, double screen_lon_min, double screen_lon_max) { +void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) { if(tree == NULL) { return; } @@ -462,7 +462,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou drawPolys(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); - double dx, dy; + float dx, dy; // if(!(tree->lat_min > screen_lat_min && // tree->lat_max < screen_lat_max && // tree->lon_min > screen_lon_min && @@ -519,7 +519,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou // } // } - // double alpha = 1.0; + // float alpha = 1.0; // //filledPolygonRGBA (appData.renderer, px, py, i, 0, 0, 0, 255); // polygonRGBA (appData.renderer, px, py, i, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha); @@ -545,7 +545,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou continue; } - double d1 = dx* dx + dy * dy; + float d1 = dx* dx + dy * dy; pxFromLonLat(&dx, &dy, currentPoint->lon, currentPoint->lat); screenCoords(&x2, &y2, dx, dy); @@ -562,9 +562,9 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou continue; } - double d2 = dx* dx + dy * dy; + float d2 = dx* dx + dy * dy; - double factor = 1.0 - (d1+d2) / (3* appData.maxDist * appData.maxDist); + float factor = 1.0 - (d1+d2) / (3* appData.maxDist * appData.maxDist); SDL_Color lineColor = lerpColor(purple, blue, factor); @@ -598,7 +598,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou } void drawGeography() { - double screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max; + float screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max; latLonFromScreenCoords(&screen_lat_min, &screen_lon_min, 0, appData.screen_height * -0.2); latLonFromScreenCoords(&screen_lat_max, &screen_lon_max, appData.screen_width, appData.screen_height * 1.2); @@ -991,7 +991,7 @@ void drawPlanes() { int x, y; - double dx, dy; + float dx, dy; pxFromLonLat(&dx, &dy, p->lon, p->lat); screenCoords(&x, &y, dx, dy); @@ -999,7 +999,7 @@ void drawPlanes() { p->created = mstime(); } - double age_ms = (double)(mstime() - p->created); + float age_ms = (float)(mstime() - p->created); if(age_ms < 500) { circleRGBA(appData.renderer, x, y, 500 - age_ms, 255,255, 255, (uint8_t)(255.0 * age_ms / 500.0)); } else { @@ -1014,8 +1014,8 @@ void drawPlanes() { pxFromLonLat(&dx, &dy, p->oldLon[idx], p->oldLat[idx]); screenCoords(&oldx, &oldy, dx, dy); - double velx = (x - oldx) / (1000.0 * (p->seenLatLon - p->oldSeen[idx])); - double vely = (y - oldy) / (1000.0 * (p->seenLatLon - p->oldSeen[idx])); + float velx = (x - oldx) / (1000.0 * (p->seenLatLon - p->oldSeen[idx])); + float vely = (y - oldy) / (1000.0 * (p->seenLatLon - p->oldSeen[idx])); usex = x + (mstime() - p->msSeenLatLon) * velx; usey = y + (mstime() - p->msSeenLatLon) * vely; diff --git a/draw.o.REMOVED.git-id b/draw.o.REMOVED.git-id index d5e9144..6241175 100644 --- a/draw.o.REMOVED.git-id +++ b/draw.o.REMOVED.git-id @@ -1 +1 @@ -4019e6c1da59af5e54909b8625f116916ed7b2de \ No newline at end of file +7a72d06a00457897159cc7ebf3afff0f1806f3ab \ No newline at end of file diff --git a/font.o b/font.o index 801bef8..3ed6ad0 100644 Binary files a/font.o and b/font.o differ diff --git a/init.o b/init.o index 332a5ab..b477807 100644 Binary files a/init.o and b/init.o differ diff --git a/input.o.REMOVED.git-id b/input.o.REMOVED.git-id index 0b023a1..cf9a1d1 100644 --- a/input.o.REMOVED.git-id +++ b/input.o.REMOVED.git-id @@ -1 +1 @@ -e65446c295519dac23cf6b702c274d4cfb873e7f \ No newline at end of file +7108d34870f6546900fb6d69ee9e1789e1e0a175 \ No newline at end of file diff --git a/list.o b/list.o index 43b9463..713d792 100644 Binary files a/list.o and b/list.o differ diff --git a/map_conversion/README.md b/map_conversion/README.md new file mode 100644 index 0000000..a7cd10f --- /dev/null +++ b/map_conversion/README.md @@ -0,0 +1,21 @@ +Very hacky map pipeline: + +using latlon maps from sourced from http://www.mccurley.org/svg/ + +get all.svg + +run mapconverted.py + +**at this point you have to manually format into a c array and get the length.** + +now compile write2bin +gcc write2bin.c allstates.c -o write2bin + +and run write2bin + +this will produce mapdata.bin that the main program reads in + + +** this should be one python that generates the binary file ** + +** then it should be grabbed from mapbox or something ** diff --git a/map_conversion/a.out.REMOVED.git-id b/map_conversion/a.out.REMOVED.git-id new file mode 100644 index 0000000..8050288 --- /dev/null +++ b/map_conversion/a.out.REMOVED.git-id @@ -0,0 +1 @@ +4a9fe852dcd3e65638b4f5a4f943c0e85c5e2ddb \ No newline at end of file diff --git a/map_conversion/allstates.c.REMOVED.git-id b/map_conversion/allstates.c.REMOVED.git-id new file mode 100644 index 0000000..9558799 --- /dev/null +++ b/map_conversion/allstates.c.REMOVED.git-id @@ -0,0 +1 @@ +a617d7924210634db9b7a5c7323d803d371319df \ No newline at end of file diff --git a/map_conversion/data.REMOVED.git-id b/map_conversion/data.REMOVED.git-id new file mode 100644 index 0000000..1e2b8d3 --- /dev/null +++ b/map_conversion/data.REMOVED.git-id @@ -0,0 +1 @@ +d970486a784f62d0e7072845fb9ba545adb51332 \ No newline at end of file diff --git a/map_conversion/write2bin.c b/map_conversion/write2bin.c new file mode 100644 index 0000000..b26c41d --- /dev/null +++ b/map_conversion/write2bin.c @@ -0,0 +1,12 @@ +// +#include + +extern float mapPoints[3878131]; + +int main(int argc, char **argv) { + FILE *file = fopen("mapdata.bin", "wb"); + fwrite(mapPoints, sizeof(mapPoints), 1, file); + fclose(file); + + return(0); +} diff --git a/mapconversion.xlsx.REMOVED.git-id b/mapconversion.xlsx.REMOVED.git-id deleted file mode 100644 index 989f816..0000000 --- a/mapconversion.xlsx.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -cef8f740e8ef23f03d0d46f43348d73f1ca76c8e \ No newline at end of file diff --git a/mapdata.bin.REMOVED.git-id b/mapdata.bin.REMOVED.git-id new file mode 100644 index 0000000..1e2b8d3 --- /dev/null +++ b/mapdata.bin.REMOVED.git-id @@ -0,0 +1 @@ +d970486a784f62d0e7072845fb9ba545adb51332 \ No newline at end of file diff --git a/mapdata.c b/mapdata.c new file mode 100644 index 0000000..098bf62 --- /dev/null +++ b/mapdata.c @@ -0,0 +1,237 @@ +#include "dump1090.h" +#include "mapdata.h" + +#include + +//sourced from http://www.mccurley.org/svg/ +// +//extern float mapPoints[3878131]; + +bool QTInsert(QuadTree *tree, Polygon* polygon) { + // printf("Inserting %d point poly\n", polygon->numPoints); + + if (!(polygon->lat_min >= tree->lat_min && + polygon->lat_max <= tree->lat_max && + polygon->lon_min >= tree->lon_min && + polygon->lon_max <= tree->lon_max)) { + // printf("doesnt fit: %f > %f, %f < %f, %f < %f,%f > %f \n",polygon->lat_min, tree->lat_min, polygon->lat_max, tree->lat_max, polygon->lon_min, tree->lon_min, polygon->lon_max,tree->lon_max); + + return false; + } + + if (tree->nw == NULL) { + tree->nw = (QuadTree*)malloc(sizeof(QuadTree)); + tree->nw->polygons = NULL; + tree->nw->nw = NULL; + tree->nw->ne = NULL; + tree->nw->sw = NULL; + tree->nw->se = NULL; + + tree->nw->lat_min = tree->lat_min; + tree->nw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); + tree->nw->lon_min = tree->lon_min; + tree->nw->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); + } + + if (QTInsert(tree->nw,polygon)){ + return true; + } + + if (tree->sw == NULL) { + tree->sw = (QuadTree*)malloc(sizeof(QuadTree)); + tree->sw->polygons = NULL; + tree->sw->nw = NULL; + tree->sw->ne = NULL; + tree->sw->sw = NULL; + tree->sw->se = NULL; + + tree->sw->lat_min = tree->lat_min; + tree->sw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); + tree->sw->lon_min = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); + tree->sw->lon_max = tree->lon_max; + } + + if (QTInsert(tree->sw,polygon)){ + return true; + } + + if (tree->ne == NULL) { + tree->ne = (QuadTree*)malloc(sizeof(QuadTree)); + tree->ne->polygons = NULL; + tree->ne->nw = NULL; + tree->ne->ne = NULL; + tree->ne->sw = NULL; + tree->ne->se = NULL; + + tree->ne->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); + tree->ne->lat_max = tree->lat_max; + tree->ne->lon_min = tree->lon_min; + tree->ne->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); + } + + if (QTInsert(tree->ne,polygon)){ + return true; + } + + if (tree->se == NULL) { + tree->se = (QuadTree*)malloc(sizeof(QuadTree)); + tree->se->polygons = NULL; + tree->se->nw = NULL; + tree->se->ne = NULL; + tree->se->sw = NULL; + tree->se->se = NULL; + + tree->se->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); + tree->se->lat_max = tree->lat_max; + tree->se->lon_min = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); + tree->se->lon_max = tree->lon_max; + } + + if (QTInsert(tree->se,polygon)){ + return true; + } + + polygon->next = tree->polygons; + tree->polygons = polygon; + // printf("insert done\n"); + return true; +} + +void initMaps() { + mapPoints_count = sizeof(mapPoints) / sizeof(float); + + + FILE *fileptr; + +fileptr = fopen("mapdata.bin", "rb"); // Open the file in binary mode +fseek(fileptr, 0, SEEK_END); // Jump to the end of the file +mapPoints_count = ftell(fileptr) / sizeof(float); // Get the current byte offset in the file +rewind(fileptr); // Jump back to the beginning of the file + +mapPoints = (float *)malloc(mapPoints_count * sizeof(float)); // Enough memory for the file +fread(mapPoints, sizeof(float), mapPoints_count, fileptr); // Read in the entire file +fclose(fileptr); // Close the fileptr + +printf("%d points read\n",mapPoints_count); + + //mapPoints_relative = (float *) malloc(sizeof(mapPoints)); + + // mapPoints_count = sizeof(mapPoints) / (2 * sizeof(double)); + // mapPoints_x = (double *) malloc(sizeof(mapPoints) / 2); + // mapPoints_y = (double *) malloc(sizeof(mapPoints) / 2); + + // int current = 0; + // for(int i = 0; i < 2 * mapPoints_count; i++) { + // if(mapPoints[i] != 0) { + // if(i%2 == 0) { //longitude points + // double dLon = mapPoints[i] - Modes.fUserLon; + // mapPoints_x[current] = 6371.0 * dLon * M_PI / 180.0 * cos(((mapPoints[i+1] + Modes.fUserLat)/2.0) * M_PI / 180.0); + // } else { //latitude points + // double dLat = mapPoints[i] - Modes.fUserLat; + // mapPoints_y[current] = 6371.0 * dLat * M_PI / 180.0f; + // current++; + // } + // } + // } + + root.lat_min = 180; + root.lon_min = 180; + root.lat_max = -180; + root.lon_max = -180; + + root.nw = NULL; + root.ne = NULL; + root.sw = NULL; + root.se = NULL; + + for(int i = 0; i < mapPoints_count; i+=2) { + if(mapPoints[i] == 0) + continue; + + if(mapPoints[i] < root.lon_min) { + root.lon_min = mapPoints[i]; + } else if(mapPoints[i] > root.lon_max) { + root.lon_max = mapPoints[i]; + } + + if(mapPoints[i+1] < root.lat_min) { + root.lat_min = mapPoints[i+1]; + } else if(mapPoints[i+1] > root.lat_max) { + root.lat_max = mapPoints[i+1]; + } + } + + Polygon *currentPolygon = (Polygon*)malloc(sizeof(Polygon)); + + currentPolygon->lat_min = 180.0; + currentPolygon->lon_min = 180.0; + currentPolygon->lat_max = -180.0; + currentPolygon->lon_max = -180.0; + + currentPolygon->numPoints = 0; + + currentPolygon->points = NULL; + currentPolygon->next = NULL; + + for(int i = 0; i < mapPoints_count; i+=2) { + + if(mapPoints[i] == 0) { //end of polygon + if(currentPolygon->numPoints != 7) + QTInsert(&root, currentPolygon); + + currentPolygon = (Polygon*)malloc(sizeof(Polygon)); + + currentPolygon->lat_min = 180.0; + currentPolygon->lon_min = 180.0; + currentPolygon->lat_max = -180.0; + currentPolygon->lon_max = -180.0; + + currentPolygon->numPoints = 0; + currentPolygon->points = NULL; + currentPolygon->next = NULL; + continue; + } + + currentPolygon->numPoints++; + + Point *currentPoint = (Point*)malloc(sizeof(Point)); + + if(mapPoints[i] < currentPolygon->lon_min) { + currentPolygon->lon_min = mapPoints[i]; + } else if(mapPoints[i] > currentPolygon->lon_max) { + currentPolygon->lon_max = mapPoints[i]; + } + + if(mapPoints[i+1] < currentPolygon->lat_min) { + currentPolygon->lat_min = mapPoints[i+1]; + } else if(mapPoints[i+1] > currentPolygon->lat_max) { + currentPolygon->lat_max = mapPoints[i+1]; + } + + currentPoint->lon = mapPoints[i]; + currentPoint->lat = mapPoints[i+1]; + + currentPoint->next = currentPolygon->points; + currentPolygon->points = currentPoint; + } + + +} + + +// void recenter() { +// for(int i = 0; i < mapPoints_count; i++) { + +// if(mapPoints[i] == 0) { +// mapPoints_relative[i] = 0; +// } else { +// if(i%2 == 0) { //longitude points +// double dLon = mapPoints[i] - Modes.fUserLon; +// mapPoints_relative[i] = 6371.0 * dLon * M_PI / 180.0 * cos(((mapPoints[i+1] + Modes.fUserLat)/2.0) * M_PI / 180.0); +// } else { //latitude points +// double dLat = mapPoints[i] - Modes.fUserLat; +// mapPoints_relative[i] = 6371.0 * dLat * M_PI / 180.0f; +// } +// } +// } +// } \ No newline at end of file diff --git a/mapdata.c.REMOVED.git-id b/mapdata.c.REMOVED.git-id deleted file mode 100644 index baee0a1..0000000 --- a/mapdata.c.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -1420a2ee0d38618a03222daea18788de0178f471 \ No newline at end of file diff --git a/mapdata.h b/mapdata.h index 2dc6d4e..d349a79 100644 --- a/mapdata.h +++ b/mapdata.h @@ -1,22 +1,24 @@ #ifndef MAPPOINTS_H #define MAPPOINTS_H -double *mapPoints_relative; +float *mapPoints_relative; int mapPoints_count; -extern double mapPoints[]; +//extern float mapPoints[]; + +float *mapPoints; typedef struct Point{ - double lat; - double lon; + float lat; + float lon; struct Point *next; } Point; typedef struct Polygon{ - double lat_min; - double lat_max; - double lon_min; - double lon_max; + float lat_min; + float lat_max; + float lon_min; + float lon_max; Point *points; int numPoints; @@ -25,10 +27,10 @@ typedef struct Polygon{ } Polygon; typedef struct QuadTree{ - double lat_min; - double lat_max; - double lon_min; - double lon_max; + float lat_min; + float lat_max; + float lon_min; + float lon_max; Polygon *polygons; diff --git a/mapdata.o b/mapdata.o index 3d33044..723c197 100644 Binary files a/mapdata.o and b/mapdata.o differ diff --git a/monokai.o b/monokai.o index 6f67008..370716e 100644 Binary files a/monokai.o and b/monokai.o differ diff --git a/planeObj.o b/planeObj.o index 56b644e..cf16ab6 100644 Binary files a/planeObj.o and b/planeObj.o differ diff --git a/status.o.REMOVED.git-id b/status.o.REMOVED.git-id index 09792e2..11d6b20 100644 --- a/status.o.REMOVED.git-id +++ b/status.o.REMOVED.git-id @@ -1 +1 @@ -00319fecb996b4196487ff551c1c4fcd04063dcc \ No newline at end of file +bf0a21d45c74ca1ec5086a28d3c765f51ca09193 \ No newline at end of file diff --git a/structs.h b/structs.h index 674d430..0151064 100644 --- a/structs.h +++ b/structs.h @@ -36,8 +36,8 @@ typedef struct AppData int screen_depth; int fullscreen; - double centerLon; - double centerLat; + float centerLon; + float centerLat; uint64_t touchDownTime; int touchx; @@ -68,9 +68,9 @@ struct planeObj { double lat, lon; // Coordinated obtained from CPR encoded data //history - double oldLon[TRAIL_LENGTH]; - double oldLat[TRAIL_LENGTH]; - double oldHeading[TRAIL_LENGTH]; + float oldLon[TRAIL_LENGTH]; + float oldLat[TRAIL_LENGTH]; + float oldHeading[TRAIL_LENGTH]; time_t oldSeen[TRAIL_LENGTH]; uint8_t oldIdx; uint64_t created; @@ -125,7 +125,7 @@ void drawList(int top); //draw.c void draw(); -void latLonFromScreenCoords(double *lat, double *lon, int x, int y); +void latLonFromScreenCoords(float *lat, float *lon, int x, int y); //status.c diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index b424937..63f1aa0 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -c71ae5a169099a989da238f49c409fb014f13fd2 \ No newline at end of file +57081b3b8e95e553e4b5ef8d741befabb4cbbcdd \ No newline at end of file diff --git a/view1090.o.REMOVED.git-id b/view1090.o.REMOVED.git-id index 2e96c58..9094a2b 100644 --- a/view1090.o.REMOVED.git-id +++ b/view1090.o.REMOVED.git-id @@ -1 +1 @@ -71f6442ad1518278cce9fee8235924b9bbe56cc6 \ No newline at end of file +14bceef428bd087e58e4552f6ee11d3afc8586ed \ No newline at end of file