Rev 2020 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2017 | linlun | 1 | |
| 2020 | arune | 2 | GDisplay_ModuleNames = [ "KS0108" ]; |
| 3 | GDisplay_Height = function() { return [ 0, 1, 2, 3 ]; }; |
||
| 4 | GDisplay_Radius = function() { return [ 2, 5, 10, 20, 30, 50, 100 ]; }; |
||
| 5 | GDisplay_Inverted = function() { return [ "Standard", "Inverted" ]; }; |
||
| 6 | GDisplay_Fill = function() { return [ "NoFill", "Fill" ]; }; |
||
| 2255 | linlun | 7 | GDisplay_Transparent = function() { return [ "Standard", "Transparent" ]; }; |
| 2020 | arune | 8 | GDisplay_Width = function() { return [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]; }; |
| 9 | GDisplay_Backlight = function() { return [ 0, 50, 100, 150, 200, 255 ]; }; |
||
| 10 | GDisplay_Aliases = function() { return Module_GetAliasNames(GDisplay_ModuleNames); }; |
||
| 11 | GDisplay_AvailableIds = function() { return Module_GetAvailableIds(GDisplay_ModuleNames); }; |
||
| 2017 | linlun | 12 | |
| 2020 | arune | 13 | function GDisplay_Clear(alias_name, inverted) |
| 2017 | linlun | 14 | { |
| 15 | if (arguments.length < 2) |
||
| 16 | { |
||
| 17 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 18 | return false; |
||
| 19 | } |
||
| 20 | |||
| 2020 | arune | 21 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 45 | Console_RegisterCommand(GDisplay_Clear, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Inverted()); }); |
| 2017 | linlun | 46 | |
| 2020 | arune | 47 | function GDisplay_SetBacklight(alias_name, strength) |
| 2017 | linlun | 48 | { |
| 49 | if (arguments.length < 2) |
||
| 50 | { |
||
| 51 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 52 | return false; |
||
| 53 | } |
||
| 54 | |||
| 2020 | arune | 55 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 85 | Console_RegisterCommand(GDisplay_SetBacklight, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Backlight()); }); |
| 2017 | linlun | 86 | |
| 87 | |||
| 2020 | arune | 88 | function GDisplay_Print(alias_name, x, y, inverted, transparent, text) |
| 2017 | linlun | 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 | |||
| 2020 | arune | 112 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 156 | Console_RegisterCommand(GDisplay_Print, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Width(), GDisplay_Height(), GDisplay_Inverted(), GDisplay_Transparent()); }); |
| 2017 | linlun | 157 | |
| 2020 | arune | 158 | function GDisplay_DrawCircle(alias_name, xCentre, yCentre, radius, inverted) |
| 2017 | linlun | 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); |
||
| 2020 | arune | 168 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 191 | Console_RegisterCommand(GDisplay_DrawCircle, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Width(), GDisplay_Height(), GDisplay_Radius(), GDisplay_Inverted()); }); |
| 2017 | linlun | 192 | |
| 2020 | arune | 193 | function GDisplay_DrawLine(alias_name, xStart, yStart, xEnd, yEnd, inverted) |
| 2017 | linlun | 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); |
||
| 2020 | arune | 204 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 228 | Console_RegisterCommand(GDisplay_DrawLine, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Width(), GDisplay_Height(),GDisplay_Width(), GDisplay_Height(), GDisplay_Inverted()); }); |
| 2017 | linlun | 229 | |
| 2020 | arune | 230 | function GDisplay_invertRect(alias_name, xStart, yStart, width, height) |
| 2017 | linlun | 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); |
||
| 2020 | arune | 241 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 264 | Console_RegisterCommand(GDisplay_invertRect, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Width(), GDisplay_Height(),GDisplay_Width(), GDisplay_Height()); }); |
| 2017 | linlun | 265 | |
| 2020 | arune | 266 | function GDisplay_DrawRect(alias_name, xStart, yStart, width, height, inverted, fill, radius) |
| 2017 | linlun | 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); |
||
| 2020 | arune | 278 | var aliases_data = Module_ResolveAlias(alias_name, GDisplay_ModuleNames); |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 304 | Console_RegisterCommand(GDisplay_DrawRect, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, GDisplay_Aliases(), GDisplay_Width(), GDisplay_Height(),GDisplay_Width(), GDisplay_Height(), GDisplay_Inverted(), GDisplay_Fill(), GDisplay_Radius()); }); |
| 2017 | linlun | 305 | |
| 2020 | arune | 306 | function GDisplay_OnMessage(module_name, module_id, command, variables) |
| 2017 | linlun | 307 | { |
| 2020 | arune | 308 | if (in_array(GDisplay_ModuleNames, module_name)) |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 341 | Module_RegisterToOnMessage("all", GDisplay_OnMessage); |
| 2017 | linlun | 342 | |
| 2020 | arune | 343 | function GDisplay_OnChange(module_name, module_id, available) |
| 2017 | linlun | 344 | { |
| 2020 | arune | 345 | if (in_array(GDisplay_ModuleNames, module_name) && available) |
| 2017 | linlun | 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 | } |
||
| 2020 | arune | 361 | Module_RegisterToOnChange("all", GDisplay_OnChange); |