Subversion Repositories HomeAutomation

Rev

Rev 999 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function HD44789(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5. }
  6.  
  7. extend(HD44789, CanService);
  8.  
  9. HD44789.prototype.myWidth = null;
  10. HD44789.prototype.myHeight = null;
  11. HD44789.prototype.myBacklightStrength = null;
  12.  
  13. HD44789.prototype.canMessageHandler = function(canMessage)
  14. {
  15.     if (canMessage.getDirectionFlag() == "From_Owner")
  16.     {
  17.         switch (canMessage.getCommandName())
  18.         {
  19.         case "LCD_Clear":
  20.         break;
  21.        
  22.         case "LCD_Cursor":
  23.         break;
  24.        
  25.         case "LCD_Text":
  26.         break;
  27.        
  28.         case "LCD_TextAt":
  29.         break;
  30.        
  31.         case "LCD_Size":
  32.         this.myWidth = canMessage.getData("Width");
  33.         this.myHeight = canMessage.getData("Height");
  34.         log(this.myName + ":" + this.myId + "> Reported size: " + this.myWidth + "x" + this.myHeight + "\n");
  35.         break;
  36.        
  37.         case "LCD_Backlight":
  38.         this.myBacklight = canMessage.getData("Strength");
  39.         log(this.myName + ":" + this.myId + "> Reported backlight strength: " + this.myBacklight + "\n");
  40.         break;
  41.         }
  42.     }
  43.    
  44.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  45. }
  46.  
  47. HD44789.prototype.onlineHandler = function()
  48. {
  49.     this.CanService.prototype.onlineHandler.call(this);
  50.  
  51.     // Request size of LCD
  52.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Size");
  53.     sendMessage(canMessage);
  54.    
  55.     // Request backlight strength
  56.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  57.     sendMessage(canMessage);
  58. }
  59.  
  60. HD44789.prototype.printText = function(x, y, text)
  61. {
  62.     while (text.length > 0)
  63.     {
  64.         var text6 = text.substr(0, 6);
  65.  
  66.         var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_TextAt");
  67.         canMessage.setData("X", x);
  68.         canMessage.setData("Y", y);
  69.         canMessage.setData("Text", text6);
  70.         sendMessage(canMessage);
  71.        
  72.         x += text6.length;
  73.         text = text.slice(text6.length);
  74.     }
  75. }
  76.  
  77. HD44789.prototype.clearScreen = function()
  78. {
  79.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Clear");
  80.     sendMessage(canMessage);
  81. }
  82.  
  83. HD44789.prototype.setBacklight = function(strength)
  84. {
  85.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  86.     canMessage.setData("Strength", strength);
  87.     sendMessage(canMessage);
  88. }
  89.  
  90. HD44789.prototype.getBacklight = function()
  91. {
  92.     return this.myBacklight;
  93. }
  94.  
  95. HD44789.prototype.getWidth = function()
  96. {
  97.     return this.myWidth;
  98. }
  99.  
  100. HD44789.prototype.getHeight = function()
  101. {
  102.     return this.myHeight;
  103. }
  104.