Subversion Repositories HomeAutomation

Rev

Rev 1899 | 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.             var tmp  = eval("(" + this.PhoneNumberList[k] + ")");
  91.                         if (tmp["direction"]=="in")
  92.                     this.PhoneNumberListKeys.push(k);
  93.             //Log("hittade: "+k+"\n");
  94.         }
  95.         this.PhoneNumberListKeys.sort(function(a, b) {return b - a;});
  96.         if (this.PhoneNumberListKeys.length > this.numberOfItemsInPhonebook) {
  97.             this.PhoneNumberListKeys.slice(0, this.numberOfItemsInPhonebook-1);
  98.         }              
  99.     } else {
  100.         //No calls found, clear list?
  101.         Log("hittade inga nummer!\n");
  102.     }
  103.     this.currentPhoneItem = 0;
  104.     this.numberOfItemsInPhonebook = this.PhoneNumberListKeys.length;
  105.     Display_Clear(this.display);
  106.     this.mode = 0;
  107.     //for(k in this.PhoneNumberList)
  108.     //{
  109.     //  Log("hittade: "+k+"\n");
  110.     //}
  111. }
  112. DtmfMenuItem.prototype.update = function ()
  113. {
  114.     if (this.mode == 0) {
  115.         if (this.PhoneNumberListKeys[0] != null) {
  116.             Display_Clear(this.display);
  117.             Display_Print(this.display, 0, 0,"Senaste nummer:");
  118.             var numbers = {};
  119.             numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[0]] + ")");
  120.             if (numbers["direction"]==null)
  121.               Display_Print(this.display, 0, 0,"Senaste nummer:   - ");
  122.             else if (numbers["direction"]=="in")
  123.               Display_Print(this.display, 0, 0,"Senaste nummer:   In");
  124.             else
  125.               Display_Print(this.display, 0, 0,"Senaste nummer:   Ut");
  126.             var date = new Date(parseInt(this.PhoneNumberListKeys[0])*1000);
  127.             Display_Print(this.display, 0, 1,""+date.getDateFormated()+" "+date.getTimeShortFormated());
  128.             Display_Print(this.display, 0, 2,""+numbers["number"]);
  129.             var phonebook = Storage_GetJsonParamter("PhoneBook",numbers["number"])
  130.             if (phonebook) {
  131.                 Display_Print(this.display, 0, 3, phonebook[0]);
  132.             }
  133.         } else {
  134.             Display_Clear(this.display);
  135.             Display_Print(this.display, 0, 0,"SenAste nummer:");
  136.             Display_Print(this.display, 0, 2,"IngA nummer");
  137.             Display_Print(this.display, 0, 3,"i liStan!");
  138.         }
  139.     } else {
  140.         Display_Clear(this.display);
  141.         var numbers = {};
  142.         numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[this.currentPhoneItem]] + ")");
  143.         var date = new Date(parseInt(this.PhoneNumberListKeys[this.currentPhoneItem])*1000);
  144.         if (numbers["direction"]==null)
  145.           Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated());
  146.         else if (numbers["direction"]=="in")
  147.           Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated()+"  In");
  148.         else
  149.           Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated()+"  Ut");
  150.         Display_Print(this.display, 0, 1,""+numbers["number"]);
  151.         var phonebook = Storage_GetJsonParamter("PhoneBook",numbers["number"])
  152.         if (phonebook) {
  153.             Display_Print(this.display, 0, 2, phonebook[0]);
  154.             if (phonebook.length > 1) {
  155.                 Display_Print(this.display, 0, 3, phonebook[1]);
  156.             }
  157.         }
  158.     }
  159. }
  160.  
  161. DtmfMenuItem.prototype.onExit = function ()
  162. {
  163.     this.mode = 0;
  164. }
  165.  
  166.  
  167.