Giter Club home page Giter Club logo

speedometer-pwa's Introduction

speedometer-pwa

A tiny no-frills speedometer progressive web app based on Geolocation API, AmbientLightSensor API, and WakeLock API.

test-drive-into-wall

Why?

Because the Combination Meter on my 2005 Prius is on the fritz, and I need a speedometer until I can tear apart and repair the faulty caps. :-)

How it works

The GeoLocation API has a Position interface, which contains a Coordinates object, coords. This Coordinates interface contains not only things you might expect (latitude, longitude), but also contains a property called speed, which is represents the device velocity in meters per second. Fun fact, Chrome on Android returns this prop with very little effort, at which point it's just a matter of some quick math to do the mph/kmh conversion.

Night mode

I implemented AmbientLightSensor API to enable a dark mode while driving at night. To get this working in Chrome on Android you have to enable Generic Sensor extra classes, which is behind a flag: chrome://flags#enable-generic-sensor-extra-classes

20181207-day-night-mode

Screen lock

Since M71, the WakeLock API has been enabled for testing purposes (see the current status on Chrome Platform Status). This ideally allows us to keep the screen from going into power saving mode and generally an off state. I've enabled this (you'll need M71 Chrome for Android) for testing.

Dev

Hop into the src folder and run the local web server of your choice. No specific tool required.

Build

I didn't really wrap this with build tooling, but I did crunch it down to 1.7K gzip'ed for fun using closure compiler and http-minifier. The rest is just some fancy Linux CLI jumping and sed (and I almost just used a make file instead ;-).

$ yarn install
$ yarn dist

FAQ

  1. How accurate is this?

When the dash is working on the Prius, it's pretty accurate from the looks of it. You're going to be constainted on any number of know problems with GPS (e.g., when the Coordinates.accuracy is not very good because of lock or assist issues).

  1. Why didn't you use build tools/a framework/something I like.

Didn't feel the need.

  1. Couldn't you have done this with the Generic Sensors API and the accelerometer?

Yeah, probably.

speedometer-pwa's People

Contributors

justinribeiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

speedometer-pwa's Issues

build issues

$ yarn google-closure-compiler --js=./src/index.js --js_output_file=./dist/index.js --compilation_level=ADVANCED --jscomp_off=checkVars --language_out=ECMASCRIPT_2017
$ /Users/duh/dev/speedometer-pwa/node_modules/.bin/google-closure-compiler --js=./src/index.js --js_output_file=./dist/index.js --compilation_level=ADVANCED --jscomp_off=checkVars --language_out=ECMASCRIPT_2017
./src/index.js:88: WARNING - Property getWakeLock never defined on Navigator
navigator.getWakeLock("screen").then((wakeLock) => {
^^^^^^^^^^^

0 error(s), 1 warning(s), 94.6% typed
$ yarn google-closure-compiler --js=./src/service-worker.js --js_output_file=./dist/service-worker.js --compilation_level=ADVANCED --jscomp_off=checkVars --allow_method_call_decomposing --language_out=ECMASCRIPT_2017
$ /Users/duh/dev/speedometer-pwa/node_modules/.bin/google-closure-compiler --js=./src/service-worker.js --js_output_file=./dist/service-worker.js --compilation_level=ADVANCED --jscomp_off=checkVars --allow_method_call_decomposing --language_out=ECMASCRIPT_2017
./src/service-worker.js:15: WARNING - Property skipWaiting never defined on Window
self.skipWaiting();
^^^^^^^^^^^

0 error(s), 1 warning(s), 53.6% typed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.