Subversion Repositories HomeAutomation

Rev

Rev 1234 | Rev 1238 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1171 arune 1
 
2
loadScript("Logic/MenuItem.js");
3
 
1175 arune 4
function Display(type, name, id)
1171 arune 5
{
1175 arune 6
    /* We must always call the parent constructor, initialization
7
       of variables could be done here, but initialize is a better place */
8
    this.Service(type, name, id);
1171 arune 9
}
10
 
1175 arune 11
/* We inherit from Service with this call, it must always be next
12
   after the constructor */
1182 arune 13
extend(Display, Service);
1175 arune 14
 
1171 arune 15
/* Declaration of instance variables, for static variables remove prototype */
16
 
1190 arune 17
/* format: dat objects, just use the time */
1189 arune 18
Display.prototype.bookFromTime = null;
19
Display.prototype.bookToTime = null;
1171 arune 20
 
21
/* the shortname for this exchangeobject */
1189 arune 22
Display.prototype.shortName = null;
1171 arune 23
 
1175 arune 24
/* the name for this display (shown on first screen) */
1189 arune 25
Display.prototype.niceName = null;
1175 arune 26
 
1172 arune 27
/* The display should regulary update and store the calendar */
1175 arune 28
Display.prototype.exchangeData = null;
1171 arune 29
 
1175 arune 30
Display.prototype.myLCDService = null;
31
Display.prototype.myRotaryService = null;
32
Display.prototype.mySoftPwmService = null;
33
Display.prototype.myInterval = null;
1189 arune 34
 
1190 arune 35
/*  */
1175 arune 36
Display.prototype.exchangeCalendar = null;
1190 arune 37
/*  */
1189 arune 38
Display.prototype.exchangeCalendarFirstMenuItem = null;
39
Display.prototype.exchangeCalendarLastMenuItem = null;
1190 arune 40
Display.prototype.statusMenuItem = null;
41
Display.prototype.bookMenuItem = null;
1216 arune 42
Display.prototype.bookResultMenuItem = null;
1175 arune 43
 
1216 arune 44
 
1190 arune 45
/* The currently displayed menuitem */
46
Display.prototype.currentMenuItem = null;
1175 arune 47
 
1203 arune 48
/* counter for calling exchange update */
49
Display.prototype.exchangeUpdateCnt = null;
1190 arune 50
 
1203 arune 51
/* counter for going to screensaver */
52
Display.prototype.screenSaverCnt = null;
53
 
54
/* counter for going to main screen */
55
Display.prototype.mainScreenCnt = null;
56
 
1204 arune 57
const exchangeUpdateTimeout = 50;
1203 arune 58
const mainScreenTimeout = 40;
59
const screenSaverTimeout = 120;
60
 
1212 arune 61
const bookingIncrease = 15;
62
 
1175 arune 63
/* This function must always be declared, this is where all the startup code
64
   should be placed. Gets called with arguments like what ids to use etc. */
65
Display.prototype.initialize = function(initialArguments)
66
{
67
    /* We must always call the parent initialize */
68
    this.Service.prototype.initialize.call(this, initialArguments);
69
 
70
    /* This is used for function declarations like the callbacks below */
71
    var self = this;
72
 
73
    if (!this.myInitialArguments["HD44789"])
74
    {
75
        log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n");
76
        return;
77
    }
78
 
79
    if (!this.myInitialArguments["Rotary"])
80
    {
81
        log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n");
82
        return;
83
    }
84
 
85
    if (!this.myInitialArguments["softPWM"])
86
    {
87
        log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n");
88
        return;
89
    }
90
 
91
    if (!this.myInitialArguments["Name"])
92
    {
93
        log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
94
        return;
95
    }
96
    this.niceName = this.myInitialArguments["Name"];
97
 
98
    if (!this.myInitialArguments["ShortName"])
99
    {
100
        log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
101
        return;
102
    }
103
    this.shortName = this.myInitialArguments["ShortName"];
104
 
1203 arune 105
    this.screenSaverCnt = 0;
106
    this.mainScreenCnt = 0;
107
    this.exchangeUpdateCnt = exchangeUpdateTimeout-10;
108
 
1175 arune 109
    /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
110
    this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
111
    /* Add a callback for when the service goes online */
112
    this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
113
    /* If the service is already online we should call the handler here */
114
    this.lcdOnline();
115
    /* Add a callback for when the service goes offline */
116
    this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); });
117
 
118
    /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
119
    this.myRotaryService = ServiceManager.getService("Can", "Rotary", this.myInitialArguments["Rotary"]["Id"]);
120
    /* Add a callback for when the encoder reports a new position */
121
    this.myRotaryService.registerEventCallback("newPosition", function(args) { self.rotaryPosUpdate(args); });
122
    /* Add a callback for when the encoder reports a new button status */
123
    this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); });
124
    /* Add a callback for when the service goes online */
125
    this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
126
    /* If the service is already online we should call the handler here */
127
    this.rotaryOnline();
128
 
129
    /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */
130
    this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]);
131
    /* Add a callback for when the service goes online */
132
    this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); });
133
    /* If the service is already online we should call the handler here */
134
    this.softPwmOnline();
135
 
136
    this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); });
1216 arune 137
    this.exchangeCalendarBook = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarBookCallback(shortname, data); });
1185 arune 138
 
139
    /* create the first menu item */
1189 arune 140
    this.statusMenuItem = new MenuItem(this);
1190 arune 141
    this.statusMenuItem.displayData[0] = this.lcdCenterText(this.niceName);
1233 arune 142
    this.statusMenuItem.doUpdate = function(args) { self.updateStatusMenuItem(); };
1189 arune 143
    this.currentMenuItem = this.statusMenuItem;
1185 arune 144
 
1189 arune 145
    /* create the menuitem where you can choose to enter the booking sub-menu */
146
    this.bookMenuItem = new MenuItem(this);
1195 arune 147
    this.bookMenuItem.displayData[0] = this.lcdCenterText("Book room");
1216 arune 148
    this.bookMenuItem.displayData[1] = this.lcdCenterText("(Push button)");
1233 arune 149
    this.bookMenuItem.doUpdate = function(args) { self.updateBookMenuItem(); };
1189 arune 150
 
1185 arune 151
    /* connect the items as a linked list */
1189 arune 152
    this.statusMenuItem.setNextItem(this.bookMenuItem);
153
    this.statusMenuItem.setPrevItem(this.bookMenuItem);
1185 arune 154
    /* set the function that shall be executed when knob is turned */
1233 arune 155
    this.statusMenuItem.doRight = function(args) { self.changeToNext(); };
156
    this.statusMenuItem.doLeft = function(args) { self.changeToPrev(); };
1185 arune 157
 
158
    /* connect the items as a linked list */
1189 arune 159
    this.bookMenuItem.setNextItem(this.statusMenuItem);
160
    this.bookMenuItem.setPrevItem(this.statusMenuItem);
1185 arune 161
    /* set the function that shall be executed when knob is turned */
1233 arune 162
    this.bookMenuItem.doRight = function(args) { self.changeToNext(); };
163
    this.bookMenuItem.doLeft = function(args) { self.changeToPrev(); };
1185 arune 164
 
1189 arune 165
    /* create the menuitem where you can choose the to-time */
166
    var menuChooseTo = new MenuItem(this);
1195 arune 167
    menuChooseTo.displayData[1] = this.lcdCenterText(" Ok     Cancel ");
1233 arune 168
    menuChooseTo.doUpdate = function(args) { self.chooseBookTimeTo(); };
1185 arune 169
 
1233 arune 170
    this.bookMenuItem.doPress = function(args) { self.prepareBookingMenu(); };
1189 arune 171
    this.bookMenuItem.setDescItem(menuChooseTo);
172
 
173
    /* create the menuitem where you can choose to book the room with OK */
174
    var menuChooseOk = new MenuItem(this);
1195 arune 175
    menuChooseOk.displayData[1] = this.lcdCenterText("<Ok>    Cancel ");
1233 arune 176
    menuChooseOk.doUpdate = function(args) { self.setBookTime(); };
1189 arune 177
 
178
    /* create the menuitem where you can choose to cancel the booking */
179
    var menuChooseCancel = new MenuItem(this);
1195 arune 180
    menuChooseCancel.displayData[1] = this.lcdCenterText(" Ok    <Cancel>");
1233 arune 181
    menuChooseCancel.doUpdate = function(args) { self.setBookTime(); };
1189 arune 182
 
183
    /* create the menuitem where you can choose the from-time */
184
    var menuChooseFrom = new MenuItem(this);
1195 arune 185
    menuChooseFrom.displayData[1] = this.lcdCenterText(" Ok     Cancel ");
1233 arune 186
    menuChooseFrom.doUpdate = function(args) { self.chooseBookTimeFrom(); };
1189 arune 187
 
1216 arune 188
    /* create the menuitem where you see the result of a booking */
189
    this.bookResultMenuItem = new MenuItem(this);
190
    this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking...");
191
    this.bookResultMenuItem.displayData[1] = this.lcdCenterText("(Push to return)");
192
    this.bookResultMenuItem.setDescItem(this.bookMenuItem);
1233 arune 193
    this.bookResultMenuItem.doPress = function(args) { self.changeToDesc(); };
1216 arune 194
 
1189 arune 195
    /* connect the items as a linked list */
196
    menuChooseTo.setNextItem(menuChooseOk);
197
    menuChooseTo.setPrevItem(menuChooseFrom);
198
    /* set the function that shall be executed when knob is turned */
1233 arune 199
    menuChooseTo.doRight = function(args) { self.changeToNext(); };
200
    menuChooseTo.doLeft = function(args) { self.changeToPrev(); };
201
    menuChooseTo.doPress = function(args) { self.changeToDesc(); };
1189 arune 202
 
203
    /* connect the items as a linked list */
204
    menuChooseOk.setNextItem(menuChooseCancel);
205
    menuChooseOk.setPrevItem(menuChooseTo);
1216 arune 206
    menuChooseOk.setDescItem(this.bookResultMenuItem);
1189 arune 207
    /* set the function that shall be executed when knob is turned */
1233 arune 208
    menuChooseOk.doRight = function(args) { self.changeToNext(); };
209
    menuChooseOk.doLeft = function(args) { self.changeToPrev(); };
210
    menuChooseOk.doPress = function(args) { self.doBooking(); };
1189 arune 211
 
212
    /* connect the items as a linked list */
213
    menuChooseCancel.setNextItem(menuChooseFrom);
214
    menuChooseCancel.setPrevItem(menuChooseOk);
215
    menuChooseCancel.setDescItem(this.bookMenuItem);
216
    /* set the function that shall be executed when knob is turned */
1233 arune 217
    menuChooseCancel.doRight = function(args) { self.changeToNext(); };
218
    menuChooseCancel.doLeft = function(args) { self.changeToPrev(); };
219
    menuChooseCancel.doPress = function(args) { self.changeToDesc(); };
1189 arune 220
 
221
    /* connect the items as a linked list */
222
    menuChooseFrom.setNextItem(menuChooseTo);
223
    menuChooseFrom.setPrevItem(menuChooseCancel);
224
    /* set the function that shall be executed when knob is turned */
1233 arune 225
    menuChooseFrom.doRight = function(args) { self.changeToNext(); };
226
    menuChooseFrom.doLeft = function(args) { self.changeToPrev(); };
227
    menuChooseFrom.doPress = function(args) { self.changeToDesc(); };
1189 arune 228
 
229
    /* create the menuitem where you can modify the to-time */
230
    var menuSetTo = new MenuItem(this);
1233 arune 231
    menuSetTo.doUpdate = function(args) { self.setBookTimeTo(); };
1190 arune 232
    menuSetTo.displayData[0] = this.lcdCenterText("Set end time");
1233 arune 233
    menuSetTo.doRight = function(args) { self.incBookTimeTo(); };
234
    menuSetTo.doLeft = function(args) { self.decBookTimeTo(); };
235
    menuSetTo.doPress = function(args) { self.changeToDesc(); };
1189 arune 236
    menuSetTo.setDescItem(menuChooseTo);
237
    menuChooseTo.setDescItem(menuSetTo);
238
 
239
    /* create the menuitem where you can modify the from-time */
240
    var menuSetFrom = new MenuItem(this);
1233 arune 241
    menuSetFrom.doUpdate = function(args) { self.setBookTimeFrom(); };
1190 arune 242
    menuSetFrom.displayData[0] = this.lcdCenterText("Set start time");
1233 arune 243
    menuSetFrom.doRight = function(args) { self.incBookTimeFrom(); };
244
    menuSetFrom.doLeft = function(args) { self.decBookTimeFrom(); };
245
    menuSetFrom.doPress = function(args) { self.changeToDesc(); };
1189 arune 246
    menuSetFrom.setDescItem(menuChooseFrom);
247
    menuChooseFrom.setDescItem(menuSetFrom);
248
 
1175 arune 249
}
250
 
1216 arune 251
Display.prototype.exchangeCalendarBookCallback = function(shortname, data)
1190 arune 252
{
1216 arune 253
    if (shortname == this.shortName)
254
    {
255
        //FIXME check if data contains error tag and error message, print to log and keep previous data?
256
        if (data.result)
257
        {
258
            if (data.error)
259
            {
260
                this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed");
261
                log("Display: got this error from exchange server: " + data.error + "\n");
262
            }
263
            else
264
            {
265
                this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking succeeded");
1228 arune 266
                log("Display: Successfully booked room\n");
1216 arune 267
 
268
                /* do an exchange lookup */
269
                this.exchangeCalendar.lookup(this.shortName);
270
            }
271
 
272
        }
273
        else if (data.error)
274
        {
275
            this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed");
276
            log("Display: got this error from exchange.php: " + data.error + "\n");
277
        }
278
        this.updateDisplay();
279
    }
280
}
281
 
282
Display.prototype.doBooking = function()
283
{
1233 arune 284
    this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking...");
285
    if (this.currentMenuItem.descItem)
1216 arune 286
    {
1233 arune 287
        this.currentMenuItem = this.currentMenuItem.descItem;
1216 arune 288
    }
1233 arune 289
    //this.changeToDesc();
1216 arune 290
 
1233 arune 291
    var bookFrom = this.bookFromTime.getTimeShortFormated();
292
    var bookTo = this.bookToTime.getTimeShortFormated();
293
    this.exchangeCalendarBook.book(this.shortName, bookFrom, bookTo);
1216 arune 294
 
295
    //bookFromTime bookToTime
296
}
297
 
298
Display.prototype.prepareBookingMenu = function()
299
{
1233 arune 300
    this.bookFromTime = new Date();
301
    this.bookToTime = new Date();
1190 arune 302
    //this.bookFromTime.setHours(8);
303
    //this.bookToTime.setHours(8);
1233 arune 304
    if (this.bookFromTime.getMinutes() < 30)
1190 arune 305
    {
1233 arune 306
        this.bookFromTime.setMinutes(0);
307
        this.bookToTime.setMinutes(30);
1190 arune 308
    }
309
    else
310
    {
1233 arune 311
        this.bookFromTime.setMinutes(30);
312
        this.bookToTime.setHours(this.bookToTime.getHours()+1);
313
        this.bookToTime.setMinutes(0);
1190 arune 314
    }
315
 
1233 arune 316
    this.currentMenuItem = this.currentMenuItem.descItem;
1190 arune 317
}
318
 
1189 arune 319
Display.prototype.changeToDesc = function()
320
{
1233 arune 321
    if (this.currentMenuItem.descItem)
1189 arune 322
    {
1233 arune 323
        this.currentMenuItem = this.currentMenuItem.descItem;
1189 arune 324
    }
325
}
326
 
1185 arune 327
Display.prototype.changeToNext = function()
328
{
1233 arune 329
    if (this.currentMenuItem.nextItem)
1185 arune 330
    {
1233 arune 331
        this.currentMenuItem = this.currentMenuItem.nextItem;
1185 arune 332
    }
333
}
1175 arune 334
 
1185 arune 335
Display.prototype.changeToPrev = function()
336
{
1233 arune 337
    if (this.currentMenuItem.prevItem)
1185 arune 338
    {
1233 arune 339
        this.currentMenuItem = this.currentMenuItem.prevItem;
1185 arune 340
    }
341
}
1175 arune 342
 
1189 arune 343
Display.prototype.incBookTimeTo = function()
1185 arune 344
{
1189 arune 345
    //FIXME: constraints?
1233 arune 346
    if (this.bookToTime.getHours() < 23)
1194 arune 347
    {
1233 arune 348
        this.bookToTime.setMinutes(this.bookToTime.getMinutes() + bookingIncrease);
1194 arune 349
    }
1189 arune 350
}
351
 
352
Display.prototype.decBookTimeTo = function()
353
{
354
    //FIXME: constraints?
1194 arune 355
    var now = new Date();
1233 arune 356
    if (this.bookToTime.getHours() >= now.getHours())
1194 arune 357
    {
1233 arune 358
        this.bookToTime.setMinutes(this.bookToTime.getMinutes() - bookingIncrease);
1194 arune 359
    }
1189 arune 360
}
361
 
362
Display.prototype.incBookTimeFrom = function()
363
{
364
    //FIXME: constraints?
1233 arune 365
    if (this.bookFromTime.getHours() < 23)
1194 arune 366
    {
1233 arune 367
        this.bookFromTime.setMinutes(this.bookFromTime.getMinutes() + bookingIncrease);
1194 arune 368
    }
1189 arune 369
}
370
 
371
Display.prototype.decBookTimeFrom = function()
372
{
373
    //FIXME: constraints?
1194 arune 374
    var now = new Date();
1233 arune 375
    if (this.bookFromTime.getHours() >= now.getHours())
1194 arune 376
    {
1233 arune 377
        this.bookFromTime.setMinutes(this.bookFromTime.getMinutes() - bookingIncrease);
1194 arune 378
    }
1189 arune 379
}
380
 
381
Display.prototype.setBookTimeFrom = function()
382
{
1233 arune 383
    this.currentMenuItem.displayData[1] = "      <"+this.bookFromTime.getTimeShortFormated()+">       ";
1189 arune 384
}
385
 
386
Display.prototype.setBookTimeTo = function()
387
{
1233 arune 388
    this.currentMenuItem.displayData[1] = "      <"+this.bookToTime.getTimeShortFormated()+">       ";
1189 arune 389
}
390
 
391
Display.prototype.chooseBookTimeTo = function()
392
{
1233 arune 393
    this.currentMenuItem.displayData[0] = "  "+this.bookFromTime.getTimeShortFormated()+"  - <"
394
                                +this.bookToTime.getTimeShortFormated()+">  ";
1189 arune 395
}
396
 
397
Display.prototype.chooseBookTimeFrom = function()
398
{
1233 arune 399
    this.currentMenuItem.displayData[0] = " <"+this.bookFromTime.getTimeShortFormated()+"> -  "
400
                                +this.bookToTime.getTimeShortFormated()+"   ";
1189 arune 401
}
402
 
403
Display.prototype.setBookTime = function()
404
{
1233 arune 405
    this.currentMenuItem.displayData[0] = "  "+this.bookFromTime.getTimeShortFormated()+"  -  "
406
                                +this.bookToTime.getTimeShortFormated()+"   ";
1189 arune 407
}
408
 
409
Display.prototype.updateStatusMenuItem = function()
410
{
1185 arune 411
    var date = new Date();
1189 arune 412
    var dateAndTime = "" + date.getTimeShortFormated();
1233 arune 413
    this.statusMenuItem.displayData[1] = this.lcdCenterText(dateAndTime);
1185 arune 414
}
415
 
1189 arune 416
Display.prototype.updateBookMenuItem = function()
417
{
1233 arune 418
    if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
1189 arune 419
    {
1233 arune 420
        this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
421
        this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
1189 arune 422
    }
1198 arune 423
    else
424
    {
1233 arune 425
        this.statusMenuItem.setNextItem(this.bookMenuItem);
426
        this.bookMenuItem.setPrevItem(this.statusMenuItem);
1198 arune 427
    }
1189 arune 428
}
1185 arune 429
 
1175 arune 430
Display.prototype.exchangeCalendarLookupCallback = function(shortname, data)
431
{
1195 arune 432
//log("callback: "+shortname+" \n");
1175 arune 433
    if (shortname == this.shortName)
434
    {
435
        //FIXME check if data contains error tag and error message, print to log and keep previous data?
1195 arune 436
        if (data.error)
437
        {
438
            log("Display: got this error from exchange.php: " + data.error + "\n");
439
        }
440
        else
441
        {
442
            this.exchangeData = data;
443
            this.createCalendarMenu();
444
        }
1175 arune 445
    }
446
}
447
 
1191 arune 448
/* this function parses calendar data from exchange-script and creates a menu */
1189 arune 449
Display.prototype.createCalendarMenu = function()
450
{
1234 arune 451
    /* This is used for function declarations like the callbacks below */
452
    var self = this;
453
 
1198 arune 454
    this.exchangeCalendarLastMenuItem = null;
455
    this.exchangeCalendarFirstMenuItem = null;
456
 
1195 arune 457
//log("createCalendar \n");
1189 arune 458
    if (this.exchangeData)
459
    {
1195 arune 460
//log("have data \n");
1189 arune 461
        var lastMenuItem;
462
        for (var i = 0; i < this.exchangeData.meetings.length; i++)
463
        {
1195 arune 464
//log("looping \n");
1189 arune 465
            /* create the menuitem for a calendar meeting */
466
            var menu = new MenuItem(this);
1204 arune 467
            menu.displayData[0] = this.lcdCenterText(this.replaceAumlauts(this.exchangeData.meetings[i].subject));
1190 arune 468
            menu.displayData[1] = this.lcdCenterText(this.exchangeData.meetings[i].start.replace(":",".") + " - "
469
                                        + this.exchangeData.meetings[i].end.replace(":","."));
1233 arune 470
            menu.doRight = function(args) { self.changeToNext(); };
471
            menu.doLeft = function(args) { self.changeToPrev(); };
1189 arune 472
 
473
            if (i == 0)
474
            {
475
                this.exchangeCalendarFirstMenuItem = menu;
476
            }
477
            else
478
            {
479
                menu.setPrevItem(lastMenuItem);
480
                lastMenuItem.setNextItem(menu);
481
            }
482
 
483
            lastMenuItem = menu;
484
        }
1203 arune 485
        if (lastMenuItem)
486
        {
487
            this.exchangeCalendarLastMenuItem = lastMenuItem;
488
            this.exchangeCalendarLastMenuItem.setNextItem(this.bookMenuItem);
489
            this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem);
490
 
491
        }
1212 arune 492
        /* to link in the newly created menuitems with exchangeinformation the display must be showing
493
           either the statusmenu or the bookingmenu */
1216 arune 494
        if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem || this.currentMenuItem == this.bookResultMenuItem)
1203 arune 495
        {
1212 arune 496
            /* if there is one or more exchangemenuitems */
1203 arune 497
            if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
498
            {
499
                this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
500
                this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
501
            }
1212 arune 502
            /* if not then link statusmenu to bookingmenu */
503
            else
504
            {
505
                this.statusMenuItem.setNextItem(this.bookMenuItem);
506
                this.bookMenuItem.setPrevItem(this.statusMenuItem);
507
            }
1203 arune 508
        }
1189 arune 509
    }
510
}
511
 
1204 arune 512
Display.prototype.replaceAumlauts = function(intext)
513
{
1237 arune 514
    intext = intext.replace(/Ã…/, String.fromCharCode(1));
515
    intext = intext.replace(/Ã¥/, String.fromCharCode(0));
516
    intext = intext.replace(/Ä/, String.fromCharCode(2));
1228 arune 517
    intext = intext.replace(/ä/, String.fromCharCode(225));
1237 arune 518
    intext = intext.replace(/Ö/, String.fromCharCode(3));
1228 arune 519
    intext = intext.replace(/ö/, String.fromCharCode(239));
1237 arune 520
    //intext = intext.replace(/:/, ";");
521
    //intext = intext.replace(/,/, ".");
1204 arune 522
    return intext;
523
}
524
 
1175 arune 525
Display.prototype.softPwmOnline = function()
526
{
527
}
528
 
529
Display.prototype.rotaryOnline = function()
530
{
531
}
532
 
533
Display.prototype.rotaryPosUpdate = function(SwitchId)
534
{
1203 arune 535
    this.screenSaverCnt = 0;
536
    this.mainScreenCnt = 0;
1185 arune 537
    for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
1181 arune 538
    {
1185 arune 539
        if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
1181 arune 540
        {
1185 arune 541
            if (this.currentMenuItem.doRight)
542
            {
543
                this.currentMenuItem.doRight();
544
            }
1181 arune 545
        }
546
        else
547
        {
1185 arune 548
            if (this.currentMenuItem.doLeft)
549
            {
550
                this.currentMenuItem.doLeft();
551
            }
1181 arune 552
        }
553
    }
1185 arune 554
 
555
    this.updateDisplay();
1175 arune 556
}
557
 
558
Display.prototype.rotaryBtnUpdate = function(SwitchId)
559
{
1203 arune 560
    this.screenSaverCnt = 0;
561
    this.mainScreenCnt = 0;
1185 arune 562
    if (this.myRotaryService.getButtonStatus(SwitchId) == "Released")
1175 arune 563
    {
1185 arune 564
        if (this.currentMenuItem.doPress)
565
        {
566
            this.currentMenuItem.doPress();
567
        }
1203 arune 568
        this.updateDisplay();
1175 arune 569
    }
570
}
571
 
1182 arune 572
Display.prototype.updateDisplay = function()
573
{
574
    /* see if the current menuitem wants to update itself */
575
    if (this.currentMenuItem.doUpdate)
576
    {
577
        this.currentMenuItem.doUpdate();
578
    }
1185 arune 579
 
580
    /* Clear the LCD screen */
1189 arune 581
    //this.myLCDService.clearScreen();
1182 arune 582
 
583
    /* send the data for the current menuitem to display */
584
    for (var i = 0; i < this.currentMenuItem.displayData.length; i++)
585
    {
1185 arune 586
        this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]);
1182 arune 587
    }
588
 
589
}
590
 
1190 arune 591
Display.prototype.lcdCenterText = function(text)
592
{
593
    returnText = text;
1195 arune 594
    var displayWidth = 20;  //this.myLCDService.getWidth();
1190 arune 595
    /* pad on both sides with spaces to displayWidth */
596
    returnText = text.pad(displayWidth, " ", 2);
597
 
598
    return returnText;
599
}
600
 
1181 arune 601
Display.prototype.lcdOffline = function()
602
{
603
    /* If we have no interval timer running do nothing */
604
    if (this.myInterval != null)
605
    {
606
        /* Stop the interval */
607
        this.myInterval.stop();
608
    }
609
}
1175 arune 610
 
611
Display.prototype.lcdOnline = function()
612
{
613
    /* If service is not online do nothing */
614
    if (this.myLCDService.isOnline())
615
    {
616
        /* Clear the LCD screen */
617
        this.myLCDService.clearScreen();
618
        /* Set backlight to max */
619
        this.myLCDService.setBacklight(255);
620
 
621
        /* If we have no interval timer running start it */
622
        if (this.myInterval == null)
623
        {
624
            var self = this;
625
 
626
            /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */
1203 arune 627
            this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
1175 arune 628
        }
629
 
630
        this.myInterval.start();
1185 arune 631
 
1189 arune 632
        this.timerUpdate();
1175 arune 633
    }
634
}
635
 
1195 arune 636
Display.prototype.setLED = function(red, green, blue)
637
{
638
 
639
}
640
 
1175 arune 641
Display.prototype.timerUpdate = function()
642
{
643
    /* If LCD service is not online do nothing */
644
    if (this.myLCDService.isOnline())
645
    {
1203 arune 646
        this.screenSaverCnt++;
647
        this.mainScreenCnt++;
648
        this.exchangeUpdateCnt++;
649
 
650
        if (this.mainScreenCnt > mainScreenTimeout/5)
651
        {
652
            /* Go to main screen (time) */
653
            this.currentMenuItem = this.statusMenuItem;
654
 
655
            /* update the info on display */
656
            this.updateDisplay();
1216 arune 657
 
658
            this.mainScreenCnt = 0;
1203 arune 659
        }
1175 arune 660
 
1203 arune 661
        if (this.screenSaverCnt > screenSaverTimeout/5)
662
        {
663
 
1216 arune 664
            this.screenSaverCnt = 0;
1203 arune 665
        }
666
 
667
        if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5)
668
        {
669
            /* update the info on display */
670
            this.updateDisplay();
671
 
672
            /* do an exchange lookup */
673
            this.exchangeCalendar.lookup(this.shortName);
674
 
675
            this.exchangeUpdateCnt = 0;
676
        }
677
 
1175 arune 678
    }
1195 arune 679
 
680
    /*if (this.mySoftPwmService.isOnline())
681
    {
682
        this.mySoftPwmService.setPWMValue(0, 0);
683
        this.mySoftPwmService.setPWMValue(11, 1);
684
        this.mySoftPwmService.setPWMValue(11, 2);
685
    }*/
1175 arune 686
}
687