From b45bcab1815c7854266858bff2b650aea4c19bd8 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sat, 19 Aug 2023 16:28:04 +0200 Subject: [PATCH 1/2] astrocalc azimuth fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixes #2651 azimuth value: 0° is south, so add 180° - Show all values in degrees --- apps/astrocalc/ChangeLog | 1 + apps/astrocalc/astrocalc-app.js | 24 +++++++++++++----------- apps/astrocalc/metadata.json | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/astrocalc/ChangeLog b/apps/astrocalc/ChangeLog index 95b9dbaf15..156cf17bf7 100644 --- a/apps/astrocalc/ChangeLog +++ b/apps/astrocalc/ChangeLog @@ -3,3 +3,4 @@ 0.03: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps 0.04: Compatibility with Bangle.js 2, get location from My Location 0.05: Enable widgets +0.06: Fix azimuth (bug #2651), only show degrees diff --git a/apps/astrocalc/astrocalc-app.js b/apps/astrocalc/astrocalc-app.js index 2e732c37a4..21e9a37fff 100644 --- a/apps/astrocalc/astrocalc-app.js +++ b/apps/astrocalc/astrocalc-app.js @@ -140,14 +140,15 @@ function drawData(title, obj, startX, startY) { function drawMoonPositionPage(gps, title) { const pos = SunCalc.getMoonPosition(new Date(), gps.lat, gps.lon); const moonColor = g.theme.dark ? {r: 1, g: 1, b: 1} : {r: 0, g: 0, b: 0}; + const azimuth = pos.azimuth + Math.PI; // 0 is south, we want 0 to be north const pageData = { - Azimuth: pos.azimuth.toFixed(2), - Altitude: pos.altitude.toFixed(2), + Azimuth: parseInt(azimuth * 180 / Math.PI + 0.5) + '°', + Altitude: parseInt(pos.altitude * 180 / Math.PI + 0.5) + '°', Distance: `${pos.distance.toFixed(0)} km`, - "Parallactic Ang": pos.parallacticAngle.toFixed(2), + "Parallactic Ang": parseInt(pos.parallacticAngle * 180 / Math.PI + 0.5) + '°', }; - const azimuthDegrees = parseInt(pos.azimuth * 180 / Math.PI); + const azimuthDegrees = parseInt(azimuth * 180 / Math.PI + 0.5); drawData(title, pageData, null, g.getHeight()/2 - Object.keys(pageData).length/2*20); drawPoints(); @@ -189,12 +190,14 @@ function drawMoonTimesPage(gps, title) { // Draw the moon rise position const risePos = SunCalc.getMoonPosition(times.rise, gps.lat, gps.lon); - const riseAzimuthDegrees = parseInt(risePos.azimuth * 180 / Math.PI); + const riseAzimuth = risePos.azimuth + Math.PI; // 0 is south, we want 0 to be north + const riseAzimuthDegrees = parseInt(riseAzimuth * 180 / Math.PI); drawPoint(riseAzimuthDegrees, 8, moonColor); // Draw the moon set position const setPos = SunCalc.getMoonPosition(times.set, gps.lat, gps.lon); - const setAzimuthDegrees = parseInt(setPos.azimuth * 180 / Math.PI); + const setAzimuth = setPos.azimuth + Math.PI; // 0 is south, we want 0 to be north + const setAzimuthDegrees = parseInt(setAzimuth * 180 / Math.PI); drawPoint(setAzimuthDegrees, 8, moonColor); Bangle.setUI({mode: "custom", back: () => moonIndexPageMenu(gps)}); @@ -207,16 +210,15 @@ function drawSunShowPage(gps, key, date) { const mins = ("0" + date.getMinutes()).substr(-2); const secs = ("0" + date.getMinutes()).substr(-2); const time = `${hrs}:${mins}:${secs}`; + const azimuth = pos.azimuth + Math.PI; // 0 is south, we want 0 to be north - const azimuth = Number(pos.azimuth.toFixed(2)); - const azimuthDegrees = parseInt(pos.azimuth * 180 / Math.PI); - const altitude = Number(pos.altitude.toFixed(2)); + const azimuthDegrees = parseInt(azimuth * 180 / Math.PI + 0.5) + '°'; + const altitude = parseInt(pos.altitude * 180 / Math.PI + 0.5) + '°'; const pageData = { Time: time, Altitude: altitude, - Azimumth: azimuth, - Degrees: azimuthDegrees + Azimuth: azimuthDegrees, }; drawData(key, pageData, null, g.getHeight()/2 - Object.keys(pageData).length/2*20 + 5); diff --git a/apps/astrocalc/metadata.json b/apps/astrocalc/metadata.json index 1f4abb356c..09dc53170d 100644 --- a/apps/astrocalc/metadata.json +++ b/apps/astrocalc/metadata.json @@ -1,10 +1,10 @@ { "id": "astrocalc", "name": "Astrocalc", - "version": "0.05", + "version": "0.06", "description": "Calculates interesting information on the sun like sunset and sunrise and moon cycles for the current day based on your location from MyLocation app", "icon": "astrocalc.png", - "tags": "app,sun,moon,cycles,tool", + "tags": "app,sun,moon,cycles,tool,outdoors", "supports": ["BANGLEJS", "BANGLEJS2"], "allow_emulator": true, "dependencies": {"mylocation":"app"}, From 5947397938afd3c05bfcbef4b2301e6f1a95c815 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sat, 19 Aug 2023 16:32:44 +0200 Subject: [PATCH 2/2] astrocalc encoding --- apps/astrocalc/astrocalc-app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/astrocalc/astrocalc-app.js b/apps/astrocalc/astrocalc-app.js index 21e9a37fff..5589a5703c 100644 --- a/apps/astrocalc/astrocalc-app.js +++ b/apps/astrocalc/astrocalc-app.js @@ -143,10 +143,10 @@ function drawMoonPositionPage(gps, title) { const azimuth = pos.azimuth + Math.PI; // 0 is south, we want 0 to be north const pageData = { - Azimuth: parseInt(azimuth * 180 / Math.PI + 0.5) + '°', - Altitude: parseInt(pos.altitude * 180 / Math.PI + 0.5) + '°', + Azimuth: parseInt(azimuth * 180 / Math.PI + 0.5) + '°', + Altitude: parseInt(pos.altitude * 180 / Math.PI + 0.5) + '°', Distance: `${pos.distance.toFixed(0)} km`, - "Parallactic Ang": parseInt(pos.parallacticAngle * 180 / Math.PI + 0.5) + '°', + "Parallactic Ang": parseInt(pos.parallacticAngle * 180 / Math.PI + 0.5) + '°', }; const azimuthDegrees = parseInt(azimuth * 180 / Math.PI + 0.5); @@ -212,8 +212,8 @@ function drawSunShowPage(gps, key, date) { const time = `${hrs}:${mins}:${secs}`; const azimuth = pos.azimuth + Math.PI; // 0 is south, we want 0 to be north - const azimuthDegrees = parseInt(azimuth * 180 / Math.PI + 0.5) + '°'; - const altitude = parseInt(pos.altitude * 180 / Math.PI + 0.5) + '°'; + const azimuthDegrees = parseInt(azimuth * 180 / Math.PI + 0.5) + '°'; + const altitude = parseInt(pos.altitude * 180 / Math.PI + 0.5) + '°'; const pageData = { Time: time,