Rev 1182 | Rev 1189 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1182 | Rev 1185 | ||
|---|---|---|---|
| Line 104... | Line 104... | ||
| 104 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
104 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
| 105 | /* 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 */ |
| 106 | this.softPwmOnline(); |
106 | this.softPwmOnline(); |
| 107 | 107 | ||
| 108 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
108 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
| 109 | } |
- | |
| 110 | 109 | ||
| - | 110 | ||
| - | 111 | /* create the first menu item */ |
|
| - | 112 | this.currentMenuItem = new MenuItem(this); |
|
| - | 113 | this.currentMenuItem.displayData[0] = " " + this.niceName; |
|
| - | 114 | this.currentMenuItem.doUpdate = this.setTime; |
|
| - | 115 | ||
| - | 116 | /* create a test item */ |
|
| - | 117 | var meny = new MenuItem(this); |
|
| - | 118 | meny.displayData[0] = "Hej "; |
|
| - | 119 | meny.displayData[1] = " "; |
|
| - | 120 | ||
| - | 121 | /* connect the items as a linked list */ |
|
| - | 122 | this.currentMenuItem.setNextItem(meny); |
|
| - | 123 | this.currentMenuItem.setPrevItem(meny); |
|
| - | 124 | /* set the function that shall be executed when knob is turned */ |
|
| - | 125 | this.currentMenuItem.doRight = this.changeToNext; |
|
| - | 126 | this.currentMenuItem.doLeft = this.changeToPrev; |
|
| - | 127 | ||
| - | 128 | /* connect the items as a linked list */ |
|
| - | 129 | meny.setNextItem(this.currentMenuItem); |
|
| - | 130 | meny.setPrevItem(this.currentMenuItem); |
|
| - | 131 | /* set the function that shall be executed when knob is turned */ |
|
| - | 132 | meny.doRight = this.changeToNext; |
|
| - | 133 | meny.doLeft = this.changeToPrev; |
|
| - | 134 | ||
| - | 135 | ||
| - | 136 | } |
|
| - | 137 | ||
| - | 138 | Display.prototype.changeToNext = function() |
|
| - | 139 | { |
|
| - | 140 | if (this.nextItem) |
|
| - | 141 | { |
|
| - | 142 | this.parentDisplay.currentMenuItem = this.nextItem; |
|
| - | 143 | } |
|
| - | 144 | ||
| - | 145 | } |
|
| - | 146 | ||
| - | 147 | Display.prototype.changeToPrev = function() |
|
| - | 148 | { |
|
| - | 149 | if (this.prevItem) |
|
| - | 150 | { |
|
| - | 151 | this.parentDisplay.currentMenuItem = this.prevItem; |
|
| - | 152 | } |
|
| - | 153 | } |
|
| - | 154 | ||
| - | 155 | Display.prototype.setTime = function() |
|
| - | 156 | { |
|
| - | 157 | var date = new Date(); |
|
| - | 158 | /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */ |
|
| - | 159 | var dateAndTime = "" + date.getHours().toString() + "." + date.getMinutes().toString().pad(2, "0", 0); |
|
| - | 160 | this.displayData[1] = " " + dateAndTime; |
|
| - | 161 | //this.currentMenuItem.displayData[1] = " " + dateAndTime; |
|
| - | 162 | } |
|
| 111 | 163 | ||
| 112 | 164 | ||
| 113 | Display.prototype.exchangeCalendarLookupCallback = function(shortname, data) |
165 | Display.prototype.exchangeCalendarLookupCallback = function(shortname, data) |
| 114 | { |
166 | { |
| 115 | if (shortname == this.shortName) |
167 | if (shortname == this.shortName) |
| 116 | { |
168 | { |
| 117 | //FIXME check if data contains error tag and error message, print to log and keep previous data? |
169 | //FIXME check if data contains error tag and error message, print to log and keep previous data? |
| 118 | this.exchangeData = data; |
170 | this.exchangeData = data; |
| 119 | } |
171 | } |
| 120 | } |
172 | } |
| 121 | 173 | ||
| 122 | Display.prototype.softPwmOnline = function() |
174 | Display.prototype.softPwmOnline = function() |
| 123 | { |
175 | { |
| 124 | } |
176 | } |
| 125 | 177 | ||
| Line 127... | Line 179... | ||
| 127 | { |
179 | { |
| 128 | } |
180 | } |
| 129 | 181 | ||
| 130 | Display.prototype.rotaryPosUpdate = function(SwitchId) |
182 | Display.prototype.rotaryPosUpdate = function(SwitchId) |
| 131 | { |
183 | { |
| 132 | for (var i = 0; i < myRotaryService.getSteps(SwitchId); i++) |
184 | for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++) |
| 133 | { |
185 | { |
| 134 | if (myRotaryService.getDirection(SwitchId) == "Clockwise") |
186 | if (this.myRotaryService.getDirection(SwitchId) == "Clockwise") |
| - | 187 | { |
|
| - | 188 | if (this.currentMenuItem.doRight) |
|
| 135 | { |
189 | { |
| 136 | this.currentMenuItem.doRight(); |
190 | this.currentMenuItem.doRight(); |
| - | 191 | } |
|
| 137 | } |
192 | } |
| 138 | else |
193 | else |
| - | 194 | { |
|
| - | 195 | if (this.currentMenuItem.doLeft) |
|
| 139 | { |
196 | { |
| 140 | this.currentMenuItem.doLeft(); |
197 | this.currentMenuItem.doLeft(); |
| - | 198 | } |
|
| 141 | } |
199 | } |
| 142 | } |
200 | } |
| - | 201 | ||
| - | 202 | this.updateDisplay(); |
|
| 143 | } |
203 | } |
| 144 | 204 | ||
| 145 | Display.prototype.rotaryBtnUpdate = function(SwitchId) |
205 | Display.prototype.rotaryBtnUpdate = function(SwitchId) |
| 146 | { |
206 | { |
| 147 | if (myRotaryService.getButtonStatus(SwitchId) == "Released") |
207 | if (this.myRotaryService.getButtonStatus(SwitchId) == "Released") |
| 148 | { |
208 | { |
| - | 209 | if (this.currentMenuItem.doPress) |
|
| - | 210 | { |
|
| 149 | this.currentMenuItem.doPress(); |
211 | this.currentMenuItem.doPress(); |
| 150 | } |
212 | } |
| - | 213 | } |
|
| - | 214 | this.updateDisplay(); |
|
| 151 | } |
215 | } |
| 152 | 216 | ||
| 153 | Display.prototype.updateDisplay = function() |
217 | Display.prototype.updateDisplay = function() |
| 154 | { |
218 | { |
| 155 | /* see if the current menuitem wants to update itself */ |
219 | /* see if the current menuitem wants to update itself */ |
| 156 | if (this.currentMenuItem.doUpdate) |
220 | if (this.currentMenuItem.doUpdate) |
| 157 | { |
221 | { |
| 158 | this.currentMenuItem.doUpdate(); |
222 | this.currentMenuItem.doUpdate(); |
| 159 | } |
223 | } |
| - | 224 | ||
| - | 225 | /* Clear the LCD screen */ |
|
| - | 226 | this.myLCDService.clearScreen(); |
|
| 160 | 227 | ||
| 161 | /* send the data for the current menuitem to display */ |
228 | /* send the data for the current menuitem to display */ |
| 162 | for (var i = 0; i < this.currentMenuItem.displayData.length; i++) |
229 | for (var i = 0; i < this.currentMenuItem.displayData.length; i++) |
| 163 | { |
230 | { |
| 164 | this.myLCDService.printText(0, i, currentMenuItem.displayData[i]); |
231 | this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]); |
| 165 | } |
232 | } |
| 166 | 233 | ||
| 167 | } |
234 | } |
| 168 | 235 | ||
| 169 | Display.prototype.lcdOffline = function() |
236 | Display.prototype.lcdOffline = function() |
| 170 | { |
237 | { |
| 171 | /* If we have no interval timer running do nothing */ |
238 | /* If we have no interval timer running do nothing */ |
| Line 183... | Line 250... | ||
| 183 | { |
250 | { |
| 184 | /* Clear the LCD screen */ |
251 | /* Clear the LCD screen */ |
| 185 | this.myLCDService.clearScreen(); |
252 | this.myLCDService.clearScreen(); |
| 186 | /* Set backlight to max */ |
253 | /* Set backlight to max */ |
| 187 | this.myLCDService.setBacklight(255); |
254 | this.myLCDService.setBacklight(255); |
| 188 | 255 | ||
| 189 | /* If we have no interval timer running start it */ |
256 | /* If we have no interval timer running start it */ |
| 190 | if (this.myInterval == null) |
257 | if (this.myInterval == null) |
| 191 | { |
258 | { |
| 192 | var self = this; |
259 | var self = this; |
| 193 | 260 | ||
| 194 | /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */ |
261 | /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */ |
| 195 | this.myInterval = new Interval(function() { self.timerUpdate() }, 60000); |
262 | this.myInterval = new Interval(function() { self.timerUpdate() }, 60000); |
| 196 | } |
263 | } |
| 197 | 264 | ||
| 198 | this.myInterval.start(); |
265 | this.myInterval.start(); |
| - | 266 | ||
| - | 267 | this.updateDisplay(); |
|
| 199 | } |
268 | } |
| 200 | } |
269 | } |
| 201 | 270 | ||
| 202 | Display.prototype.timerUpdate = function() |
271 | Display.prototype.timerUpdate = function() |
| 203 | { |
272 | { |
| 204 | /* If LCD service is not online do nothing */ |
273 | /* If LCD service is not online do nothing */ |
| 205 | if (this.myLCDService.isOnline()) |
274 | if (this.myLCDService.isOnline()) |
| 206 | { |
275 | { |
| 207 |
|
276 | //this.exchangeCalendar.lookup(this.shortName); |
| 208 | 277 | ||
| 209 | /* update the info on display */ |
278 | /* update the info on display */ |
| 210 | this.updateDisplay(); |
279 | this.updateDisplay(); |
| 211 | 280 | ||
| 212 | //var date = new Date(); |
281 | //var date = new Date(); |