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