Dependencies:   1-wire clock crypto fram log lpc1768 net web wiz mbed

Committer:
andrewboyson
Date:
Mon May 10 10:23:48 2021 +0000
Revision:
0:22b158d3c76f
New version as old one would not commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 0:22b158d3c76f 1 //Program script
andrewboyson 0:22b158d3c76f 2 'use strict';
andrewboyson 0:22b158d3c76f 3
andrewboyson 0:22b158d3c76f 4 let programOut = false;
andrewboyson 0:22b158d3c76f 5 let program1 = '';
andrewboyson 0:22b158d3c76f 6 let program2 = '';
andrewboyson 0:22b158d3c76f 7 let program3 = '';
andrewboyson 0:22b158d3c76f 8 let monProgram = 0;
andrewboyson 0:22b158d3c76f 9 let tueProgram = 0;
andrewboyson 0:22b158d3c76f 10 let wedProgram = 0;
andrewboyson 0:22b158d3c76f 11 let thuProgram = 0;
andrewboyson 0:22b158d3c76f 12 let friProgram = 0;
andrewboyson 0:22b158d3c76f 13 let satProgram = 0;
andrewboyson 0:22b158d3c76f 14 let sunProgram = 0;
andrewboyson 0:22b158d3c76f 15 let newDayHour = 0;
andrewboyson 0:22b158d3c76f 16
andrewboyson 0:22b158d3c76f 17 function parseDayPrograms(line)
andrewboyson 0:22b158d3c76f 18 {
andrewboyson 0:22b158d3c76f 19 let fields = line.split(',');
andrewboyson 0:22b158d3c76f 20 monProgram = parseInt(fields[0]) + 1;
andrewboyson 0:22b158d3c76f 21 tueProgram = parseInt(fields[1]) + 1;
andrewboyson 0:22b158d3c76f 22 wedProgram = parseInt(fields[2]) + 1;
andrewboyson 0:22b158d3c76f 23 thuProgram = parseInt(fields[3]) + 1;
andrewboyson 0:22b158d3c76f 24 friProgram = parseInt(fields[4]) + 1;
andrewboyson 0:22b158d3c76f 25 satProgram = parseInt(fields[5]) + 1;
andrewboyson 0:22b158d3c76f 26 sunProgram = parseInt(fields[6]) + 1;
andrewboyson 0:22b158d3c76f 27 }
andrewboyson 0:22b158d3c76f 28 function parse()
andrewboyson 0:22b158d3c76f 29 {
andrewboyson 0:22b158d3c76f 30 let lines = Ajax.response.split('\n');
andrewboyson 0:22b158d3c76f 31 programOut = Ajax.hexToBit(lines[0], 0);
andrewboyson 0:22b158d3c76f 32 newDayHour = Ajax.hexToSignedInt8(lines[1]);
andrewboyson 0:22b158d3c76f 33 parseDayPrograms (lines[2]);
andrewboyson 0:22b158d3c76f 34 program1 = lines[3];
andrewboyson 0:22b158d3c76f 35 program2 = lines[4];
andrewboyson 0:22b158d3c76f 36 program3 = lines[5];
andrewboyson 0:22b158d3c76f 37 }
andrewboyson 0:22b158d3c76f 38 function display()
andrewboyson 0:22b158d3c76f 39 {
andrewboyson 0:22b158d3c76f 40 let elem;
andrewboyson 0:22b158d3c76f 41 elem = Ajax.getElementOrNull('ajax-program-toggle' ); if (elem) elem.setAttribute('dir', programOut ? 'rtl' : 'ltr');
andrewboyson 0:22b158d3c76f 42 elem = Ajax.getElementOrNull('ajax-program-1' ); if (elem) elem.value = program1;
andrewboyson 0:22b158d3c76f 43 elem = Ajax.getElementOrNull('ajax-program-2' ); if (elem) elem.value = program2;
andrewboyson 0:22b158d3c76f 44 elem = Ajax.getElementOrNull('ajax-program-3' ); if (elem) elem.value = program3;
andrewboyson 0:22b158d3c76f 45 elem = Ajax.getElementOrNull('ajax-mon-program' ); if (elem) elem.value = monProgram;
andrewboyson 0:22b158d3c76f 46 elem = Ajax.getElementOrNull('ajax-tue-program' ); if (elem) elem.value = tueProgram;
andrewboyson 0:22b158d3c76f 47 elem = Ajax.getElementOrNull('ajax-wed-program' ); if (elem) elem.value = wedProgram;
andrewboyson 0:22b158d3c76f 48 elem = Ajax.getElementOrNull('ajax-thu-program' ); if (elem) elem.value = thuProgram;
andrewboyson 0:22b158d3c76f 49 elem = Ajax.getElementOrNull('ajax-fri-program' ); if (elem) elem.value = friProgram;
andrewboyson 0:22b158d3c76f 50 elem = Ajax.getElementOrNull('ajax-sat-program' ); if (elem) elem.value = satProgram;
andrewboyson 0:22b158d3c76f 51 elem = Ajax.getElementOrNull('ajax-sun-program' ); if (elem) elem.value = sunProgram;
andrewboyson 0:22b158d3c76f 52 elem = Ajax.getElementOrNull('ajax-new-day-hour' ); if (elem) elem.value = newDayHour;
andrewboyson 0:22b158d3c76f 53 }
andrewboyson 0:22b158d3c76f 54
andrewboyson 0:22b158d3c76f 55 Ajax.server = '/program-ajax';
andrewboyson 0:22b158d3c76f 56 Ajax.onResponse = function() { parse(); display(); };
andrewboyson 0:22b158d3c76f 57 Ajax.init();