-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgauges.js
4348 lines (3952 loc) · 202 KB
/
gauges.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* A starter gauges page for Cumulus and Weather Display, based
* on the JavaScript SteelSeries gauges by Gerrit Grunwald.
*
* Created by Mark Crossley, July 2011
* see scriptVer below for latest release
*
* Last Updated: 2023/09/01 16:44:34
*
* Released under GNU GENERAL PUBLIC LICENSE, Version 2, June 1991
* See the enclosed License file
*
* File encoding = UTF-8
*
*/
/* exported gauges */
/*!
* Tiny Pub/Sub - v0.7.0 - 2013-01-29
* https://github.com/cowboy/jquery-tiny-pubsub
* Copyright (c) 2013 "Cowboy" Ben Alman; Licensed MIT
*/
(function ($) {
'use strict';
var o = $({});
$.subscribe = function () {o.on.apply(o, arguments);};
$.unsubscribe = function () {o.off.apply(o, arguments);};
$.publish = function () {o.trigger.apply(o, arguments);};
}(jQuery));
var gauges;
gauges = (function () {
'use strict';
var strings = LANG.EN, // Set to your default language. Store all the strings in one object
config = {
// Script configuration parameters you may want to 'tweak'
scriptVer : '2.7.7',
weatherProgram : 0, // Set 0=Cumulus, 1=Weather Display, 2=VWS, 3=WeatherCat, 4=Meteobridge, 5=WView, 6=WeeWX, 7=WLCOM
imgPathURL : './images/', // *** Change this to the relative path for your 'Trend' graph images
oldGauges : 'gauges.htm', // *** Change this to the relative path for your 'old' gauges page.
realtimeInterval : 15, // *** Download data interval, set to your realtime data update interval in seconds
longPoll : false, // if enabled, use long polling and PHP generated data !!only enable if you understand how this is implemented!!
gaugeMobileScaling : 0.85, // scaling factor to apply when displaying the gauges mobile devices, set to 1 to disable (default 0.85)
graphUpdateTime : 15, // period of pop-up data graph refresh, in minutes (default 15)
stationTimeout : 3, // period of no data change before we declare the station off-line, in minutes (default 3)
pageUpdateLimit : 20, // period after which the page stops automatically updating, in minutes (default 20),
// - set to 0 (zero) to disable this feature
pageUpdatePswd : 'its-me', // password to over ride the page updates time-out, do not set to blank even if you do not use a password - http://<URL>&pageUpdate=its-me
digitalFont : false, // Font control for the gauges & timer
digitalForecast : false, // Font control for the status display, set this to false for languages that use accented characters in the forecasts
showPopupData : true, // Pop-up data displayed
showPopupGraphs : true, // If pop-up data is displayed, show the graphs?
mobileShowGraphs : false, // If false, on a mobile/narrow display, always disable the graphs
showWindVariation : true, // Show variation in wind direction over the last 10 minutes on the direction gauge
showWindMetar : false, // Show the METAR substring for wind speed/direction over the last 10 minutes on the direction gauge popup
showIndoorTempHum : true, // Show the indoor temperature/humidity options
showCloudGauge : true, // Display the Cloud Base gauge
showUvGauge : true, // Display the UV Index gauge
showSolarGauge : true, // Display the Solar gauge
showSunshineLed : true, // Show 'sun shining now' LED on solar gauge
showRoseGauge : true, // Show the optional Wind Rose gauge
showRoseGaugeOdo : true, // Show the optional Wind Rose gauge wind run Odometer
showRoseOnDirGauge : true, // Show the rose data as sectors on the direction gauge
showGaugeShadow : true, // Show a drop shadow outside the gauges
roundCloudbaseVal : true, // Round the value shown on the cloud base gauge to make it easier to read
// The realtime files should be absolute paths, "/xxx.txt" refers to the public root of your web server
realTimeUrlLongPoll: 'realtimegauges-longpoll.php', // *** ALL Users: If using long polling, change to your location of the PHP long poll realtime file ***
// *** the supplied file is for Cumulus only
realTimeUrlCumulus : 'realtimegauges.txt', // *** Cumulus Users: Change to your location of the realtime file ***
realTimeUrlWD : 'customclientraw.txt', // *** WD Users: Change to your location of the ccr file ***
realTimeUrlVWS : 'steelseriesVWSjson.php', // *** VWS Users: Change to your location of the JSON script generator ***
realTimeUrlWC : 'realtimegaugesWC.txt', // *** WeatherCat Users: Change to your location of the JSON script generator ***
realTimeUrlMB : 'MBrealtimegauges.txt', // *** Meteobridge Users: Change to the location of the JSON file
realTimeUrlWView : 'customclientraw.txt', // *** WView Users: Change to your location of the customclientraw.txt file ***
realTimeUrlWeewx : 'gauge-data.txt', // *** WeeWX Users: Change to your location of the gauge data file ***
realTimeUrlWLCOM : 'WLrealtimegauges.php', // *** WLCOM Users: change to location of WLCOMtags.php file ***
useCookies : true, // Persistently store user preferences in a cookie?
tipImages : [],
dashboardMode : false, // Used by Cumulus MX dashboard - SET TO FALSE OTHERWISE
dewDisplayType : 'app' // Initial 'scale' to display on the 'dew point' gauge.
// 'dew' - Dewpoint
// 'app' - Apparent temperature
// 'wnd' - Wind Chill
// 'hea' - Heat Index
// 'hum' - Humidex
},
// Gauge global look'n'feel settings
gaugeGlobals = {
minMaxArea : 'rgba(212,132,134,0.3)', // area sector for today's max/min. (red, green, blue, transparency)
windAvgArea : 'rgba(132,212,134,0.3)',
windVariationSector : 'rgba(120,200,120,0.7)', // only used when rose data is shown on direction gauge
frameDesign : steelseries.FrameDesign.TILTED_GRAY,
background : steelseries.BackgroundColor.BEIGE,
foreground : steelseries.ForegroundType.TYPE1,
pointer : steelseries.PointerType.TYPE8,
pointerColour : steelseries.ColorDef.RED,
dirAvgPointer : steelseries.PointerType.TYPE8,
dirAvgPointerColour : steelseries.ColorDef.BLUE,
gaugeType : steelseries.GaugeType.TYPE4,
lcdColour : steelseries.LcdColor.STANDARD,
knob : steelseries.KnobType.STANDARD_KNOB,
knobStyle : steelseries.KnobStyle.SILVER,
labelFormat : steelseries.LabelNumberFormat.STANDARD,
tickLabelOrientation : steelseries.TickLabelOrientation.HORIZONTAL, // was .NORMAL up to v1.6.4
rainUseSectionColours : false, // Only one of these colour options should be true
rainUseGradientColours: false, // Set both to false to use the pointer colour
tempTrendVisible : true,
pressureTrendVisible : true,
uvLcdDecimals : 1,
// sunshine threshold values
sunshineThreshold : 50, // the value in W/m² above which we can consider the Sun to be shining, *if* the current value exceeds...
sunshineThresholdPct : 75, // the percentage of theoretical solar irradiance above which we consider the Sun to be shining
// default gauge ranges - before auto-scaling/ranging
tempScaleDefMinC : -20,
tempScaleDefMaxC : 40,
tempScaleDefMinF : 0,
tempScaleDefMaxF : 100,
baroScaleDefMinhPa : 990,
baroScaleDefMaxhPa : 1030,
baroScaleDefMinkPa : 99,
baroScaleDefMaxkPa : 103,
baroScaleDefMininHg : 29.2,
baroScaleDefMaxinHg : 30.4,
windScaleDefMaxMph : 20,
windScaleDefMaxKts : 20,
windScaleDefMaxMs : 10,
windScaleDefMaxKmh : 30,
rainScaleDefMaxmm : 10,
rainScaleDefMaxIn : 0.5,
rainRateScaleDefMaxmm : 10,
rainRateScaleDefMaxIn : 0.5,
uvScaleDefMax : 10, // Northern Europe may be lower - max. value recorded in the UK is 8, so use a scale of 10 for UK
solarGaugeScaleMax : 1000, // Max value to be shown on the solar gauge - theoretical max without atmosphere ~ 1374 W/m²
// - but Davis stations can read up to 1800, use 1000 for Northern Europe?
cloudScaleDefMaxft : 3000,
cloudScaleDefMaxm : 1000,
shadowColour : 'rgba(0,0,0,0.3)' // Colour to use for gauge shadows - default 30% transparent black
},
commonParams = {
// Common parameters for all the SteelSeries gauges
fullScaleDeflectionTime: 4, // Bigger numbers (seconds) slow the gauge pointer movements more
gaugeType : gaugeGlobals.gaugeType,
minValue : 0,
niceScale : true,
ledVisible : false,
frameDesign : gaugeGlobals.frameDesign,
backgroundColor : gaugeGlobals.background,
foregroundType : gaugeGlobals.foreground,
pointerType : gaugeGlobals.pointer,
pointerColor : gaugeGlobals.pointerColour,
knobType : gaugeGlobals.knob,
knobStyle : gaugeGlobals.knobStyle,
lcdColor : gaugeGlobals.lcdColour,
lcdDecimals : 1,
digitalFont : config.digitalFont,
tickLabelOrientation : gaugeGlobals.tickLabelOrientation,
labelNumberFormat : gaugeGlobals.labelFormat
},
firstRun = true, // Used to set-up units & scales etc
userUnitsSet = false, // Tracks if the display units have been set by a user preference
data = {}, // Stores all the values from realtime.txt
tickTockInterval, // The 1s clock interval timer
// ajaxDelay, used by long polling, the delay between getting a response and queueing the next request, as the default PHP
// script runtime timout is 30 seconds, we do not want the PHP task to run for more than 20 seconds. So queue the next
// request half of the realtime interval, or 20 seconds before it is due, which ever is the larger.
ajaxDelay = config.longPoll ? Math.max(config.realtimeInterval - 20, 0) : config.realtimeInterval,
downloadTimer, // Stores a reference to the ajax download setTimout() timer
timestamp = 0, // the timestamp of last data update on the server.
jqXHR = null, // handle to the jQuery web request
displayUnits = null, // Stores the display units cookie settings
sampleDate,
realtimeVer, // minimum version of the realtime JSON file required
programLink = [
'<a href="https://cumuluswiki.wxforum.net/a/Software" target="_blank" rel="noopener">Cumulus</a>',
'<a href="//www.weather-display.com/" target="_blank" rel="noopener">Weather Display</a>',
'<a href="//www.ambientweather.com/virtualstation.html" target="_blank" rel="noopener">Virtual Weather Station</a>',
'<a href="//trixology.com/weathercat/" target="_blank" rel="noopener">WeatherCat</a>',
'<a href="//www.meteobridge.com/" target="_blank rel="noopener"">Meteobridge</a>',
'<a href="//www.wviewweather.com/" target="_blank" rel="noopener">Wview</a>',
'<a href="//www.weewx.com/" target="_blank" rel="noopener">weewx</a>',
'<a href="//weatherlink.com/" target="_blank" rel="noopener">Weatherlink.com</a>'
],
ledIndicator, statusScroller, statusTimer,
gaugeTemp, gaugeDew, gaugeRain, gaugeRRate,
gaugeHum, gaugeBaro, gaugeWind, gaugeDir,
gaugeUV, gaugeSolar, gaugeCloud, gaugeRose,
/* _imgBackground, // Uncomment if using a background image on the gauges */
// ==================================================================================================================
// Nothing below this line needs to be modified for the gauges as supplied
// - unless you really know what you are doing
// - but remember, if you break it, it's up to you to fix it ;-)
// ==================================================================================================================
//
// init() Called when the document is ready, pre-draws the Status Display then calls
// the first Ajax fetch of realtimegauges.txt. First draw of the gauges now deferred until
// the Ajax data is available as a 'speed up'.
//
init = function (dashboard) {
// Cumulus, Weather Display, VWS, WeatherCat?
switch (config.weatherProgram) {
case 0:
// Cumulus
realtimeVer = 12; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlCumulus;
// the trend images to be used for the pop-up data, used in conjunction with config.imgPathURL
// by default this is configured for the Cumulus 'standard' web site
// ** If you specify one image in a sub-array, then you MUST provide images for all the other sub-elements
config.tipImgs = [ // config.tipImgs for Cumulus users using the 'default' weather site
['temp.png', 'intemp.png'], // Temperature: outdoor, indoor
// Temperature: dewpoint, apparent, windChill, heatIndex, humidex
['temp.png', 'temp.png', 'temp.png', 'temp.png', 'temp.png'],
'raint.png', // Rainfall
'rain.png', // Rainfall rate
['hum.png', 'hum.png'], // Humidity: outdoor, indoor
'press.png', // Pressure
'wind.png', // Wind speed
'windd.png', // Wind direction
(config.showUvGauge ? 'uv.png' : null), // UV graph if UV sensor is present | =null if no UV sensor
(config.showSolarGauge ? 'solar.png' : null), // Solar rad graph if Solar sensor is present | Solar =null if no Solar sensor
(config.showRoseGauge ? 'windd.png' : null), // Wind direction if Rose is enabled | =null if Rose is disabled
(config.showCloudGauge ? 'press.png' : null) // Pressure for cloud height | =null if Cloud Height is disabled
];
break;
case 1:
// Weather Display
realtimeVer = 14; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlWD;
config.tipImgs = [ // config.tipImgs for Weather Display users with wxgraph
['temp+hum_24hr.php', 'indoor_temp_24hr.php'], // Temperature: outdoor, indoor
// Temperature: dewpnt, apparent, windChill, HeatIndx, humidex
['temp+dew+hum_1hr.php', 'temp+dew+hum_1hr.php', 'temp+dew+hum_1hr.php', 'temp+dew+hum_1hr.php', 'temp+dew+hum_1hr.php'],
'rain_24hr.php', // Rainfall
'rain_1hr.php', // Rainfall rate
['humidity_1hr.php', 'humidity_7days.php'], // Humidity: outdoor, indoor
'baro_24hr.php', // Pressure
'windgust_1hr.php', // Wind speed
'winddir_24hr.php', // Wind direction
(config.showUvGauge ? 'uv_24hr.php' : null), // UV graph if UV sensor is present | =null if no UV sensor
(config.showSolarGauge ? 'solar_24hr.php' : null), // Solar rad graph if Solar sensor is present | Solar =null if no Solar sensor
(config.showRoseGauge ? 'winddir_24hr.php' : null), // Wind direction if Rose is enabled | =null if Rose is disabled
(config.showCloudGauge ? 'baro_24hr.php' : null) // Pressure for cloud height | =null if Cloud Height is disabled
];
// WD useer generally use wxgraphs - tweak the CSS to accomadate the different aspect ratio
$('.tipimg').css({
width : '360px',
height: '260px'});
break;
case 2:
// WVS
realtimeVer = 11; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlVWS;
config.showRoseGauge = false; // no wind rose data from VWS
config.showCloudGauge = false;
config.tipImgs = [ // config.tipImgs for VWS users
['vws742.jpg', 'vws741.jpg'], // Temperature: outdoor, indoor
// Temperature: dewpnt, apparent, windChill, HeatIndx, humidex
['vws757.jpg', 'vws762.jpg', 'vws754.jpg', 'vws756.jpg', null],
'vws744.jpg', // Rainfall
'vws859.jpg', // Rainfall rate
['vws740.jpg', 'vws739.jpg'], // Humidity: outdoor, indoor
'vws758.jpg', // Pressure
'vws737.jpg', // Wind speed
'vws736.jpg', // Wind direction
(config.showUvGauge ? 'vws752.jpg' : null), // UV graph if UV sensor is present | =null if no UV sensor
(config.showSolarGauge ? 'vws753.jpg' : null), // Solar rad graph if Solar sensor is present | Solar =null if no Solar sensor
(config.showRoseGauge ? 'vws736.jpg' : null), // Wind direction if Rose is enabled | =null if Rose is disabled
(config.showCloudGauge ? 'vws758.jpg' : null) // Pressure for cloud height | =null if Cloud Height is disabled
];
break;
case 3:
// WeatherCat
realtimeVer = 14; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlWC;
config.tipImgs = [ // config.tipImgs - WeatherCat users using the 'default' weather site
['temperature1.jpg', 'tempin1.jpg'], // Temperature: outdoor, indoor
// Temperature: dewpoint, apparent, windChill, heatIndex, humidex
['dewpoint1.jpg', 'temperature1.jpg', 'windchill1.jpg', 'heatindex1.jpg', 'temperature1.jpg'],
'precipitationc1.jpg', // Rainfall
'precipitation1.jpg', // Rainfall rate
['rh1.jpg', 'rhin1.jpg'], // Humidity: outdoor, indoor
'pressure1.jpg', // Pressure
'windspeed1.jpg', // Wind speed
'winddirection1.jpg', // Wind direction
(config.showUvGauge ? 'uv1.jpg' : null), // UV graph if UV sensor is present | =null if no UV sensor
(config.showSolarGauge ? 'solarrad1.jpg' : null), // Solar rad graph if Solar sensor is present | Solar =null if no Solar sensor
(config.showRoseGauge ? 'winddirection1.jpg' : null), // Wind direction if Rose is enabled | =null if Rose is disabled
(config.showCloudGauge ? 'cloudbase1.jpg' : null) // Pressure for cloud height | =null if Cloud Height is disabled
];
break;
case 4:
// Meteobridge
realtimeVer = 10; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlMB;
config.showPopupGraphs = false; // config.tipImgs - no Meteobridge images available
config.showRoseGauge = false; // no windrose data from MB
config.showCloudGauge = false;
config.tipImgs = null; // config.tipImgs - no Meteobridge images available
config.showWindVariation = false; // no wind variation data from MB
break;
case 5:
// WView
realtimeVer = 11; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlWView;
config.showSunshineLed = false; // WView does not provide the current theoretical solar max required to determine sunshine
config.showWindVariation = false; // no wind variation from WView
config.showRoseGauge = false; // No wind rose array from WView by default - there is a user supplied modification to enable it though.
config.showCloudGauge = false;
config.tipImgs = [ // config.tipImgs for WView users
['tempdaycomp.png', 'indoor_temp.png'], // Temperature: outdoor, indoor
// Temperature: dewpnt, apparent, windChill, HeatIndx, humidex
['tempdaycomp.png', 'tempdaycomp.png', 'heatchillcomp.png', 'heatchillcomp.png', 'tempdaycomp.png'],
'rainday.png', // Rainfall
'rainrate.png', // Rainfall rate
['humidday.png', 'humidday.png'], // Humidity: outdoor, indoor
'baromday.png', // Pressure
'wspeeddaycomp.png', // Wind speed
'wdirday.png', // Wind direction
(config.showUvGauge ? 'uvday.png' : null), // UV graph if UV sensor is present | =null if no UV sensor
(config.showSolarGauge ? 'solarday.png' : null), // Solar rad graph if Solar sensor is present | Solar =null if no Solar sensor
(config.showRoseGauge ? 'windroseday.png' : null), // Wind direction if Rose is enabled | =null if Rose is disabled
(config.showCloudGauge ? 'baromday.png' : null) // Pressure for cloud height | =null if Cloud Height is disabled
];
break;
case 6:
// weewx
realtimeVer = 14; // minimum version of the realtime JSON file required
config.realTimeURL = config.longPoll ? config.realTimeUrlLongPoll : config.realTimeUrlWeewx;
config.showSunshineLed = true;
config.showWindVariation = true;
config.tipImgs = [ // config.tipImgs for weewx
['dayinouttemp.png', 'dayinouttemp.png'], // Temperature: outdoor, indoor
// Temperature: dewpnt, apparent, windChill, HeatIndx, humidex
['dayouttemphum.png', 'dayouttemphum.png', 'dayouttemphum.png', 'dayouttemphum.png', 'dayouttemphum.png'],
'dayrain.png', // Rainfall
'dayrainrate.png', // Rainfall rate
['dayinouthum.png', 'dayinouthum.png'], // Humidity: outdoor, indoor
'daybarometer.png', // Pressure
'daywind.png', // Wind speed
'daywinddir.png', // Wind direction
(config.showUvGauge ? 'dayuv.png' : null), // UV graph if UV sensor is present | =null if no UV sensor
(config.showSolarGauge ? 'dayradiation.png' : null), // Solar rad graph if Solar sensor is present | Solar =null if no Solar sensor
(config.showRoseGauge ? 'daywindvec.png' : null), // Wind direction if Rose is enabled | =null if Rose is disabled
(config.showCloudGauge ? 'daybarometer.png' : null) // Pressure for cloud height | =null if Cloud Height is disabled
];
break;
case 7:
// WLCOM
realtimeVer = 10; // minimum version of the realtime JSON file required
config.realTimeURL = config.realTimeUrlWLCOM;
config.showPopupGraphs = false; // config.tipImgs - no WL images available
config.showRoseGauge = false; // no windrose data from WL
config.showCloudGauge = false;
config.tipImgs = null; // config.tipImgs - no WL images available
config.showWindVariation = false; // no wind variation data from WL
break;
default:
// Who knows!
realtimeVer = 0; // minimum version of the realtime JSON file required
config.realtimeURL = null;
config.showPopupGraphs = false;
config.tipImgs = null; // config.tipImgs - unknown
}
// Are we running on a phone device (or really low res screen)?
if ($(window).width() < 480) {
// Change the gauge scaling
config.gaugeScaling = config.gaugeMobileScaling;
// Switch off graphs?
config.showPopupGraphs = config.mobileShowGraphs;
} else {
config.gaugeScaling = 1;
}
// Logo images are used to 'personalise' the gauge backgrounds
// To add a logo to a gauge, add the parameter:
// params.customLayer = _imgBackground;
// to the corresponding drawXxxx() function below.
//
// These are for demo only, to add them remove the comments around the following lines, and
// the _imgBackground definition line above...
/*
_imgBackground = document.createElement('img'); // small logo
$(_imgBackground).attr('src', config.imgPathURL + 'logoSmall.png');
*/
// End of logo images
// Get the display units the user last used when they visited before - if present
displayUnits = getCookie('units');
// Set 'units' radio buttons to match preferred units
if (displayUnits !== null) {
// User wants specific units
userUnitsSet = true;
// temperature
setRadioCheck('rad_unitsTemp', displayUnits.temp);
data.tempunit = '°' + displayUnits.temp;
// rain
setRadioCheck('rad_unitsRain', displayUnits.rain);
data.rainunit = displayUnits.rain;
// pressure
setRadioCheck('rad_unitsPress', displayUnits.press);
data.pressunit = displayUnits.press;
// wind
setRadioCheck('rad_unitsWind', displayUnits.wind);
data.windunit = displayUnits.wind;
displayUnits.windrun = getWindrunUnits(data.windunit);
// cloud base
setRadioCheck('rad_unitsCloud', displayUnits.cloud);
data.cloudunit = displayUnits.cloud;
} else {
// Set the defaults to metric )
// DO NOT CHANGE THESE - THE SCRIPT DEPENDS ON THESE DEFAULTS
// The units actually displayed will be read from the realtime.txt file, or from the users last visit cookie
displayUnits = {
temp : 'C',
rain : 'mm',
press : 'hPa',
wind : 'km/h',
windrun: 'km',
cloud : 'm'
};
data.tempunit = '°C';
data.rainunit = 'mm';
data.pressunit = 'hPa';
data.windunit = 'km/h';
data.cloudunit = 'm';
}
// enable popup data
if (config.showPopupData) {
ddimgtooltip.showTips = config.showPopupData;
}
if (config.showPopupGraphs) {
// Note the number of array elements must match 'i' in ddimgtooltip.tiparray()
ddimgtooltip.tiparray[0][0] = (config.tipImgs[0][0] === null ? null : '');
ddimgtooltip.tiparray[1][0] = (config.tipImgs[1][0] === null ? null : '');
ddimgtooltip.tiparray[2][0] = (config.tipImgs[2] === null ? null : '');
ddimgtooltip.tiparray[3][0] = (config.tipImgs[3] === null ? null : '');
ddimgtooltip.tiparray[4][0] = (config.tipImgs[4][0] === null ? null : '');
ddimgtooltip.tiparray[5][0] = (config.tipImgs[5] === null ? null : '');
ddimgtooltip.tiparray[6][0] = (config.tipImgs[6] === null ? null : '');
ddimgtooltip.tiparray[7][0] = (config.tipImgs[7] === null ? null : '');
ddimgtooltip.tiparray[8][0] = (config.tipImgs[8] === null ? null : '');
ddimgtooltip.tiparray[9][0] = (config.tipImgs[9] === null ? null : '');
ddimgtooltip.tiparray[10][0] = (config.tipImgs[10] === null ? null : '');
ddimgtooltip.tiparray[11][0] = (config.tipImgs[11] === null ? null : '');
}
// draw the status gadgets first, they will display any errors in the initial set-up
ledIndicator = singleLed.getInstance();
statusScroller = singleStatus.getInstance();
statusTimer = singleTimer.getInstance();
gaugeTemp = singleTemp.getInstance();
// Export gaugeTemp.update() so it can be called from the HTML code
if (gaugeTemp) {gauges.doTemp = gaugeTemp.update;}
gaugeDew = singleDew.getInstance();
// Export gaugeDew.update() so it can be called from the HTML code
if (gaugeDew) {gauges.doDew = gaugeDew.update;}
gaugeHum = singleHum.getInstance();
// Export gaugeHum.update() so it can be called from the HTML code
if (gaugeHum) {gauges.doHum = gaugeHum.update;}
gaugeBaro = singleBaro.getInstance();
gaugeWind = singleWind.getInstance();
gaugeDir = singleDir.getInstance();
gaugeRain = singleRain.getInstance();
gaugeRRate = singleRRate.getInstance();
// remove the UV gauge?
if (!config.showUvGauge) {
$('#canvas_uv').parent().remove();
} else {
gaugeUV = singleUV.getInstance();
}
// remove the Solar gauge?
if (!config.showSolarGauge) {
$('#canvas_solar').parent().remove();
} else {
gaugeSolar = singleSolar.getInstance();
}
// remove the Wind Rose?
if (!config.showRoseGauge) {
$('#canvas_rose').parent().remove();
} else {
gaugeRose = singleRose.getInstance();
}
// remove the cloud base gauge?
if (!config.showCloudGauge) {
$('#canvas_cloud').parent().remove();
// and remove cloudbase unit selection options
$('#cloud').parent().remove();
} else {
gaugeCloud = singleCloudBase.getInstance();
}
// Set the language
changeLang(strings, false);
if (!dashboard) {
// Go do get the data!
getRealtime();
// start a timer to update the status time
tickTockInterval = setInterval(
function () {
$.publish('gauges.clockTick', null);
},
1000);
// start a timer to stop the page updates after the timeout period
if (config.pageUpdateLimit > 0 && getUrlParam('pageUpdate') !== config.pageUpdatePswd) {
setTimeout(pageTimeout, config.pageUpdateLimit * 60 * 1000);
}
}
},
//
// singleXXXX functions define a singleton for each of the gauges
//
//
// Singleton for the LED Indicator
//
singleLed = (function () {
var instance; // Stores a reference to the Singleton
var led; // Stores a reference to the SS LED
function init() {
// create led indicator
if ($('#canvas_led').length) {
led = new steelseries.Led(
'canvas_led', {
ledColor: steelseries.LedColor.GREEN_LED,
size : $('#canvas_led').width()
});
setTitle(strings.led_title);
}
function setTitle(newTitle) {
$('#canvas_led').attr('title', newTitle);
}
function setLedColor(newColour) {
if (led) {
led.setLedColor(newColour);
}
}
function setLedOnOff(onState) {
if (led) {
led.setLedOnOff(onState);
}
}
function blink(blinkState) {
if (led) {
led.blink(blinkState);
}
}
return {
setTitle : setTitle,
setLedColor: setLedColor,
setLedOnOff: setLedOnOff,
blink : blink
};
}
return {
// Get the Singleton instance if one exists
// or create one if it doesn't
getInstance: function () {
if (!instance) {
instance = init();
}
return instance;
}
};
})(),
//
// Singleton for the Status Scroller
//
singleStatus = (function () {
var instance; // Stores a reference to the Singleton
var scroller; // Stores a reference to the SS scrolling display
function init() {
// create forecast display
if ($('#canvas_status').length) {
scroller = new steelseries.DisplaySingle(
'canvas_status', {
width : $('#canvas_status').width(),
height : $('#canvas_status').height(),
lcdColor : gaugeGlobals.lcdColour,
unitStringVisible: false,
value : strings.statusStr,
digitalFont : config.digitalForecast,
valuesNumeric : false,
autoScroll : true,
alwaysScroll : false
});
}
function setValue(newTxt) {
if (scroller) {
scroller.setValue(newTxt);
}
}
return {setText: setValue};
}
return {
// Get the Singleton instance if one exists
// or create one if it doesn't
getInstance: function () {
if (!instance) {
instance = init();
}
return instance;
}
};
})(),
//
// Singleton for the Status Timer
//
singleTimer = (function () {
var instance, // Stores a reference to the Singleton
lcd, // Stores a reference to the SS LED
count = 1;
function init() {
function tick() {
if (lcd) {
lcd.setValue(count);
count += config.longPoll ? 1 : -1;
}
}
function reset(val) {
count = val;
}
function setValue(newVal) {
if (lcd) {
lcd.setValue(newVal);
}
}
// create timer display
if ($('#canvas_timer').length) {
lcd = new steelseries.DisplaySingle(
'canvas_timer', {
width : $('#canvas_timer').width(),
height : $('#canvas_timer').height(),
lcdColor : gaugeGlobals.lcdColour,
lcdDecimals : 0,
unitString : strings.timer,
unitStringVisible: true,
digitalFont : config.digitalFont,
value : count
});
// subscribe to data updates
$.subscribe('gauges.clockTick', tick);
}
return {
reset : reset,
setValue: setValue
};
}
return {
// Get the Singleton instance if one exists
// or create one if it doesn't
getInstance: function () {
if (!instance) {
instance = init();
}
return instance;
}
};
})(),
//
// Singleton for the Temperature Gauge
//
singleTemp = (function () {
var instance; // Stores a reference to the Singleton
var ssGauge; // Stores a reference to the SS Gauge
var cache = {}; // Stores various config values and parameters
function init() {
var params = $.extend(true, {}, commonParams);
// define temperature gauge start values
cache.sections = createTempSections(true);
cache.areas = [];
cache.minValue = gaugeGlobals.tempScaleDefMinC;
cache.maxValue = gaugeGlobals.tempScaleDefMaxC;
cache.title = strings.temp_title_out;
cache.value = gaugeGlobals.tempScaleDefMinC + 0.0001;
cache.maxMinVisible = false;
cache.selected = 'out';
// create temperature radial gauge
if ($('#canvas_temp').length) {
params.size = Math.ceil($('#canvas_temp').width() * config.gaugeScaling);
params.section = cache.sections;
params.area = cache.areas;
params.minValue = cache.minValue;
params.maxValue = cache.maxValue;
params.thresholdVisible = false;
params.minMeasuredValueVisible = cache.maxMinVisible;
params.maxMeasuredValueVisible = cache.maxMinVisible;
params.titleString = cache.title;
params.unitString = data.tempunit;
params.trendVisible = gaugeGlobals.tempTrendVisible;
// params.customLayer = _imgBackground; // uncomment to add a background image - See Logo Images above
ssGauge = new steelseries.Radial('canvas_temp', params);
ssGauge.setValue(cache.value);
// over-ride CSS applied size?
if (config.gaugeScaling !== 1) {
$('#canvas_temp').css({width: params.size + 'px', height: params.size + 'px'});
}
// add a shadow to the gauge
if (config.showGaugeShadow) {
$('#canvas_temp').css(gaugeShadow(params.size));
}
// remove indoor temperature/humidity options?
if (!config.showIndoorTempHum) {
$('#rad_temp1').remove();
$('#lab_temp1').remove();
$('#rad_temp2').remove();
$('#lab_temp2').remove();
$('#rad_hum1').remove();
$('#lab_hum1').remove();
$('#rad_hum2').remove();
$('#lab_hum2').remove();
}
// subscribe to data updates
$.subscribe('gauges.dataUpdated', update);
$.subscribe('gauges.graphUpdate', updateGraph);
} else {
// cannot draw gauge, return null
return null;
}
function update() {
var sel = cache.selected;
// Argument length === 1 when called from radio input
// Argument length === 2 when called from event handler
if (arguments.length === 1) {
sel = arguments[0].value;
}
// if rad isn't specified, just use existing value
var t1, scaleStep, tip;
cache.minValue = data.tempunit[1] === 'C' ? gaugeGlobals.tempScaleDefMinC : gaugeGlobals.tempScaleDefMinF;
cache.maxValue = data.tempunit[1] === 'C' ? gaugeGlobals.tempScaleDefMaxC : gaugeGlobals.tempScaleDefMaxF;
if (sel === 'out') {
cache.low = extractDecimal(data.tempTL);
cache.high = extractDecimal(data.tempTH);
cache.lowScale = getMinTemp(cache.minValue);
cache.highScale = getMaxTemp(cache.maxValue);
cache.value = extractDecimal(data.temp);
cache.title = strings.temp_title_out;
cache.loc = strings.temp_out_info;
cache.trendVal = extractDecimal(data.temptrend);
cache.popupImg = 0;
if (gaugeGlobals.tempTrendVisible) {
t1 = tempTrend(+cache.trendVal, data.tempunit, false);
if (t1 === -9999) {
// trend value isn't currently available
cache.trend = steelseries.TrendState.OFF;
} else if (t1 > 0) {
cache.trend = steelseries.TrendState.UP;
} else if (t1 < 0) {
cache.trend = steelseries.TrendState.DOWN;
} else {
cache.trend = steelseries.TrendState.STEADY;
}
}
} else {
// Indoor
cache.title = strings.temp_title_in;
cache.loc = strings.temp_in_info;
cache.value = extractDecimal(data.intemp);
cache.popupImg = 1;
if (data.intempTL && data.intempTH) {
// Indoor - and Max/Min values supplied
cache.low = extractDecimal(data.intempTL);
cache.high = extractDecimal(data.intempTH);
cache.lowScale = getMinTemp(cache.minValue);
cache.highScale = getMaxTemp(cache.maxValue);
} else {
// Indoor - no Max/Min values supplied
cache.low = cache.value;
cache.lowScale = cache.value;
cache.high = cache.value;
cache.highScale = cache.value;
}
if (gaugeGlobals.tempTrendVisible) {
cache.trend = steelseries.TrendState.OFF;
}
}
// has the gauge type changed?
if (cache.selected !== sel) {
cache.selected = sel;
// Change gauge title
ssGauge.setTitleString(cache.title);
ssGauge.setMaxMeasuredValueVisible(cache.maxMinVisible);
ssGauge.setMinMeasuredValueVisible(cache.maxMinVisible);
if (config.showPopupGraphs && config.tipImgs[0][cache.popupImg] !== null) {
var cacheDefeat = '?' + $('#imgtip0_img').attr('src').split('?')[1];
$('#imgtip0_img').attr('src', config.imgPathURL + config.tipImgs[0][cache.popupImg] + cacheDefeat);
}
}
// auto scale the ranges
scaleStep = data.tempunit[1] === 'C' ? 10 : 20;
while (cache.lowScale < cache.minValue) {
cache.minValue -= scaleStep;
if (cache.highScale <= cache.maxValue - scaleStep) {
cache.maxValue -= scaleStep;
}
}
while (cache.highScale > cache.maxValue) {
cache.maxValue += scaleStep;
if (cache.minValue >= cache.minValue + scaleStep) {
cache.minValue += scaleStep;
}
}
if (cache.minValue !== ssGauge.getMinValue() || cache.maxValue !== ssGauge.getMaxValue()) {
ssGauge.setMinValue(cache.minValue);
ssGauge.setMaxValue(cache.maxValue);
ssGauge.setValue(cache.minValue);
}
if (cache.selected === 'out') {
cache.areas = [steelseries.Section(+cache.low, +cache.high, gaugeGlobals.minMaxArea)];
} else if (data.intempTL && data.intempTH) {
// Indoor and min/max avaiable
cache.areas = [steelseries.Section(+cache.low, +cache.high, gaugeGlobals.minMaxArea)];
} else {
// Nndoor no min/max avaiable
cache.areas = [];
}
if (gaugeGlobals.tempTrendVisible) {
ssGauge.setTrend(cache.trend);
}
ssGauge.setArea(cache.areas);
ssGauge.setValueAnimated(+cache.value);
if (ddimgtooltip.showTips) {
// update tooltip
if (cache.selected === 'out') {
tip = cache.loc + ' - ' + strings.lowestF_info + ': ' + cache.low + data.tempunit + ' ' + strings.at + ' ' + data.TtempTL +
' | ' +
strings.highestF_info + ': ' + cache.high + data.tempunit + ' ' + strings.at + ' ' + data.TtempTH;
if (cache.trendVal !== -9999) {
tip += '<br>' +
strings.temp_trend_info + ': ' + tempTrend(cache.trendVal, data.tempunit, true) +
' ' + cache.trendVal + data.tempunit + '/h';
}
} else if (data.TintempTL && data.TintempTH) {
// Indoor and min/max available
tip = cache.loc + ' - ' + strings.lowestF_info + ': ' + cache.low + data.tempunit + ' ' + strings.at + ' ' + data.TintempTL +
' | ' +
strings.highestF_info + ': ' + cache.high + data.tempunit + ' ' + strings.at + ' ' + data.TintempTH;
} else {
// Indoor no min/max
tip = cache.loc + ': ' + data.intemp + data.tempunit;
}
$('#imgtip0_txt').html(tip);
}
} // End of update()
function updateGraph(evnt, cacheDefeat) {
if (config.tipImgs[0][cache.popupImg] !== null) {
$('#imgtip0_img').attr('src', config.imgPathURL + config.tipImgs[0][cache.popupImg] + cacheDefeat);
}
}
return {
data : cache,
update: update,
gauge : ssGauge
};
} // End of init()
return {
// Get the Singleton instance if one exists
// or create one if it doesn't
getInstance: function () {
if (!instance) {
instance = init();
}
return instance;
}
};
})(), // End singleTemp()
//
// Singleton for the Dewpoint Gauge
//
singleDew = (function () {
var instance; // Stores a reference to the Singleton
var ssGauge; // Stores a reference to the SS Gauge
var cache = {}; // Stores various config values and parameters
function init() {
var params = $.extend(true, {}, commonParams);
var tmp;
// define dew point gauge start values
cache.sections = createTempSections(true);
cache.areas = [];
cache.minValue = gaugeGlobals.tempScaleDefMinC;
cache.maxValue = gaugeGlobals.tempScaleDefMaxC;
cache.value = gaugeGlobals.tempScaleDefMinC + 0.0001;
// Has the end user selected a preferred 'scale' before
tmp = getCookie('dewGauge');
cache.selected = tmp !== null ? tmp : config.dewDisplayType;
setRadioCheck('rad_dew', cache.selected);
switch (cache.selected) {
case 'dew':
cache.title = strings.dew_title;
cache.popupImg = 0;
break;
case 'app':
cache.title = strings.apptemp_title;
cache.popupImg = 1;
break;
case 'wnd':
cache.title = strings.chill_title;
cache.popupImg = 2;
break;
case 'hea':
cache.title = strings.heat_title;
cache.popupImg = 3;
break;
case 'hum':
cache.title = strings.humdx_title;
cache.popupImg = 4;
// no default
}
cache.minMeasuredVisible = false;
cache.maxMeasuredVisible = false;
// create dew point radial gauge
if ($('#canvas_dew').length) {
params.size = Math.ceil($('#canvas_dew').width() * config.gaugeScaling);
params.section = cache.sections;
params.area = cache.areas;
params.minValue = cache.minValue;
params.maxValue = cache.maxValue;
params.thresholdVisible = false;
params.titleString = cache.title;
params.unitString = data.tempunit;
ssGauge = new steelseries.Radial('canvas_dew', params);
ssGauge.setValue(cache.value);
// over-ride CSS applied size?
if (config.gaugeScaling !== 1) {
$('#canvas_dew').css({width: params.size + 'px', height: params.size + 'px'});
}