Subversion Repositories HomeAutomation

Rev

Rev 1198 | Rev 1204 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1198 Rev 1203
Line 41... Line 41...
41
Display.prototype.bookMenuItem = null;
41
Display.prototype.bookMenuItem = null;
42
 
42
 
43
/* The currently displayed menuitem */
43
/* The currently displayed menuitem */
44
Display.prototype.currentMenuItem = null;
44
Display.prototype.currentMenuItem = null;
45
 
45
 
-
 
46
/* counter for calling exchange update */
-
 
47
Display.prototype.exchangeUpdateCnt = null;
-
 
48
 
-
 
49
/* counter for going to screensaver */
-
 
50
Display.prototype.screenSaverCnt = null;
-
 
51
 
-
 
52
/* counter for going to main screen */
-
 
53
Display.prototype.mainScreenCnt = null;
-
 
54
 
-
 
55
const exchangeUpdateTimeout = 20;
-
 
56
const mainScreenTimeout = 40;
-
 
57
const screenSaverTimeout = 120;
46
 
58
 
47
/* This function must always be declared, this is where all the startup code
59
/* This function must always be declared, this is where all the startup code
48
   should be placed. Gets called with arguments like what ids to use etc. */
60
   should be placed. Gets called with arguments like what ids to use etc. */
49
Display.prototype.initialize = function(initialArguments)
61
Display.prototype.initialize = function(initialArguments)
50
{
62
{
Line 55... Line 67...
55
    var self = this;
67
    var self = this;
56
 
68
 
57
    if (!this.myInitialArguments["HD44789"])
69
    if (!this.myInitialArguments["HD44789"])
58
    {
70
    {
59
        log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n");
71
        log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n");
60
        return;
72
        return;
61
    }
73
    }
62
   
74
   
63
    if (!this.myInitialArguments["Rotary"])
75
    if (!this.myInitialArguments["Rotary"])
64
    {
76
    {
65
        log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n");
77
        log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n");
66
        return;
78
        return;
67
    }
79
    }
68
   
80
   
69
    if (!this.myInitialArguments["softPWM"])
81
    if (!this.myInitialArguments["softPWM"])
70
    {
82
    {
71
        log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n");
83
        log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n");
72
        return;
84
        return;
73
    }
85
    }
74
   
86
   
75
    if (!this.myInitialArguments["Name"])
87
    if (!this.myInitialArguments["Name"])
76
    {
88
    {
77
        log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
89
        log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
78
        return;
90
        return;
79
    }
91
    }
80
    this.niceName = this.myInitialArguments["Name"];
92
    this.niceName = this.myInitialArguments["Name"];
81
 
93
 
82
    if (!this.myInitialArguments["ShortName"])
94
    if (!this.myInitialArguments["ShortName"])
83
    {
95
    {
84
        log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
96
        log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
85
        return;
97
        return;
86
    }
98
    }
87
    this.shortName = this.myInitialArguments["ShortName"];
99
    this.shortName = this.myInitialArguments["ShortName"];
-
 
100
   
-
 
101
    this.screenSaverCnt = 0;
-
 
102
    this.mainScreenCnt = 0;
-
 
103
    this.exchangeUpdateCnt = exchangeUpdateTimeout-10;
88
   
104
   
89
    /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
105
    /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
90
    this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
106
    this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
91
    /* Add a callback for when the service goes online */
107
    /* Add a callback for when the service goes online */
92
    this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
108
    this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
93
    /* If the service is already online we should call the handler here */
109
    /* If the service is already online we should call the handler here */
94
    this.lcdOnline();
110
    this.lcdOnline();
95
    /* Add a callback for when the service goes offline */
111
    /* Add a callback for when the service goes offline */
96
    this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); });
112
    this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); });
97
   
113
   
98
    /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
114
    /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
Line 103... Line 119...
103
    this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); });
119
    this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); });
104
    /* Add a callback for when the service goes online */
120
    /* Add a callback for when the service goes online */
105
    this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
121
    this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
106
    /* If the service is already online we should call the handler here */
122
    /* If the service is already online we should call the handler here */
107
    this.rotaryOnline();
123
    this.rotaryOnline();
108
   
124
   
109
    /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */
125
    /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */
110
    this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]);
126
    this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]);
111
    /* Add a callback for when the service goes online */
127
    /* Add a callback for when the service goes online */
112
    this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); });
128
    this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); });
113
    /* If the service is already online we should call the handler here */
129
    /* If the service is already online we should call the handler here */
Line 287... Line 303...
287
    //FIXME: constraints?
303
    //FIXME: constraints?
288
    if (this.parentDisplay.bookFromTime.getHours() < 23)
304
    if (this.parentDisplay.bookFromTime.getHours() < 23)
289
    {
305
    {
290
        this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() + 30);
306
        this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() + 30);
291
    }
307
    }
292
}
308
}
293
 
309
 
294
Display.prototype.decBookTimeFrom = function()
310
Display.prototype.decBookTimeFrom = function()
295
{
311
{
296
    //FIXME: constraints?
312
    //FIXME: constraints?
297
    var now = new Date();
313
    var now = new Date();
Line 300... Line 316...
300
        this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() - 30);
316
        this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() - 30);
301
    }
317
    }
302
}
318
}
303
 
319
 
304
Display.prototype.setBookTimeFrom = function()
320
Display.prototype.setBookTimeFrom = function()
305
{
321
{
306
    this.displayData[1] = "      <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+">       ";
322
    this.displayData[1] = "      <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+">       ";
307
}
323
}
308
 
324
 
309
Display.prototype.setBookTimeTo = function()
325
Display.prototype.setBookTimeTo = function()
310
{
326
{
Line 313... Line 329...
313
 
329
 
314
Display.prototype.chooseBookTimeTo = function()
330
Display.prototype.chooseBookTimeTo = function()
315
{
331
{
316
    this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  - <"
332
    this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  - <"
317
                                +this.parentDisplay.bookToTime.getTimeShortFormated()+">  ";
333
                                +this.parentDisplay.bookToTime.getTimeShortFormated()+">  ";
318
}
334
}
319
 
335
 
320
Display.prototype.chooseBookTimeFrom = function()
336
Display.prototype.chooseBookTimeFrom = function()
321
{
337
{
322
    this.displayData[0] = " <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+"> -  "
338
    this.displayData[0] = " <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+"> -  "
323
                                +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
339
                                +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
324
}
340
}
325
 
341
 
326
Display.prototype.setBookTime = function()
342
Display.prototype.setBookTime = function()
327
{
343
{
328
    this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  -  "
344
    this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  -  "
329
                                +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
345
                                +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
330
}
346
}
331
 
347
 
332
Display.prototype.updateStatusMenuItem = function()
348
Display.prototype.updateStatusMenuItem = function()
333
{
349
{
334
    var date = new Date();
350
    var date = new Date();
335
    var dateAndTime = "" + date.getTimeShortFormated();
351
    var dateAndTime = "" + date.getTimeShortFormated();
336
    this.displayData[1] = "       " + dateAndTime + "        ";
352
    this.displayData[1] = "       " + dateAndTime + "        ";
337
   
-
 
338
    if (this.parentDisplay.exchangeCalendarFirstMenuItem && this.parentDisplay.exchangeCalendarLastMenuItem)
-
 
339
    {
-
 
340
        this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.exchangeCalendarFirstMenuItem);
-
 
341
        this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.exchangeCalendarLastMenuItem);
-
 
342
    }
-
 
343
}
353
}
344
 
354
 
345
Display.prototype.updateBookMenuItem = function()
355
Display.prototype.updateBookMenuItem = function()
346
{
356
{
347
    if (this.parentDisplay.exchangeCalendarFirstMenuItem && this.parentDisplay.exchangeCalendarLastMenuItem)
357
    if (this.parentDisplay.exchangeCalendarFirstMenuItem && this.parentDisplay.exchangeCalendarLastMenuItem)
348
    {
358
    {
349
        this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.exchangeCalendarFirstMenuItem);
359
        this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.exchangeCalendarFirstMenuItem);
350
        this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.exchangeCalendarLastMenuItem);
360
        this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.exchangeCalendarLastMenuItem);
351
    }
361
    }
352
    else
362
    else
353
    {
363
    {
354
        this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.bookMenuItem);
364
        this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.bookMenuItem);
355
        this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.statusMenuItem);
365
        this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.statusMenuItem);
356
    }
366
    }
357
}
367
}
358
 
368
 
Line 363... Line 373...
363
    {
373
    {
364
        //FIXME check if data contains error tag and error message, print to log and keep previous data?
374
        //FIXME check if data contains error tag and error message, print to log and keep previous data?
365
        if (data.error)
375
        if (data.error)
366
        {
376
        {
367
            log("Display: got this error from exchange.php: " + data.error + "\n");
377
            log("Display: got this error from exchange.php: " + data.error + "\n");
368
        }
378
        }
369
        else
379
        else
370
        {
380
        {
371
            this.exchangeData = data;
381
            this.exchangeData = data;
372
            this.createCalendarMenu();
382
            this.createCalendarMenu();
373
        }
383
        }
374
    }
384
    }
375
}
385
}
376
 
386
 
377
/* this function parses calendar data from exchange-script and creates a menu */
387
/* this function parses calendar data from exchange-script and creates a menu */
378
Display.prototype.createCalendarMenu = function()
388
Display.prototype.createCalendarMenu = function()
379
{
389
{
380
    this.exchangeCalendarLastMenuItem = null;
390
    this.exchangeCalendarLastMenuItem = null;
381
    this.exchangeCalendarFirstMenuItem = null;
391
    this.exchangeCalendarFirstMenuItem = null;
Line 402... Line 412...
402
            }
412
            }
403
            else
413
            else
404
            {
414
            {
405
                menu.setPrevItem(lastMenuItem);
415
                menu.setPrevItem(lastMenuItem);
406
                lastMenuItem.setNextItem(menu);
416
                lastMenuItem.setNextItem(menu);
407
            }
417
            }
408
           
418
           
409
            lastMenuItem = menu;
419
            lastMenuItem = menu;
410
        }
420
        }
-
 
421
        if (lastMenuItem)
-
 
422
        {
411
        this.exchangeCalendarLastMenuItem = lastMenuItem;
423
            this.exchangeCalendarLastMenuItem = lastMenuItem;
412
        this.exchangeCalendarLastMenuItem.setNextItem(this.bookMenuItem);
424
            this.exchangeCalendarLastMenuItem.setNextItem(this.bookMenuItem);
413
        this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem);
425
            this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem);
-
 
426
       
-
 
427
        }
-
 
428
        if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem)
-
 
429
        {
-
 
430
            if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
-
 
431
            {
-
 
432
                this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
-
 
433
                this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
-
 
434
            }
-
 
435
        }
414
    }
436
    }
415
}
437
}
416
 
438
 
417
Display.prototype.softPwmOnline = function()
439
Display.prototype.softPwmOnline = function()
418
{
440
{
419
}
441
}
420
 
442
 
421
Display.prototype.rotaryOnline = function()
443
Display.prototype.rotaryOnline = function()
422
{
444
{
423
}
445
}
424
 
446
 
425
Display.prototype.rotaryPosUpdate = function(SwitchId)
447
Display.prototype.rotaryPosUpdate = function(SwitchId)
426
{
448
{
-
 
449
    this.screenSaverCnt = 0;
-
 
450
    this.mainScreenCnt = 0;
427
    for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
451
    for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
428
    {
452
    {
429
        if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
453
        if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
430
        {
454
        {
431
            if (this.currentMenuItem.doRight)
455
            if (this.currentMenuItem.doRight)
432
            {
456
            {
433
                this.currentMenuItem.doRight();
457
                this.currentMenuItem.doRight();
434
            }
458
            }
435
        }
459
        }
436
        else
460
        else
437
        {
461
        {
438
            if (this.currentMenuItem.doLeft)
462
            if (this.currentMenuItem.doLeft)
439
            {
463
            {
440
                this.currentMenuItem.doLeft();
464
                this.currentMenuItem.doLeft();
441
            }
465
            }
442
        }
466
        }
443
    }
467
    }
444
   
468
   
445
    this.updateDisplay();
469
    this.updateDisplay();
446
}
470
}
447
 
471
 
448
Display.prototype.rotaryBtnUpdate = function(SwitchId)
472
Display.prototype.rotaryBtnUpdate = function(SwitchId)
449
{
473
{
-
 
474
    this.screenSaverCnt = 0;
-
 
475
    this.mainScreenCnt = 0;
450
    if (this.myRotaryService.getButtonStatus(SwitchId) == "Released")
476
    if (this.myRotaryService.getButtonStatus(SwitchId) == "Released")
451
    {
477
    {
452
        if (this.currentMenuItem.doPress)
478
        if (this.currentMenuItem.doPress)
453
        {
479
        {
454
            this.currentMenuItem.doPress();
480
            this.currentMenuItem.doPress();
455
        }
-
 
456
    }
481
        }
457
    this.updateDisplay();
482
        this.updateDisplay();
-
 
483
    }
458
}
484
}
459
 
485
 
460
Display.prototype.updateDisplay = function()
486
Display.prototype.updateDisplay = function()
461
{
487
{
462
    /* see if the current menuitem wants to update itself */
488
    /* see if the current menuitem wants to update itself */
Line 470... Line 496...
470
   
496
   
471
    /* send the data for the current menuitem to display */
497
    /* send the data for the current menuitem to display */
472
    for (var i = 0; i < this.currentMenuItem.displayData.length; i++)
498
    for (var i = 0; i < this.currentMenuItem.displayData.length; i++)
473
    {
499
    {
474
        this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]);
500
        this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]);
475
    }
501
    }
476
   
502
   
477
}
503
}
478
 
504
 
479
Display.prototype.lcdCenterText = function(text)
505
Display.prototype.lcdCenterText = function(text)
480
{
506
{
Line 491... Line 517...
491
    /* If we have no interval timer running do nothing */
517
    /* If we have no interval timer running do nothing */
492
    if (this.myInterval != null)
518
    if (this.myInterval != null)
493
    {
519
    {
494
        /* Stop the interval */
520
        /* Stop the interval */
495
        this.myInterval.stop();
521
        this.myInterval.stop();
496
    }
522
    }
497
}
523
}
498
 
524
 
499
Display.prototype.lcdOnline = function()
525
Display.prototype.lcdOnline = function()
500
{
526
{
501
    /* If service is not online do nothing */
527
    /* If service is not online do nothing */
502
    if (this.myLCDService.isOnline())
528
    if (this.myLCDService.isOnline())
503
    {
529
    {
Line 510... Line 536...
510
        if (this.myInterval == null)
536
        if (this.myInterval == null)
511
        {
537
        {
512
            var self = this;
538
            var self = this;
513
       
539
       
514
            /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */
540
            /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */
515
            this.myInterval = new Interval(function() { self.timerUpdate() }, 60000);
541
            this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
516
        }
542
        }
517
       
543
       
518
        this.myInterval.start();
544
        this.myInterval.start();
519
       
545
       
520
        this.timerUpdate();
546
        this.timerUpdate();
521
    }
547
    }
522
}
548
}
523
 
549
 
524
Display.prototype.setLED = function(red, green, blue)
550
Display.prototype.setLED = function(red, green, blue)
525
{
551
{
526
   
552
   
527
}
553
}
528
 
554
 
529
Display.prototype.timerUpdate = function()
555
Display.prototype.timerUpdate = function()
530
{
556
{
531
    /* If LCD service is not online do nothing */
557
    /* If LCD service is not online do nothing */
532
    if (this.myLCDService.isOnline())
558
    if (this.myLCDService.isOnline())
533
    {
559
    {
-
 
560
        this.screenSaverCnt++;
-
 
561
        this.mainScreenCnt++;
-
 
562
        this.exchangeUpdateCnt++;
-
 
563
 
-
 
564
        if (this.mainScreenCnt > mainScreenTimeout/5)
-
 
565
        {
-
 
566
            /* Go to main screen (time) */
534
        this.exchangeCalendar.lookup(this.shortName);
567
            this.currentMenuItem = this.statusMenuItem;
-
 
568
 
-
 
569
            /* update the info on display */
-
 
570
            this.updateDisplay();
-
 
571
        }
535
       
572
       
-
 
573
        if (this.screenSaverCnt > screenSaverTimeout/5)
-
 
574
        {
-
 
575
           
-
 
576
        }
-
 
577
 
-
 
578
        if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5)
-
 
579
        {
536
        /* update the info on display */
580
            /* update the info on display */
537
        this.updateDisplay();
581
            this.updateDisplay();
-
 
582
           
-
 
583
            /* do an exchange lookup */
-
 
584
            this.exchangeCalendar.lookup(this.shortName);
-
 
585
           
-
 
586
            this.exchangeUpdateCnt = 0;
-
 
587
        }
-
 
588
       
538
    }
589
    }
539
   
590
   
540
    /*if (this.mySoftPwmService.isOnline())
591
    /*if (this.mySoftPwmService.isOnline())
541
    {
592
    {
542
        this.mySoftPwmService.setPWMValue(0, 0);
593
        this.mySoftPwmService.setPWMValue(0, 0);