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