MCPcopy Create free account
hub / github.com/OpenEPaperLink/OpenEPaperLink / handleWSdata

Function handleWSdata

ESP32_AP-Flasher/src/webflasher.cpp:468–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466}
467
468void handleWSdata(uint8_t* data, size_t len, AsyncWebSocketClient* client) {
469 JsonDocument doc;
470 DeserializationError error = deserializeJson(doc, (const char*)data);
471 JsonDocument response;
472 response["flashstatus"] = 1;
473
474 if (error) {
475 wsSerial("Failed to parse JSON");
476 return;
477 }
478
479 if (doc["flashcmd"].is<int>()) {
480 uint16_t flashcmd = doc["flashcmd"].as<int>();
481 switch (flashcmd) {
482 case WEBFLASH_ENABLE_AUTOFLASH:
483 wsSerial("Switching to autoflash", "yellow");
484 webFlashMode = FLASHMODE_AUTO_FOCUS;
485 autoFlashStep = AUTOFLASH_STEP_STARTUP;
486 break;
487 case WEBFLASH_ENABLE_USBFLASHER:
488 wsSerial("Switching to usbflasher", "yellow");
489 wsSerial("You can now use OEPL-flasher.py to flash your tags", "silver");
490 autoFlashStep = AUTOFLASH_START_USBFLASHER;
491 webFlashMode = FLASHMODE_OFF;
492 break;
493 case WEBFLASH_FOCUS:
494 if (webFlashMode == FLASHMODE_AUTO_BACKGROUND) webFlashMode = FLASHMODE_AUTO_FOCUS;
495 if (webFlashMode == FLASHMODE_OFF) {
496 autoFlashStep = AUTOFLASH_START_USBFLASHER;
497 } else {
498 autoFlashStep = AUTOFLASH_STEP_STARTUP;
499 }
500#ifdef HAS_TFT
501 tftOverride = true;
502#endif
503 break;
504 case WEBFLASH_BLUR:
505 if (webFlashMode == FLASHMODE_AUTO_FOCUS) webFlashMode = FLASHMODE_AUTO_BACKGROUND;
506#ifdef HAS_TFT
507 tftOverride = false;
508 sendAvail(0xFC);
509#endif
510 break;
511 case WEBFLASH_POWER_ON: {
512 wsSerial("Power up", "yellow");
513
514 extern bool rxSerialStopTask2;
515 if (rxSerialStopTask2 == false) {
516 rxSerialStopTask2 = true;
517 vTaskDelay(500 / portTICK_PERIOD_MS);
518 }
519
520 int8_t powerPins2[] = FLASHER_EXT_POWER;
521 uint8_t numPowerPins = sizeof(powerPins2);
522 powerControl(true, (uint8_t*)powerPins2, numPowerPins);
523
524 /* work in progress
525 if (Serial2) Serial2.end();

Callers 1

init_webFunction · 0.85

Calls 4

wsSerialFunction · 0.85
sendAvailFunction · 0.85
powerControlFunction · 0.70
endMethod · 0.45

Tested by

no test coverage detected