Andrew Boyson / gps

Dependencies:   net lpc1768 crypto clock web log

Committer:
andrewboyson
Date:
Wed May 01 14:08:56 2019 +0000
Revision:
60:7cab896b0fd4
Parent:
59:d2d25c2265f8
Child:
87:5052e316994a
Updated this site's js to use the web common ajax module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 60:7cab896b0fd4 1 "//Home script\n"
andrewboyson 27:eb5728b9052b 2 "'use strict';\n"
andrewboyson 27:eb5728b9052b 3 "\n"
andrewboyson 60:7cab896b0fd4 4 "let pseudo = new Clock();\n"
andrewboyson 60:7cab896b0fd4 5 "let rtc = new Clock();\n"
andrewboyson 60:7cab896b0fd4 6 "\n"
andrewboyson 60:7cab896b0fd4 7 "let pseudoDisplay = false;\n"
andrewboyson 60:7cab896b0fd4 8 "let pseudoStartMs = 0;\n"
andrewboyson 60:7cab896b0fd4 9 "\n"
andrewboyson 60:7cab896b0fd4 10 "let diffMs = 0;\n"
andrewboyson 27:eb5728b9052b 11 "\n"
andrewboyson 60:7cab896b0fd4 12 "let rtcIsSet = false;\n"
andrewboyson 60:7cab896b0fd4 13 "let clockIsSet = false;\n"
andrewboyson 60:7cab896b0fd4 14 "let ppsStable = false;\n"
andrewboyson 60:7cab896b0fd4 15 "let nmeaStable = false;\n"
andrewboyson 60:7cab896b0fd4 16 "let rateIsLocked = false;\n"
andrewboyson 60:7cab896b0fd4 17 "let timeIsLocked = false;\n"
andrewboyson 27:eb5728b9052b 18 "\n"
andrewboyson 60:7cab896b0fd4 19 "const DISPLAY_LEAP_MS = 10000;\n"
andrewboyson 60:7cab896b0fd4 20 "\n"
andrewboyson 60:7cab896b0fd4 21 "function parse()\n"
andrewboyson 27:eb5728b9052b 22 "{\n"
andrewboyson 60:7cab896b0fd4 23 " let lines = Ajax.response.split('\\n');\n"
andrewboyson 60:7cab896b0fd4 24 " rtc.ms = Ajax.date.getTime();\n"
andrewboyson 60:7cab896b0fd4 25 " rtc.ms += parseInt(lines[0], 16);\n"
andrewboyson 60:7cab896b0fd4 26 " rtc.ms -= Ajax.ms;\n"
andrewboyson 60:7cab896b0fd4 27 " diffMs = rtc.ms + Ajax.ms - Date.now();\n"
andrewboyson 60:7cab896b0fd4 28 " rtcIsSet = Ajax.hexToBit(lines[1], 0);\n"
andrewboyson 60:7cab896b0fd4 29 " clockIsSet = Ajax.hexToBit(lines[1], 1);\n"
andrewboyson 60:7cab896b0fd4 30 " ppsStable = Ajax.hexToBit(lines[1], 2);\n"
andrewboyson 60:7cab896b0fd4 31 " nmeaStable = Ajax.hexToBit(lines[1], 3);\n"
andrewboyson 60:7cab896b0fd4 32 " rateIsLocked = Ajax.hexToBit(lines[1], 4);\n"
andrewboyson 60:7cab896b0fd4 33 " timeIsLocked = Ajax.hexToBit(lines[1], 5);\n"
andrewboyson 60:7cab896b0fd4 34 " rtc.leapEnable = Ajax.hexToBit(lines[1], 6);\n"
andrewboyson 60:7cab896b0fd4 35 " rtc.leapForward = Ajax.hexToBit(lines[1], 7);\n"
andrewboyson 60:7cab896b0fd4 36 " rtc.months1970 = parseInt(lines[2], 16);\n"
andrewboyson 60:7cab896b0fd4 37 " rtc.leaps = parseInt(lines[3], 16);\n"
andrewboyson 27:eb5728b9052b 38 "}\n"
andrewboyson 60:7cab896b0fd4 39 "function display()\n"
andrewboyson 27:eb5728b9052b 40 "{\n"
andrewboyson 60:7cab896b0fd4 41 " let elem;\n"
andrewboyson 60:7cab896b0fd4 42 " elem = Ajax.getElementOrNull('ajax-rtc-set' ); if (elem) elem.setAttribute('dir', rtcIsSet ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 43 " elem = Ajax.getElementOrNull('ajax-clock-set' ); if (elem) elem.setAttribute('dir', clockIsSet ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 44 " elem = Ajax.getElementOrNull('ajax-pps-stable' ); if (elem) elem.setAttribute('dir', ppsStable ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 45 " elem = Ajax.getElementOrNull('ajax-nmea-stable' ); if (elem) elem.setAttribute('dir', nmeaStable ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 46 " elem = Ajax.getElementOrNull('ajax-rate-locked' ); if (elem) elem.setAttribute('dir', rateIsLocked ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 47 " elem = Ajax.getElementOrNull('ajax-time-locked' ); if (elem) elem.setAttribute('dir', timeIsLocked ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 48 " \n"
andrewboyson 60:7cab896b0fd4 49 " elem = Ajax.getElementOrNull('ajax-leap-enable' ); if (elem) elem.setAttribute('dir', rtc.leapEnable ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 50 " elem = Ajax.getElementOrNull('ajax-leap-forward' ); if (elem) elem.setAttribute('dir', rtc.leapForward ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 51 " \n"
andrewboyson 60:7cab896b0fd4 52 " elem = Ajax.getElementOrNull('ajax-leap-year' ); if (elem) elem.value = rtc.months1970 ? rtc.leapYear : '';\n"
andrewboyson 60:7cab896b0fd4 53 " elem = Ajax.getElementOrNull('ajax-leap-month' ); if (elem) elem.value = rtc.months1970 ? rtc.leapMonth : '';\n"
andrewboyson 60:7cab896b0fd4 54 " \n"
andrewboyson 60:7cab896b0fd4 55 " elem = Ajax.getElementOrNull('ajax-leap-count' ); if (elem) elem.value = rtc.leaps;\n"
andrewboyson 60:7cab896b0fd4 56 " \n"
andrewboyson 60:7cab896b0fd4 57 " elem = Ajax.getElementOrNull('ajax-date-diff' ); if (elem) elem.textContent = diffMs;\n"
andrewboyson 27:eb5728b9052b 58 "}\n"
andrewboyson 27:eb5728b9052b 59 "\n"
andrewboyson 60:7cab896b0fd4 60 "function handleTick() //This typically called every 100ms\n"
andrewboyson 27:eb5728b9052b 61 "{\n"
andrewboyson 60:7cab896b0fd4 62 " if (pseudoDisplay)\n"
andrewboyson 27:eb5728b9052b 63 " {\n"
andrewboyson 60:7cab896b0fd4 64 " pseudo.adjustLeap (Ajax.ms);\n"
andrewboyson 60:7cab896b0fd4 65 " pseudo.displayTime(Ajax.ms);\n"
andrewboyson 60:7cab896b0fd4 66 " if (Ajax.ms >= pseudoStartMs + DISPLAY_LEAP_MS + 500) pseudoDisplay = false;\n"
andrewboyson 60:7cab896b0fd4 67 " }\n"
andrewboyson 60:7cab896b0fd4 68 " else\n"
andrewboyson 27:eb5728b9052b 69 " {\n"
andrewboyson 60:7cab896b0fd4 70 " rtc.adjustLeap (Ajax.ms);\n"
andrewboyson 60:7cab896b0fd4 71 " rtc.displayTime(Ajax.ms);\n"
andrewboyson 27:eb5728b9052b 72 " }\n"
andrewboyson 27:eb5728b9052b 73 "}\n"
andrewboyson 27:eb5728b9052b 74 "\n"
andrewboyson 60:7cab896b0fd4 75 "function displayLeap() //Called by display leap button in HTML\n"
andrewboyson 27:eb5728b9052b 76 "{\n"
andrewboyson 60:7cab896b0fd4 77 " pseudoDisplay = true;\n"
andrewboyson 60:7cab896b0fd4 78 " pseudoStartMs = Ajax.ms;\n"
andrewboyson 60:7cab896b0fd4 79 " \n"
andrewboyson 60:7cab896b0fd4 80 " pseudo.leapEnable = true;\n"
andrewboyson 60:7cab896b0fd4 81 " pseudo.leapForward = rtc.leapForward;\n"
andrewboyson 60:7cab896b0fd4 82 " pseudo.leaps = rtc.leaps;\n"
andrewboyson 60:7cab896b0fd4 83 " pseudo.leapMonth = rtc.leapMonth;\n"
andrewboyson 60:7cab896b0fd4 84 " pseudo.leapYear = rtc.leapYear;\n"
andrewboyson 60:7cab896b0fd4 85 " pseudo.ms = Date.UTC(rtc.leapYear, rtc.leapMonth - 1, 1) - DISPLAY_LEAP_MS / 2 - Ajax.ms;\n"
andrewboyson 27:eb5728b9052b 86 "}\n"
andrewboyson 60:7cab896b0fd4 87 "Ajax.server = '/home-ajax';\n"
andrewboyson 60:7cab896b0fd4 88 "Ajax.onResponse = function() { parse(); display(); };\n"
andrewboyson 60:7cab896b0fd4 89 "Ajax.onTick = handleTick;\n"
andrewboyson 60:7cab896b0fd4 90 "Ajax.init();\n"
andrewboyson 27:eb5728b9052b 91 "\n"
andrewboyson 34:d9586fc921dc 92 ""