// Path: app/src/main/java/eu/basicairdata/graziano/gpslogger/GPSApplication.java
// public static final int NOT_AVAILABLE = -100000;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static eu.basicairdata.graziano.gpslogger.GPSApplication.NOT_AVAILABLE;
import androidx.documentfile.provider.DocumentFile;
import android.net.Uri;
import android.util.Log;
import org.greenrobot.eventbus.EventBus;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
/*
 * EGM96 - Singleton Java Class for Android
 * Created by G.Capelli on 24/4/2016
 * This file is part of BasicAirData GPS Logger
 *
 * Copyright (C) 2011 BasicAirData
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package eu.basicairdata.graziano.gpslogger;






/**
 * The Class that manage the EGM96 Altitude Correction.
 * It loads the geoid heights from the WW15MGH.DAC binary file into a 1440x721 array
 * and uses it to return the altitude correction basing on coordinates.
 */
class EGM96 {

    // ---------------------------------------------------------------------------- Singleton Class
    private static final EGM96 instance = new EGM96();

    private EGM96(){}

    /**
     * The Singleton instance
     */
    public static EGM96 getInstance(){
        return instance;
    }

    // ------------------------------------------------------------------------ Listeners interface
    // Not used
    /*
    public interface EGM96Listener {
        // These methods are the different events and
        // need to pass relevant arguments related to the event triggered
        public void onEGMGridLoaded(boolean isConnected);
    }

    // This variable represents the listener passed in by the owning object
    // The listener must implement the events interface and passes messages up to the parent.
    private EGM96Listener listener;

    // Assign the listener implementing events interface that will receive the events
    public void setBluetoothHelperListener(EGM96Listener listener) {
        this.listener = listener;
    }
    */


    private static final int BOUNDARY = 3; // The grid extensions (in each of the 4 sides) of the real 721 x 1440 grid
    private final short[][] EGMGrid = new short[BOUNDARY + 1440 + BOUNDARY][BOUNDARY + 721 + BOUNDARY];
    private boolean isEGMGridLoaded = false;
    private boolean isEGMGridLoading = false;
    DocumentFile sharedFolder;
    DocumentFile privateFolder;

// Path: app/src/main/java/eu/basicairdata/graziano/gpslogger/GPSApplication.java
// public static final int NOT_AVAILABLE = -100000;


// Path: app/src/main/java/eu/basicairdata/graziano/gpslogger/EGM96.java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static eu.basicairdata.graziano.gpslogger.GPSApplication.NOT_AVAILABLE;
import androidx.documentfile.provider.DocumentFile;
import android.net.Uri;
import android.util.Log;
import org.greenrobot.eventbus.EventBus;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;

/*
 * EGM96 - Singleton Java Class for Android
 * Created by G.Capelli on 24/4/2016
 * This file is part of BasicAirData GPS Logger
 *
 * Copyright (C) 2011 BasicAirData
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package eu.basicairdata.graziano.gpslogger;






/**
 * The Class that manage the EGM96 Altitude Correction.
 * It loads the geoid heights from the WW15MGH.DAC binary file into a 1440x721 array
 * and uses it to return the altitude correction basing on coordinates.
 */
class EGM96 {

    // ---------------------------------------------------------------------------- Singleton Class
    private static final EGM96 instance = new EGM96();

    private EGM96(){}

    /**
     * The Singleton instance
     */
    public static EGM96 getInstance(){
        return instance;
    }

    // ------------------------------------------------------------------------ Listeners interface
    // Not used
    /*
    public interface EGM96Listener {
        // These methods are the different events and
        // need to pass relevant arguments related to the event triggered
        public void onEGMGridLoaded(boolean isConnected);
    }

    // This variable represents the listener passed in by the owning object
    // The listener must implement the events interface and passes messages up to the parent.
    private EGM96Listener listener;

    // Assign the listener implementing events interface that will receive the events
    public void setBluetoothHelperListener(EGM96Listener listener) {
        this.listener = listener;
    }
    */


    private static final int BOUNDARY = 3; // The grid extensions (in each of the 4 sides) of the real 721 x 1440 grid
    private final short[][] EGMGrid = new short[BOUNDARY + 1440 + BOUNDARY][BOUNDARY + 721 + BOUNDARY];
    private boolean isEGMGridLoaded = false;
    private boolean isEGMGridLoading = false;
    DocumentFile sharedFolder;
    DocumentFile privateFolder;

    public static final double EGM96_VALUE_INVALID = NOT_AVAILABLE;