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