diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-02-09 13:40:29 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-02-09 13:40:29 -0500 |
commit | 108b9991d293eecbd02fa87ea6dea1c239959dc4 (patch) | |
tree | 1916070e548c4261d5f3dd9302488474f3db0134 | |
parent | 79b037b4fb0a3f401406875c281afe2cf0864830 (diff) | |
download | Sensor-Watch-108b9991d293eecbd02fa87ea6dea1c239959dc4.tar.gz Sensor-Watch-108b9991d293eecbd02fa87ea6dea1c239959dc4.tar.bz2 Sensor-Watch-108b9991d293eecbd02fa87ea6dea1c239959dc4.zip |
simulator: add geolocation support
-rw-r--r-- | movement/watch_faces/complication/sunrise_sunset_face.c | 21 | ||||
-rw-r--r-- | watch-library/simulator/shell.html | 29 |
2 files changed, 50 insertions, 0 deletions
diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 1e6f3425..fef9b4df 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -33,6 +33,10 @@ #include "watch_utility.h" #include "sunriset.h" +#if __EMSCRIPTEN__ +#include <emscripten.h> +#endif + static void _sunrise_sunset_set_expiration(sunrise_sunset_state_t *state, watch_date_time next_rise_set) { uint32_t timestamp = watch_utility_date_time_to_unix_time(next_rise_set, 0); state->rise_set_expires = watch_utility_date_time_from_unix_time(timestamp + 60, 0); @@ -279,6 +283,23 @@ void sunrise_sunset_face_setup(movement_settings_t *settings, uint8_t watch_face void sunrise_sunset_face_activate(movement_settings_t *settings, void *context) { (void) settings; if (watch_tick_animation_is_running()) watch_stop_tick_animation(); + +#if __EMSCRIPTEN__ + int16_t browser_lat = EM_ASM_INT({ + return lat; + }); + int16_t browser_lon = EM_ASM_INT({ + return lon; + }); + if ((watch_get_backup_data(1) == 0) && (browser_lat || browser_lon)) { + movement_location_t browser_loc; + browser_loc.bit.latitude = browser_lat; + browser_loc.bit.longitude = browser_lon; + watch_store_backup_data(browser_loc.reg, 1); + } +#endif + + sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context; movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude); diff --git a/watch-library/simulator/shell.html b/watch-library/simulator/shell.html index 1a4de984..2f560aba 100644 --- a/watch-library/simulator/shell.html +++ b/watch-library/simulator/shell.html @@ -321,6 +321,8 @@ <p style="text-align: center;"><a href="https://github.com/alexisphilip/Casio-F-91W">Original F-91W SVG</a> is © 2020 Alexis Philip, and is used here under the terms of the MIT license.</p> </div> +<button onclick="getLocation()">Set location register (will prompt for access)</button> +<br> <textarea id="output" rows="8" style="width: 100%"></textarea> <script type='text/javascript'> @@ -361,6 +363,33 @@ if (text) Module.printErr('[post-exception status] ' + text); }; }; + lat = 0; + lon = 0; + function updateLocation(location) { + lat = Math.round(location.coords.latitude * 100); + lon = Math.round(location.coords.longitude * 100); + } + function showError(error) { + switch(error.code) { + case error.PERMISSION_DENIED: + alert("Permission denied"); + break; + case error.POSITION_UNAVAILABLE: + alert("Location unavailable"); + break; + case error.TIMEOUT: + alert("Request timed out"); + break; + case error.UNKNOWN_ERROR: + alert("Unknown error"); + break; + } + } + function getLocation() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(updateLocation, showError); + } + } </script> {{{ SCRIPT }}} </body> |