Rev 1344 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1344 | Rev 1346 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | loadScript("Logic/gLCD_MenuItems/MainMenuItem.js"); |
2 | loadScript("Logic/gLCD_MenuItems/MainMenuItem.js"); |
| 3 | loadScript("Logic/gLCD_MenuItems/SettingsMenuItem.js"); |
3 | loadScript("Logic/gLCD_MenuItems/SettingsMenuItem.js"); |
| - | 4 | loadScript("Logic/gLCD_MenuItems/DimmerGlcdMenuItem.js"); |
|
| 4 | 5 | ||
| 5 | function DorrDisplay(type, name, id) |
6 | function DorrDisplay(type, name, id) |
| 6 | { |
7 | { |
| 7 | /* We must always call the parent constructor, initialization |
8 | /* We must always call the parent constructor, initialization |
| 8 | of variables could be done here, but initialize is a better place */ |
9 | of variables could be done here, but initialize is a better place */ |
| Line 20... | Line 21... | ||
| 20 | 21 | ||
| 21 | DorrDisplay.prototype.myInterval = null; |
22 | DorrDisplay.prototype.myInterval = null; |
| 22 | DorrDisplay.prototype.myIntervalAlways = null; |
23 | DorrDisplay.prototype.myIntervalAlways = null; |
| 23 | 24 | ||
| 24 | DorrDisplay.prototype.MainMenuItem = null; |
25 | DorrDisplay.prototype.MainMenuItem = null; |
| 25 | DorrDisplay.prototype. |
26 | DorrDisplay.prototype.SettingMenuItem = null; |
| - | 27 | DorrDisplay.prototype.DimmerGlcdMenuItem = null; |
|
| 26 | 28 | ||
| 27 | /* The currently displayed menuitem */ |
29 | /* The currently displayed menuitem */ |
| 28 | DorrDisplay.prototype.currentMenuItem = null; |
30 | DorrDisplay.prototype.currentMenuItem = null; |
| 29 | 31 | ||
| 30 | /* counter for going to screensaver */ |
32 | /* counter for going to screensaver */ |
| Line 34... | Line 36... | ||
| 34 | DorrDisplay.prototype.mainScreenCnt = null; |
36 | DorrDisplay.prototype.mainScreenCnt = null; |
| 35 | 37 | ||
| 36 | const DorrDisplay_mainScreenTimeout = 20; |
38 | const DorrDisplay_mainScreenTimeout = 20; |
| 37 | const DorrDisplay_screenSaverTimeout = 25; |
39 | const DorrDisplay_screenSaverTimeout = 25; |
| 38 | 40 | ||
| - | 41 | DorrDisplay.prototype.defaultBacklight = 60; |
|
| 39 | 42 | ||
| 40 | /* This function must always be declared, this is where all the startup code |
43 | /* 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. */ |
44 | should be placed. Gets called with arguments like what ids to use etc. */ |
| 42 | DorrDisplay.prototype.initialize = function(initialArguments) |
45 | DorrDisplay.prototype.initialize = function(initialArguments) |
| 43 | { |
46 | { |
| Line 58... | Line 61... | ||
| 58 | if (!this.myInitialArguments["Rotary"]) |
61 | if (!this.myInitialArguments["Rotary"]) |
| 59 | { |
62 | { |
| 60 | log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n"); |
63 | log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n"); |
| 61 | return; |
64 | return; |
| 62 | } |
65 | } |
| 63 | /* create the first menu item */ |
- | |
| 64 | this.MainMenuItem = new MainMenuItem(this, this.myGLCDService); |
- | |
| 65 | this.SettingMenuItem = new SettingsMenuItem(this, this.myGLCDService); |
- | |
| 66 | - | ||
| 67 | 66 | ||
| 68 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
67 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
| 69 | used to make sure an eth-node gets its init packet (600s) */ |
68 | used to make sure an eth-node gets its init packet (600s) */ |
| 70 | this.myIntervalAlways = new Interval(function() { self.sendTimeStamp() }, 600000); |
69 | this.myIntervalAlways = new Interval(function() { self.sendTimeStamp() }, 600000); |
| 71 | this.myIntervalAlways.start(); |
70 | this.myIntervalAlways.start(); |
| Line 98... | Line 97... | ||
| 98 | this.rotaryOnline(); |
97 | this.rotaryOnline(); |
| 99 | 98 | ||
| 100 | /* create the first menu item */ |
99 | /* create the first menu item */ |
| 101 | this.MainMenuItem = new MainMenuItem(this, this.myGLCDService); |
100 | this.MainMenuItem = new MainMenuItem(this, this.myGLCDService); |
| 102 | this.SettingMenuItem = new SettingsMenuItem(this, this.myGLCDService); |
101 | this.SettingMenuItem = new SettingsMenuItem(this, this.myGLCDService); |
| - | 102 | this.DimmerGlcdMenuItem = new DimmerGlcdMenuItem(this, this.myGLCDService); |
|
| 103 | 103 | ||
| 104 | this.currentMenuItem = this.MainMenuItem; |
104 | this.currentMenuItem = this.MainMenuItem; |
| 105 | 105 | ||
| 106 | 106 | ||
| 107 | /* create the screensaver menu item */ |
107 | /* create the screensaver menu item */ |
| 108 | this.SettingMenuItem.LeftItem=this.MainMenuItem; |
108 | this.SettingMenuItem.LeftItem=this.MainMenuItem; |
| 109 | this.SettingMenuItem.RightItem=this. |
109 | this.SettingMenuItem.RightItem=this.DimmerGlcdMenuItem; |
| 110 | 110 | ||
| 111 | /* set the function that shall be executed when knob is turned */ |
111 | /* set the function that shall be executed when knob is turned */ |
| 112 | /* create the screensaver menu item */ |
112 | /* create the screensaver menu item */ |
| 113 | this.MainMenuItem.LeftItem=this. |
113 | this.MainMenuItem.LeftItem=this.DimmerGlcdMenuItem; |
| 114 | this.MainMenuItem.RightItem=this.SettingMenuItem; |
114 | this.MainMenuItem.RightItem=this.SettingMenuItem; |
| - | 115 | this.DimmerGlcdMenuItem.RightItem=this.MainMenuItem; |
|
| - | 116 | this.DimmerGlcdMenuItem.LeftItem=this.SettingMenuItem; |
|
| - | 117 | ||
| 115 | 118 | ||
| 116 | } |
119 | } |
| 117 | // |
120 | // |
| 118 | DorrDisplay.prototype.changeToLeft = function() |
121 | DorrDisplay.prototype.changeToLeft = function() |
| 119 | { |
122 | { |
| 120 | if (this.currentMenuItem.LeftItem) |
123 | if (this.currentMenuItem.LeftItem) |
| 121 | { |
124 | { |
| 122 | this.currentMenuItem.onExit(); |
125 | this.currentMenuItem.onExit(); |
| 123 | this.currentMenuItem = this.currentMenuItem.LeftItem; |
126 | this.currentMenuItem = this.currentMenuItem.LeftItem; |
| 124 | this.currentMenuItem.onEnter(); |
127 | this.currentMenuItem.onEnter(); |
| 125 | } |
128 | } |
| 126 | } |
129 | } |
| 127 | 130 | ||
| 128 | DorrDisplay.prototype.changeToRight = function() |
131 | DorrDisplay.prototype.changeToRight = function() |
| 129 | { |
132 | { |
| Line 173... | Line 176... | ||
| 173 | this.currentMenuItem.onEnter(); |
176 | this.currentMenuItem.onEnter(); |
| 174 | } |
177 | } |
| 175 | } |
178 | } |
| 176 | 179 | ||
| 177 | DorrDisplay.prototype.rotaryOnline = function() |
180 | DorrDisplay.prototype.rotaryOnline = function() |
| 178 | { |
181 | { |
| 179 | } |
182 | } |
| 180 | 183 | ||
| 181 | DorrDisplay.prototype.rotaryPosUpdate1 = function(SwitchId) |
184 | DorrDisplay.prototype.rotaryPosUpdate1 = function(SwitchId) |
| 182 | { |
185 | { |
| 183 | this.screenSaverCnt = 0; |
186 | this.screenSaverCnt = 0; |
| 184 | this.mainScreenCnt = 0; |
187 | this.mainScreenCnt = 0; |
| 185 | if (SwitchId != 1) { |
188 | if (SwitchId != 1) { |
| 186 | for (var i = 0; i < this.myRotaryService1.getSteps(SwitchId); i++) |
189 | for (var i = 0; i < this.myRotaryService1.getSteps(SwitchId); i++) |
| 187 | { |
190 | { |
| 188 | if (this.myRotaryService1.getDirection(SwitchId) == "Clockwise") |
191 | if (this.myRotaryService1.getDirection(SwitchId) == "Clockwise") |
| 189 | { |
192 | { |
| 190 | this.currentMenuItem.processEvent("right"); |
193 | this.currentMenuItem.processEvent("right"); |
| 191 | } |
194 | } |
| 192 | else |
195 | else |
| 193 | { |
196 | { |
| 194 | this.currentMenuItem.processEvent("left"); |
197 | this.currentMenuItem.processEvent("left"); |
| 195 | } |
198 | } |
| 196 | } |
199 | } |
| 197 | } else { |
200 | } else { |
| 198 | for (var i = 0; i < this.myRotaryService1.getSteps(SwitchId); i++) |
201 | for (var i = 0; i < this.myRotaryService1.getSteps(SwitchId); i++) |
| 199 | { |
202 | { |
| 200 | if (this.myRotaryService1.getDirection(SwitchId) == "Clockwise") |
203 | if (this.myRotaryService1.getDirection(SwitchId) == "Clockwise") |
| 201 | { |
204 | { |
| 202 | this.currentMenuItem.processEvent("up"); |
205 | this.currentMenuItem.processEvent("up"); |
| 203 | } |
206 | } |
| 204 | else |
207 | else |
| 205 | { |
208 | { |
| 206 | this.currentMenuItem.processEvent("down"); |
209 | this.currentMenuItem.processEvent("down"); |
| 207 | } |
210 | } |
| 208 | } |
211 | } |
| 209 | } |
212 | } |
| 210 | this.updateDisplay(); |
213 | this.updateDisplay(); |
| 211 | } |
214 | } |
| 212 | 215 | ||
| 213 | DorrDisplay.prototype.rotaryBtnUpdate1 = function(SwitchId) |
216 | DorrDisplay.prototype.rotaryBtnUpdate1 = function(SwitchId) |
| 214 | { |
217 | { |
| 215 | this.screenSaverCnt = 0; |
218 | this.screenSaverCnt = 0; |
| 216 | this.mainScreenCnt = 0; |
219 | this.mainScreenCnt = 0; |
| 217 | if (SwitchId != 1) { |
220 | if (SwitchId != 1) { |
| 218 | if (this.myRotaryService1.getButtonStatus(SwitchId) == "Released") |
221 | if (this.myRotaryService1.getButtonStatus(SwitchId) == "Released") |
| 219 | { |
222 | { |
| 220 | this.currentMenuItem.processEvent("enter"); |
223 | this.currentMenuItem.processEvent("enter"); |
| 221 | this.updateDisplay(); |
224 | this.updateDisplay(); |
| 222 | } |
225 | } |
| 223 | }else { |
226 | }else { |
| 224 | if (this.myRotaryService1.getButtonStatus(SwitchId) == "Released") |
227 | if (this.myRotaryService1.getButtonStatus(SwitchId) == "Released") |
| 225 | { |
228 | { |
| 226 | this.currentMenuItem.processEvent("back"); |
229 | this.currentMenuItem.processEvent("back"); |
| 227 | this.updateDisplay(); |
230 | this.updateDisplay(); |
| 228 | } |
231 | } |
| 229 | } |
232 | } |
| 230 | } |
233 | } |
| 231 | 234 | ||
| 232 | DorrDisplay.prototype.updateDisplay = function() |
235 | DorrDisplay.prototype.updateDisplay = function() |
| 233 | { |
236 | { |
| - | 237 | if (this.myGLCDService.getBacklight() == 0) { |
|
| - | 238 | this.myGLCDService.setBacklight(this.defaultBacklight); |
|
| - | 239 | } |
|
| 234 | this.currentMenuItem.update(); |
240 | this.currentMenuItem.update(); |
| 235 | } |
241 | } |
| 236 | 242 | ||
| 237 | DorrDisplay.prototype.lcdCenterText = function(text) |
243 | DorrDisplay.prototype.lcdCenterText = function(text) |
| 238 | { |
244 | { |
| 239 | returnText = text; |
245 | returnText = text; |
| 240 | var displayWidth = 20; //this.myLCDService.getWidth(); |
246 | var displayWidth = 20; //this.myLCDService.getWidth(); |
| 241 | /* pad on both sides with spaces to displayWidth */ |
247 | /* pad on both sides with spaces to displayWidth */ |
| 242 | returnText = text.pad(displayWidth, " ", 2); |
248 | returnText = text.pad(displayWidth, " ", 2); |
| 243 | 249 | ||
| 244 | return returnText; |
250 | return returnText; |
| 245 | } |
251 | } |
| 246 | 252 | ||
| 247 | DorrDisplay.prototype.lcdOffline = function() |
253 | DorrDisplay.prototype.lcdOffline = function() |
| 248 | { |
254 | { |
| 249 | } |
255 | } |
| 250 | 256 | ||
| 251 | DorrDisplay.prototype.lcdOnline = function() |
257 | DorrDisplay.prototype.lcdOnline = function() |
| 252 | { |
258 | { |
| 253 | /* If service is not online do nothing */ |
259 | /* If service is not online do nothing */ |
| 254 | if (this.myGLCDService.isOnline()) |
260 | if (this.myGLCDService.isOnline()) |
| 255 | { |
261 | { |
| 256 | /* Clear the LCD screen */ |
262 | /* Clear the LCD screen */ |
| 257 | this.myGLCDService.clearScreen("Standard"); |
263 | this.myGLCDService.clearScreen("Standard"); |
| 258 | /* Set backlight to max */ |
264 | /* Set backlight to max */ |
| 259 | this.myGLCDService.setBacklight( |
265 | this.myGLCDService.setBacklight(this.defaultBacklight); |
| 260 | this.timerUpdate(); |
266 | this.timerUpdate(); |
| 261 | } |
267 | } |
| 262 | } |
268 | } |
| 263 | 269 | ||
| 264 | 270 | ||
| 265 | DorrDisplay.prototype.sendTimeStamp = function() |
271 | DorrDisplay.prototype.sendTimeStamp = function() |
| 266 | { |
272 | { |
| 267 | var canMessage = new CanNMTMessage("nmt", "Time"); |
273 | var canMessage = new CanNMTMessage("nmt", "Time"); |
| 268 | canMessage.send(); |
274 | canMessage.send(); |
| 269 | } |
275 | } |
| 270 | 276 | ||
| 271 | DorrDisplay.prototype.timerUpdate = function() |
277 | DorrDisplay.prototype.timerUpdate = function() |
| 272 | { |
278 | { |
| 273 | /* If LCD service is not online do nothing */ |
279 | /* If LCD service is not online do nothing */ |
| 274 | if (this.myGLCDService.isOnline()) |
280 | if (this.myGLCDService.isOnline()) |
| 275 | { |
281 | { |
| 276 | this.screenSaverCnt++; |
282 | this.screenSaverCnt++; |
| 277 | this.mainScreenCnt++; |
283 | this.mainScreenCnt++; |
| 278 | if (this.mainScreenCnt > DorrDisplay_mainScreenTimeout/5 && this.currentMenuItem != this.MainMenuItem) |
284 | if (this.mainScreenCnt > DorrDisplay_mainScreenTimeout/5 && this.currentMenuItem != this.MainMenuItem) |
| 279 | { |
285 | { |
| 280 | /* Go to main screen (time) */ |
286 | /* Go to main screen (time) */ |
| 281 | this.currentMenuItem.onExit(); |
287 | this.currentMenuItem.onExit(); |
| 282 | this.currentMenuItem = this.MainMenuItem; |
288 | this.currentMenuItem = this.MainMenuItem; |
| 283 | this.currentMenuItem.onEnter(); |
289 | this.currentMenuItem.onEnter(); |
| 284 | /* update the info on display */ |
290 | /* update the info on display */ |
| 285 | this.updateDisplay(); |
291 | this.updateDisplay(); |
| 286 | 292 | ||
| 287 | this.mainScreenCnt = 0; |
293 | this.mainScreenCnt = 0; |
| 288 | 294 | ||
| 289 | } |
295 | } |
| 290 | 296 | ||
| 291 | if (this.screenSaverCnt > DorrDisplay_screenSaverTimeout/5 |
297 | if (this.screenSaverCnt > DorrDisplay_screenSaverTimeout/5) |
| 292 | { |
298 | { |
| 293 | /* Go to screensaver menu */ |
299 | /* Go to screensaver menu */ |
| 294 | this.currentMenuItem.onExit(); |
- | |
| 295 | this.currentMenuItem = this.SettingMenuItem; |
- | |
| 296 | this.currentMenuItem.onEnter(); |
- | |
| 297 |
|
300 | this.myGLCDService.setBacklight(0); |
| 298 | /* update the info on display */ |
- | |
| 299 | this.updateDisplay(); |
- | |
| 300 | 301 | ||
| 301 | this.screenSaverCnt = 0; |
302 | this.screenSaverCnt = 0; |
| 302 | } |
303 | } |
| 303 | 304 | ||
| 304 | } |
305 | } |