Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var UI = require('ui');
- var Vector2 = require('vector2');
- //Constants
- var defaultCurrentSpeed = 5;
- var defaultBufferSpeed = 1;
- var main = new UI.Card({
- title: 'Speed Check!',
- body: 'Say Good-Bye to speeding tickets. Press Select',
- });
- main.show();
- //console.log("Before Select");
- main.on('click', 'select', function(e) {
- //console.log("After Select");
- var selectWindow = new UI.Window({
- fullscreen: true,
- });
- var instructions = new UI.Text({
- position: new Vector2(0, 20),
- size: new Vector2(144, 30),
- font: 'gothic-24-bold',
- text: 'Scroll up or down to set speed limit',
- textAlign: 'center'
- });
- var speedValue = new UI.Text({
- position: new Vector2(50, 100),
- size: new Vector2(100, 100),
- font: 'gothic-24-bold',
- text: defaultCurrentSpeed,
- textAlign: 'center'
- });
- selectWindow.add(instructions);
- selectWindow.add(speedValue);
- selectWindow.show();
- selectWindow.on('click', 'up', function(e) {
- speedValue.text(++defaultCurrentSpeed);
- selectWindow.show();
- });
- selectWindow.on('click', 'down', function(e) {
- //add functionality to prevent negative speed limits
- speedValue.text(--defaultCurrentSpeed);
- selectWindow.show();
- });
- selectWindow.on('click','select',function(e){
- //console.log("Select Test Syntax");
- var bufferWindow = new UI.Window({
- fullscreen : true,
- });
- var instructions_2 = new UI.Text({
- position: new Vector2(30, 15),
- size: new Vector2(100, 100),
- font: 'gothic-24-bold',
- text: 'select your buffer speed',
- textAlign: 'center'
- });
- var bufferSpeed = new UI.Text({
- position: new Vector2(50, 100),
- size: new Vector2(100, 100),
- font: 'gothic-24-bold',
- text: defaultBufferSpeed,
- textAlign: 'center'
- });
- bufferWindow.add(bufferSpeed);
- bufferWindow.add(instructions_2);
- bufferWindow.show();
- bufferWindow.on('click', 'up', function(e) {
- bufferSpeed.text(++defaultBufferSpeed);
- bufferWindow.show();
- });
- bufferWindow.on('click', 'down', function(e) {
- if (defaultBufferSpeed > 0) {
- bufferSpeed.text(--defaultBufferSpeed);
- bufferWindow.show();
- }
- });
- //console.log("result pretest");
- bufferWindow.on('click', 'select', function(e) {
- var resultWindow = new UI.Window({
- fullscreen: true,
- });
- var resultText = new UI.Text({
- position: new Vector2(0, 15),
- size: new Vector2(150, 150),
- font: 'gothic-24-bold',
- text: 'Speedr will warn you when you exceed ' + (defaultBufferSpeed + defaultCurrentSpeed) + ' mph',
- textAlign: 'center'
- });
- resultWindow.add(resultText);
- resultWindow.show();
- var currentLat;
- var currentLong;
- var prevLat;
- var prevLong;
- var locationOptions = {
- enableHighAccuracy: true,
- maximumAge: 10000,
- timeout: 1000
- };
- function updateLocation() {
- navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);
- }
- function locationSuccess(pos) {
- currentLat = pos.coords.latitude;
- //console.log(currentLat);
- currentLong = pos.coords.longitude;
- //console.log(currentLong);
- }
- function locationError(err) {
- console.log('location error (' + err.code + '): ' + err.message);
- }
- function distance(lat1, lon1, lat2, lon2) {
- var radlat1 = Math.PI * lat1/180;
- var radlat2 = Math.PI * lat2/180;
- var theta = lon1-lon2;
- var radtheta = Math.PI * theta/180;
- var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
- dist = Math.acos(dist);
- dist = dist * 180/Math.PI;
- dist = dist * 60 * 1.1515;
- //if (unit=="K") { dist = dist * 1.609344; }
- //if (unit=="N") { dist = dist * 0.8684; }
- //console.log(dist);
- return dist;
- }
- /*updateLocation();
- //var currentTime = get the current time
- prevLat = currentLat;
- prevLong = currentLong;
- //resultWindow.on('click', 'down', function(e){
- //break;
- //});
- for(var i = 0; i < 3; i++){
- speedCheck();
- }
- function speedCheck() {
- updateLocation();
- var dist = distance(currentLat, currentLong, prevLat, prevLong);
- var mph = dist * 3600; // divide by time difference;
- if(mph > (defaultCurrentSpeed + defaultBufferSpeed)) {
- var vibe = require('ul/vibe');
- vibe.vibrate('short');
- }
- prevLat = currentLat;
- prevLong = currentLong;
- //console.log("WhileLat" + currentLat);
- //console.log("WhileLong" + currentLong);
- }*/
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement