diff --git a/Ejectable/App.tsx b/Ejectable/App.tsx index 23cd68ec..f06ee32f 100644 --- a/Ejectable/App.tsx +++ b/Ejectable/App.tsx @@ -12,8 +12,8 @@ import { Trips } from './GT2'; var debug:boolean = false; var expoGeoState:any = null; - var advised:boolean = false; + export function getAdvised() : boolean { return advised; } export function setAdvised() : void { advised = true; } @@ -30,6 +30,7 @@ export default function App() { let { status } = await Location.requestForegroundPermissionsAsync(); if (status !== 'granted') { setErrorMsg('Permission to access location was denied'); + Trips.setLocEnabled(false); return; } else Trips.setLocEnabled(true); diff --git a/Ejectable/GT2.tsx b/Ejectable/GT2.tsx index 644fdb05..e6ecb66b 100644 --- a/Ejectable/GT2.tsx +++ b/Ejectable/GT2.tsx @@ -4,17 +4,17 @@ import { Text, View } from './components/Themed'; import { StyleSheet } from 'react-native'; import * as geolib from 'geolib'; - var debug:number = 9; + var debug:number = 0; var testCount = 0; var bgEnabled:boolean = false; var expoGeoState:any = null; export var locEnabled:boolean = false; const heartbeat:number = 500; - const displayBeat:number = 3; - const ticksPerDs = 1; - const geoLibAccuracy = 0.01; - const waitForSettle = 6; /* ticks of initial motion to discard */ + const displayBeat:number = 3; + + const geoLibAccuracy:number = 0.1; + const minExpoAccuracy:number = 10; const styles = StyleSheet.create({ tripText: { @@ -101,13 +101,12 @@ class Trip { lastFix: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; - this.ticks += ( 1000 / heartbeat ) ; - { /* TODO: guard by actual second discrimination later */ - hours = this.ticks < 3600 ? 0 : (this.ticks / 3600); - minutes = this.ticks < 60 ? 0 : (this.ticks - (hours * 3600)) / 60; - seconds = this.ticks % 60; - } + tick() {let hours:number = 0, minutes:number = 0, seconds:number = 0, totals:number = 0; + this.ticks++; + totals = this.ticks * ( heartbeat / 1000 ) ; + hours = totals < 3600 ? 0 : (totals / 3600); + minutes = totals < 60 ? 0 : (totals - (hours * 3600)) / 60; + seconds = totals % 60; this.elapsed = hours.toFixed(0) + ":" + minutes.toFixed(0) + ":" + seconds.toFixed(0); } @@ -152,25 +151,34 @@ export class GT2 { m:number = 0.0; public deltaLoc(lastFix:any) { - + var t:number = 0.0; lastFix = JSON.stringify(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) 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) this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); 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); - if (debug > 10) console.log(this.trip.ds); - } + {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('delta ' + this.trip.ds); + } } @@ -180,6 +188,7 @@ export class GT2 { this.trip.stop(); this.inProgress = false; + if (this.distance < 250) this.distance = 0; this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate; this.nTrips++; diff --git a/Ejectable/components/EndScreenInfo.tsx b/Ejectable/components/EndScreenInfo.tsx index d3482db4..336a9a78 100644 --- a/Ejectable/components/EndScreenInfo.tsx +++ b/Ejectable/components/EndScreenInfo.tsx @@ -11,14 +11,18 @@ export default function EndScreenInfo({ path }: { path: string }) { return ( - + Summary of this trip: + + Min trip is 250 meters. + @@ -39,31 +43,21 @@ function handleHelpPress() { } const styles = StyleSheet.create({ - getStartedContainer: { + summaryContainer: { alignItems: 'center', marginHorizontal: 50, }, - homeScreenFilename: { - marginVertical: 7, - }, - codeHighlightContainer: { - borderRadius: 3, - paddingHorizontal: 4, - }, - getStartedText: { - fontSize: 17, - lineHeight: 24, - textAlign: 'center', - }, helpContainer: { marginTop: 15, marginHorizontal: 20, alignItems: 'center', - }, - helpLink: { + }, + helpLink: { paddingVertical: 15, }, helpLinkText: { textAlign: 'center', }, + + }); diff --git a/Ejectable/components/ScreenInfo.tsx b/Ejectable/components/ScreenInfo.tsx index 80a2498a..0d7a2f30 100644 --- a/Ejectable/components/ScreenInfo.tsx +++ b/Ejectable/components/ScreenInfo.tsx @@ -46,6 +46,12 @@ export function ScreenInfo3() { darkColor="rgba(255,255,255,0.8)"> expo version + + If getting erratic results, try another device. + ); } @@ -76,4 +82,10 @@ const styles = StyleSheet.create({ fontSize: 10, textAlign: 'center', }, + cautionText: { + top: 90, + color: 'white', + fontSize: 14, + textAlign: 'center', + }, }); diff --git a/Ejectable/screens/TripScreen.tsx b/Ejectable/screens/TripScreen.tsx index 90d8e72f..d724de0d 100644 --- a/Ejectable/screens/TripScreen.tsx +++ b/Ejectable/screens/TripScreen.tsx @@ -7,7 +7,7 @@ import { locEnabled, TripDisplay, Trips } from '../GT2'; import { RootTabScreenProps } from '../types'; import { getAdvised, setAdvised } from './ModalScreen'; -var debug:number = 10; +var debug:number = 0; const styles = StyleSheet.create({ container: { @@ -34,10 +34,10 @@ const styles = StyleSheet.create({ function startTrip() { - /* if (!locEnabled) { - Alert.alert("Location permission required."); + if (!locEnabled) { + Alert.alert("Location services unavailable can't start trip."); return; - } */ + } Trips.start(); @@ -71,7 +71,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>) title={sButtonText} onPress={() => { if (!getAdvised()) { - Alert.alert("Expo version only tracks while in foreground."); + Alert.alert("2.0.0 foreground only, 2.1 first production."); setAdvised(); } if (!Trips.inProgress) {startTrip(); diff --git a/Ejectable/tsconfig.json b/Ejectable/tsconfig.json index 67e95e4c..99d561d4 100644 --- a/Ejectable/tsconfig.json +++ b/Ejectable/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "expo/tsconfig.base", "compilerOptions": { + "suppressImplicitAnyIndexErrors": true, "strict": true } }