Subversion Repositories HomeAutomation

Rev

Blame | 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. const numberOfItemsInPhonebook = 15;
  7. DtmfMenuItem.prototype.PhoneNumberList = new Array();
  8. DtmfMenuItem.prototype.PhoneNumberListLatest = -1;
  9.  
  10. function DtmfMenuItem(parentDisplay, hd44789Object)
  11. {
  12.     var self = this;
  13.     this.parentDisplay = parentDisplay;
  14.     this.display = hd44789Object;
  15.  
  16.     if (!this.parentDisplay.myInitialArguments["SimpleDTMF"])
  17.     {
  18.         log(this.myName + ":" + this.myId + "> Failed to initialize, SimpleDTMF-config missing from config.\n");
  19.         return;
  20.     }
  21.  
  22.     this.myDTMFService = ServiceManager.getService("Can", "SimpleDTMF", this.parentDisplay.myInitialArguments["SimpleDTMF"]["Id"]);
  23.     this.myDTMFService.registerEventCallback("newPhonenumber", function(args) { self.dtmfUpdate(args); });
  24.     //this.myDTMFService.registerEventCallback("online", function(args) { self.dtmfOnline(); });
  25.     this.dtmfOnline();
  26.  
  27.     this.myOnlinePhonebook = new OnlinePhonebook(function(phonenumber, persons) { self.phonebookLookupCallback(phonenumber, persons); });
  28.  
  29.     for (var i = 0; i <= numberOfItemsInPhonebook-1; i++)
  30.     {
  31.         this.PhoneNumberList[i] = new Array();
  32.         this.PhoneNumberList[i]['time'] = "";
  33.         this.PhoneNumberList[i]['number'] = "";
  34.         this.PhoneNumberList[i]['persons'] = new Array();
  35.     }
  36. }
  37.  
  38. /* the display object who created the menu item */
  39. DtmfMenuItem.prototype.parentDisplay = null;
  40. /* the display that we are writing to */
  41. DtmfMenuItem.prototype.display = null;
  42.  
  43. /* How often the display shall update [ms]*/
  44. DtmfMenuItem.prototype.UpdateTime = 5000;
  45.  
  46. /* what DtmfMenuItem is left of this item, if used */
  47. DtmfMenuItem.prototype.LeftItem = null;
  48. /* what DtmfMenuItem is right of this item, if used */
  49. DtmfMenuItem.prototype.RightItem = null;
  50. /* what DtmfMenuItem is after of this item, if used */
  51. DtmfMenuItem.prototype.PressEnterItem = null;
  52. /* what DtmfMenuItem is before of this item, if used */
  53. DtmfMenuItem.prototype.PressBackItem = null;
  54. /* what DtmfMenuItem is below of this item, if used */
  55. DtmfMenuItem.prototype.DownItem = null;
  56. /* what DtmfMenuItem is abowe of this item, if used */
  57. DtmfMenuItem.prototype.UpItem = null;
  58.  
  59. /*
  60. Standard events can be:
  61. left, right, enter, back, up, down....
  62. */
  63. DtmfMenuItem.prototype.processEvent = function (event)
  64. {
  65.     switch (event)
  66.     {
  67.     case "left":
  68.         if (this.mode == 0) {
  69.             this.parentDisplay.changeToLeft();
  70.         } else {
  71.             this.currentPhoneItem--;
  72.             if (this.currentPhoneItem < 0) {
  73.                 this.currentPhoneItem = numberOfItemsInPhonebook-1;
  74.             }
  75. for (n=0;0<=numberOfItemsInPhonebook;n++) {
  76. if (this.PhoneNumberList[this.currentPhoneItem]['number'] != "")
  77. break;
  78.                 this.currentPhoneItem--;
  79.                 if (this.currentPhoneItem < 0) {
  80.                     this.currentPhoneItem = numberOfItemsInPhonebook-1;
  81.                 }              
  82.             }
  83.         }
  84.         break;
  85.  
  86.     case "right":
  87.         if (this.mode == 0) {
  88.             this.parentDisplay.changeToRight();
  89.         } else {
  90.             this.currentPhoneItem++;
  91.             if (this.currentPhoneItem >= numberOfItemsInPhonebook) {
  92.                 this.currentPhoneItem = 0;
  93.             }
  94. for (n=0;0<=numberOfItemsInPhonebook;n++) {
  95. if (this.PhoneNumberList[this.currentPhoneItem]['number'] != "")
  96. break;
  97.             this.currentPhoneItem++;
  98.                 if (this.currentPhoneItem  >= numberOfItemsInPhonebook) {
  99.                     this.currentPhoneItem = 0;
  100.                 }
  101.             }
  102.         }
  103.         break;
  104.    
  105.     case "up":
  106.         //parentDisplay.changeToUp();
  107.         break;
  108.    
  109.     case "down":
  110.         //parentDisplay.changeToDown();
  111.         break;
  112.    
  113.     case "enter":
  114.  
  115.         if (this.mode == 0) {
  116.             if (this.PhoneNumberList[this.PhoneNumberListLatest] != null) {
  117.                 this.currentPhoneItem = this.PhoneNumberListLatest;
  118.                 this.mode = 1;
  119.             }
  120.         } else {
  121.             this.mode = 0;
  122.         }
  123.         break;
  124.    
  125.     case "back":
  126.         //parentDisplay.changeToBack();
  127.         break;
  128.     }
  129. }
  130.  
  131. DtmfMenuItem.prototype.onEnter = function ()
  132. {
  133.     this.display.clearScreen();
  134. }
  135. DtmfMenuItem.prototype.update = function ()
  136. {
  137.     if (this.mode == 0) {
  138.         if (this.PhoneNumberList[this.PhoneNumberListLatest] != null) {
  139. this.display.clearScreen();
  140.             this.display.printText(0, 0, this.parentDisplay.lcdCenterText("Senaste nummer:"));
  141.             this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.PhoneNumberListLatest]['time']));
  142.             this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.PhoneNumberListLatest]['number']));
  143. if (this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][0] != null) {          
  144. this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][0]));
  145. }
  146.         } else {
  147. this.display.clearScreen();
  148.             this.display.printText(0, 0, this.parentDisplay.lcdCenterText("Senaste nummer:"));
  149.             this.display.printText(0, 2, this.parentDisplay.lcdCenterText("Inga nummer"));
  150.             this.display.printText(0, 3, this.parentDisplay.lcdCenterText("i listan!"));
  151.         }
  152.     } else {
  153. this.display.clearScreen();
  154.         this.display.printText(0, 0,this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['time']));
  155.         this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['number']));
  156. if (this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][0] != null) {
  157.         this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['persons'][0]));
  158. }
  159. if (this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][1] != null) {
  160.         this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['persons'][1]));
  161. }
  162.     }
  163. }
  164.  
  165. DtmfMenuItem.prototype.onExit = function ()
  166. {
  167.     this.mode = 0;
  168. }
  169.  
  170.  
  171. DtmfMenuItem.prototype.dtmfOnline = function()
  172. {
  173. }
  174.  
  175. DtmfMenuItem.prototype.dtmfUpdate = function(args)
  176. {
  177.     this.myOnlinePhonebook.lookup(this.myDTMFService.getLastPhonenumber());
  178. }
  179.  
  180. DtmfMenuItem.prototype.phonebookLookupCallback = function(phonenumber, persons)
  181. {
  182.     // Update main dtmf menu
  183.     var date = new Date();
  184.     /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
  185.     var dateAndTime = date.getDateTimeFormated();
  186. this.PhoneNumberListLatest++;
  187. if (this.PhoneNumberListLatest >= numberOfItemsInPhonebook) {
  188. this.PhoneNumberListLatest=0;
  189. }
  190.  
  191. this.PhoneNumberList[this.PhoneNumberListLatest]['time'] = dateAndTime;
  192. this.PhoneNumberList[this.PhoneNumberListLatest]['number'] = phonenumber;
  193. this.PhoneNumberList[this.PhoneNumberListLatest]['persons'] = persons; 
  194. }
  195.