diff --git a/README.md b/README.md index f3eed0c9..32fdf81b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571 ## Donate +------ If you would like to support the developer with a cup of coffee you can do that via [Paypal](https://www.paypal.com/donate?hosted_button_id=8TRSVYNYKDSWL). @@ -38,7 +39,11 @@ If you would like to support the developer with a cup of coffee you can do that **General remark:** Beside the `firmware.bin`, typically also the content of `/html` needs to be updated! -##### Rolling - (2020-12-31) +##### Rolling - (2021-01-01) + +* Increased stability (internal image handling) + +2020-12-31 * Bug-Fixing: internal change of camera handling to avoid reboots diff --git a/code/components/jomjol_controlGPIO/server_GPIO.cpp b/code/components/jomjol_controlGPIO/server_GPIO.cpp index 45ab4b84..02bd4411 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.cpp +++ b/code/components/jomjol_controlGPIO/server_GPIO.cpp @@ -18,9 +18,13 @@ #include "Helper.h" +#define DEBUG_DETAIL_ON + esp_err_t handler_switch_GPIO(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_switch_GPIO - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_switch_GPIO - Start"); +#endif LogFile.WriteToFile("handler_switch_GPIO"); char _query[200]; diff --git a/code/components/jomjol_controlGPIO/server_GPIO.h b/code/components/jomjol_controlGPIO/server_GPIO.h index ecfa0a3c..f91e24c2 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.h +++ b/code/components/jomjol_controlGPIO/server_GPIO.h @@ -8,5 +8,3 @@ static const char *TAGPARTGPIO = "server_GPIO"; void register_server_GPIO_uri(httpd_handle_t server); - -extern bool debug_detail_heap; \ No newline at end of file diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index b07b16a8..dfd693a6 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -192,7 +192,7 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) LEDOnOff(true); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - Start"); + LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - Start"); #endif if (delay > 0) @@ -203,7 +203,7 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) } #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After LightOn"); + LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After LightOn"); #endif camera_fb_t * fb = esp_camera_fb_get(); @@ -220,7 +220,7 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) esp_camera_fb_return(fb); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After fb_get"); + LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After fb_get"); #endif LEDOnOff(false); @@ -237,7 +237,9 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) _zwImage.LoadFromMemory(zwischenspeicher, _size); free(zwischenspeicher); - if (debug_detail_heap) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After LoadFromMemory"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After LoadFromMemory"); +#endif stbi_uc* p_target; stbi_uc* p_source; @@ -248,7 +250,7 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) #ifdef DEBUG_DETAIL_ON std::string _zw = "Targetimage: " + std::to_string((int) _Image->rgb_image) + " Size: " + std::to_string(_Image->width) + ", " + std::to_string(_Image->height); _zw = _zw + " _zwImage: " + std::to_string((int) _zwImage.rgb_image) + " Size: " + std::to_string(_zwImage.width) + ", " + std::to_string(_zwImage.height); - if (debug_detail_heap) LogFile.WriteToFile(_zw); + LogFile.WriteToFile(_zw); #endif for (int x = 0; x < width; ++x) @@ -262,13 +264,13 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) } #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After Copy To Target"); + LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After Copy To Target"); #endif free(buf); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - Done"); + LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - Done"); #endif return ESP_OK; @@ -338,9 +340,7 @@ esp_err_t CCamera::CaptureToFile(std::string nm, int delay) FILE * fp = OpenFileAndWait(nm.c_str(), "wb"); if (fp == NULL) /* If an error occurs during the file creation */ { -#ifdef DEBUG_DETAIL_ON fprintf(stderr, "fopen() failed for '%s'\n", nm.c_str()); -#endif } else { diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.h b/code/components/jomjol_controlcamera/ClassControllCamera.h index 702bc286..7e4dd6bb 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.h +++ b/code/components/jomjol_controlcamera/ClassControllCamera.h @@ -45,6 +45,4 @@ class CCamera { extern CCamera Camera; -extern bool debug_detail_heap; - #endif \ No newline at end of file diff --git a/code/components/jomjol_controlcamera/server_camera.cpp b/code/components/jomjol_controlcamera/server_camera.cpp index 4cb29566..21eb9363 100644 --- a/code/components/jomjol_controlcamera/server_camera.cpp +++ b/code/components/jomjol_controlcamera/server_camera.cpp @@ -11,7 +11,7 @@ #define SCRATCH_BUFSIZE2 8192 char scratch2[SCRATCH_BUFSIZE2]; -// #define DEBUG_DETAIL_ON +//#define DEBUG_DETAIL_ON @@ -33,8 +33,7 @@ void PowerResetCamera(){ esp_err_t handler_lightOn(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_lightOn - Start"); - LogFile.WriteToFile("handler_lightOn"); + LogFile.WriteHeapInfo("handler_lightOn - Start"); printf("handler_lightOn uri:\n"); printf(req->uri); printf("\n"); #endif @@ -43,7 +42,7 @@ esp_err_t handler_lightOn(httpd_req_t *req) httpd_resp_send(req, resp_str, strlen(resp_str)); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_lightOn - Done"); + LogFile.WriteHeapInfo("handler_lightOn - Done"); #endif return ESP_OK; @@ -52,8 +51,7 @@ esp_err_t handler_lightOn(httpd_req_t *req) esp_err_t handler_lightOff(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_lightOff - Start"); - LogFile.WriteToFile("handler_lightOff"); + LogFile.WriteHeapInfo("handler_lightOff - Start"); printf("handler_lightOff uri:\n"); printf(req->uri); printf("\n"); #endif Camera.LightOnOff(false); @@ -61,7 +59,7 @@ esp_err_t handler_lightOff(httpd_req_t *req) httpd_resp_send(req, resp_str, strlen(resp_str)); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_lightOff - Done"); + LogFile.WriteHeapInfo("handler_lightOff - Done"); #endif return ESP_OK; @@ -70,8 +68,7 @@ esp_err_t handler_lightOff(httpd_req_t *req) esp_err_t handler_capture(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_capture - Start"); - LogFile.WriteToFile("handler_capture"); + LogFile.WriteHeapInfo("handler_capture - Start"); #endif int quality; @@ -89,7 +86,7 @@ esp_err_t handler_capture(httpd_req_t *req) ressult = Camera.CaptureToHTTP(req); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_capture - Done"); + LogFile.WriteHeapInfo("handler_capture - Done"); #endif return ressult; @@ -98,7 +95,8 @@ esp_err_t handler_capture(httpd_req_t *req) esp_err_t handler_capture_with_ligth(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_capture_with_ligth - Start"); + + LogFile.WriteHeapInfo("handler_capture_with_ligth - Start"); LogFile.WriteToFile("handler_capture_with_ligth"); char _query[100]; @@ -140,7 +138,7 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req) Camera.LightOnOff(false); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_capture_with_ligth - Done"); + LogFile.WriteHeapInfo("handler_capture_with_ligth - Done"); #endif return ressult; @@ -151,8 +149,7 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req) esp_err_t handler_capture_save_to_file(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_capture_save_to_file - Start"); - LogFile.WriteToFile("handler_capture_save_to_file"); + LogFile.WriteHeapInfo("handler_capture_save_to_file - Start"); #endif char _query[100]; @@ -206,7 +203,7 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req) httpd_resp_send(req, resp_str, strlen(resp_str)); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_capture_save_to_file - Done"); + LogFile.WriteHeapInfo("handler_capture_save_to_file - Done"); #endif return ressult; diff --git a/code/components/jomjol_controlcamera/server_camera.h b/code/components/jomjol_controlcamera/server_camera.h index c0177356..b3f1fe19 100644 --- a/code/components/jomjol_controlcamera/server_camera.h +++ b/code/components/jomjol_controlcamera/server_camera.h @@ -13,7 +13,4 @@ void register_server_camera_uri(httpd_handle_t server); void PowerResetCamera(); - -extern bool debug_detail_heap; - #endif \ No newline at end of file diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp index e035b598..6c69ae1e 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.cpp +++ b/code/components/jomjol_fileserver_ota/server_ota.cpp @@ -34,6 +34,8 @@ #include "Helper.h" +// #define DEBUG_DETAIL_ON + #define BUFFSIZE 1024 #define HASH_LEN 32 /* SHA-256 digest length */ @@ -303,7 +305,9 @@ void CheckOTAUpdate(void) esp_err_t handler_ota_update(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_ota_update - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_ota_update - Start"); +#endif LogFile.WriteToFile("handler_ota_update"); char _query[200]; @@ -381,7 +385,9 @@ esp_err_t handler_ota_update(httpd_req_t *req) httpd_resp_send(req, resp_str, strlen(resp_str)); - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_ota_update - Done"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_ota_update - Done"); +#endif return ESP_OK; }; @@ -418,7 +424,9 @@ void doReboot(){ esp_err_t handler_reboot(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_reboot - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_reboot - Start"); +#endif LogFile.WriteToFile("handler_reboot"); ESP_LOGI(TAGPARTOTA, "!!! System will restart within 5 sec!!!"); @@ -427,7 +435,10 @@ esp_err_t handler_reboot(httpd_req_t *req) doReboot(); - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_reboot - Done"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_reboot - Done"); +#endif + return ESP_OK; } diff --git a/code/components/jomjol_fileserver_ota/server_ota.h b/code/components/jomjol_fileserver_ota/server_ota.h index 87ae1319..622fd0a8 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.h +++ b/code/components/jomjol_fileserver_ota/server_ota.h @@ -10,4 +10,3 @@ void register_server_ota_sdcard_uri(httpd_handle_t server); void CheckOTAUpdate(); void doReboot(); -extern bool debug_detail_heap; \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 934d9749..0402fa26 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -11,6 +11,8 @@ #include "server_help.h" +//#define DEBUG_DETAIL_ON + static const char* TAG = "flow_controll"; @@ -198,18 +200,20 @@ bool ClassFlowControll::doFlow(string time) std::string zw_time; int repeat = 0; - -///////////////////////////////////////////////////// - if (debug_detail_heap) LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow - Start"); -///////////////////////////////////////////////////////// +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow - Start"); +#endif for (int i = 0; i < FlowControll.size(); ++i) { zw_time = gettimestring("%Y%m%d-%H%M%S"); aktstatus = zw_time + ": " + FlowControll[i]->name(); + +#ifdef DEBUG_DETAIL_ON string zw = "FlowControll.doFlow - " + FlowControll[i]->name(); - if (debug_detail_heap) LogFile.WriteHeapInfo(zw); -// LogFile.WriteToFile(zw); + LogFile.WriteHeapInfo(zw); +#endif + if (!FlowControll[i]->doFlow(time)){ repeat++; LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt"); @@ -225,8 +229,11 @@ bool ClassFlowControll::doFlow(string time) { result = true; } + +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow"); +#endif - if (debug_detail_heap) LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow"); } zw_time = gettimestring("%Y%m%d-%H%M%S"); aktstatus = zw_time + ": Flow is done"; diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.h b/code/components/jomjol_flowcontroll/ClassFlowControll.h index c491cb87..d46d1829 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.h +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.h @@ -56,5 +56,4 @@ public: string name(){return "ClassFlowControll";}; }; -extern bool debug_detail_heap; diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp index e8a938a4..d6d948ab 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp @@ -7,6 +7,8 @@ #include +// #define DEBUG_DETAIL_ON + static const char* TAG = "flow_make_image"; esp_err_t ClassFlowMakeImage::camera_capture(){ @@ -100,16 +102,23 @@ bool ClassFlowMakeImage::doFlow(string zwtime) int flashdauer = (int) waitbeforepicture * 1000; - if (debug_detail_heap) LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash"); + #ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash"); +#endif takePictureWithFlash(flashdauer); - if (debug_detail_heap) LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After takePictureWithFlash"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After takePictureWithFlash"); +#endif LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage); RemoveOldLogs(); - if (debug_detail_heap) LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After RemoveOldLogs"); + +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After RemoveOldLogs"); +#endif return true; } diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h index 19fdcb45..744c2cd3 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h @@ -49,5 +49,3 @@ public: }; -extern bool debug_detail_heap; - diff --git a/code/components/jomjol_image_proc/CAlignAndCutImage.cpp b/code/components/jomjol_image_proc/CAlignAndCutImage.cpp index b219b3a0..cb38b211 100644 --- a/code/components/jomjol_image_proc/CAlignAndCutImage.cpp +++ b/code/components/jomjol_image_proc/CAlignAndCutImage.cpp @@ -18,7 +18,9 @@ CAlignAndCutImage::CAlignAndCutImage(CImageBasis *_org, CImageBasis *_temp) width = _org->width; height = _org->height; bpp = _org->bpp; - externalImage = true; + externalImage = true; + + islocked = false; ImageTMP = _temp; } @@ -110,6 +112,8 @@ void CAlignAndCutImage::CutAndSave(std::string _template1, int x1, int y1, int d stbi_uc* p_target; stbi_uc* p_source; + RGBImageLock(); + for (int x = x1; x < x2; ++x) for (int y = y1; y < y2; ++y) { @@ -122,6 +126,8 @@ void CAlignAndCutImage::CutAndSave(std::string _template1, int x1, int y1, int d // stbi_write_jpg(_template1.c_str(), dx, dy, channels, odata, 0); stbi_write_bmp(_template1.c_str(), dx, dy, channels, odata); + RGBImageRelease(); + stbi_image_free(odata); } @@ -143,7 +149,8 @@ void CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy, CImageBasis * return; } - uint8_t* odata = _target->rgb_image; + uint8_t* odata = _target->RGBImageLock(); + RGBImageLock(); stbi_uc* p_target; stbi_uc* p_source; @@ -156,6 +163,9 @@ void CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy, CImageBasis * for (int _channels = 0; _channels < channels; ++_channels) p_target[_channels] = p_source[_channels]; } + + RGBImageRelease(); + _target->RGBImageRelease(); } @@ -177,6 +187,8 @@ CImageBasis* CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy) stbi_uc* p_target; stbi_uc* p_source; + RGBImageLock(); + for (int x = x1; x < x2; ++x) for (int y = y1; y < y2; ++y) { @@ -187,6 +199,7 @@ CImageBasis* CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy) } CImageBasis* rs = new CImageBasis(odata, channels, dx, dy, bpp); + RGBImageRelease(); rs->SetIndepended(); return rs; } diff --git a/code/components/jomjol_image_proc/CFindTemplate.cpp b/code/components/jomjol_image_proc/CFindTemplate.cpp index 4af20ccc..33f02eae 100644 --- a/code/components/jomjol_image_proc/CFindTemplate.cpp +++ b/code/components/jomjol_image_proc/CFindTemplate.cpp @@ -44,6 +44,8 @@ void CFindTemplate::FindTemplate(std::string _template, int* found_x, int* found double aktSAD; double minSAD = pow(tpl_width * tpl_height * 255, 2); + RGBImageLock(); + for (int xouter = ow_start; xouter <= ow_stop; xouter++) for (int youter = oh_start; youter <= oh_stop; ++youter) { @@ -66,6 +68,8 @@ void CFindTemplate::FindTemplate(std::string _template, int* found_x, int* found } } + RGBImageRelease(); + stbi_write_bmp("sdcard\\find.bmp", ow, oh, channels, odata); stbi_image_free(odata); diff --git a/code/components/jomjol_image_proc/CImageBasis.cpp b/code/components/jomjol_image_proc/CImageBasis.cpp index 434bd68c..b850210c 100644 --- a/code/components/jomjol_image_proc/CImageBasis.cpp +++ b/code/components/jomjol_image_proc/CImageBasis.cpp @@ -19,6 +19,43 @@ using namespace std; static const char *TAG = "CImageBasis"; +//#define DEBUG_DETAIL_ON + + + +uint8_t * CImageBasis::RGBImageLock(int _waitmaxsec) +{ + if (islocked) + { +#ifdef DEBUG_DETAIL_ON + printf("Image is locked: sleep for : %ds\n", _waitmaxsec); +#endif + TickType_t xDelay; + xDelay = 1000 / portTICK_PERIOD_MS; + for (int i = 0; i <= _waitmaxsec; ++i) + { + vTaskDelay( xDelay ); + if (!islocked) + break; + } + } + + if (islocked) + return NULL; + + return rgb_image; +} + +void CImageBasis::RGBImageRelease() +{ + islocked = false; +} + +uint8_t * CImageBasis::RGBImageGet() +{ + return rgb_image; +} + void writejpghelp(void *context, void *data, int size) @@ -42,7 +79,9 @@ ImageData* CImageBasis::writeToMemoryAsJPG(const int quality) { ImageData* ii = new ImageData; + RGBImageLock(); stbi_write_jpg_to_func(writejpghelp, ii, width, height, channels, rgb_image, quality); + RGBImageRelease(); return ii; } @@ -83,7 +122,9 @@ esp_err_t CImageBasis::SendJPGtoHTTP(httpd_req_t *_req, const int quality) ii.res = ESP_OK; ii.size = 0; + RGBImageLock(); stbi_write_jpg_to_func(writejpgtohttphelp, &ii, width, height, channels, rgb_image, quality); + RGBImageRelease(); if (ii.size > 0) { @@ -107,7 +148,10 @@ bool CImageBasis::CopyFromMemory(uint8_t* _source, int _size) printf("Kann Bild nicht von Speicher kopierte - Größen passen nicht zusammen: soll %d, ist %d\n", _size, gr); return false; } + + RGBImageLock(); memCopy(_source, rgb_image, _size); + RGBImageRelease(); return true; } @@ -145,6 +189,7 @@ void CImageBasis::setPixelColor(int x, int y, int r, int g, int b) { stbi_uc* p_source; + RGBImageLock(); p_source = rgb_image + (channels * (y * width + x)); p_source[0] = r; if ( channels > 2) @@ -152,6 +197,7 @@ void CImageBasis::setPixelColor(int x, int y, int r, int g, int b) p_source[1] = g; p_source[2] = b; } + RGBImageRelease(); } void CImageBasis::drawRect(int x, int y, int dx, int dy, int r, int g, int b, int thickness) @@ -251,6 +297,7 @@ CImageBasis::CImageBasis() width = 0; height = 0; channels = 0; + islocked = false; } void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels) @@ -260,6 +307,9 @@ void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels) height = _height; channels = _channels; + RGBImageLock(); + + int memsize = width * height * channels; rgb_image = (unsigned char*)GET_MEMORY(memsize); @@ -274,31 +324,38 @@ void CImageBasis::CreateEmptyImage(int _width, int _height, int _channels) p_source[_channels] = (uint8_t) 0; } + RGBImageRelease(); + } void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len) { + RGBImageLock(); if (rgb_image) stbi_image_free(rgb_image); rgb_image = stbi_load_from_memory(_buffer, len, &width, &height, &channels, 3); bpp = channels; printf("Image loaded from memory: %d, %d, %d\n", width, height, channels); + RGBImageRelease(); } CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat) { + islocked = false; externalImage = false; channels = _copyfrom->channels; width = _copyfrom->width; height = _copyfrom->height; bpp = _copyfrom->bpp; + RGBImageLock(); + int memsize = width * height * channels; rgb_image = (unsigned char*)GET_MEMORY(memsize); - int anz = 1; TickType_t xDelay; + int anz = 1; while (!rgb_image && (anz < _anzrepeat)) { printf("Create Image from Copy - Speicher ist voll - Versuche es erneut: %d.\n", anz); @@ -312,14 +369,17 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat) { printf(getESPHeapInfo().c_str()); printf("\nKein freier Speicher mehr!!!! Benötigt: %d %d %d %d\n", width, height, channels, memsize); + RGBImageRelease(); return; } memCopy(_copyfrom->rgb_image, rgb_image, memsize); + RGBImageRelease(); } CImageBasis::CImageBasis(int _width, int _height, int _channels) { + islocked = false; externalImage = false; channels = _channels; width = _width; @@ -327,6 +387,7 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels) bpp = _channels; int memsize = width * height * channels; + rgb_image = (unsigned char*)GET_MEMORY(memsize); if (!rgb_image) { @@ -339,13 +400,17 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels) CImageBasis::CImageBasis(std::string _image) { + islocked = false; channels = 3; externalImage = false; filename = _image; long zwld = esp_get_free_heap_size(); printf("freeheapsize before: %ld\n", zwld); + RGBImageLock(); rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels); + RGBImageRelease(); + zwld = esp_get_free_heap_size(); printf("freeheapsize after : %ld\n", zwld); @@ -355,6 +420,7 @@ CImageBasis::CImageBasis(std::string _image) zw = "CImageBasis after load " + _image + "\n"; printf(zw.c_str()); printf("w %d, h %d, b %d, c %d\n", width, height, bpp, channels); + } bool CImageBasis::ImageOkay(){ @@ -363,6 +429,7 @@ bool CImageBasis::ImageOkay(){ CImageBasis::CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) { + islocked = false; rgb_image = _rgb_image; channels = _channels; width = _width; @@ -378,6 +445,9 @@ void CImageBasis::Contrast(float _contrast) //input range [-100..100] float contrast = (_contrast/100) + 1; //convert to decimal & shift range: [0..2] float intercept = 128 * (1 - contrast); + RGBImageLock(); + + for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) { @@ -385,10 +455,13 @@ void CImageBasis::Contrast(float _contrast) //input range [-100..100] for (int _channels = 0; _channels < channels; ++_channels) p_source[_channels] = (uint8_t) std::min(255, std::max(0, (int) (p_source[_channels] * contrast + intercept))); } + + RGBImageRelease(); } CImageBasis::~CImageBasis() { + RGBImageLock(); if (!externalImage) stbi_image_free(rgb_image); } @@ -397,6 +470,8 @@ void CImageBasis::SaveToFile(std::string _imageout) { string typ = getFileType(_imageout); + RGBImageLock(); + if ((typ == "jpg") || (typ == "JPG")) // ACHTUNG PROBLEMATISCH IM ESP32 { stbi_write_jpg(_imageout.c_str(), width, height, channels, rgb_image, 0); @@ -406,6 +481,7 @@ void CImageBasis::SaveToFile(std::string _imageout) { stbi_write_bmp(_imageout.c_str(), width, height, channels, rgb_image); } + RGBImageRelease(); } @@ -414,12 +490,17 @@ void CImageBasis::Resize(int _new_dx, int _new_dy) int memsize = _new_dx * _new_dy * channels; uint8_t* odata = (unsigned char*)GET_MEMORY(memsize); + RGBImageLock(); + + stbir_resize_uint8(rgb_image, width, height, 0, odata, _new_dx, _new_dy, 0, channels); stbi_image_free(rgb_image); rgb_image = (unsigned char*)GET_MEMORY(memsize); memCopy(odata, rgb_image, memsize); + RGBImageRelease(); + width = _new_dx; height = _new_dy; stbi_image_free(odata); @@ -433,7 +514,10 @@ void CImageBasis::Resize(int _new_dx, int _new_dy, CImageBasis *_target) return; } + RGBImageLock(); + uint8_t* odata = _target->rgb_image; stbir_resize_uint8(rgb_image, width, height, 0, odata, _new_dx, _new_dy, 0, channels); + RGBImageRelease(); } diff --git a/code/components/jomjol_image_proc/CImageBasis.h b/code/components/jomjol_image_proc/CImageBasis.h index 65f822b2..c754aa24 100644 --- a/code/components/jomjol_image_proc/CImageBasis.h +++ b/code/components/jomjol_image_proc/CImageBasis.h @@ -40,11 +40,17 @@ class CImageBasis void memCopy(uint8_t* _source, uint8_t* _target, int _size); bool isInImage(int x, int y); + bool islocked; + public: uint8_t* rgb_image; int channels; int width, height, bpp; + uint8_t * RGBImageLock(int _waitmaxsec = 60); + void RGBImageRelease(); + uint8_t * RGBImageGet(); + int getWidth(){return this->width;}; int getHeight(){return this->height;}; int getChannels(){return this->channels;}; diff --git a/code/components/jomjol_image_proc/CRotateImage.cpp b/code/components/jomjol_image_proc/CRotateImage.cpp index 53edbf43..e40efda5 100644 --- a/code/components/jomjol_image_proc/CRotateImage.cpp +++ b/code/components/jomjol_image_proc/CRotateImage.cpp @@ -10,6 +10,7 @@ CRotateImage::CRotateImage(CImageBasis *_org, CImageBasis *_temp) bpp = _org->bpp; externalImage = true; ImageTMP = _temp; + islocked = false; } void CRotateImage::Mirror(){ @@ -17,7 +18,7 @@ void CRotateImage::Mirror(){ uint8_t* odata; if (ImageTMP) { - odata = ImageTMP->rgb_image; + odata = ImageTMP->RGBImageLock(); } else { @@ -29,6 +30,8 @@ void CRotateImage::Mirror(){ stbi_uc* p_target; stbi_uc* p_source; + RGBImageLock(); + for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) { @@ -45,9 +48,12 @@ void CRotateImage::Mirror(){ // memcpy(rgb_image, odata, memsize); memCopy(odata, rgb_image, memsize); if (!ImageTMP) - { stbi_image_free(odata); - } + + if (ImageTMP) + ImageTMP->RGBImageRelease(); + + RGBImageRelease(); } void CRotateImage::Rotate(float _angle, int _centerx, int _centery) @@ -70,7 +76,7 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery) uint8_t* odata; if (ImageTMP) { - odata = ImageTMP->rgb_image; + odata = ImageTMP->RGBImageLock(); } else { @@ -82,6 +88,8 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery) stbi_uc* p_target; stbi_uc* p_source; + RGBImageLock(); + for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) { @@ -113,6 +121,10 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery) { stbi_image_free(odata); } + if (ImageTMP) + ImageTMP->RGBImageRelease(); + + RGBImageRelease(); } void CRotateImage::Rotate(float _angle) @@ -127,7 +139,7 @@ void CRotateImage::Translate(int _dx, int _dy) uint8_t* odata; if (ImageTMP) { - odata = ImageTMP->rgb_image; + odata = ImageTMP->RGBImageLock(); } else { @@ -140,6 +152,8 @@ void CRotateImage::Translate(int _dx, int _dy) stbi_uc* p_target; stbi_uc* p_source; + RGBImageLock(); + for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) { @@ -167,5 +181,12 @@ void CRotateImage::Translate(int _dx, int _dy) { stbi_image_free(odata); } + + if (ImageTMP) + { + ImageTMP->RGBImageRelease(); + } + RGBImageRelease(); + } diff --git a/code/components/jomjol_tfliteclass/CTfLiteClass.cpp b/code/components/jomjol_tfliteclass/CTfLiteClass.cpp index 195223bc..fc0043d3 100644 --- a/code/components/jomjol_tfliteclass/CTfLiteClass.cpp +++ b/code/components/jomjol_tfliteclass/CTfLiteClass.cpp @@ -4,7 +4,7 @@ #include -//#define DEBUG_DETAIL_ON +// #define DEBUG_DETAIL_ON float CTfLiteClass::GetOutputValue(int nr) { @@ -175,10 +175,8 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn) if (size == -1) { -#ifdef DEBUG_DETAIL_ON - printf("\nFile existiert nicht.\n"); -#endif - return NULL; + printf("\nFile existiert nicht.\n"); + return NULL; } unsigned char *result = (unsigned char*) malloc(size); diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 9e2cb3bc..963fa9b5 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -131,10 +131,8 @@ void blink_task_doFlow(void *pvParameter) esp_err_t handler_init(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_init - Start"); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteToFile("handler_init"); + LogFile.WriteHeapInfo("handler_init - Start"); printf("handler_doinit uri:\n"); printf(req->uri); printf("\n"); #endif @@ -149,7 +147,7 @@ esp_err_t handler_init(httpd_req_t *req) httpd_resp_send_chunk(req, NULL, 0); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_init - Done"); + LogFile.WriteHeapInfo("handler_init - Done"); #endif return ESP_OK; @@ -158,8 +156,7 @@ esp_err_t handler_init(httpd_req_t *req) esp_err_t handler_doflow(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_doflow - Start"); - LogFile.WriteToFile("handler_doflow"); + LogFile.WriteHeapInfo("handler_doflow - Start"); #endif char* resp_str; @@ -182,7 +179,7 @@ esp_err_t handler_doflow(httpd_req_t *req) httpd_resp_send_chunk(req, NULL, 0); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_doflow - Done"); + LogFile.WriteHeapInfo("handler_doflow - Done"); #endif return ESP_OK; @@ -194,8 +191,7 @@ esp_err_t handler_doflow(httpd_req_t *req) esp_err_t handler_wasserzaehler(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_wasserzaehler - Start"); - LogFile.WriteToFile("handler_wasserzaehler"); + LogFile.WriteHeapInfo("handler_wasserzaehler - Start"); #endif bool _rawValue = false; @@ -283,7 +279,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) httpd_resp_sendstr_chunk(req, NULL); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_wasserzaehler - Done"); + LogFile.WriteHeapInfo("handler_wasserzaehler - Done"); #endif return ESP_OK; }; @@ -292,8 +288,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) esp_err_t handler_editflow(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_editflow - Start"); - LogFile.WriteToFile("handler_editflow"); + LogFile.WriteHeapInfo("handler_editflow - Start"); #endif printf("handler_editflow uri: "); printf(req->uri); printf("\n"); @@ -459,7 +454,7 @@ esp_err_t handler_editflow(httpd_req_t *req) httpd_resp_sendstr_chunk(req, NULL); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_editflow - Done"); + LogFile.WriteHeapInfo("handler_editflow - Done"); #endif return ESP_OK; @@ -469,8 +464,7 @@ esp_err_t handler_editflow(httpd_req_t *req) esp_err_t handler_prevalue(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_prevalue - Start"); - LogFile.WriteToFile("handler_prevalue"); + LogFile.WriteHeapInfo("handler_prevalue - Start"); #endif const char* resp_str; @@ -504,7 +498,7 @@ esp_err_t handler_prevalue(httpd_req_t *req) httpd_resp_send_chunk(req, NULL, 0); #ifdef DEBUG_DETAIL_ON - if (debug_detail_heap) LogFile.WriteHeapInfo("handler_prevalue - Start"); + LogFile.WriteHeapInfo("handler_prevalue - Start"); #endif return ESP_OK; diff --git a/code/components/jomjol_tfliteclass/server_tflite.h b/code/components/jomjol_tfliteclass/server_tflite.h index da778839..148be20e 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.h +++ b/code/components/jomjol_tfliteclass/server_tflite.h @@ -18,5 +18,3 @@ bool isSetupModusActive(); esp_err_t GetJPG(std::string _filename, httpd_req_t *req); esp_err_t GetRawJPG(httpd_req_t *req); - -extern bool debug_detail_heap; \ No newline at end of file diff --git a/code/main/main.cpp b/code/main/main.cpp index 9f200199..0970180e 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -26,12 +26,8 @@ #include "server_main.h" #include "server_camera.h" #include "server_GPIO.h" - static const char *TAGMAIN = "connect_wlan_main"; - -bool debug_detail_heap = false; - #define FLASH_GPIO GPIO_NUM_4 void Init_NVS_SDCard() @@ -144,7 +140,6 @@ extern "C" void app_main(void) register_server_tflite_uri(server); register_server_file_uri(server, "/sdcard"); register_server_ota_sdcard_uri(server); - register_server_GPIO_uri(server); register_server_main_uri(server, "/sdcard"); TFliteDoAutoStart(); diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index c71e6e2c..37802ebf 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -15,6 +15,9 @@ #include "server_tflite.h" +//#define DEBUG_DETAIL_ON + + httpd_handle_t server = NULL; @@ -24,7 +27,9 @@ std::string starttime = ""; /* An HTTP GET handler */ esp_err_t info_get_handler(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("info_get_handler - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("info_get_handler - Start"); +#endif LogFile.WriteToFile("info_get_handler"); char _query[200]; @@ -126,26 +131,35 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (debug_detail_heap) LogFile.WriteHeapInfo("info_get_handler - Done"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("info_get_handler - Done"); +#endif return ESP_OK; } esp_err_t starttime_get_handler(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("starttime_get_handler - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("starttime_get_handler - Start"); +#endif + httpd_resp_send(req, starttime.c_str(), strlen(starttime.c_str())); /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); - if (debug_detail_heap) LogFile.WriteHeapInfo("starttime_get_handler - Done"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("starttime_get_handler - Done"); +#endif return ESP_OK; } esp_err_t hello_main_handler(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("hello_main_handler - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("hello_main_handler - Start"); +#endif char filepath[50]; printf("uri: %s\n", req->uri); @@ -197,7 +211,9 @@ esp_err_t hello_main_handler(httpd_req_t *req) /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); - if (debug_detail_heap) LogFile.WriteHeapInfo("hello_main_handler - Stop"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("hello_main_handler - Stop"); +#endif return ESP_OK; } @@ -228,7 +244,10 @@ esp_err_t img_tmp_handler(httpd_req_t *req) esp_err_t img_tmp_virtual_handler(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("img_tmp_virtual_handler - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("img_tmp_virtual_handler - Start"); +#endif + char filepath[50]; printf("uri: %s\n", req->uri); @@ -254,7 +273,9 @@ esp_err_t img_tmp_virtual_handler(httpd_req_t *req) return ESP_OK; // File wird nicht intern bereit gestellt --> klassischer weg: - if (debug_detail_heap) LogFile.WriteHeapInfo("img_tmp_virtual_handler - Done"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("img_tmp_virtual_handler - Done"); +#endif return img_tmp_handler(req); } @@ -265,7 +286,9 @@ esp_err_t img_tmp_virtual_handler(httpd_req_t *req) esp_err_t sysinfo_handler(httpd_req_t *req) { - if (debug_detail_heap) LogFile.WriteHeapInfo("sysinfo_handler - Start"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("sysinfo_handler - Start"); +#endif const char* resp_str; std::string zw; @@ -302,7 +325,9 @@ esp_err_t sysinfo_handler(httpd_req_t *req) /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); - if (debug_detail_heap) LogFile.WriteHeapInfo("sysinfo_handler - Done"); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("sysinfo_handler - Done"); +#endif return ESP_OK; } diff --git a/code/main/server_main.h b/code/main/server_main.h index bab0665e..e4f75b4c 100644 --- a/code/main/server_main.h +++ b/code/main/server_main.h @@ -22,7 +22,4 @@ httpd_handle_t start_webserver(void); void register_server_main_uri(httpd_handle_t server, const char *base_path); -extern bool debug_detail_heap; - - #endif diff --git a/code/main/version.cpp b/code/main/version.cpp index 0e7f121c..16d381a8 100644 --- a/code/main/version.cpp +++ b/code/main/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="ae11698"; +const char* GIT_REV="9c8f64f"; const char* GIT_TAG=""; -const char* GIT_BRANCH="rolling"; -const char* BUILD_TIME="2020-12-31 11:13"; \ No newline at end of file +const char* GIT_BRANCH="rolling-update-cimage"; +const char* BUILD_TIME="2021-01-01 09:32"; \ No newline at end of file diff --git a/code/version.cpp b/code/version.cpp index 0e7f121c..16d381a8 100644 --- a/code/version.cpp +++ b/code/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="ae11698"; +const char* GIT_REV="9c8f64f"; const char* GIT_TAG=""; -const char* GIT_BRANCH="rolling"; -const char* BUILD_TIME="2020-12-31 11:13"; \ No newline at end of file +const char* GIT_BRANCH="rolling-update-cimage"; +const char* BUILD_TIME="2021-01-01 09:32"; \ No newline at end of file diff --git a/firmware/bootloader.bin b/firmware/bootloader.bin index 31ac746a..078426e6 100644 Binary files a/firmware/bootloader.bin and b/firmware/bootloader.bin differ diff --git a/firmware/firmware.bin b/firmware/firmware.bin index d8b6396f..d7a46520 100644 Binary files a/firmware/firmware.bin and b/firmware/firmware.bin differ