Ejemplo n.º 1
0
var loop = function() {
	if (autoTakePhotoSwitch.isOn() && false == takePhotoInProgress) {
		if (distanceCheckIntervalInSeconds < currentTimestamp() - lastDistanceCheckTimestamp) {
            if (photoDinstanceInKm < distance.getDistance(currentGeolocation.geolocation, lastGeolocation.geolocation, 2) ||
                (false == hasGps && noGpsFallbackPhotoIntervalInSeconds < currentTimestamp() - lastPhotoTimestamp)) {
                takePhoto();
                displayGpsDetails("Capture gps photo.");
            }
            lastDistanceCheckTimestamp = currentTimestamp();
		}
	}

	if(true == takePhotoButton.isPressed() && false == takePhotoInProgress) {
		if (true == takePhotoButtonLastState) {
			setImmediate(loop);
			return;
		}

		takePhotoButtonLastState = true;
        takePhoto(true);
        displayGpsDetails("Capture instant photo.");
	} else {
		takePhotoButtonLastState = false;
	}

    if(true == showOverallInfoScreenButton.isPressed()) {
        if (true == showOverallInfoScreenButtonLastState) {
            setImmediate(loop);
            return;
        }

        showOverallInfoScreenButtonLastState = true;
        displayOverallInfoScreen();
    } else {
        showOverallInfoScreenButtonLastState = false;
    }
  	
	setImmediate(loop);
}
Ejemplo n.º 2
0
 .then(() => (typeof message != "undefined") ? null : OLEDExpr.write(distance.getDistance(currentGeolocation.geolocation, lastGeolocation.geolocation, 2) + "km", 7, 12))
Ejemplo n.º 3
0
function handleRequest(request, response){
    var request = url.parse(request.url, true);
    var action = request.pathname;
    var contentType = "text/html";
    var responseBody = "";
    var autoEnd = true;

    if (-1 != action.indexOf(defaultStorageDir)) {
        responseBody = fs.readFileSync(action);
        contentType = "image/jpeg";
    } else if (action == '/takePhoto') {
        takePhoto(function (lastPhoto) {
            responseBody = fs.readFileSync(lastPhoto);
            contentType = 'image/jpeg';
        });
    } else if (action == '/lastPhoto.jpg' && null != lastPhotoFileName) {
        responseBody = fs.readFileSync(lastPhotoFileName);
        contentType = "image/jpeg";
    } else if (action == '/map') {
        autoEnd = false;
        var parser = parse({delimiter: ','}, function(err, data){
            var features = [];
            var images = [];
            var coordinates = [];
            var allCoordinates = [];
            data.forEach(function(row, index) {
                if (0 < parseFloat(row[0]) && 0 < parseFloat(row[1])) {
                    if (45 < parseFloat(row[0])) {
                        coordinates.push([parseFloat(row[1]), parseFloat(row[0])]);
                        allCoordinates.push([parseFloat(row[1]), parseFloat(row[0])]);
                    } else {
                        coordinates.push([parseFloat(row[0]), parseFloat(row[1])]);
                        allCoordinates.push([parseFloat(row[0]), parseFloat(row[1])]);
                    }
                }

                if (-1 == row[4].indexOf("null")) {
                    images.push(row[4]);
                }

                if (120 == coordinates.length || (10 == images.length && 0 < coordinates.length) || index == data.length) {
                    features.push({
                        name: "Segment" + index,
                        images: JSON.stringify(images),
                        coordinates: JSON.stringify(coordinates)
                    });
                    coordinates = [];
                    images = [];
                }
            });

            var responseData = {
                lastGeolocation: JSON.stringify(allCoordinates.pop()),
                features: features
            };

            var template = fs.readFileSync(mustacheTemplatesDir + "map.html", "utf8");
            response.end(mustache.to_html(template, responseData));
        });

        fs.createReadStream(gpsLogFile).pipe(parser);
    } else if (action == '/') {
        var responseData = {
            currentGeolocation: currentGeolocation,
            lastGeolocation: lastGeolocation,
            lastPhoto: {
                filename: lastPhotoFileName,
                timestamp: lastPhotoTimestamp,
                distance: distance.getDistance(currentGeolocation.geolocation, lastGeolocation.geolocation, 2) * 1000 + " m"
            }
        };

        var template = fs.readFileSync(mustacheTemplatesDir + "index.html", "utf8");
        responseBody = mustache.to_html(template, responseData);
    }

    response.writeHead(200, {'Content-Type': contentType});

    if (true == autoEnd) {
        if (contentType != "text/html") {
            response.end(responseBody, 'binary');
        }
        response.end(responseBody);
    }
}
Ejemplo n.º 4
0
 .then(() => OLEDExpr.write(distance.getDistance(currentGeolocation.geolocation, lastGeolocation.geolocation, 2) * 1000 + " m", 7, 10))