diff --git a/Ejectable/App.tsx b/Ejectable/App.tsx
index 3e1003e9..d06e8d88 100644
--- a/Ejectable/App.tsx
+++ b/Ejectable/App.tsx
@@ -1,16 +1,18 @@
import 'react-native-gesture-handler';
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
-import { Text } from 'react-native';
+import { Alert,Text } from 'react-native';
import * as Location from 'expo-location';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation';
+import { Trips } from './GT2';
+import * as fs from 'fs';
+
export var debug:boolean = false;
-export var lastLoc:any;
var expoGeoState:any;
export default function App() {
@@ -31,14 +33,15 @@ export default function App() {
let location = await Location.getCurrentPositionAsync({});
setLocation(location);
+ if (!errorMsg && location)
+ Trips.deltaLoc(JSON.stringify(location));
})();
}, []);
expoGeoState = 'Waiting..';
if (errorMsg) {
expoGeoState = errorMsg;
- } else if (location) {
- lastLoc = location;
+ } else if (location) {
expoGeoState = JSON.stringify(location);
}
diff --git a/Ejectable/Coordinate.tsx b/Ejectable/Coordinate.tsx
index 2d3d3530..8becb22b 100644
--- a/Ejectable/Coordinate.tsx
+++ b/Ejectable/Coordinate.tsx
@@ -1,8 +1,8 @@
/** Class for handling coordinates original by Linus Helgesson */
export class Coordinate {
- mLatitude:number = 0.0;
- mLongitude:number = 0.0;
+ public mLatitude:number = 0.0;
+ public mLongitude:number = 0.0;
mResults:any = [0, 0];
PI_OVER_180:number = 0.017453292519943295769236907684886;
EARTH_RADIUS:number = 6371009;
diff --git a/Ejectable/GT2.tsx b/Ejectable/GT2.tsx
index 9717edbb..53d7dfbc 100644
--- a/Ejectable/GT2.tsx
+++ b/Ejectable/GT2.tsx
@@ -1,25 +1,26 @@
import * as React from 'react';
import { Coordinate } from "./Coordinate";
import { Text, View } from './components/Themed';
-import { StyleSheet } from 'react-native';
+import { Alert, StyleSheet } from 'react-native';
import { useState, useEffect } from 'react';
const styles = StyleSheet.create({
tripText: {
marginHorizontal: -10,
marginVertical: 60,
- textAlign: 'center',
+ textAlign: 'left',
width: "80%",
fontSize: 12,
fontWeight: 'bold',
}});
-var lastLoc:any = null;
-const heartbeat:number = 500;
+var lastLoc:any = null;
+const heartbeat:number = 500;
+const displayBeat:number = 3;
class Chronometer {
- public display:string = "";
+ public display:string = "00.00.00";
clock:number = 0;
intervalID:any = null;
@@ -38,23 +39,34 @@ class Chronometer {
}
+
export class GT2 {
loc:Coordinate = new Coordinate(0,0);
clock:Chronometer = new Chronometer();
startPoint:Coordinate = new Coordinate(0,0);
- displayInterval:any = null;
- public distance:number = 0.0;
- co2Rate:number = 0.0;
- currTime:number = 0;
- lastTime:number = 0;
- public v:number = 0;
- public inProgress:boolean = false;
- public paused:boolean = false;
- public elapsed:number = 0.0;
- segments:number = 1;
+ displayInterval:number = displayBeat * heartbeat;
+ public distance:number = 0.0;
+ co2Rate:number = 0.0;
+ currTime:number = 0;
+ lastTime:number = 0;
+ z:number = 0.0;
+ public v:number = 0.0;
+ public inProgress:boolean = false;
+ public paused:boolean = false;
+ public elapsed:number = 0.0;
+ segments:number = 0;
+ elevation:number = 0.0;
+ nTrips:number = 0;
+
+ parseGeoExpo(key:string, value:any) {}
+
+ public deltaLoc(lastFix:any) {
+
+
+ }
public reset() {
@@ -75,39 +87,76 @@ export class GT2 {
this.clock.stop();
this.inProgress = false;
+ this.nTrips++;
}
public pause() {
- this.clock.stop();
- this.paused = true;
+ if (!this.paused) {
+ this.clock.stop();
+ this.paused = true;
+ } else {
+ this.clock.start();
+ this.paused = false;
+ }
}
- public resume() {
-
- this.clock.start();
- this.paused = false;
- }
-
public start() {
+ this.reset();
this.clock.start();
this.inProgress = true;
}
+ public getTripPanel() : string {
+
+ if (this.inProgress)
+ return (
+ 'Elapsed - ' + this.clock.display + '\n' +
+ 'Geo: ' + 'lat: ' + this.loc.mLatitude + ' long: ' + this.loc.mLatitude + '\n' +
+ 'Vector: ' + 'distance: ' + this.distance + ' velocity: ' + this.v + '\n' +
+ 'Altitude: ' + this.elevation + '\n');
+ else return("No trip in progress. " + this.nTrips + " trip(s) completed");
+
+ }
+
+}
+
+export class TripDisplay extends React.Component {
+
+ constructor(props:any) {
+ super(props);
+ this.state = { seconds: 0 };
+ }
+
+ interval:any;
+
+ tick() {
+ this.setState(state => ({
+ seconds: 1
+ }));
+ }
+
+ componentDidMount() {
+ this.interval = setInterval(() => this.tick(), Trips.displayInterval);
+ }
+
+ componentWillUnmount() {
+ clearInterval(this.interval);
+ }
+
+ render() {
- public tripDisplay() {
-
return(
- {' No trip started yet.\n'}
+ {Trips.getTripPanel() }
);
}
}
-export var ThisTrip:GT2 = new GT2();
+export var Trips:GT2 = new GT2();
diff --git a/Ejectable/components/ScreenInfo.tsx b/Ejectable/components/ScreenInfo.tsx
index 6c768342..80a2498a 100644
--- a/Ejectable/components/ScreenInfo.tsx
+++ b/Ejectable/components/ScreenInfo.tsx
@@ -13,7 +13,7 @@ export default function ScreenInfo() {
style={styles.settingsText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
- Switch dark km/ light mi, select fuel used, or specify CO2 g per distance
+ {'Switch dark: km, light: mi\nset fuel, or CO2 g per km'}
);
@@ -25,7 +25,7 @@ export function ScreenInfo2() {
style={styles.settingsText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
- Use Pause if fuel burning portion of trip interrupted
+ Pause trip if fuel burning interrupted.
);
diff --git a/Ejectable/screens/TripScreen.tsx b/Ejectable/screens/TripScreen.tsx
index f9aed419..b4dce39f 100644
--- a/Ejectable/screens/TripScreen.tsx
+++ b/Ejectable/screens/TripScreen.tsx
@@ -1,8 +1,9 @@
import * as React from 'react';
-import { Button, StyleSheet, Alert } from 'react-native';
+import { useState } from 'react';
+import { Alert, Button, StyleSheet } from 'react-native';
import { Text, View } from '../components/Themed';
import { ScreenInfo2 } from '../components/ScreenInfo';
-import { ThisTrip } from '../GT2';
+import { TripDisplay, Trips } from '../GT2';
const styles = StyleSheet.create({
container: {
@@ -29,26 +30,35 @@ const styles = StyleSheet.create({
function startTrip() {
- ThisTrip.start();
+ Trips.start();
Alert.alert('Trip Started');
}
function pauseTrip() {
- ThisTrip.pause();
- Alert.alert('Trip Paused');
+ if (!Trips.paused) {
+ Alert.alert('Trip Paused');
+ Trips.pause();
+ }
+ else {
+ Alert.alert('Trip Resumed');
+ Trips.pause();
+ }
}
function endTrip() {
- ThisTrip.end();
+ Trips.end();
Alert.alert('Trip Ended');
}
export default function TripScreen() {
+
+ const [sButtonText, setSButtonText] = useState("Start");
+ const [pButtonText, setPButtonText] = useState("Pause");
return (
@@ -57,19 +67,21 @@ export default function TripScreen() {
- < ThisTrip.tripDisplay />
+
);
diff --git a/Ejectable/tsconfig.json b/Ejectable/tsconfig.json
index b98a13ee..88044a25 100644
--- a/Ejectable/tsconfig.json
+++ b/Ejectable/tsconfig.json
@@ -1,4 +1,4 @@
-{
+{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true