Rev 1247 | Rev 1249 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1247 | Rev 1248 | ||
|---|---|---|---|
| Line 52... | Line 52... | ||
| 52 | /* counter for going to screensaver */ |
52 | /* counter for going to screensaver */ |
| 53 | Display.prototype.screenSaverCnt = null; |
53 | Display.prototype.screenSaverCnt = null; |
| 54 | 54 | ||
| 55 | /* counter for going to main screen */ |
55 | /* counter for going to main screen */ |
| 56 | Display.prototype.mainScreenCnt = null; |
56 | Display.prototype.mainScreenCnt = null; |
| - | 57 | ||
| - | 58 | /* LED status */ |
|
| - | 59 | Display.prototype.LEDstatus = null; |
|
| 57 | 60 | ||
| 58 | const exchangeUpdateTimeout = 50; |
61 | const exchangeUpdateTimeout = 50; |
| 59 | const mainScreenTimeout = 40; |
62 | const mainScreenTimeout = 40; |
| 60 | const screenSaverTimeout = 120; |
63 | const screenSaverTimeout = 120; |
| 61 | 64 | ||
| Line 72... | Line 75... | ||
| 72 | var self = this; |
75 | var self = this; |
| 73 | 76 | ||
| 74 | if (!this.myInitialArguments["HD44789"]) |
77 | if (!this.myInitialArguments["HD44789"]) |
| 75 | { |
78 | { |
| 76 | log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n"); |
79 | log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n"); |
| 77 | return; |
80 | return; |
| 78 | } |
81 | } |
| 79 | 82 | ||
| 80 | if (!this.myInitialArguments["Rotary"]) |
83 | if (!this.myInitialArguments["Rotary"]) |
| 81 | { |
84 | { |
| 82 | log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n"); |
85 | log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n"); |
| 83 | return; |
86 | return; |
| 84 | } |
87 | } |
| 85 | 88 | ||
| 86 | if (!this.myInitialArguments["softPWM"]) |
89 | if (!this.myInitialArguments["softPWM"]) |
| 87 | { |
90 | { |
| 88 | log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n"); |
91 | log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n"); |
| 89 | return; |
92 | return; |
| 90 | } |
93 | } |
| 91 | 94 | ||
| 92 | if (!this.myInitialArguments["Name"]) |
95 | if (!this.myInitialArguments["Name"]) |
| 93 | { |
96 | { |
| 94 | log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n"); |
97 | log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n"); |
| Line 105... | Line 108... | ||
| 105 | 108 | ||
| 106 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
109 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
| 107 | used to make sure an eth-node gets its init packet */ |
110 | used to make sure an eth-node gets its init packet */ |
| 108 | this.myIntervalAlways = new Interval(function() { self.sendTimeStamp() }, 10000); |
111 | this.myIntervalAlways = new Interval(function() { self.sendTimeStamp() }, 10000); |
| 109 | this.myIntervalAlways.start(); |
112 | this.myIntervalAlways.start(); |
| 110 | 113 | ||
| 111 | this.screenSaverCnt = 0; |
114 | this.screenSaverCnt = 0; |
| 112 | this.mainScreenCnt = 0; |
115 | this.mainScreenCnt = 0; |
| 113 | this.exchangeUpdateCnt = exchangeUpdateTimeout-10; |
116 | this.exchangeUpdateCnt = exchangeUpdateTimeout-10; |
| - | 117 | ||
| - | 118 | LEDstatus = "none"; |
|
| 114 | 119 | ||
| 115 | /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */ |
120 | /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */ |
| 116 | this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]); |
121 | this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]); |
| 117 | /* Add a callback for when the service goes online */ |
122 | /* Add a callback for when the service goes online */ |
| 118 | this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); }); |
123 | this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); }); |
| Line 136... | Line 141... | ||
| 136 | this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]); |
141 | this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]); |
| 137 | /* Add a callback for when the service goes online */ |
142 | /* Add a callback for when the service goes online */ |
| 138 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
143 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
| 139 | /* If the service is already online we should call the handler here */ |
144 | /* If the service is already online we should call the handler here */ |
| 140 | this.softPwmOnline(); |
145 | this.softPwmOnline(); |
| 141 | 146 | ||
| 142 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
147 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
| 143 | this.exchangeCalendarBook = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarBookCallback(shortname, data); }); |
148 | this.exchangeCalendarBook = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarBookCallback(shortname, data); }); |
| 144 | 149 | ||
| 145 | /* create the first menu item */ |
150 | /* create the first menu item */ |
| 146 | this.statusMenuItem = new MenuItem(this); |
151 | this.statusMenuItem = new MenuItem(this); |
| Line 444... | Line 449... | ||
| 444 | } |
449 | } |
| 445 | else |
450 | else |
| 446 | { |
451 | { |
| 447 | this.exchangeData = data; |
452 | this.exchangeData = data; |
| 448 | this.createCalendarMenu(); |
453 | this.createCalendarMenu(); |
| 449 | - | ||
| 450 | this.setLEDtoCalendar(); |
- | |
| 451 | } |
- | |
| 452 | } |
454 | } |
| 453 | } |
455 | } |
| - | 456 | } |
|
| 454 | 457 | ||
| 455 | /* this function parses calendar data from exchange-script and creates a menu */ |
458 | /* this function parses calendar data from exchange-script and creates a menu */ |
| 456 | Display.prototype.createCalendarMenu = function() |
459 | Display.prototype.createCalendarMenu = function() |
| 457 | { |
460 | { |
| 458 | /* This is used for function declarations like the callbacks below */ |
461 | /* This is used for function declarations like the callbacks below */ |
| 459 | var self = this; |
462 | var self = this; |
| 460 | 463 | ||
| 461 | this.exchangeCalendarLastMenuItem = null; |
464 | this.exchangeCalendarLastMenuItem = null; |
| 462 | this.exchangeCalendarFirstMenuItem = null; |
465 | this.exchangeCalendarFirstMenuItem = null; |
| 463 | 466 | ||
| 464 | if (this.exchangeData) |
467 | if (this.exchangeData) |
| 465 | { |
468 | { |
| 466 | var lastMenuItem; |
469 | var lastMenuItem; |
| 467 | for (var i = 0; i < this.exchangeData.meetings.length; i++) |
470 | for (var i = 0; i < this.exchangeData.meetings.length; i++) |
| 468 | { |
471 | { |
| 469 | /* create the menuitem for a calendar meeting */ |
472 | /* create the menuitem for a calendar meeting */ |
| 470 | var menu = new MenuItem(this); |
473 | var menu = new MenuItem(this); |
| 471 | menu.displayData[0] = this.lcdCenterText(this.replaceAumlauts(this.exchangeData.meetings[i].subject)); |
474 | menu.displayData[0] = this.lcdCenterText(this.replaceAumlauts(this.exchangeData.meetings[i].subject)); |
| 472 | menu.displayData[1] = this.lcdCenterText(this.exchangeData.meetings[i].start |
475 | menu.displayData[1] = this.lcdCenterText(this.exchangeData.meetings[i].start + " - " |
| 473 | + this.exchangeData.meetings[i].end |
476 | + this.exchangeData.meetings[i].end); |
| 474 | menu.doRight = function(args) { self.changeToNext(); }; |
477 | menu.doRight = function(args) { self.changeToNext(); }; |
| 475 | menu.doLeft = function(args) { self.changeToPrev(); }; |
478 | menu.doLeft = function(args) { self.changeToPrev(); }; |
| 476 | 479 | ||
| 477 | if (i == 0) |
480 | if (i == 0) |
| 478 | { |
481 | { |
| 479 | this.exchangeCalendarFirstMenuItem = menu; |
482 | this.exchangeCalendarFirstMenuItem = menu; |
| 480 | } |
483 | } |
| 481 | else |
484 | else |
| 482 | { |
485 | { |
| 483 | menu.setPrevItem(lastMenuItem); |
486 | menu.setPrevItem(lastMenuItem); |
| Line 641... | Line 644... | ||
| 641 | if (this.exchangeData) |
644 | if (this.exchangeData) |
| 642 | { |
645 | { |
| 643 | var now = new Date(); |
646 | var now = new Date(); |
| 644 | //for (var i = 0; i < this.exchangeData.meetings.length; i++) |
647 | //for (var i = 0; i < this.exchangeData.meetings.length; i++) |
| 645 | if (this.exchangeData.meetings.length > 0) |
648 | if (this.exchangeData.meetings.length > 0) |
| 646 | { |
649 | { |
| 647 | /* check if current time is before start of first meeting |
650 | /* check if current time is before start of first meeting |
| 648 | first meeting is always the next meeting or current meeting */ |
651 | first meeting is always the next meeting or current meeting */ |
| 649 | //var startDate = new Date.parse(this.exchangeData.meetings[0].start); |
652 | //var startDate = new Date.parse(this.exchangeData.meetings[0].start); |
| 650 | var startTimeSplit = this.exchangeData.meetings[0].start.split(":"); |
653 | var startTimeSplit = this.exchangeData.meetings[0].start.split(":"); |
| 651 | if (now.getHours() < startTimeSplit[0] || now.getHours() == startTimeSplit[0] && now.getMinutes() < startTimeSplit[1]) |
654 | if (now.getHours() < startTimeSplit[0] || now.getHours() == startTimeSplit[0] && now.getMinutes() < startTimeSplit[1]) |
| 652 | { |
655 | { |
| - | 656 | if (LEDstatus != "green") |
|
| - | 657 | { |
|
| - | 658 | LEDstatus = "green"; |
|
| 653 | this.setLEDgreen(); |
659 | this.setLEDgreen(); |
| - | 660 | } |
|
| 654 | } |
661 | } |
| 655 | else |
662 | else |
| 656 | { |
663 | { |
| - | 664 | if (LEDstatus != "red") |
|
| - | 665 | { |
|
| - | 666 | LEDstatus = "red"; |
|
| 657 | this.setLEDred(); |
667 | this.setLEDred(); |
| - | 668 | } |
|
| 658 | } |
669 | } |
| 659 | } |
670 | } |
| 660 | else |
671 | else |
| 661 | { |
672 | { |
| - | 673 | if (LEDstatus != "green") |
|
| - | 674 | { |
|
| - | 675 | LEDstatus = "green"; |
|
| 662 | this.setLEDgreen(); |
676 | this.setLEDgreen(); |
| - | 677 | } |
|
| 663 | } |
678 | } |
| 664 | } |
679 | } |
| 665 | } |
680 | } |
| 666 | 681 | ||
| 667 | Display.prototype.setLEDred = function() |
682 | Display.prototype.setLEDred = function() |
| Line 673... | Line 688... | ||
| 673 | { |
688 | { |
| 674 | this.setLED(0, 255, 0); |
689 | this.setLED(0, 255, 0); |
| 675 | } |
690 | } |
| 676 | 691 | ||
| 677 | Display.prototype.setLED = function(red, green, blue) |
692 | Display.prototype.setLED = function(red, green, blue) |
| 678 | { |
693 | { |
| 679 | log("trying to set leds to red " +red+" green "+green+" blue "+blue+"\n"); |
694 | log("trying to set leds to red " +red+" green "+green+" blue "+blue+"\n"); |
| 680 | if (this.mySoftPwmService.isOnline()) |
695 | if (this.mySoftPwmService.isOnline()) |
| 681 | { |
696 | { |
| 682 | this.mySoftPwmService.setPWMValue(255-(red&0xff), 1); |
697 | this.mySoftPwmService.setPWMValue(255-(red&0xff), 1); |
| 683 | this.mySoftPwmService.setPWMValue(255-(green&0xff), 2); |
698 | this.mySoftPwmService.setPWMValue(255-(green&0xff), 2); |
| Line 693... | Line 708... | ||
| 693 | 708 | ||
| 694 | Display.prototype.timerUpdate = function() |
709 | Display.prototype.timerUpdate = function() |
| 695 | { |
710 | { |
| 696 | /* If LCD service is not online do nothing */ |
711 | /* If LCD service is not online do nothing */ |
| 697 | if (this.myLCDService.isOnline()) |
712 | if (this.myLCDService.isOnline()) |
| 698 | { |
713 | { |
| 699 | this.screenSaverCnt++; |
714 | this.screenSaverCnt++; |
| 700 | this.mainScreenCnt++; |
715 | this.mainScreenCnt++; |
| 701 | this.exchangeUpdateCnt++; |
716 | this.exchangeUpdateCnt++; |
| 702 | 717 | ||
| 703 | if (this.mainScreenCnt > mainScreenTimeout/5) |
718 | if (this.mainScreenCnt > mainScreenTimeout/5) |
| 704 | { |
719 | { |
| 705 | /* Go to main screen (time) */ |
720 | /* Go to main screen (time) */ |
| 706 | this.currentMenuItem = this.statusMenuItem; |
721 | this.currentMenuItem = this.statusMenuItem; |
| 707 | 722 | ||
| 708 | /* update the info on display */ |
723 | /* update the info on display */ |
| 709 | this.updateDisplay(); |
724 | this.updateDisplay(); |
| 710 | 725 | ||
| 711 | this.mainScreenCnt = 0; |
726 | this.mainScreenCnt = 0; |
| 712 | } |
727 | } |
| 713 | 728 | ||
| 714 | if (this.screenSaverCnt > screenSaverTimeout/5) |
729 | if (this.screenSaverCnt > screenSaverTimeout/5) |
| 715 | { |
730 | { |
| 716 | 731 | ||
| 717 | this.screenSaverCnt = 0; |
732 | this.screenSaverCnt = 0; |
| 718 | } |
733 | } |
| 719 | 734 | ||
| 720 | if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5) |
735 | if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5) |
| 721 | { |
736 | { |
| 722 | /* update the info on display */ |
737 | /* update the info on display */ |
| 723 | this.updateDisplay(); |
738 | this.updateDisplay(); |
| 724 | 739 | ||
| 725 | /* do an exchange lookup */ |
740 | /* do an exchange lookup */ |
| 726 | this.exchangeCalendar.lookup(this.shortName); |
741 | this.exchangeCalendar.lookup(this.shortName); |
| 727 | 742 | ||
| 728 | this.exchangeUpdateCnt = 0; |
743 | this.exchangeUpdateCnt = 0; |
| 729 | } |
744 | } |
| - | 745 | ||
| - | 746 | this.setLEDtoCalendar(); |
|
| 730 | } |
747 | } |
| 731 | } |
748 | } |
| 732 | 749 | ||