GT2 2.0.0
This commit is contained in:
parent
8d83acad60
commit
98870adc75
|
@ -13,6 +13,10 @@ import { Trips } from './GT2';
|
||||||
var debug:boolean = false;
|
var debug:boolean = false;
|
||||||
var expoGeoState:any = null;
|
var expoGeoState:any = null;
|
||||||
|
|
||||||
|
var advised:boolean = false;
|
||||||
|
export function getAdvised() : boolean { return advised; }
|
||||||
|
export function setAdvised() : void { advised = true; }
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const isLoadingComplete = useCachedResources();
|
const isLoadingComplete = useCachedResources();
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = useColorScheme();
|
||||||
|
|
|
@ -3,7 +3,6 @@ import * as Location from 'expo-location';
|
||||||
import { Text, View } from './components/Themed';
|
import { Text, View } from './components/Themed';
|
||||||
import { StyleSheet } from 'react-native';
|
import { StyleSheet } from 'react-native';
|
||||||
import * as geolib from 'geolib';
|
import * as geolib from 'geolib';
|
||||||
import { GeolibInputCoordinates } from 'geolib/es/types';
|
|
||||||
|
|
||||||
var debug:number = 9;
|
var debug:number = 9;
|
||||||
var testCount = 0;
|
var testCount = 0;
|
||||||
|
@ -14,7 +13,8 @@ export var locEnabled:boolean = false;
|
||||||
const heartbeat:number = 500;
|
const heartbeat:number = 500;
|
||||||
const displayBeat:number = 3;
|
const displayBeat:number = 3;
|
||||||
const ticksPerDs = 1;
|
const ticksPerDs = 1;
|
||||||
const geoLibAccuracy = 0.34;
|
const geoLibAccuracy = 0.01;
|
||||||
|
const waitForSettle = 6; /* ticks of initial motion to discard */
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
tripText: {
|
tripText: {
|
||||||
|
@ -39,16 +39,23 @@ interface expoGeoObj {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Coordinate {
|
class Coordinate {
|
||||||
|
|
||||||
public mLatitude:number = 0.0;
|
public mLatitude:number = 0.0;
|
||||||
public mLongitude:number = 0.0;
|
public mLongitude:number = 0.0;
|
||||||
public glCoords:any = {};
|
public glCoords:any = {};
|
||||||
|
|
||||||
constructor (longitude:number, latitude:number) {
|
constructor (latitude:number, longitude:number ) {
|
||||||
this.mLongitude = longitude;
|
this.mLongitude = longitude;
|
||||||
this.mLatitude = latitude;
|
this.mLatitude = latitude;
|
||||||
this,this.get_glcoords();
|
this.get_glcoords();
|
||||||
|
}
|
||||||
|
|
||||||
|
public set(lat:number,lon:number) {
|
||||||
|
this.mLatitude = lat;
|
||||||
|
this.mLongitude = lon;
|
||||||
|
this.get_glcoords();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get_glcoords() {
|
public get_glcoords() {
|
||||||
|
@ -57,11 +64,12 @@ interface expoGeoObj {
|
||||||
}
|
}
|
||||||
|
|
||||||
public distanceTo(otherPoint:Coordinate) : number {
|
public distanceTo(otherPoint:Coordinate) : number {
|
||||||
return geolib.getDistance(this.glCoords,otherPoint.glCoords,geoLibAccuracy);
|
return geolib.getPreciseDistance(this.glCoords,otherPoint.glCoords,geoLibAccuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function startTracking(client:any){
|
async function startTracking(client:any){
|
||||||
if (debug > 5) console.log('Starting tracking')
|
if (debug > 5) console.log('Starting tracking')
|
||||||
if(!client.location){
|
if(!client.location){
|
||||||
|
@ -82,31 +90,35 @@ async function stopTracking(client:any){
|
||||||
|
|
||||||
class Trip {
|
class Trip {
|
||||||
|
|
||||||
public elapsed:string = "00.00.00";
|
public elapsed:string = "00.00.00";
|
||||||
ticks:number = 0;
|
ticks:number = 0;
|
||||||
interval:any;
|
interval:any;
|
||||||
segments:number = 1;
|
segments:number = 1;
|
||||||
ds:number = 0;
|
ds:number = 0;
|
||||||
CO2:number = 0.0;
|
CO2:number = 0.0;
|
||||||
location:any = null;
|
location:any = null;
|
||||||
lastDSFixTick = 0;
|
lastDSFixTick = 0;
|
||||||
lastFix:Coordinate = new Coordinate(0.0,0.0);
|
lastFix:Coordinate = new Coordinate(0.0,0.0);
|
||||||
loc:Coordinate = new Coordinate(0.0,0.0);
|
loc:Coordinate = new Coordinate(0.0,0.0);
|
||||||
|
|
||||||
tick() {let hours:number = 0, minutes:number = 0, seconds:number = 0;
|
tick() {let hours:number = 0, minutes:number = 0, seconds:number = 0;
|
||||||
this.ticks += ( 1000 / heartbeat ) ;
|
this.ticks += ( 1000 / heartbeat ) ;
|
||||||
|
{ /* TODO: guard by actual second discrimination later */
|
||||||
hours = this.ticks < 3600 ? 0 : (this.ticks / 3600);
|
hours = this.ticks < 3600 ? 0 : (this.ticks / 3600);
|
||||||
minutes = this.ticks < 60 ? 0 : (this.ticks - (hours * 3600)) / 60;
|
minutes = this.ticks < 60 ? 0 : (this.ticks - (hours * 3600)) / 60;
|
||||||
seconds = this.ticks % 60;
|
seconds = this.ticks % 60;
|
||||||
this.elapsed = hours.toFixed(0) + ":" + minutes.toFixed(0) + ":" + seconds.toFixed(0);
|
}
|
||||||
}
|
this.elapsed = hours.toFixed(0) + ":" + minutes.toFixed(0) + ":" + seconds.toFixed(0);
|
||||||
|
}
|
||||||
|
|
||||||
public start() { this.interval = setInterval(() => this.tick(), heartbeat);
|
public start() { this.interval = setInterval(() => this.tick(), heartbeat);
|
||||||
if (!bgEnabled) startTracking(this);
|
if (!bgEnabled) startTracking(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public resume() { this.lastFix.mLatitude = 0.0;
|
public resume() { this.lastFix.mLatitude = 0.0;
|
||||||
this.segments++;
|
this.segments++;
|
||||||
this.interval = setInterval(() => this.tick(), heartbeat); }
|
this.interval = setInterval(() => this.tick(), heartbeat); }
|
||||||
|
|
||||||
public stop() { Trips.distance += this.ds;
|
public stop() { Trips.distance += this.ds;
|
||||||
this.ds = 0.0;
|
this.ds = 0.0;
|
||||||
clearInterval(this.interval);
|
clearInterval(this.interval);
|
||||||
|
@ -141,54 +153,34 @@ export class GT2 {
|
||||||
|
|
||||||
public deltaLoc(lastFix:any) {
|
public deltaLoc(lastFix:any) {
|
||||||
|
|
||||||
lastFix = JSON.stringify(lastFix);
|
var t:number = 0.0;
|
||||||
|
lastFix = JSON.stringify(lastFix);
|
||||||
let expoFix:expoGeoObj = JSON.parse(lastFix);
|
let expoFix:expoGeoObj = JSON.parse(lastFix);
|
||||||
|
|
||||||
if (testCount < 1) {
|
this.trip.loc.set(expoFix.coords['latitude'],expoFix.coords['longitude']);
|
||||||
var n:number = -1;
|
|
||||||
|
if (Trips.startPoint.mLatitude == 0.0)
|
||||||
var nyc:Coordinate = new Coordinate ( 40.7128 , 74.0060 );
|
Trips.startPoint.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
|
||||||
var ord:Coordinate = new Coordinate ( 41.8781 , 87.6298);
|
|
||||||
|
if (this.trip.lastFix.mLatitude == 0.0)
|
||||||
n = nyc.distanceTo(ord);
|
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
|
||||||
|
else
|
||||||
console.log('nyc ord ' + n);
|
{if ((this.trip.ticks - this.trip.lastDSFixTick) >= ticksPerDs) {
|
||||||
testCount++;
|
|
||||||
|
this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc);
|
||||||
}
|
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
|
||||||
|
if (debug > 10) console.log(this.trip.ds);
|
||||||
this.trip.loc.mLongitude = expoFix.coords['longitude'];
|
}
|
||||||
this.trip.loc.mLatitude = expoFix.coords['latitude'];
|
|
||||||
this.trip.loc.get_glcoords();
|
|
||||||
|
|
||||||
if (Trips.startPoint.mLatitude == 0.0) {
|
|
||||||
Trips.startPoint.mLatitude = this.trip.loc.mLatitude;
|
|
||||||
Trips.startPoint.mLongitude = this.trip.loc.mLongitude;
|
|
||||||
this.trip.loc.get_glcoords();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.trip.lastFix.mLatitude != 0.0) {
|
|
||||||
if ((this.trip.ticks - this.trip.lastDSFixTick) >= ticksPerDs) {
|
|
||||||
this.trip.lastDSFixTick = this.trip.ticks;
|
|
||||||
this.trip.lastFix.mLatitude = this.trip.loc.mLatitude;
|
|
||||||
this.trip.lastFix.mLatitude = this.trip.loc.mLatitude;
|
|
||||||
this.trip.loc.get_glcoords();
|
|
||||||
this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc);
|
|
||||||
if (debug > 8) console.log(this.trip.ds);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.trip.lastFix.mLatitude = this.trip.loc.mLatitude;
|
|
||||||
this.trip.lastFix.mLatitude = this.trip.loc.mLatitude;
|
|
||||||
this.trip.loc.get_glcoords();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public end() {
|
public end() {
|
||||||
|
|
||||||
|
|
||||||
this.trip.stop();
|
this.trip.stop();
|
||||||
this.inProgress = false;
|
this.inProgress = false;
|
||||||
|
this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate;
|
||||||
this.nTrips++;
|
this.nTrips++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -241,21 +233,23 @@ export class GT2 {
|
||||||
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
|
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
|
||||||
'Destination: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
|
'Destination: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
|
||||||
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
|
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
|
||||||
'CO2: ' + this.trip.CO2 + ' grams ' + this.CO2Effect + '\n\n' +
|
'CO2: ' + this.trip.CO2.toFixed(1) + ' grams ' + this.CO2Effect + '\n\n' +
|
||||||
'Distance covered while consuming fuel: ' + preferredUnits.toFixed(4) + ' ' + this.units );
|
'Distance covered while consuming fuel: ' + preferredUnits.toFixed(2) + ' ' + this.units );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTripPanel() : string {
|
public getTripPanel() : string {
|
||||||
|
|
||||||
var bigDS:number = this.distance + this.trip.ds;
|
var bigDS:number = this.distance + this.trip.ds;
|
||||||
|
var seconds:number = this.trip.ticks;
|
||||||
|
|
||||||
if (this.inProgress) {
|
if (this.inProgress) {
|
||||||
|
this.v = this.trip.ds / seconds;
|
||||||
return (
|
return (
|
||||||
'Elapsed - ' + this.trip.elapsed + '\n' +
|
'Elapsed - ' + this.trip.elapsed + '\n' +
|
||||||
'Geo: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
|
'Geo: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
|
||||||
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
|
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
|
||||||
'Vector: ' + 'distance: ' + bigDS.toFixed(4) + ' velocity: ' + this.v + 'm/s \n' +
|
'Vector: ' + 'distance: ' + bigDS.toFixed(2) + ' meters, velocity: ' + this.v.toFixed(1) + ' m/s \n' +
|
||||||
'Altitude: ' + this.elevation + '\n');
|
'Altitude: ' + this.elevation + '\n');
|
||||||
}
|
}
|
||||||
else return("No trip in progress. " + this.nTrips + " trip(s) completed.");
|
else return("No trip in progress. " + this.nTrips + " trip(s) completed.");
|
||||||
|
|
|
@ -6,6 +6,10 @@ import EndScreenInfo from '../components/EndScreenInfo';
|
||||||
import { Text, View } from '../components/Themed';
|
import { Text, View } from '../components/Themed';
|
||||||
import { RootTabScreenProps } from '../types';
|
import { RootTabScreenProps } from '../types';
|
||||||
|
|
||||||
|
var advised:boolean = false;
|
||||||
|
export function getAdvised() : boolean { return advised; }
|
||||||
|
export function setAdvised() : void { advised = true; }
|
||||||
|
|
||||||
export default function ModalScreen({ navigation }: RootTabScreenProps<'Settings'>) {
|
export default function ModalScreen({ navigation }: RootTabScreenProps<'Settings'>) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { Alert, Button, StyleSheet, Switch, TextInput } from 'react-native';
|
||||||
import { Text, View } from '../components/Themed';
|
import { Text, View } from '../components/Themed';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import ScreenInfo from '../components/ScreenInfo';
|
import ScreenInfo from '../components/ScreenInfo';
|
||||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
||||||
import { Trips } from '../GT2';
|
import { Trips } from '../GT2';
|
||||||
import { RootTabScreenProps } from '../types';
|
import { RootTabScreenProps } from '../types';
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import { Text, View } from '../components/Themed';
|
||||||
import { ScreenInfo2 } from '../components/ScreenInfo';
|
import { ScreenInfo2 } from '../components/ScreenInfo';
|
||||||
import { locEnabled, TripDisplay, Trips } from '../GT2';
|
import { locEnabled, TripDisplay, Trips } from '../GT2';
|
||||||
import { RootTabScreenProps } from '../types';
|
import { RootTabScreenProps } from '../types';
|
||||||
|
import { getAdvised, setAdvised } from './ModalScreen';
|
||||||
|
|
||||||
var advised:boolean = false;
|
|
||||||
var debug:number = 10;
|
var debug:number = 10;
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
@ -70,9 +70,9 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
|
||||||
<Button
|
<Button
|
||||||
title={sButtonText}
|
title={sButtonText}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (!advised) {
|
if (!getAdvised()) {
|
||||||
Alert.alert("2.1.0 and later will use background tracking.");
|
Alert.alert("Expo version only tracks while in foreground.");
|
||||||
advised = true;
|
setAdvised();
|
||||||
}
|
}
|
||||||
if (!Trips.inProgress) {startTrip();
|
if (!Trips.inProgress) {startTrip();
|
||||||
if (Trips.inProgress) { setSButtonText("End"); setPButtonText('Pause');}}
|
if (Trips.inProgress) { setSButtonText("End"); setPButtonText('Pause');}}
|
||||||
|
|
Loading…
Reference in New Issue