Subversion Repositories HomeAutomation

Rev

Rev 1806 | 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.             //Log("currentPhoneItem is now-: "+ this.currentPhoneItem + "\n");
  41.             if (this.currentPhoneItem < 0) {
  42.                 this.currentPhoneItem = this.numberOfItemsInPhonebook-1;
  43.             }
  44.         }
  45.         break;
  46.  
  47.     case "right":
  48.         if (this.mode == 0) {
  49.             this.parentDisplay.changeToRight();
  50.         } else {
  51.             this.currentPhoneItem++;
  52.             //Log("currentPhoneItem is now+: "+ this.currentPhoneItem + "\n");
  53.             if (this.currentPhoneItem >= this.numberOfItemsInPhonebook) {
  54.                 this.currentPhoneItem = 0;
  55.             }
  56.         }
  57.         break;
  58.    
  59.     case "up":
  60.         //parentDisplay.changeToUp();
  61.         break;
  62.    
  63.     case "down":
  64.         //parentDisplay.changeToDown();
  65.         break;
  66.    
  67.     case "enter":
  68.         //Log("DTMF onEnter\n");
  69.         if (this.mode == 0) {
  70.             this.currentPhoneItem = 0;
  71.             this.mode = 1;
  72.         } else {
  73.             this.mode = 0;
  74.         }
  75.         break;
  76.    
  77.     case "back":
  78.         //parentDisplay.changeToBack();
  79.         break;
  80.     }
  81. }
  82.  
  83. DtmfMenuItem.prototype.onEnter = function ()
  84. {
  85.     this.PhoneNumberList = Storage_GetParameters("PhoneCalls");
  86.     if (this.PhoneNumberList)
  87.     {
  88.         for(k in this.PhoneNumberList)
  89.         {
  90.                 this.PhoneNumberListKeys.push(k);
  91.             //Log("hittade: "+k+"\n");
  92.         }
  93.         this.PhoneNumberListKeys.sort(function(a, b) {return b - a;});
  94.         if (this.PhoneNumberListKeys.length > this.numberOfItemsInPhonebook) {
  95.             this.PhoneNumberListKeys.slice(0, this.numberOfItemsInPhonebook-1);
  96.         }              
  97.     } else {
  98.         //No calls found, clear list?
  99.         Log("hittade inga nummer!\n");
  100.     }
  101.     this.currentPhoneItem = 0;
  102.     this.numberOfItemsInPhonebook = this.PhoneNumberListKeys.length;
  103.     Display_Clear(this.display);
  104.     this.mode = 0;
  105.     //for(k in this.PhoneNumberList)
  106.     //{
  107.     //  Log("hittade: "+k+"\n");
  108.     //}
  109. }
  110. DtmfMenuItem.prototype.update = function ()
  111. {
  112.     if (this.mode == 0) {
  113.         if (this.PhoneNumberListKeys[0] != null) {
  114.             Display_Clear(this.display);
  115.             Display_Print(this.display, 0, 0,"Senaste nummer:");
  116.             var numbers = {};
  117.             numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[0]] + ")");
  118.             if (numbers["direction"]==null)
  119.               Display_Print(this.display, 0, 0,"Senaste nummer:   - ");
  120.             else if (numbers["direction"]=="in")
  121.               Display_Print(this.display, 0, 0,"Senaste nummer:   In");
  122.             else
  123.               Display_Print(this.display, 0, 0,"Senaste nummer:   Ut");
  124.             var date = new Date(parseInt(this.PhoneNumberListKeys[0])*1000);
  125.             Display_Print(this.display, 0, 1,""+date.getDateFormated()+" "+date.getTimeShortFormated());
  126.             Display_Print(this.display, 0, 2,""+numbers["number"]);
  127.             var phonebook = Storage_GetJsonParamter("PhoneBook",numbers["number"])
  128.             if (phonebook) {
  129.                 Display_Print(this.display, 0, 3, phonebook[0]);
  130.             }
  131.         } else {
  132.             Display_Clear(this.display);
  133.             Display_Print(this.display, 0, 0,"SenAste nummer:");
  134.             Display_Print(this.display, 0, 2,"IngA nummer");
  135.             Display_Print(this.display, 0, 3,"i liStan!");
  136.         }
  137.     } else {
  138.         Display_Clear(this.display);
  139.         var numbers = {};
  140.         numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[this.currentPhoneItem]] + ")");
  141.         var date = new Date(parseInt(this.PhoneNumberListKeys[this.currentPhoneItem])*1000);
  142.         if (numbers["direction"]==null)
  143.           Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated());
  144.         else if (numbers["direction"]=="in")
  145.           Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated()+"  In");
  146.         else
  147.           Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated()+"  Ut");
  148.         Display_Print(this.display, 0, 1,""+numbers["number"]);
  149.         var phonebook = Storage_GetJsonParamter("PhoneBook",numbers["number"])
  150.         if (phonebook) {
  151.             Display_Print(this.display, 0, 2, phonebook[0]);
  152.             if (phonebook.length > 1) {
  153.                 Display_Print(this.display, 0, 3, phonebook[1]);
  154.             }
  155.         }
  156.     }
  157. }
  158.  
  159. DtmfMenuItem.prototype.onExit = function ()
  160. {
  161.     this.mode = 0;
  162. }
  163.  
  164.  
  165.