Subversion Repositories HomeAutomation

Rev

Rev 1786 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /* the display object who created the menu item */
  2. DtmfMenuItem.prototype.parentDisplay = null;
  3.  
  4. DtmfMenuItem.prototype.mode = 0;
  5. DtmfMenuItem.prototype.currentPhoneItem = 0;
  6. DtmfMenuItem.prototype.numberOfItemsInPhonebook = 15;
  7. DtmfMenuItem.prototype.PhoneNumberList = new Array();
  8. DtmfMenuItem.prototype.PhoneNumberListKeys = new Array();
  9. DtmfMenuItem.prototype.PhoneNumberListLatest = -1;
  10.  
  11.  
  12. function DtmfMenuItem(parentDisplay, hd44789Object)
  13. {
  14.     var self = this;
  15.     this.parentDisplay = parentDisplay;
  16.     this.display = hd44789Object;
  17. }
  18.  
  19. /* the display object who created the menu item */
  20. DtmfMenuItem.prototype.parentDisplay = null;
  21. /* the display that we are writing to */
  22. DtmfMenuItem.prototype.display = null;
  23.  
  24. /* How often the display shall update [ms]*/
  25. DtmfMenuItem.prototype.UpdateTime = 5000;
  26.  
  27. /*
  28. Standard events can be:
  29. left, right, enter, back, up, down....
  30. */
  31. DtmfMenuItem.prototype.processEvent = function (event)
  32. {
  33.     switch (event)
  34.     {
  35.     case "left":
  36.         if (this.mode == 0) {
  37.             this.parentDisplay.changeToLeft();
  38.         } else {
  39.             this.currentPhoneItem--;
  40.             if (this.currentPhoneItem < 0) {
  41.                 this.currentPhoneItem = this.numberOfItemsInPhonebook-1;
  42.             }
  43.         }
  44.         break;
  45.  
  46.     case "right":
  47.         if (this.mode == 0) {
  48.             this.parentDisplay.changeToRight();
  49.         } else {
  50.             this.currentPhoneItem++;
  51.             if (this.currentPhoneItem >= this.numberOfItemsInPhonebook) {
  52.                 this.currentPhoneItem = 0;
  53.             }
  54.         }
  55.         break;
  56.    
  57.     case "up":
  58.         //parentDisplay.changeToUp();
  59.         break;
  60.    
  61.     case "down":
  62.         //parentDisplay.changeToDown();
  63.         break;
  64.    
  65.     case "enter":
  66.         //Log("DTMF onEnter\n");
  67.         if (this.mode == 0) {
  68.             this.currentPhoneItem = 0;
  69.             this.mode = 1;
  70.         } else {
  71.             this.mode = 0;
  72.         }
  73.         break;
  74.    
  75.     case "back":
  76.         //parentDisplay.changeToBack();
  77.         break;
  78.     }
  79. }
  80.  
  81. DtmfMenuItem.prototype.onEnter = function ()
  82. {
  83.     this.PhoneNumberList = Storage_GetParameters("PhoneCalls");
  84.     if (this.PhoneNumberList)
  85.     {
  86.  
  87.         for(k in this.PhoneNumberList)
  88.         {
  89.                 this.PhoneNumberListKeys.push(k);
  90.             //Log("hittade: "+k+"\n");
  91.         }
  92.         this.PhoneNumberListKeys.sort(function(a, b) {return b - a;});
  93.         if (this.PhoneNumberListKeys.length > this.numberOfItemsInPhonebook) {
  94.             this.PhoneNumberListKeys.slice(0, this.numberOfItemsInPhonebook-1);
  95.         }              
  96.     } else {
  97.         //No calls found, clear list?
  98.         Log("hittade inga nummer!\n");
  99.     }
  100.     this.currentPhoneItem = 0;
  101.     this.numberOfItemsInPhonebook = this.PhoneNumberListKeys.length;
  102.     Display_Clear(this.display);
  103.     this.mode = 0;
  104. }
  105. DtmfMenuItem.prototype.update = function ()
  106. {
  107.     if (this.mode == 0) {
  108.         if (this.PhoneNumberListKeys[0] != null) {
  109.             Display_Clear(this.display);
  110.             Display_Print(this.display, 0, 0,"Senaste nummer:");
  111.             var numbers = {};
  112.             numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[0]] + ")");
  113.             var date = new Date(parseInt(this.PhoneNumberListKeys[0])*1000);
  114.             Display_Print(this.display, 0, 1,""+date.getDateFormated()+" "+date.getTimeShortFormated());
  115.             Display_Print(this.display, 0, 2,""+numbers["number"]);
  116.         } else {
  117.             Display_Clear(this.display);
  118.             Display_Print(this.display, 0, 0,"SenAste nummer:");
  119.             Display_Print(this.display, 0, 2,"IngA nummer");
  120.             Display_Print(this.display, 0, 3,"i liStan!");
  121.         }
  122.     } else {
  123.         Display_Clear(this.display);
  124.         var numbers = {};
  125.         numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[this.currentPhoneItem]] + ")");
  126.         var date = new Date(parseInt(this.PhoneNumberListKeys[this.currentPhoneItem])*1000);
  127.  
  128.         Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated());
  129.         Display_Print(this.display, 0, 1,""+numbers["number"]);
  130.     }
  131. }
  132.  
  133. DtmfMenuItem.prototype.onExit = function ()
  134. {
  135.     this.mode = 0;
  136. }
  137.  
  138.  
  139.