This commit is contained in:
Ren Juan 2021-08-26 03:46:39 +00:00
parent c8ffd5b1af
commit 3d92a384db
6 changed files with 61 additions and 44 deletions

View File

@ -12,8 +12,8 @@ import { Trips } from './GT2';
var debug:boolean = false; var debug:boolean = false;
var expoGeoState:any = null; var expoGeoState:any = null;
var advised:boolean = false; var advised:boolean = false;
export function getAdvised() : boolean { return advised; } export function getAdvised() : boolean { return advised; }
export function setAdvised() : void { advised = true; } export function setAdvised() : void { advised = true; }
@ -30,6 +30,7 @@ export default function App() {
let { status } = await Location.requestForegroundPermissionsAsync(); let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') { if (status !== 'granted') {
setErrorMsg('Permission to access location was denied'); setErrorMsg('Permission to access location was denied');
Trips.setLocEnabled(false);
return; return;
} else Trips.setLocEnabled(true); } else Trips.setLocEnabled(true);

View File

@ -4,17 +4,17 @@ 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';
var debug:number = 9; var debug:number = 0;
var testCount = 0; var testCount = 0;
var bgEnabled:boolean = false; var bgEnabled:boolean = false;
var expoGeoState:any = null; var expoGeoState:any = null;
export var locEnabled:boolean = false; 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 geoLibAccuracy = 0.01; const geoLibAccuracy:number = 0.1;
const waitForSettle = 6; /* ticks of initial motion to discard */ const minExpoAccuracy:number = 10;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
tripText: { tripText: {
@ -101,13 +101,12 @@ class Trip {
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, totals:number = 0;
this.ticks += ( 1000 / heartbeat ) ; this.ticks++;
{ /* TODO: guard by actual second discrimination later */ totals = this.ticks * ( heartbeat / 1000 ) ;
hours = this.ticks < 3600 ? 0 : (this.ticks / 3600); hours = totals < 3600 ? 0 : (totals / 3600);
minutes = this.ticks < 60 ? 0 : (this.ticks - (hours * 3600)) / 60; minutes = totals < 60 ? 0 : (totals - (hours * 3600)) / 60;
seconds = this.ticks % 60; seconds = totals % 60;
}
this.elapsed = hours.toFixed(0) + ":" + minutes.toFixed(0) + ":" + seconds.toFixed(0); this.elapsed = hours.toFixed(0) + ":" + minutes.toFixed(0) + ":" + seconds.toFixed(0);
} }
@ -152,25 +151,34 @@ export class GT2 {
m:number = 0.0; m:number = 0.0;
public deltaLoc(lastFix:any) { public deltaLoc(lastFix:any) {
var t:number = 0.0; var t:number = 0.0;
lastFix = JSON.stringify(lastFix); lastFix = JSON.stringify(lastFix);
let expoFix:expoGeoObj = JSON.parse(lastFix); let expoFix:expoGeoObj = JSON.parse(lastFix);
this.trip.loc.set(expoFix.coords['latitude'],expoFix.coords['longitude']); if (debug > 10) {
console.log("lat " + expoFix.coords['latitude'] + " lon " + expoFix.coords['longitude']);
console.log("heading " + expoFix.coords['heading']);
console.log("accuracy " + expoFix.coords['accuracy']);
console.log("speed " + expoFix.coords['speed']);
}
this.trip.loc.set(expoFix.coords['latitude'],expoFix.coords['longitude']);
if (Trips.startPoint.mLatitude == 0.0) if (Trips.startPoint.mLatitude == 0.0)
Trips.startPoint.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); Trips.startPoint.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
t = expoFix.coords['accuracy']; if (t < minExpoAccuracy ) return;
if (this.trip.lastFix.mLatitude == 0.0) if (this.trip.lastFix.mLatitude == 0.0)
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
else else
{if ((this.trip.ticks - this.trip.lastDSFixTick) >= ticksPerDs) { {this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc);
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc); if (debug > 10) console.log('delta ' + this.trip.ds);
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
if (debug > 10) console.log(this.trip.ds);
}
} }
} }
@ -180,6 +188,7 @@ export class GT2 {
this.trip.stop(); this.trip.stop();
this.inProgress = false; this.inProgress = false;
if (this.distance < 250) this.distance = 0;
this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate; this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate;
this.nTrips++; this.nTrips++;

View File

@ -11,14 +11,18 @@ export default function EndScreenInfo({ path }: { path: string }) {
return ( return (
<View> <View>
<View style={styles.getStartedContainer}> <View style={styles.summaryContainer}>
<Text <Text
style={styles.getStartedText}
lightColor="rgba(0,0,0,0.8)" lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
Summary of this trip: Summary of this trip:
</Text> </Text>
<TripSummary/> <TripSummary/>
<Text
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
Min trip is 250 meters.
</Text>
</View> </View>
<View style={styles.helpContainer}> <View style={styles.helpContainer}>
@ -39,31 +43,21 @@ function handleHelpPress() {
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
getStartedContainer: { summaryContainer: {
alignItems: 'center', alignItems: 'center',
marginHorizontal: 50, marginHorizontal: 50,
}, },
homeScreenFilename: {
marginVertical: 7,
},
codeHighlightContainer: {
borderRadius: 3,
paddingHorizontal: 4,
},
getStartedText: {
fontSize: 17,
lineHeight: 24,
textAlign: 'center',
},
helpContainer: { helpContainer: {
marginTop: 15, marginTop: 15,
marginHorizontal: 20, marginHorizontal: 20,
alignItems: 'center', alignItems: 'center',
}, },
helpLink: { helpLink: {
paddingVertical: 15, paddingVertical: 15,
}, },
helpLinkText: { helpLinkText: {
textAlign: 'center', textAlign: 'center',
}, },
}); });

View File

@ -46,6 +46,12 @@ export function ScreenInfo3() {
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
expo version expo version
</Text> </Text>
<Text
style={styles.cautionText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
If getting erratic results, try another device.
</Text>
</View> </View>
); );
} }
@ -76,4 +82,10 @@ const styles = StyleSheet.create({
fontSize: 10, fontSize: 10,
textAlign: 'center', textAlign: 'center',
}, },
cautionText: {
top: 90,
color: 'white',
fontSize: 14,
textAlign: 'center',
},
}); });

View File

@ -7,7 +7,7 @@ import { locEnabled, TripDisplay, Trips } from '../GT2';
import { RootTabScreenProps } from '../types'; import { RootTabScreenProps } from '../types';
import { getAdvised, setAdvised } from './ModalScreen'; import { getAdvised, setAdvised } from './ModalScreen';
var debug:number = 10; var debug:number = 0;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@ -34,10 +34,10 @@ const styles = StyleSheet.create({
function startTrip() { function startTrip() {
/* if (!locEnabled) { if (!locEnabled) {
Alert.alert("Location permission required."); Alert.alert("Location services unavailable can't start trip.");
return; return;
} */ }
Trips.start(); Trips.start();
@ -71,7 +71,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
title={sButtonText} title={sButtonText}
onPress={() => { onPress={() => {
if (!getAdvised()) { if (!getAdvised()) {
Alert.alert("Expo version only tracks while in foreground."); Alert.alert("2.0.0 foreground only, 2.1 first production.");
setAdvised(); setAdvised();
} }
if (!Trips.inProgress) {startTrip(); if (!Trips.inProgress) {startTrip();

View File

@ -1,6 +1,7 @@
{ {
"extends": "expo/tsconfig.base", "extends": "expo/tsconfig.base",
"compilerOptions": { "compilerOptions": {
"suppressImplicitAnyIndexErrors": true,
"strict": true "strict": true
} }
} }