Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1.  
  2. Display_ModuleNames    = [ "HD44789" ];
  3. Display_Height         = function() { return [ 0, 1, 2, 3  ]; };
  4. Display_Width          = function() { return [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]; };
  5. Display_Backlight      = function() { return [ 0, 50, 100, 150, 200, 255 ]; };
  6. Display_Aliases        = function() { return Module_GetAliasNames(Display_ModuleNames); };
  7. Display_AvailableIds   = function() { return Module_GetAvailableIds(Display_ModuleNames); };
  8.  
  9. function Display_Clear(alias_name)
  10. {
  11.     if (arguments.length < 1)
  12.     {
  13.         Log("\033[31mNot enough parameters given.\033[0m\n");
  14.         return false;
  15.     }
  16.    
  17.     var aliases_data = Module_ResolveAlias(alias_name, Display_ModuleNames);
  18.     var found = false;
  19.    
  20.     for (var name in aliases_data)
  21.     {
  22.         var variables = {};
  23.            
  24.         if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_Clear", variables))
  25.         {
  26.             Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
  27.         }
  28.         else
  29.         {
  30.             Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
  31.         }
  32.        
  33.         found = true;
  34.     }
  35.    
  36.     if (!found)
  37.     {
  38.         Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
  39.         return false;
  40.     }
  41.    
  42.     return true;
  43. }
  44. Console_RegisterCommand(Display_Clear, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Display_Aliases()); });
  45.  
  46. function Display_SetBacklight(alias_name, strength)
  47. {
  48.     if (arguments.length < 2)
  49.     {
  50.         Log("\033[31mNot enough parameters given.\033[0m\n");
  51.         return false;
  52.     }
  53.    
  54.     var aliases_data = Module_ResolveAlias(alias_name, Display_ModuleNames);
  55.     var found = false;
  56.    
  57.     for (var name in aliases_data)
  58.     {
  59.         var variables = {
  60.         "Strength" : strength,
  61.         "AutoLight" : "OFF"
  62.         };
  63.        
  64.         if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_Backlight", variables))
  65.         {
  66.             Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
  67.         }
  68.         else
  69.         {
  70.             Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
  71.         }
  72.        
  73.         found = true;
  74.     }
  75.    
  76.     if (!found)
  77.     {
  78.         Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
  79.         return false;
  80.     }
  81.    
  82.     return true;
  83. }
  84. Console_RegisterCommand(Display_SetBacklight, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Display_Aliases(), Display_Backlight()); });
  85.  
  86.  
  87. function Display_Print(alias_name, x, y, text)
  88. {
  89.     if (arguments.length < 4)
  90.     {
  91.         Log("\033[31mNot enough parameters given.\033[0m\n");
  92.         return false;
  93.     }
  94.    
  95.     text = text.replace(/Å/, String.fromCharCode(1));
  96.     text = text.replace(/å/, String.fromCharCode(0));
  97.     text = text.replace(/Ä/, String.fromCharCode(2));
  98.     text = text.replace(/ä/, String.fromCharCode(225));
  99.     text = text.replace(/Ö/, String.fromCharCode(3));
  100.     text = text.replace(/ö/, String.fromCharCode(239));
  101.     text = text.replace(/¤/, String.fromCharCode(223));
  102.    
  103.     x = parseInt(x);
  104.     y = parseInt(y);
  105.    
  106.     for (var n = 4;  n < arguments.length; n++)
  107.     {
  108.         text += " " + arguments[n];
  109.     }
  110.    
  111.     var aliases_data = Module_ResolveAlias(alias_name, Display_ModuleNames);
  112.     var found = false;
  113.    
  114.     for (var name in aliases_data)
  115.     {
  116.         var org_text = text;
  117.        
  118.         while (text.length > 0)
  119.         {
  120.             var length = text.length < 6 ? text.length : 6;
  121.             var text_part = text.substr(0, length);
  122.            
  123.             var variables = {
  124.             "X"    : x,
  125.             "Y"    : y,
  126.             "Text" : text_part };
  127.            
  128.             if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_TextAt", variables))
  129.             {
  130.                 Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
  131.             }
  132.             else
  133.             {
  134.                 Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
  135.             }
  136.            
  137.             text = text.substr(6);
  138.             x += 6;
  139.         }
  140.        
  141.         text = org_text;
  142.         found = true;
  143.     }
  144.    
  145.     if (!found)
  146.     {
  147.         Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
  148.         return false;
  149.     }
  150.    
  151.     return true;
  152. }
  153. Console_RegisterCommand(Display_Print, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Display_Aliases(), Display_Width(), Display_Height()); });
  154.  
  155.  
  156. function Display_OnMessage(module_name, module_id, command, variables)
  157. {
  158.     if (in_array(Display_ModuleNames, module_name))
  159.     {
  160.         var aliases_data = Module_LookupAliases({
  161.             "module_name" : module_name,
  162.             "module_id"   : module_id,
  163.             "group"       : false
  164.         });
  165.        
  166.         switch (command)
  167.         {
  168.             case "LCD_Size":
  169.             {
  170.                 for (var alias_name in aliases_data)
  171.                 {
  172.                     var last_value = {};
  173.                     var last_value_string = Storage_GetParameter("LastValues", alias_name);
  174.                    
  175.                     if (last_value_string)
  176.                     {
  177.                         last_value = eval("(" + last_value_string + ")");
  178.                     }
  179.                    
  180.                     last_value["Width"] = { "value" : variables["Width"], "timestamp" : get_time() };
  181.                     last_value["Height"] = { "value" : variables["Height"], "timestamp" : get_time() };
  182.                    
  183.                     Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
  184.                 }
  185.                
  186.                 break;
  187.             }
  188.             case "LCD_Backlight":
  189.             {
  190.                 for (var alias_name in aliases_data)
  191.                 {
  192.                     var last_value = {};
  193.                     var last_value_string = Storage_GetParameter("LastValues", alias_name);
  194.                    
  195.                     if (last_value_string)
  196.                     {
  197.                         last_value = eval("(" + last_value_string + ")");
  198.                     }
  199.                    
  200.                     last_value["Strength"] = { "value" : variables["Strength"], "timestamp" : get_time() };
  201.                     last_value["AutoLight"] = { "value" : variables["AutoLight"], "timestamp" : get_time() };
  202.                    
  203.                     Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
  204.                 }
  205.                
  206.                 break;
  207.             }
  208.         }
  209.     }
  210. }
  211. Module_RegisterToOnMessage("all", Display_OnMessage);
  212.  
  213. function Display_OnChange(module_name, module_id, available)
  214. {
  215.     if (in_array(Display_ModuleNames, module_name) && available)
  216.     {
  217.         var aliases_data = Module_LookupAliases({
  218.             "module_name" : module_name,
  219.             "module_id"   : module_id,
  220.             "group"       : false
  221.         });
  222.        
  223.         for (var alias_name in aliases_data)
  224.         {
  225.             var variables = { };
  226.            
  227.             Module_SendMessage(aliases_data[alias_name]["module_name"], aliases_data[alias_name]["module_id"], "LCD_Backlight", variables);
  228.             Module_SendMessage(aliases_data[alias_name]["module_name"], aliases_data[alias_name]["module_id"], "LCD_Size", variables);
  229.         }
  230.     }
  231. }
  232. Module_RegisterToOnChange("all", Display_OnChange);
  233.