Subversion Repositories HomeAutomation

Rev

Rev 1352 | 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.setOnline = function()
  48. {
  49.     this.CanService.prototype.setOnline.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.     text = text.replace(/Å/, String.fromCharCode(1));
  63.     text = text.replace(/å/, String.fromCharCode(0));
  64.     text = text.replace(/Ä/, String.fromCharCode(2));
  65.     text = text.replace(/ä/, String.fromCharCode(225));
  66.     text = text.replace(/Ö/, String.fromCharCode(3));
  67.     text = text.replace(/ö/, String.fromCharCode(239));
  68.     text = text.replace(/¤/, String.fromCharCode(223));
  69.  
  70.     while (text.length > 0 && y < this.myHeight)
  71.     {
  72.         var text6 = text.substr(0, 6);
  73.        
  74.         if (text6.length > this.myWidth - x)
  75.         {
  76.             text6 = text6.substr(0, this.myWidth - x);
  77.         }
  78.  
  79.         var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_TextAt");
  80.         canMessage.setData("X", x);
  81.         canMessage.setData("Y", y);
  82.         canMessage.setData("Text", text6);
  83.         sendMessage(canMessage);
  84.        
  85.         x += text6.length;
  86.         text = text.slice(text6.length);
  87.        
  88.         if (text6.length < 6)
  89.         {
  90.             y++;
  91.             x = 0;
  92.         }
  93.     }
  94. }
  95.  
  96. HD44789.prototype.clearScreen = function()
  97. {
  98.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Clear");
  99.     sendMessage(canMessage);
  100. }
  101.  
  102. HD44789.prototype.setBacklight = function(strength)
  103. {
  104.     if (strength != this.myBacklight)
  105.     {
  106.         var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  107.         canMessage.setData("Strength", strength);
  108.         sendMessage(canMessage);
  109.     }
  110. }
  111.  
  112. HD44789.prototype.getBacklight = function()
  113. {
  114.     return this.myBacklight;
  115. }
  116.  
  117. HD44789.prototype.getWidth = function()
  118. {
  119.     return this.myWidth;
  120. }
  121.  
  122. HD44789.prototype.getHeight = function()
  123. {
  124.     return this.myHeight;
  125. }
  126.