Skip to content

Commit

Permalink
Merge pull request #11 from ajayyy/october-sky
Browse files Browse the repository at this point in the history
Run google earth only once per second
  • Loading branch information
ajayyy authored Nov 7, 2020
2 parents 57dfe2c + 4ebee83 commit 4899534
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/uorocketry/basestation/GoogleEarthUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,19 @@ public String generateKMLFile(List<List<DataHandler>> allData, List<Integer> min
* The task is run to force Google Earth to update the display.
*/
public void updateKMLFile(List<List<DataHandler>> allData, List<Integer> minDataIndex, List<Integer> currentDataIndex, JSONArray dataSets, boolean secondRun) {
String fileContent = generateKMLFile(allData, minDataIndex, currentDataIndex, dataSets);

try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(Main.GOOGLE_EARTH_DATA_LOCATION), StandardCharsets.UTF_8))) {
writer.write(fileContent);
} catch (IOException e) {
e.printStackTrace();
}

if (!secondRun) {
if (mapRefreshTaskTimer != null) {
try {
mapRefreshTaskTimer.cancel();
} catch (IllegalStateException e) {
// Ignore if it is already canceled
}
// No need to update again that recently
return;
}

// Start a new task
mapRefreshTaskTimer = new TimerTask() {
@Override
public void run() {
updateKMLFile(allData, minDataIndex, currentDataIndex, dataSets, true);

mapRefreshTaskTimer = null;
}
};
try {
Expand All @@ -134,6 +124,15 @@ public void run() {
// Ignore as another has already started
}
}

String fileContent = generateKMLFile(allData, minDataIndex, currentDataIndex, dataSets);

try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(Main.GOOGLE_EARTH_DATA_LOCATION), StandardCharsets.UTF_8))) {
writer.write(fileContent);
} catch (IOException e) {
e.printStackTrace();
}
}

public String getCoordinateString(DataHandler dataPoint, JSONObject coordinateIndexes) {
Expand Down

0 comments on commit 4899534

Please sign in to comment.