| 2338 | } |
| 2339 | |
| 2340 | void DisplayManager_::processDrawInstructions(int16_t xOffset, int16_t yOffset, String &drawInstructions) |
| 2341 | { |
| 2342 | DynamicJsonDocument doc(8192); |
| 2343 | DeserializationError error = deserializeJson(doc, drawInstructions); |
| 2344 | |
| 2345 | if (error) |
| 2346 | { |
| 2347 | Serial.println("Error parsing JSON draw instructions"); |
| 2348 | return; |
| 2349 | } |
| 2350 | |
| 2351 | if (!doc.is<JsonArray>()) |
| 2352 | { |
| 2353 | Serial.println("Invalid JSON draw instructions format"); |
| 2354 | return; |
| 2355 | } |
| 2356 | |
| 2357 | JsonArray instructions = doc.as<JsonArray>(); |
| 2358 | for (JsonObject instruction : instructions) |
| 2359 | { |
| 2360 | for (auto kvp : instruction) |
| 2361 | { |
| 2362 | String command = kvp.key().c_str(); |
| 2363 | |
| 2364 | JsonArray params = kvp.value().as<JsonArray>(); |
| 2365 | if (command == "dp") |
| 2366 | { |
| 2367 | int x = params[0].as<int>(); |
| 2368 | int y = params[1].as<int>(); |
| 2369 | auto color1 = params[2]; |
| 2370 | uint32_t color = getColorFromJsonVariant(color1, TEXTCOLOR_888); |
| 2371 | matrix->drawPixel(x + xOffset, y + yOffset, color); |
| 2372 | } |
| 2373 | else if (command == "dl") |
| 2374 | { |
| 2375 | int x0 = params[0].as<int>(); |
| 2376 | int y0 = params[1].as<int>(); |
| 2377 | int x1 = params[2].as<int>(); |
| 2378 | int y1 = params[3].as<int>(); |
| 2379 | auto color2 = params[4]; |
| 2380 | uint32_t color = getColorFromJsonVariant(color2, TEXTCOLOR_888); |
| 2381 | drawLine(x0 + xOffset, y0 + yOffset, x1 + xOffset, y1 + yOffset, color); |
| 2382 | } |
| 2383 | else if (command == "dr") |
| 2384 | { |
| 2385 | int x = params[0].as<int>(); |
| 2386 | int y = params[1].as<int>(); |
| 2387 | int w = params[2].as<int>(); |
| 2388 | int h = params[3].as<int>(); |
| 2389 | auto color3 = params[4]; |
| 2390 | uint32_t color = getColorFromJsonVariant(color3, TEXTCOLOR_888); |
| 2391 | drawRect(x + xOffset, y + yOffset, w, h, color); |
| 2392 | } |
| 2393 | else if (command == "df") |
| 2394 | { |
| 2395 | int x = params[0].as<int>(); |
| 2396 | int y = params[1].as<int>(); |
| 2397 | int w = params[2].as<int>(); |
no test coverage detected