Rev 1181 | Rev 1185 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1181 | Rev 1182 | ||
|---|---|---|---|
| Line 8... | Line 8... | ||
| 8 | this.Service(type, name, id); |
8 | this.Service(type, name, id); |
| 9 | } |
9 | } |
| 10 | 10 | ||
| 11 | /* We inherit from Service with this call, it must always be next |
11 | /* We inherit from Service with this call, it must always be next |
| 12 | after the constructor */ |
12 | after the constructor */ |
| 13 | extend( |
13 | extend(Display, Service); |
| 14 | 14 | ||
| 15 | /* Declaration of instance variables, for static variables remove prototype */ |
15 | /* Declaration of instance variables, for static variables remove prototype */ |
| 16 | /* The currently displayed menuitem */ |
16 | /* The currently displayed menuitem */ |
| 17 | Display.prototype.currentMenuItem = null; |
17 | Display.prototype.currentMenuItem = null; |
| 18 | 18 | ||
| Line 32... | Line 32... | ||
| 32 | Display.prototype.myLCDService = null; |
32 | Display.prototype.myLCDService = null; |
| 33 | Display.prototype.myRotaryService = null; |
33 | Display.prototype.myRotaryService = null; |
| 34 | Display.prototype.mySoftPwmService = null; |
34 | Display.prototype.mySoftPwmService = null; |
| 35 | Display.prototype.myInterval = null; |
35 | Display.prototype.myInterval = null; |
| 36 | Display.prototype.exchangeCalendar = null; |
36 | Display.prototype.exchangeCalendar = null; |
| 37 | - | ||
| 38 | 37 | ||
| 39 | 38 | ||
| 40 | /* This function must always be declared, this is where all the startup code |
39 | /* This function must always be declared, this is where all the startup code |
| 41 | should be placed. Gets called with arguments like what ids to use etc. */ |
40 | should be placed. Gets called with arguments like what ids to use etc. */ |
| 42 | Display.prototype.initialize = function(initialArguments) |
41 | Display.prototype.initialize = function(initialArguments) |
| Line 44... | Line 43... | ||
| 44 | /* We must always call the parent initialize */ |
43 | /* We must always call the parent initialize */ |
| 45 | this.Service.prototype.initialize.call(this, initialArguments); |
44 | this.Service.prototype.initialize.call(this, initialArguments); |
| 46 | 45 | ||
| 47 | /* This is used for function declarations like the callbacks below */ |
46 | /* This is used for function declarations like the callbacks below */ |
| 48 | var self = this; |
47 | var self = this; |
| 49 | 48 | ||
| 50 | if (!this.myInitialArguments["HD44789"]) |
49 | if (!this.myInitialArguments["HD44789"]) |
| 51 | { |
50 | { |
| 52 | log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n"); |
51 | log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n"); |
| 53 | return; |
52 | return; |
| 54 | } |
53 | } |
| 55 | 54 | ||
| 56 | if (!this.myInitialArguments["Rotary"]) |
55 | if (!this.myInitialArguments["Rotary"]) |
| 57 | { |
56 | { |
| 58 | log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n"); |
57 | log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n"); |
| 59 | return; |
58 | return; |
| 60 | } |
59 | } |
| 61 | 60 | ||
| 62 | if (!this.myInitialArguments["softPWM"]) |
61 | if (!this.myInitialArguments["softPWM"]) |
| 63 | { |
62 | { |
| 64 | log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n"); |
63 | log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n"); |
| Line 96... | Line 95... | ||
| 96 | this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); }); |
95 | this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); }); |
| 97 | /* Add a callback for when the service goes online */ |
96 | /* Add a callback for when the service goes online */ |
| 98 | this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); }); |
97 | this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); }); |
| 99 | /* If the service is already online we should call the handler here */ |
98 | /* If the service is already online we should call the handler here */ |
| 100 | this.rotaryOnline(); |
99 | this.rotaryOnline(); |
| 101 | 100 | ||
| 102 | /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */ |
101 | /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */ |
| 103 | this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]); |
102 | this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]); |
| 104 | /* Add a callback for when the service goes online */ |
103 | /* Add a callback for when the service goes online */ |
| 105 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
104 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
| 106 | /* If the service is already online we should call the handler here */ |
105 | /* If the service is already online we should call the handler here */ |
| 107 | this.softPwmOnline(); |
106 | this.softPwmOnline(); |
| 108 | 107 | ||
| 109 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
108 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
| 110 | } |
109 | } |
| 111 | 110 | ||
| 112 | 111 | ||
| 113 | 112 | ||
| 114 | Display.prototype.exchangeCalendarLookupCallback = function(shortname, data) |
113 | Display.prototype.exchangeCalendarLookupCallback = function(shortname, data) |
| 115 | { |
114 | { |
| 116 | if (shortname == this.shortName) |
115 | if (shortname == this.shortName) |
| 117 | { |
116 | { |
| 118 | //FIXME check if data contains error tag and error message, print to log and keep previous data? |
117 | //FIXME check if data contains error tag and error message, print to log and keep previous data? |
| 119 | this.exchangeData = data; |
118 | this.exchangeData = data; |
| 120 | } |
119 | } |
| 121 | } |
120 | } |
| 122 | 121 | ||
| 123 | Display.prototype.softPwmOnline = function() |
122 | Display.prototype.softPwmOnline = function() |
| 124 | { |
123 | { |
| 125 | } |
124 | } |
| 126 | 125 | ||
| 127 | Display.prototype.rotaryOnline = function() |
126 | Display.prototype.rotaryOnline = function() |
| 128 | { |
127 | { |
| 129 | } |
128 | } |
| 130 | 129 | ||
| 131 | Display.prototype.rotaryPosUpdate = function(SwitchId) |
130 | Display.prototype.rotaryPosUpdate = function(SwitchId) |
| 132 | { |
131 | { |
| 133 | for (var i = 0; i < myRotaryService.getSteps(SwitchId); i++) |
132 | for (var i = 0; i < myRotaryService.getSteps(SwitchId); i++) |
| 134 | { |
133 | { |
| 135 | if (myRotaryService.getDirection(SwitchId) == "Clockwise") |
134 | if (myRotaryService.getDirection(SwitchId) == "Clockwise") |
| 136 | { |
135 | { |
| 137 | this.currentMenuItem.doRight(); |
136 | this.currentMenuItem.doRight(); |
| 138 | } |
137 | } |
| 139 | else |
138 | else |
| 140 | { |
139 | { |
| 141 | this.currentMenuItem.doLeft(); |
140 | this.currentMenuItem.doLeft(); |
| 142 | } |
141 | } |
| 143 | } |
142 | } |
| 144 | - | ||
| 145 | } |
143 | } |
| 146 | 144 | ||
| 147 | Display.prototype.rotaryBtnUpdate = function(SwitchId) |
145 | Display.prototype.rotaryBtnUpdate = function(SwitchId) |
| 148 | { |
146 | { |
| 149 | if (myRotaryService.getButtonStatus(SwitchId) == "Released") |
147 | if (myRotaryService.getButtonStatus(SwitchId) == "Released") |
| 150 | { |
148 | { |
| 151 | this.currentMenuItem.doPress(); |
149 | this.currentMenuItem.doPress(); |
| 152 | } |
150 | } |
| - | 151 | } |
|
| - | 152 | ||
| - | 153 | Display.prototype.updateDisplay = function() |
|
| - | 154 | { |
|
| - | 155 | /* see if the current menuitem wants to update itself */ |
|
| - | 156 | if (this.currentMenuItem.doUpdate) |
|
| - | 157 | { |
|
| - | 158 | this.currentMenuItem.doUpdate(); |
|
| - | 159 | } |
|
| - | 160 | ||
| - | 161 | /* send the data for the current menuitem to display */ |
|
| - | 162 | for (var i = 0; i < this.currentMenuItem.displayData.length; i++) |
|
| - | 163 | { |
|
| - | 164 | this.myLCDService.printText(0, i, currentMenuItem.displayData[i]); |
|
| - | 165 | } |
|
| - | 166 | ||
| 153 | } |
167 | } |
| 154 | 168 | ||
| 155 | Display.prototype.lcdOffline = function() |
169 | Display.prototype.lcdOffline = function() |
| 156 | { |
170 | { |
| 157 | /* If we have no interval timer running do nothing */ |
171 | /* If we have no interval timer running do nothing */ |
| 158 | if (this.myInterval != null) |
172 | if (this.myInterval != null) |
| 159 | { |
173 | { |
| 160 | /* Stop the interval */ |
174 | /* Stop the interval */ |
| 161 | this.myInterval.stop(); |
175 | this.myInterval.stop(); |
| 162 | } |
176 | } |
| 163 | } |
177 | } |
| 164 | 178 | ||
| 165 | Display.prototype.lcdOnline = function() |
179 | Display.prototype.lcdOnline = function() |
| 166 | { |
180 | { |
| 167 | /* If service is not online do nothing */ |
181 | /* If service is not online do nothing */ |
| 168 | if (this.myLCDService.isOnline()) |
182 | if (this.myLCDService.isOnline()) |
| 169 | { |
183 | { |
| Line 181... | Line 195... | ||
| 181 | this.myInterval = new Interval(function() { self.timerUpdate() }, 60000); |
195 | this.myInterval = new Interval(function() { self.timerUpdate() }, 60000); |
| 182 | } |
196 | } |
| 183 | 197 | ||
| 184 | this.myInterval.start(); |
198 | this.myInterval.start(); |
| 185 | } |
199 | } |
| 186 | } |
200 | } |
| 187 | 201 | ||
| 188 | Display.prototype.timerUpdate = function() |
202 | Display.prototype.timerUpdate = function() |
| 189 | { |
203 | { |
| 190 | /* If LCD service is not online do nothing */ |
204 | /* If LCD service is not online do nothing */ |
| 191 | if (this.myLCDService.isOnline()) |
205 | if (this.myLCDService.isOnline()) |
| 192 | { |
206 | { |
| 193 | this.exchangeCalendar.lookup(this.shortName); |
207 | this.exchangeCalendar.lookup(this.shortName); |
| 194 | 208 | ||
| 195 | /* see if the current menuitem wants to update itself */ |
- | |
| 196 |
|
209 | /* update the info on display */ |
| 197 | { |
- | |
| 198 |
|
210 | this.updateDisplay(); |
| 199 | } |
- | |
| 200 | - | ||
| 201 | /* send the data for the current menuitem to display */ |
- | |
| 202 | for (var i = 0; i < this.currentMenuItem.displayData.length; i++) |
- | |
| 203 | { |
- | |
| 204 | this.myLCDService.printText(0, i, currentMenuItem.displayData[i]); |
- | |
| 205 | } |
- | |
| 206 | 211 | ||
| 207 | //var date = new Date(); |
212 | //var date = new Date(); |
| 208 | /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */ |
213 | /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */ |
| 209 | //var dateAndTime = date.getDateTimeFormated(); |
214 | //var dateAndTime = date.getDateTimeFormated(); |
| 210 | /* Print the text to the LCD */ |
215 | /* Print the text to the LCD */ |