make new widget

28 views
Skip to first unread message

snoo...@gmail.com

unread,
Mar 20, 2021, 8:37:42 PM3/20/21
to GPS Essentials
Hi All 

Love this App 

What I want to do is make a widget that will display a calculated number.

I have a waypoint Name called  'HH:MM:SS'  'which is the time I should arrive' 
I have the target ETA  widget showing  the calculated ETA as follows   'HH:MM:SS'  

So both are numbers, I want to make a widget 'Target ETA - Waypoint Name = 'new widget value'          example 10:20:21 - 10:20:19 =  2    'so new widget value is "2"  

Is this possible..

cheers Phil... 

Michael Schollmeyer

unread,
Mar 23, 2021, 12:16:37 AM3/23/21
to gpsess...@googlegroups.com
You can do this in version 4.4.57 which is is currently in review, it will be available on the Beta test channel soon.

Here is a script that does what you want. Copy everything between but excluding the dashes, open

Settings > Edit Script
Tap on +
Paste the script into the editor
Tap on refresh button (The circular arrows)
Open a dashboard
Tap on +
Tap on "Delta ETA" (If the entry is not there you did something different above)

To use the new widget, tap on it to save the target time and start to navigate. The time is saved across restarts of the app, but the actual value is the current date plus the given time so if you want to use the widget on different days you need to re-enter the time.


---------------------------
// Widget and expression to calculate delta between a manual time and totalEta.
//
var w = new Widget("deltaEta");
w.title = "Delta ETA";
w.description = "The current delta between manual target time and actual ETA";

function formattedTargetTime() {
var t = w.targetTime ? new Date(+w.targetTime) : new Date();
return "" + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
}

w.setDrawListener(function(fmt, value) {
fmt.timeSpan(value, formattedTargetTime());
});

w.setTapListener(function(event) {
var tm = formattedTargetTime();
event.input("Target Time (HH:MM[:SS])", tm, function(hms) {
var a = hms.split(':');
var d = new Date();
d.setHours(+a[0], +a[1], +a[2] || 0);
w.targetTime = d.getTime();
});
})

var deltaEta = new Expression("deltaEta");
deltaEta.setCalculateListener(function(totalEta) {
var e = totalEta.getTime();
var t = new Date(+w.targetTime);
return e == 0 ? undefined : e - t;
});

register(deltaEta, w);

---------------------------

Regards, Michael
mictale.com/ms
--
> --
> You received this message because you are subscribed to the Google Groups "GPS Essentials" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gpsessential...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/gpsessentials/0afe7f80-abbd-4b3d-afe8-7cdc9b2e1cc9n%40googlegroups.com.

snoo...@gmail.com

unread,
Mar 23, 2021, 5:50:57 PM3/23/21
to GPS Essentials

Thank you very much, look forward to the new version

Cheers Phil...
Reply all
Reply to author
Forward
0 new messages