Rev 2019 | Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2017 | linlun | 1 | |
| 2 | g_display_ModuleNames = [ "KS0108" ]; |
||
| 3 | g_display_Height = function() { return [ 0, 1, 2, 3 ]; }; |
||
| 4 | g_display_Radius = function() { return [ 2, 5, 10, 20, 30, 50, 100 ]; }; |
||
| 5 | g_display_Inverted = function() { return [ "Standard", "Inverted" ]; }; |
||
| 6 | g_display_Fill = function() { return [ "NoFill", "Fill" ]; }; |
||
| 7 | g_display_Transparent = function() { return [ "Standard", "Transparent" ]; }; |
||
| 8 | g_display_Width = function() { return [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]; }; |
||
| 9 | g_display_Backlight = function() { return [ 0, 50, 100, 150, 200, 255 ]; }; |
||
| 10 | g_display_Aliases = function() { return Module_GetAliasNames(g_display_ModuleNames); }; |
||
| 11 | g_display_AvailableIds = function() { return Module_GetAvailableIds(g_display_ModuleNames); }; |
||
| 12 | |||
| 13 | function g_display_Clear(alias_name, inverted) |
||
| 14 | { |
||
| 15 | if (arguments.length < 2) |
||
| 16 | { |
||
| 17 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 18 | return false; |
||
| 19 | } |
||
| 20 | |||
| 21 | var aliases_data = Module_ResolveAlias(alias_name, g_display_ModuleNames); |
||
| 22 | var found = false; |
||
| 23 | |||
| 24 | for (var name in aliases_data) |
||
| 25 | { |
||
| 26 | var variables = { |
||
| 27 | "Inverted" : inverted |
||
| 28 | }; |
||
| 29 | if (!Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_Clear", variables)) |
||
| 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(g_display_Clear, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Inverted()); }); |
||
| 46 | |||
| 47 | function g_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, g_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 | { |
||
| 67 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 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(g_display_SetBacklight, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Backlight()); }); |
||
| 86 | |||
| 87 | |||
| 88 | function g_display_Print(alias_name, x, y, inverted, transparent, text) |
||
| 89 | { |
||
| 90 | if (arguments.length < 6) |
||
| 91 | { |
||
| 92 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 93 | return false; |
||
| 94 | } |
||
| 95 | |||
| 96 | text = text.replace(/å/, String.fromCharCode(128)); |
||
| 97 | text = text.replace(/Å/, String.fromCharCode(129)); |
||
| 98 | text = text.replace(/ä/, String.fromCharCode(130)); |
||
| 99 | text = text.replace(/Ä/, String.fromCharCode(131)); |
||
| 100 | text = text.replace(/ö/, String.fromCharCode(132)); |
||
| 101 | text = text.replace(/Ö/, String.fromCharCode(133)); |
||
| 102 | text = text.replace(/¤/, String.fromCharCode(134)); |
||
| 103 | |||
| 104 | x = parseInt(x); |
||
| 105 | y = parseInt(y); |
||
| 106 | |||
| 107 | for (var n = 6; n < arguments.length; n++) |
||
| 108 | { |
||
| 109 | text += " " + arguments[n]; |
||
| 110 | } |
||
| 111 | |||
| 112 | var aliases_data = Module_ResolveAlias(alias_name, g_display_ModuleNames); |
||
| 113 | var found = false; |
||
| 114 | |||
| 115 | for (var name in aliases_data) |
||
| 116 | { |
||
| 117 | var org_text = text; |
||
| 118 | |||
| 119 | while (text.length > 0) |
||
| 120 | { |
||
| 121 | var length = text.length < 6 ? text.length : 6; |
||
| 122 | var text_part = text.substr(0, length); |
||
| 123 | |||
| 124 | var variables = { |
||
| 125 | "X" : x, |
||
| 126 | "Y" : y, |
||
| 127 | "Inverted" : inverted, |
||
| 128 | "Transparent" : transparent, |
||
| 129 | "Text" : text_part }; |
||
| 130 | |||
| 131 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_TextAt", variables)) |
||
| 132 | { |
||
| 133 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 134 | } |
||
| 135 | else |
||
| 136 | { |
||
| 137 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 138 | } |
||
| 139 | |||
| 140 | text = text.substr(6); |
||
| 141 | x += 6; |
||
| 142 | } |
||
| 143 | |||
| 144 | text = org_text; |
||
| 145 | found = true; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (!found) |
||
| 149 | { |
||
| 150 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 151 | return false; |
||
| 152 | } |
||
| 153 | |||
| 154 | return true; |
||
| 155 | } |
||
| 156 | Console_RegisterCommand(g_display_Print, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Width(), g_display_Height(), g_display_Inverted(), g_display_Transparent()); }); |
||
| 157 | |||
| 158 | function g_display_drawCircle(alias_name, xCentre, yCentre, radius, inverted) |
||
| 159 | { |
||
| 160 | if (arguments.length < 5) |
||
| 161 | { |
||
| 162 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 163 | return false; |
||
| 164 | } |
||
| 165 | xCentre = parseInt(xCentre); |
||
| 166 | yCentre = parseInt(yCentre); |
||
| 167 | radius = parseInt(radius); |
||
| 168 | var aliases_data = Module_ResolveAlias(alias_name, g_display_ModuleNames); |
||
| 169 | var found = false; |
||
| 170 | for (var name in aliases_data) |
||
| 171 | { |
||
| 172 | var variables = { |
||
| 173 | "Xcentre" : xCentre, |
||
| 174 | "Ycentre" : yCentre, |
||
| 175 | "Inverted" : inverted, |
||
| 176 | "Radius" : radius}; |
||
| 177 | |||
| 178 | if (!Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_DrawCircle", variables)) |
||
| 179 | { |
||
| 180 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 181 | } |
||
| 182 | found = true; |
||
| 183 | } |
||
| 184 | if (!found) |
||
| 185 | { |
||
| 186 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 187 | return false; |
||
| 188 | } |
||
| 189 | return true; |
||
| 190 | } |
||
| 191 | Console_RegisterCommand(g_display_drawCircle, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Width(), g_display_Height(), g_display_Radius(), g_display_Inverted()); }); |
||
| 192 | |||
| 193 | function g_display_drawLine(alias_name, xStart, yStart, xEnd, yEnd, inverted) |
||
| 194 | { |
||
| 195 | if (arguments.length < 6) |
||
| 196 | { |
||
| 197 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 198 | return false; |
||
| 199 | } |
||
| 200 | xStart = parseInt(xStart); |
||
| 201 | yStart = parseInt(yStart); |
||
| 202 | xEnd = parseInt(xEnd); |
||
| 203 | yEnd = parseInt(yEnd); |
||
| 204 | var aliases_data = Module_ResolveAlias(alias_name, g_display_ModuleNames); |
||
| 205 | var found = false; |
||
| 206 | for (var name in aliases_data) |
||
| 207 | { |
||
| 208 | var variables = { |
||
| 209 | "X1" : xStart, |
||
| 210 | "Y1" : yStart, |
||
| 211 | "Inverted" : inverted, |
||
| 212 | "X2" : xEnd, |
||
| 213 | "Y2" : yEnd}; |
||
| 214 | |||
| 215 | if (!Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_DrawLine", variables)) |
||
| 216 | { |
||
| 217 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 218 | } |
||
| 219 | found = true; |
||
| 220 | } |
||
| 221 | if (!found) |
||
| 222 | { |
||
| 223 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 224 | return false; |
||
| 225 | } |
||
| 226 | return true; |
||
| 227 | } |
||
| 228 | Console_RegisterCommand(g_display_drawLine, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Width(), g_display_Height(),g_display_Width(), g_display_Height(), g_display_Inverted()); }); |
||
| 229 | |||
| 230 | function g_display_invertRect(alias_name, xStart, yStart, width, height) |
||
| 231 | { |
||
| 232 | if (arguments.length < 5) |
||
| 233 | { |
||
| 234 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 235 | return false; |
||
| 236 | } |
||
| 237 | xStart = parseInt(xStart); |
||
| 238 | yStart = parseInt(yStart); |
||
| 239 | width = parseInt(width); |
||
| 240 | height = parseInt(height); |
||
| 241 | var aliases_data = Module_ResolveAlias(alias_name, g_display_ModuleNames); |
||
| 242 | var found = false; |
||
| 243 | for (var name in aliases_data) |
||
| 244 | { |
||
| 245 | var variables = { |
||
| 246 | "X" : xStart, |
||
| 247 | "Y" : yStart, |
||
| 248 | "Width" : width, |
||
| 249 | "Height" : height}; |
||
| 250 | |||
| 251 | if (!Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_InvertRect", variables)) |
||
| 252 | { |
||
| 253 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 254 | } |
||
| 255 | found = true; |
||
| 256 | } |
||
| 257 | if (!found) |
||
| 258 | { |
||
| 259 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 260 | return false; |
||
| 261 | } |
||
| 262 | return true; |
||
| 263 | } |
||
| 264 | Console_RegisterCommand(g_display_invertRect, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Width(), g_display_Height(),g_display_Width(), g_display_Height()); }); |
||
| 265 | |||
| 266 | function g_display_DrawRect(alias_name, xStart, yStart, width, height, inverted, fill, radius) |
||
| 267 | { |
||
| 268 | if (arguments.length < 8) |
||
| 269 | { |
||
| 270 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 271 | return false; |
||
| 272 | } |
||
| 273 | xStart = parseInt(xStart); |
||
| 274 | yStart = parseInt(yStart); |
||
| 275 | width = parseInt(width); |
||
| 276 | height = parseInt(height); |
||
| 277 | radius = parseInt(radius); |
||
| 278 | var aliases_data = Module_ResolveAlias(alias_name, g_display_ModuleNames); |
||
| 279 | var found = false; |
||
| 280 | for (var name in aliases_data) |
||
| 281 | { |
||
| 282 | var variables = { |
||
| 283 | "X" : xStart, |
||
| 284 | "Y" : yStart, |
||
| 285 | "Width" : width, |
||
| 286 | "Height" : height, |
||
| 287 | "Inverted" : inverted, |
||
| 288 | "Fill" : fill, |
||
| 289 | "Radius" : radius}; |
||
| 290 | |||
| 291 | if (!Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "LCD_DrawRect", variables)) |
||
| 292 | { |
||
| 293 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 294 | } |
||
| 295 | found = true; |
||
| 296 | } |
||
| 297 | if (!found) |
||
| 298 | { |
||
| 299 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 300 | return false; |
||
| 301 | } |
||
| 302 | return true; |
||
| 303 | } |
||
| 304 | Console_RegisterCommand(g_display_DrawRect, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, g_display_Aliases(), g_display_Width(), g_display_Height(),g_display_Width(), g_display_Height(), g_display_Inverted(), g_display_Fill(), g_display_Radius()); }); |
||
| 305 | |||
| 306 | function g_display_OnMessage(module_name, module_id, command, variables) |
||
| 307 | { |
||
| 308 | if (in_array(g_display_ModuleNames, module_name)) |
||
| 309 | { |
||
| 310 | var aliases_data = Module_LookupAliases({ |
||
| 311 | "module_name" : module_name, |
||
| 312 | "module_id" : module_id, |
||
| 313 | "group" : false |
||
| 314 | }); |
||
| 315 | |||
| 316 | switch (command) |
||
| 317 | { |
||
| 318 | case "LCD_Backlight": |
||
| 319 | { |
||
| 320 | for (var alias_name in aliases_data) |
||
| 321 | { |
||
| 322 | var last_value = {}; |
||
| 323 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 324 | |||
| 325 | if (last_value_string) |
||
| 326 | { |
||
| 327 | last_value = eval("(" + last_value_string + ")"); |
||
| 328 | } |
||
| 329 | |||
| 330 | last_value["Strength"] = { "value" : variables["Strength"], "timestamp" : get_time() }; |
||
| 331 | last_value["AutoLight"] = { "value" : variables["AutoLight"], "timestamp" : get_time() }; |
||
| 332 | |||
| 333 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
||
| 334 | } |
||
| 335 | |||
| 336 | break; |
||
| 337 | } |
||
| 338 | } |
||
| 339 | } |
||
| 340 | } |
||
| 341 | Module_RegisterToOnMessage("all", g_display_OnMessage); |
||
| 342 | |||
| 343 | function g_display_OnChange(module_name, module_id, available) |
||
| 344 | { |
||
| 345 | if (in_array(g_display_ModuleNames, module_name) && available) |
||
| 346 | { |
||
| 347 | var aliases_data = Module_LookupAliases({ |
||
| 348 | "module_name" : module_name, |
||
| 349 | "module_id" : module_id, |
||
| 350 | "group" : false |
||
| 351 | }); |
||
| 352 | |||
| 353 | for (var alias_name in aliases_data) |
||
| 354 | { |
||
| 355 | var variables = { }; |
||
| 356 | |||
| 357 | Module_SendMessage(aliases_data[alias_name]["module_name"], aliases_data[alias_name]["module_id"], "LCD_Backlight", variables); |
||
| 358 | } |
||
| 359 | } |
||
| 360 | } |
||
| 361 | Module_RegisterToOnChange("all", g_display_OnChange); |