This commit is contained in:
Ren Juan 2021-08-23 06:34:16 +00:00
parent fc00582125
commit 31a55ff5f5
6 changed files with 116 additions and 52 deletions

View File

@ -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,6 +33,8 @@ export default function App() {
let location = await Location.getCurrentPositionAsync({});
setLocation(location);
if (!errorMsg && location)
Trips.deltaLoc(JSON.stringify(location));
})();
}, []);
@ -38,7 +42,6 @@ export default function App() {
if (errorMsg) {
expoGeoState = errorMsg;
} else if (location) {
lastLoc = location;
expoGeoState = JSON.stringify(location);
}

View File

@ -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;

View File

@ -1,14 +1,14 @@
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',
@ -16,10 +16,11 @@ const styles = StyleSheet.create({
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;
displayInterval:number = displayBeat * heartbeat;
public distance:number = 0.0;
co2Rate:number = 0.0;
currTime:number = 0;
lastTime:number = 0;
public v: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 = 1;
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() {
if (!this.paused) {
this.clock.stop();
this.paused = true;
}
public resume() {
} else {
this.clock.start();
this.paused = false;
}
}
public start() {
this.reset();
this.clock.start();
this.inProgress = true;
}
public getTripPanel() : string {
public tripDisplay() {
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() {
return(
<View>
<Text style={styles.tripText}>
{' No trip started yet.\n'}
{Trips.getTripPanel() }
</Text>
</View> );
}
}
export var ThisTrip:GT2 = new GT2();
export var Trips:GT2 = new GT2();

View File

@ -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'}
</Text>
</View>
);
@ -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.
</Text>
</View>
);

View File

@ -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,27 +30,36 @@ const styles = StyleSheet.create({
function startTrip() {
ThisTrip.start();
Trips.start();
Alert.alert('Trip Started');
}
function pauseTrip() {
ThisTrip.pause();
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 (
<View style={styles.container}>
<Text style={styles.title}>Trip Control</Text>
@ -57,19 +67,21 @@ export default function TripScreen() {
<ScreenInfo2 />
<View style={styles.controls} >
<Button
title="Start"
onPress={() => startTrip() }
title={sButtonText}
onPress={() => {
if (!Trips.inProgress) {setSButtonText("End");startTrip();}
else {setSButtonText('Start');setPButtonText('Pause');endTrip();}}
}
/>
<Button
title="Pause"
onPress={() => pauseTrip()}
/>
<Button
title="Stop"
onPress={() => endTrip() }
title={pButtonText}
onPress={() => { if (!Trips.inProgress) Alert.alert("No trip in progress!"); else {
if (!Trips.paused) {setPButtonText("Resume");pauseTrip();}
else {setPButtonText('Pause');pauseTrip();}}}
}
/>
</View>
< ThisTrip.tripDisplay />
<TripDisplay></TripDisplay>
</View>
);