ClassFlowMakeImage.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "ClassFlowMakeImage.h"
  2. #include "Helper.h"
  3. #include "CFindTemplate.h"
  4. #include "ClassControllCamera.h"
  5. #include <time.h>
  6. static const char* TAG = "flow_make_image";
  7. esp_err_t ClassFlowMakeImage::camera_capture(){
  8. string nm = namerawimage;
  9. Camera.CaptureToFile(nm);
  10. return ESP_OK;
  11. }
  12. void ClassFlowMakeImage::takePictureWithFlash(int flashdauer)
  13. {
  14. string nm = namerawimage;
  15. if (isImageSize && (ImageQuality > 0))
  16. Camera.SetQualitySize(ImageQuality, ImageSize);
  17. printf("Start CaptureFile\n");
  18. Camera.CaptureToFile(nm, flashdauer);
  19. }
  20. ClassFlowMakeImage::ClassFlowMakeImage() : ClassFlowImage(TAG)
  21. {
  22. waitbeforepicture = 5;
  23. isImageSize = false;
  24. ImageQuality = -1;
  25. TimeImageTaken = 0;
  26. namerawimage = "/sdcard/img_tmp/raw.jpg";
  27. }
  28. ClassFlowMakeImage::ClassFlowMakeImage(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
  29. {
  30. waitbeforepicture = 5;
  31. isImageSize = false;
  32. ImageQuality = -1;
  33. TimeImageTaken = 0;
  34. namerawimage = "/sdcard/img_tmp/raw.jpg";
  35. }
  36. bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph)
  37. {
  38. std::vector<string> zerlegt;
  39. aktparamgraph = trim(aktparamgraph);
  40. if (aktparamgraph.size() == 0)
  41. if (!this->GetNextParagraph(pfile, aktparamgraph))
  42. return false;
  43. if (aktparamgraph.compare("[MakeImage]") != 0) // Paragraph passt nich zu MakeImage
  44. return false;
  45. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  46. {
  47. zerlegt = this->ZerlegeZeile(aktparamgraph);
  48. if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
  49. {
  50. LogImageLocation = "/sdcard" + zerlegt[1];
  51. isLogImage = true;
  52. }
  53. if ((zerlegt[0] == "ImageQuality") && (zerlegt.size() > 1))
  54. this->ImageQuality = std::stod(zerlegt[1]);
  55. if ((zerlegt[0] == "ImageSize") && (zerlegt.size() > 1))
  56. {
  57. ImageSize = Camera.TextToFramesize(zerlegt[1].c_str());
  58. isImageSize = true;
  59. }
  60. }
  61. return true;
  62. }
  63. string ClassFlowMakeImage::getHTMLSingleStep(string host)
  64. {
  65. string result;
  66. result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
  67. return result;
  68. }
  69. bool ClassFlowMakeImage::doFlow(string zwtime)
  70. {
  71. ////////////////////////////////////////////////////////////////////
  72. // TakeImage and Store into /image_tmp/raw.jpg TO BE DONE
  73. ////////////////////////////////////////////////////////////////////
  74. string logPath = CreateLogFolder(zwtime);
  75. int flashdauer = (int) waitbeforepicture * 1000;
  76. takePictureWithFlash(flashdauer);
  77. time(&TimeImageTaken);
  78. localtime(&TimeImageTaken);
  79. LogImage(logPath, "raw", NULL, NULL, zwtime);
  80. RemoveOldLogs();
  81. return true;
  82. }
  83. time_t ClassFlowMakeImage::getTimeImageTaken()
  84. {
  85. return TimeImageTaken;
  86. }