diff --git a/.github/label-commenter-config.yaml b/.github/label-commenter-config.yaml index e2d08f5ad..e8bb86d69 100644 --- a/.github/label-commenter-config.yaml +++ b/.github/label-commenter-config.yaml @@ -115,9 +115,9 @@ labeled: issue: body: | - See [Digital Digits](https://jomjol.github.io/neural-network-digital-counter-readout) resp. [Analogue Pointers](https://jomjol.github.io/neural-network-analog-needle-readout) for an overview of all trained data. + See [Digits](https://jomjol.github.io/neural-network-digital-counter-readout) resp. [Analogue Pointers](https://jomjol.github.io/neural-network-analog-needle-readout) for an overview of all trained data. If your type is not contained it can be added to our training material, see [here](https://jomjol.github.io/AI-on-the-edge-device-docs/collect-new-images/). discussion: body: | - See [Digital Digits](https://jomjol.github.io/neural-network-digital-counter-readout) resp. [Analogue Pointers](https://jomjol.github.io/neural-network-analog-needle-readout) for an overview of all trained data. + See [Digits](https://jomjol.github.io/neural-network-digital-counter-readout) resp. [Analogue Pointers](https://jomjol.github.io/neural-network-analog-needle-readout) for an overview of all trained data. If your type is not contained it can be added to our training material, see [here](https://jomjol.github.io/AI-on-the-edge-device-docs/collect-new-images/). diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 00f39750f..5192cdef2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,7 +14,7 @@ jobs: uses: fkirc/skip-duplicate-actions@v5 with: concurrent_skipping: same_content_newer - + - uses: actions/checkout@v4 with: submodules: recursive @@ -37,14 +37,14 @@ jobs: path: ~/.platformio key: platformio-${{ github.run_id }} restore-keys: platformio # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache - + - name: Update Build cache on every commit uses: actions/cache@v4 with: path: ./code/.pio/ key: build-${{ github.run_id }} restore-keys: build # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache - + - name: Update generated-files cache on every commit uses: actions/cache@v4 with: @@ -86,7 +86,7 @@ jobs: echo "Replacing variables..." cd html; find . -type f -exec sed -i 's/$COMMIT_HASH/${{ steps.vars.outputs.sha_short }}/g' {} \; - + ######################################################################################### ## Pack for Update @@ -120,7 +120,7 @@ jobs: path: update key: update-${{ github.run_id }} restore-keys: update # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache - + - name: Set Variables id: vars run: | @@ -150,7 +150,6 @@ jobs: path: ./update/* - ######################################################################################### ## Pack for Remote Setup ######################################################################################### @@ -176,7 +175,7 @@ jobs: ./html/* key: generated-files-${{ github.run_id }} restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache - + - name: Update remote_setup cache on every commit uses: actions/cache@v4 with: @@ -261,7 +260,7 @@ jobs: cp -r ./html ./sd-card/ # Overwrite the Web UI with the preprocessed files cd sd-card; zip -r ../manual_setup/sd-card.zip *; cd .. cd ./manual_setup - + - name: Upload manual_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI) uses: actions/upload-artifact@v4 with: @@ -285,21 +284,21 @@ jobs: steps: - uses: actions/checkout@v4 - + - name: Update update cache on every commit uses: actions/cache@v4 with: path: update key: update-${{ github.run_id }} restore-keys: update # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache - + - name: Update remote_setup cache on every commit uses: actions/cache@v4 with: path: remote_setup key: remote_setup-${{ github.run_id }} restore-keys: remote_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache - + - name: Update manual_setup cache on every commit uses: actions/cache@v4 with: @@ -342,7 +341,7 @@ jobs: # with: # changelogPath: Changelog.md # version: ${{ steps.get_version.outputs.version-without-v }} - + # # the release notes will be extracted from changelog # - name: Extract release notes # id: extract-release-notes @@ -397,7 +396,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + - name: Get version of last release id: last_release uses: mindojo/get-latest-release@0b8ef1434d7468d6bffcc8263baff5c777f72321 @@ -405,7 +404,7 @@ jobs: myToken: ${{ github.token }} exclude_types: "draft|prerelease" view_top: 1 - + - name: Add binary to Web Installer and update manifest run: | echo "Updating Web installer to use firmware from ${{ steps.last_release.outputs.tag_name }}..." diff --git a/.github/workflows/manual-update-webinstaller.yaml b/.github/workflows/manual-update-webinstaller.yaml index c421c9513..2dde67515 100644 --- a/.github/workflows/manual-update-webinstaller.yaml +++ b/.github/workflows/manual-update-webinstaller.yaml @@ -12,7 +12,7 @@ on: # - rolling # paths: # - docs # The path filter somehow does not work, so lets run it on every change to rolling - + jobs: manually-update-web-installer: environment: @@ -29,7 +29,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - + - name: Get version of last release id: last_release uses: mindojo/get-latest-release@0b8ef1434d7468d6bffcc8263baff5c777f72321 @@ -37,7 +37,7 @@ jobs: myToken: ${{ github.token }} exclude_types: "draft|prerelease" view_top: 1 - + - name: Add binary to Web Installer and update manifest run: | echo "Updating Web installer to use firmware from ${{ steps.last_release.outputs.tag_name }}..." @@ -60,4 +60,3 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v1 - diff --git a/.github/workflows/reply-bot.yaml b/.github/workflows/reply-bot.yaml index 7c7bb9c5d..692191ef6 100644 --- a/.github/workflows/reply-bot.yaml +++ b/.github/workflows/reply-bot.yaml @@ -20,9 +20,8 @@ jobs: comment: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - + - uses: actions/checkout@v4 + #################################################################### ## Remove labels again (issues only) ## Make sure to also add the reply message to .github/label-commenter-config.yaml! @@ -69,12 +68,12 @@ jobs: # with: # actions: 'remove-labels' # labels: 'bot-reply Show Trained Digits/Pointers' - + #################################################################### ## Write the response #################################################################### - name: Write Response - uses: peaceiris/actions-label-commenter@v1 + uses: peaceiris/actions-label-commenter@c2d00660c86f2b9ed0fb35b372c451558eba85b3 with: github_token: "${{ secrets.GITHUB_TOKEN }}" config_file: .github/label-commenter-config.yaml diff --git a/Changelog.md b/Changelog.md index a42dabb04..3fbb4c640 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,32 @@ +## [16.0.0-RC1] - 2024-09-24 + +For a full list of changes see [Full list of changes](https://github.com/jomjol/AI-on-the-edge-device/compare/v15.7.0...v16.0.0-RC1) + +#### Known issues +Please check the [issues](https://github.com/jomjol/AI-on-the-edge-device/issues) and +[discussions](https://github.com/jomjol/AI-on-the-edge-device/discussions) before reporting a new issue. + +#### Core Changes +Those are just the major changes: +- Add support for OV5640 camera (#3063) +- New tflite-Models +- Homeassistant service discovery: derive node_id when using nested topics (#3088) +- Added Prometheus/OpenMetrics exporter (#3081) +- Added Webhook (#3148, #3163, #3174) +- Add rate threshold parameter (#3195) +- Added a Delay between the WiFi reconnections (#3068) +- Web UI improvements +- Various minor changes +- Update platformIO to 6.9.0 (Contains ESP IDF 5.3.1) + +#### Bug Fixes +Those are just the major changes: +- Handle crash on corrupted model (#3220) +- Bugfix for boot loop (#3175) +- Bugfix for time stamp (#3180) +- Handle empty prevalue.ini gracefully (#3162) +- Added note about only TLS 1.2 is supported (#3213) + ## [15.7.0] - 2024-02-17 For a full list of changes see [Full list of changes](https://github.com/jomjol/AI-on-the-edge-device/compare/v15.6.0...v15.7.0) @@ -10,7 +39,7 @@ For a full list of changes see [Full list of changes](https://github.com/jomjol/ - Add Firmware Version to MQTT #### Bug Fixes -- Reverted "Implemented late analog / digital transition [#2778](https://github.com/jomjol/AI-on-the-edge-device/pull/2778) (introduced in `v15.5`) as is seems to cause issues for many users. +- Reverted "Implemented late analog / digit transition [#2778](https://github.com/jomjol/AI-on-the-edge-device/pull/2778) (introduced in `v15.5`) as is seems to cause issues for many users. ## [15.6.0] - 2024-02-09 @@ -29,7 +58,7 @@ For a full list of changes see [Full list of changes](https://github.com/jomjol/ - Update PlattformIO to v6.5.0, which means esp-idf to v5.1 - Enhance busy notification - - Implemented late analog / digital transition + - Implemented late analog / digit transition #### Fixed @@ -189,7 +218,7 @@ For a full list of changes see [Full list of changes](https://github.com/jomjol/ :bangbang: **Attention:** Update your configuration! - Hybrid CNN network to `dig-cont_0611_s3` - Analog CNN network to `ana-cont-11.0.5` and `ana-clas100-1.5.7` - - Digital CNN network to `dig-class100-1.6.0` + - Digit CNN network to `dig-class100-1.6.0` - Various Web interface Improvements/Enhancements: - Restructured Menu (Needs cache clearing to be applied) - Enhanced `Previous Value` page @@ -325,7 +354,7 @@ For a full list of changes see [Full list of changes](https://github.com/jomjol/ - Improved OTA Update mechanism (only working after installation for next update) - Added data logging in `/log/data` - One day per file and each measurement is on one line - Format: csv - comma separated - - Content: `time`, `name-of-number`, `raw-value`, `return-value`, `pre-value`, `change-rate`, `change-absolute`, `error-text`, `cnn-digital`, `cnn-analog` + - Content: `time`, `name-of-number`, `raw-value`, `return-value`, `pre-value`, `change-rate`, `change-absolute`, `error-text`, `cnn-digit`, `cnn-analog` - Show graph of values direct in the user interface (thanks to [@rdmueller](https://github.com/rdmueller)) - Using new data logging (see above) @@ -343,10 +372,10 @@ For a full list of changes see [Full list of changes](https://github.com/jomjol/ - Updated OTA functionality (more robust, but not fully bullet prove yet) - Updated Espressif library to `espressif32@v5.2.0` - [#1176](https://github.com/jomjol/AI-on-the-edge-device/discussions/1176) accept minor negative values (-0.2) if extended resolution is enabled -- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) added config parameter `AnalogDigitalTransitionStart`. It can setup very early and very late digit transition starts. +- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) added config parameter `AnalogDigTransitionStart`. It can setup very early and very late digit transition starts. - New version of `dig-class100` (v1.4.0): added images of heliowatt powermeter - NEW v13.0.2: Update Tool "Logfile downloader and combiner" to handle the new csv file format. -- NEW v13.0.2: MQTT: Added MQTT topic `status` (Digitalization Status), Timezone to MQTT topic `timestamp`.# +- NEW v13.0.2: MQTT: Added MQTT topic `status` (Digitization Status), Timezone to MQTT topic `timestamp`.# - NEW v13.0.2: Logging: Disable heap logs by default, cleanup - NEW v13.0.7: - log NTP server name @@ -471,7 +500,7 @@ Intermediate Digits - Updated analog neural network file (`ana-cont_11.3.0_s2.tflite` - default, `ana-class100_0120_s1_q.tflite`) -- Updated digital neural network file (`dig-cont_0570_s3.tflite` - default, `dig-class100_0120_s2_q.tflite`) +- Updated digit neural network file (`dig-cont_0570_s3.tflite` - default, `dig-class100_0120_s2_q.tflite`) - Added automated filtering of tflite-file in the graphical configuration (thanks to @**[caco3](https://github.com/caco3)**) @@ -483,8 +512,8 @@ Intermediate Digits Intermediate Digits -- New and improved consistency check (especially with analog and digital counters mixed) -- Bug Fix: digital counter algorithm +- New and improved consistency check (especially with analog and digit counters mixed) +- Bug Fix: digit counter algorithm ## [11.0.1](https://github.com/jomjol/AI-on-the-edge-device/releases/tag/v11.0.1), 2022-08-18 @@ -524,7 +553,7 @@ Stability Increase - `config.ini`: removal of modelsize (readout from tflite) -- Updated analog neural network file (`ana1000s2.tflite`) & digital neural network file (`dig1400s2q.tflite`) +- Updated analog neural network file (`ana1000s2.tflite`) & digit neural network file (`dig1400s2q.tflite`) - TFMicro/Lite: Update (espressif Version 20220716) @@ -560,7 +589,7 @@ Stability Increase - In the future the new files will also be copied to the `firmware` directory of the repository - Added Wifi RSSI to MQTT information - Updated analog neural network file (`ana-s3-q-20220105.tflite`) -- Updated digital neural network file (`dig-s1-q-20220102.tflite`) +- Updated digit neural network file (`dig-s1-q-20220102.tflite`) - Updated build environment to `Espressif 3.5.0` ## [10.3.0] - (2022-01-29) @@ -626,7 +655,7 @@ Stability Increase - Update analog neural network (ana-s3-q-20220105.tflite) -- Update digital neural network (dig-s1-q-20220102.tflite) +- Update digit neural network (dig-s1-q-20220102.tflite) - Increased web-server buffers @@ -663,7 +692,7 @@ External Illumination - Direct JSON access: `http://IP-ADRESS/json` - Error message in log file in case camera error during startup - Upgrade analog CNN to v9.1.0 -- Upgrade digital CNN to v13.3.0 (added new images) +- Upgrade digit CNN to v13.3.0 (added new images) - html: support of different ports ## [9.1.1] - External Illumination (2021-11-16) @@ -688,7 +717,7 @@ External Illumination ### Changed -- Upgrade digital CNN to v13.1.0 (added new images) +- Upgrade digit CNN to v13.1.0 (added new images) - bug fix: wlan password with space, double digit output ## [8.4.0] - Multi Meter Support (2021-09-25) @@ -718,7 +747,7 @@ External Illumination ### Changed -- Upgrade digital CNN to v12.1.0 (added new images) +- Upgrade digit CNN to v12.1.0 (added new images) - Dedicated NaN handling, internal refactoring (CNN-Handling) - HTML: confirmation after config.ini update - Bug fixing @@ -740,7 +769,7 @@ External Illumination - GPIO: using the general mqtt main topic for GPIO -- Upgrade digital CNN to v12.0.0 (added new images) +- Upgrade digit CNN to v12.0.0 (added new images) - Update tfmicro to new master (2021-08-07) - Bug fix: remove text in mqtt value, remove connect limit in wlan reconnet @@ -776,7 +805,7 @@ External Illumination - Update wlan handling to esp-idf 4.1 -- Upgrade digital CNN to v8.7.0 (added new images) +- Upgrade digit CNN to v8.7.0 (added new images) - Bug fix: MQTT, WLAN, LED-Controll, GPIO usage, fixed IP, calculation flow rate @@ -787,7 +816,7 @@ External Illumination - NEW: 7.0.1: bug fix wlan password with "=" -- Upgrade digital CNN to v8.5.0 (added new images) +- Upgrade digit CNN to v8.5.0 (added new images) - New MQTT topics: flow rate (units/minute), time stamp (last correct read readout) @@ -804,7 +833,7 @@ External Illumination - NEW 6.7.1: Improved stability of camera (back to v6.6.1) - remove black strips and areas -- Upgrade digital CNN to v8.3.0 (added new type of digits) +- Upgrade digit CNN to v8.3.0 (added new type of digits) - Internal update: TFlite (v2.5), esp32cam, startup sequence @@ -825,7 +854,7 @@ External Illumination ### Changed -- Upgrade digital CNN to v8.2.0 (added new type of digits) +- Upgrade digit CNN to v8.2.0 (added new type of digits) - Supporting alignment structures in ROI definition @@ -861,7 +890,7 @@ External Illumination - Determination of fixed illumination settings during startup - speed up of 5s in each run -- Update digital CNN to v8.1.1 (additional digital images trained) +- Update digit CNN to v8.1.1 (additional digit images trained) - Extended error message in MQTT error message @@ -873,7 +902,7 @@ External Illumination ### Changed -- Disabling of analog / digital counters in configuration +- Disabling of analog / digit counters in configuration - Improved Alignment Algorithm (`AlignmentAlgo` = `Default`, `Accurate` , `Fast`) @@ -893,7 +922,7 @@ External Illumination - MQTT: Last Will Testament (LWT) implemented: "connection lost" in case of connection lost to `TopicError` - Disabled `CheckDigitIncreaseConsistency` in default configuration - must now be explicit enabled if needed -- Update digital CNN to v7.2.1 (additional digital images trained) +- Update digit CNN to v7.2.1 (additional digit images trained) - Setting of arbitrary time server in `config.ini` - Option for fixed IP-, DNS-Settings in `wlan.ini` - Increased stability (internal image and camera handling) @@ -927,7 +956,7 @@ External Illumination - standardized access to current logfile via `http://IP-ADRESS/logfileact` -- Update digital CNN to v7.2.0, analog CNN to 6.3.0 +- Update digit CNN to v7.2.0, analog CNN to 6.3.0 - Bug fixing: truncation error, CheckDigitConsistency & PreValue implementation @@ -946,7 +975,7 @@ External Illumination ### Changed -- Update digital CNN to v6.5.0 and HTML (Info to hostname, IP, ssid) +- Update digit CNN to v6.5.0 and HTML (Info to hostname, IP, ssid) - New implementation of "checkDigitConsistency" also for digits diff --git a/code/components/esp-tflite-micro b/code/components/esp-tflite-micro index 13f26b829..0032f1734 160000 --- a/code/components/esp-tflite-micro +++ b/code/components/esp-tflite-micro @@ -1 +1 @@ -Subproject commit 13f26b829405e9323e4212ffa954c261b1e21eeb +Subproject commit 0032f1734e1e7b5fcf1b588cf1abb9ef53fed4c3 diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 33b00bc8b..bd830ed92 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -41,24 +41,34 @@ #include "soc/io_mux_reg.h" #include "esp_rom_gpio.h" #define gpio_pad_select_gpio esp_rom_gpio_pad_select_gpio -#define gpio_matrix_in(a,b,c) esp_rom_gpio_connect_in_signal(a,b,c) -#define gpio_matrix_out(a,b,c,d) esp_rom_gpio_connect_out_signal(a,b,c,d) +#define gpio_matrix_in(a, b, c) esp_rom_gpio_connect_in_signal(a, b, c) +#define gpio_matrix_out(a, b, c, d) esp_rom_gpio_connect_out_signal(a, b, c, d) #define ets_delay_us(a) esp_rom_delay_us(a) #endif -static const char *TAG = "CAM"; +CCamera Camera; +camera_controll_config_temp_t CCstatus; +static const char *TAG = "CAM"; /* Camera live stream */ #define PART_BOUNDARY "123456789000000000000987654321" -static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY; -static const char* _STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n"; -static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n"; +static const char *_STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY; +static const char *_STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n"; +static const char *_STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n"; -// OV2640 Camera SDE Indirect Register Access -#define OV2640_IRA_BPADDR 0x7C -#define OV2640_IRA_BPDATA 0x7D +uint8_t *demoImage = NULL; // Buffer holding the demo image in bytes +#define DEMO_IMAGE_SIZE 30000 // Max size of demo image in bytes +// Camera module bus communications frequency. +// Originally: config.xclk_freq_mhz = 20000000, but this lead to visual artifacts on many modules. +// See https://github.com/espressif/esp32-camera/issues/150#issuecomment-726473652 et al. +#if !defined(XCLK_FREQ_MHZ) +// int xclk = 8; +int xclk = 20; // Orginal value +#else +int xclk = XCLK_FREQ_MHZ; +#endif static camera_config_t camera_config = { .pin_pwdn = CAM_PIN_PWDN, @@ -79,387 +89,540 @@ static camera_config_t camera_config = { .pin_href = CAM_PIN_HREF, .pin_pclk = CAM_PIN_PCLK, - //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental) - .xclk_freq_hz = 20000000, // Orginal value -// .xclk_freq_hz = 5000000, // Test to get rid of the image errors !!!! Hangs in version 9.2 !!!! - .ledc_timer = LEDC_TIMER_0, - .ledc_channel = LEDC_CHANNEL_0, - - .pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG - .frame_size = FRAMESIZE_VGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG -// .frame_size = FRAMESIZE_UXGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG - .jpeg_quality = 12, //0-63 lower number means higher quality - .fb_count = 1, //if more than one, i2s runs in continuous mode. Use only with JPEG + .xclk_freq_hz = (xclk * 1000000), + .ledc_timer = LEDC_TIMER_0, // LEDC timer to be used for generating XCLK + .ledc_channel = LEDC_CHANNEL_0, // LEDC channel to be used for generating XCLK + + .pixel_format = PIXFORMAT_JPEG, // YUV422,GRAYSCALE,RGB565,JPEG + .frame_size = FRAMESIZE_VGA, // QQVGA-UXGA Do not use sizes above QVGA when not JPEG + // .frame_size = FRAMESIZE_UXGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG + .jpeg_quality = 6, // 0-63 lower number means higher quality + .fb_count = 1, // if more than one, i2s runs in continuous mode. Use only with JPEG .fb_location = CAMERA_FB_IN_PSRAM, /*!< The location where the frame buffer will be allocated */ - .grab_mode = CAMERA_GRAB_LATEST, // only from new esp32cam version + .grab_mode = CAMERA_GRAB_LATEST, // only from new esp32cam version }; +typedef struct +{ + httpd_req_t *req; + size_t len; +} jpg_chunking_t; -CCamera Camera; +CCamera::CCamera(void) +{ +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "CreateClassCamera"); +#endif + CCstatus.WaitBeforePicture = 2; -uint8_t *demoImage = NULL; // Buffer holding the demo image in bytes + ledc_init(); +} -#define DEMO_IMAGE_SIZE 30000 // Max size of demo image in bytes +esp_err_t CCamera::InitCam(void) +{ + ESP_LOGD(TAG, "Init Camera"); -typedef struct { - httpd_req_t *req; - size_t len; -} jpg_chunking_t; + CCstatus.ImageQuality = camera_config.jpeg_quality; + CCstatus.ImageFrameSize = camera_config.frame_size; + + // initialize the camera + esp_camera_deinit(); // De-init in case it was already initialized + esp_err_t err = esp_camera_init(&camera_config); + + if (err != ESP_OK) + { + ESP_LOGE(TAG, "Camera Init Failed"); + return err; + } + CCstatus.CameraInitSuccessful = true; -bool CCamera::testCamera(void) { + // Get a reference to the sensor + sensor_t *s = esp_camera_sensor_get(); + + if (s != NULL) + { + CCstatus.CamSensor_id = s->id.PID; + + // Dump camera module, warn for unsupported modules. + switch (CCstatus.CamSensor_id) + { + case OV2640_PID: + ESP_LOGI(TAG, "OV2640 camera module detected"); + break; + case OV3660_PID: + ESP_LOGI(TAG, "OV3660 camera module detected"); + break; + case OV5640_PID: + ESP_LOGI(TAG, "OV5640 camera module detected"); + break; + default: + ESP_LOGE(TAG, "Camera module is unknown and not properly supported!"); + CCstatus.CameraInitSuccessful = false; + } + } + + if (CCstatus.CameraInitSuccessful) + { + return ESP_OK; + } + else + { + return ESP_FAIL; + } +} + +bool CCamera::testCamera(void) +{ bool success; camera_fb_t *fb = esp_camera_fb_get(); - if (fb) { + + if (fb) + { success = true; } - else { + else + { success = false; } - + esp_camera_fb_return(fb); + return success; } - void CCamera::ledc_init(void) { #ifdef USE_PWM_LEDFLASH - // Prepare and then apply the LEDC PWM timer configuration - ledc_timer_config_t ledc_timer = { }; + ledc_timer_config_t ledc_timer = {}; - ledc_timer.speed_mode = LEDC_MODE; - ledc_timer.timer_num = LEDC_TIMER; - ledc_timer.duty_resolution = LEDC_DUTY_RES; - ledc_timer.freq_hz = LEDC_FREQUENCY; // Set output frequency at 5 kHz - ledc_timer.clk_cfg = LEDC_AUTO_CLK; + ledc_timer.speed_mode = LEDC_MODE; + ledc_timer.timer_num = LEDC_TIMER; + ledc_timer.duty_resolution = LEDC_DUTY_RES; + ledc_timer.freq_hz = LEDC_FREQUENCY; // Set output frequency at 5 kHz + ledc_timer.clk_cfg = LEDC_AUTO_CLK; ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); // Prepare and then apply the LEDC PWM channel configuration - ledc_channel_config_t ledc_channel = { }; + ledc_channel_config_t ledc_channel = {}; - ledc_channel.speed_mode = LEDC_MODE; - ledc_channel.channel = LEDC_CHANNEL; - ledc_channel.timer_sel = LEDC_TIMER; - ledc_channel.intr_type = LEDC_INTR_DISABLE; - ledc_channel.gpio_num = LEDC_OUTPUT_IO; - ledc_channel.duty = 0; // Set duty to 0% - ledc_channel.hpoint = 0; + ledc_channel.speed_mode = LEDC_MODE; + ledc_channel.channel = LEDC_CHANNEL; + ledc_channel.timer_sel = LEDC_TIMER; + ledc_channel.intr_type = LEDC_INTR_DISABLE; + ledc_channel.gpio_num = LEDC_OUTPUT_IO; + ledc_channel.duty = 0; // Set duty to 0% + ledc_channel.hpoint = 0; + // ledc_channel.flags.output_invert = LEDC_OUTPUT_INVERT; ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel)); - #endif } +void CCamera::SetLEDIntensity(float _intrel) +{ + _intrel = min(_intrel, (float)100); + _intrel = max(_intrel, (float)0); + _intrel = _intrel / 100; + CCstatus.ImageLedIntensity = (int)(_intrel * 8191); + ESP_LOGD(TAG, "Set led_intensity to %d of 8191", CCstatus.ImageLedIntensity); +} -static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size_t len) +bool CCamera::getCameraInitSuccessful(void) { - jpg_chunking_t *j = (jpg_chunking_t *)arg; + return CCstatus.CameraInitSuccessful; +} - if(!index) { - j->len = 0; - } +esp_err_t CCamera::setSensorDatenFromCCstatus(void) +{ + sensor_t *s = esp_camera_sensor_get(); - if(httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK) { - return 0; - } + if (s != NULL) + { + s->set_framesize(s, CCstatus.ImageFrameSize); + s->set_quality(s, CCstatus.ImageQuality); // 0 - 63 - j->len += len; + s->set_brightness(s, CCstatus.ImageBrightness); // -2 to 2 + s->set_contrast(s, CCstatus.ImageContrast); // -2 to 2 + s->set_saturation(s, CCstatus.ImageSaturation); // -2 to 2 + // s->set_sharpness(s, CCstatus.ImageSharpness); // auto-sharpness is not officially supported, default to 0 + SetCamSharpness(CCstatus.ImageAutoSharpness, CCstatus.ImageSharpness); - return len; -} + s->set_denoise(s, CCstatus.ImageDenoiseLevel); // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) + s->set_special_effect(s, CCstatus.ImageSpecialEffect); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia) + s->set_wb_mode(s, CCstatus.ImageWbMode); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) -bool CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation, int _autoExposureLevel, bool _grayscale, bool _negative, bool _aec2, int _sharpnessLevel) -{ - _brightness = min(2, max(-2, _brightness)); - _contrast = min(2, max(-2, _contrast)); - _saturation = min(2, max(-2, _saturation)); - _autoExposureLevel = min(2, max(-2, _autoExposureLevel)); - bool _autoSharpness = false; - if (_sharpnessLevel <= -4) - _autoSharpness = true; - _sharpnessLevel = min(3, max(-3, _sharpnessLevel)); - - sensor_t * s = esp_camera_sensor_get(); - if (s) { - // camera gives precedence to negative over grayscale, so it's easier to do negative ourselves. - // if (_negative) { - // s->set_special_effect(s, 1); // 0 - no effect, 1 - negative, 2 - grayscale, 3 - reddish, 4 - greenish, 5 - blue, 6 - retro - // } - if (_grayscale) { - s->set_special_effect(s, 2); // 0 - no effect, 1 - negative, 2 - grayscale, 3 - reddish, 4 - greenish, 5 - blue, 6 - retro - } + s->set_ae_level(s, CCstatus.ImageAeLevel); // -2 to 2 + s->set_aec_value(s, CCstatus.ImageAecValue); // 0 to 1200 + s->set_agc_gain(s, CCstatus.ImageAgcGain); // 0 to 30 - // auto exposure controls - s->set_aec2(s, _aec2 ? 1 : 0); - s->set_ae_level(s, _autoExposureLevel); // -2 to 2 - s->set_gainceiling(s, GAINCEILING_2X); // GAINCEILING_2X 4X 8X 16X 32X 64X 128X + // s->set_gainceiling(s, CCstatus.ImageGainceiling); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) + ov5640_set_gainceiling(s, CCstatus.ImageGainceiling); - // post processing - if (_autoSharpness) { - s->set_sharpness(s, 0); // auto-sharpness is not officially supported, default to 0 - } - s->set_saturation(s, _saturation); - s->set_contrast(s, _contrast); - s->set_brightness(s, _brightness); - - camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&(s->id)); - if (sensor_info != NULL) { - if (sensor_info->model == CAMERA_OV2640) { - if (_autoSharpness) { - ov2640_enable_auto_sharpness(s); - } else { - ov2640_set_sharpness(s, _sharpnessLevel); - } + s->set_lenc(s, CCstatus.ImageLenc); // 0 = disable , 1 = enable + s->set_gain_ctrl(s, CCstatus.ImageAgc); // 0 = disable , 1 = enable + s->set_exposure_ctrl(s, CCstatus.ImageAec); // 0 = disable , 1 = enable - /* Workaround - bug in cam library - enable bits are set without using bitwise OR logic -> only latest enable setting is used */ - /* Library version: https://github.com/espressif/esp32-camera/commit/5c8349f4cf169c8a61283e0da9b8cff10994d3f3 */ - /* Reference: https://esp32.com/viewtopic.php?f=19&t=14376#p93178 */ - /* The memory structure is as follows for - byte_0 = enable_bits - byte_0->bit0 = enable saturation and hue --> OK - byte_0->bit1 = enable saturation --> OK - byte_0->bit2 = enable brightness and contrast --> OK - byte_0->bit3 = enable green -> blue spitial effect (Antique and blunish and greenish and readdish and b&w) enable - byte_0->bit4 = anable gray -> read spitial effect (Antique and blunish and greenish and readdish and b&w) enable - byte_0->bit5 = remove (UV) in YUV color system - byte_0->bit6 = enable negative - byte_0->bit7 = remove (Y) in YUV color system - byte_1 = saturation1 0-255 --> ? - byte_2 = hue 0-255 --> OK - byte_3 = saturation2 0-255 --> OK - byte_4 = reenter saturation2 in documents --> ? - byte_5 = spital effect green -> blue 0-255 --> ? - byte_6 = spital effect gray -> read 0-255 --> ? - byte_7 = contrast lower byte 0-255 --> OK - byte_8 = contrast higher byte 0-255 --> OK - byte_9 = brightness 0-255 --> OK - byte_10= if byte_10==4 contrast effective --> ? - */ - - //s->set_reg(s, 0x7C, 0xFF, 2); // Optional feature - hue setting: Select byte 2 in register 0x7C to set hue value - //s->set_reg(s, 0x7D, 0xFF, 0); // Optional feature - hue setting: Hue value 0 - 255 - int indirectReg0 = 0x07; // Set bit 0, 1, 2 to enable saturation, contrast, brightness and hue control - if (_grayscale) { - indirectReg0 |= 0x18; - } - // camera gives precedence to negative over grayscale, so it's easier to do negative ourselves. - // if (_negative) { - // indirectReg0 |= 0x40; - // } - // Indirect register access - s->set_reg(s, 0xFF, 0x01, 0); // Select DSP bank - s->set_reg(s, OV2640_IRA_BPADDR, 0xFF, 0x00); // Address 0x00 - s->set_reg(s, OV2640_IRA_BPDATA, 0xFF, indirectReg0); - s->set_reg(s, OV2640_IRA_BPADDR, 0xFF, 0x05); // Address 0x05 - s->set_reg(s, OV2640_IRA_BPDATA, 0xFF, 0x80); - s->set_reg(s, OV2640_IRA_BPDATA, 0xFF, 0x80); - } - } - } - else { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SetBrightnessContrastSaturation: Failed to get control structure"); - } + s->set_hmirror(s, CCstatus.ImageHmirror); // 0 = disable , 1 = enable + s->set_vflip(s, CCstatus.ImageVflip); // 0 = disable , 1 = enable + s->set_aec2(s, CCstatus.ImageAec2); // 0 = disable , 1 = enable - if (((_brightness != brightness) || (_contrast != contrast) || (_saturation != saturation)) && isFixedExposure) - EnableAutoExposure(waitbeforepicture_org); + s->set_bpc(s, CCstatus.ImageBpc); // 0 = disable , 1 = enable + s->set_wpc(s, CCstatus.ImageWpc); // 0 = disable , 1 = enable - brightness = _brightness; - contrast = _contrast; - saturation = _saturation; - autoExposureLevel = _autoExposureLevel; - imageGrayscale = _grayscale; - imageNegative = _negative; - imageAec2 = _aec2; - imageAutoSharpness = _autoSharpness; - imageSharpnessLevel = _sharpnessLevel; + s->set_raw_gma(s, CCstatus.ImageRawGma); // 0 = disable , 1 = enable - ESP_LOGD(TAG, "brightness %d, contrast: %d, saturation %d, autoExposureLevel %d, grayscale %d", brightness, contrast, saturation, autoExposureLevel, (int)imageGrayscale); + s->set_awb_gain(s, CCstatus.ImageAwbGain); // 0 = disable , 1 = enable + s->set_whitebal(s, CCstatus.ImageAwb); // 0 = disable , 1 = enable - return true; -} + s->set_dcw(s, CCstatus.ImageDcw); // 0 = disable , 1 = enable + TickType_t xDelay2 = 100 / portTICK_PERIOD_MS; + vTaskDelay(xDelay2); -/* -* resolution = 0 \\ 1600 x 1200 -* resolution = 1 \\ 800 x 600 -* resolution = 2 \\ 400 x 296 -*/ -void CCamera::SetCamWindow(sensor_t *s, int resolution, int xOffset, int yOffset, int xLength, int yLength) -{ - s->set_res_raw(s, resolution, 0, 0, 0, xOffset, yOffset, xLength, yLength, xLength, yLength, false, false); + return ESP_OK; + } + else + { + return ESP_FAIL; + } } - -void CCamera::SetImageWidthHeightFromResolution(framesize_t resol) +esp_err_t CCamera::getSensorDatenToCCstatus(void) { - if (resol == FRAMESIZE_QVGA) + sensor_t *s = esp_camera_sensor_get(); + + if (s != NULL) { - image_height = 240; - image_width = 320; + CCstatus.CamSensor_id = s->id.PID; + + CCstatus.ImageFrameSize = (framesize_t)s->status.framesize; + CCstatus.ImageGainceiling = (gainceiling_t)s->status.gainceiling; + + CCstatus.ImageQuality = s->status.quality; + CCstatus.ImageBrightness = s->status.brightness; + CCstatus.ImageContrast = s->status.contrast; + CCstatus.ImageSaturation = s->status.saturation; + // CCstatus.ImageSharpness = s->status.sharpness; // gibt -1 zurück, da es nicht unterstützt wird + CCstatus.ImageWbMode = s->status.wb_mode; + CCstatus.ImageAwb = s->status.awb; + CCstatus.ImageAwbGain = s->status.awb_gain; + CCstatus.ImageAec = s->status.aec; + CCstatus.ImageAec2 = s->status.aec2; + CCstatus.ImageAeLevel = s->status.ae_level; + CCstatus.ImageAecValue = s->status.aec_value; + CCstatus.ImageAgc = s->status.agc; + CCstatus.ImageAgcGain = s->status.agc_gain; + CCstatus.ImageBpc = s->status.bpc; + CCstatus.ImageWpc = s->status.wpc; + CCstatus.ImageRawGma = s->status.raw_gma; + CCstatus.ImageLenc = s->status.lenc; + CCstatus.ImageSpecialEffect = s->status.special_effect; + CCstatus.ImageHmirror = s->status.hmirror; + CCstatus.ImageVflip = s->status.vflip; + CCstatus.ImageDcw = s->status.dcw; + CCstatus.ImageDenoiseLevel = s->status.denoise; + + return ESP_OK; } - else if (resol == FRAMESIZE_VGA) + else { - image_height = 480; - image_width = 640; + return ESP_FAIL; } - else if (resol == FRAMESIZE_SVGA) +} + +// on the OV5640, gainceiling must be set with the real value (x2>>>level = 2, .... x128>>>level = 128) +int CCamera::ov5640_set_gainceiling(sensor_t *s, gainceiling_t level) +{ + int ret = 0; + + if (CCstatus.CamSensor_id == OV2640_PID) { - image_height = 600; - image_width = 800; + ret = s->set_gainceiling(s, CCstatus.ImageGainceiling); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) } - else if (resol == FRAMESIZE_XGA) + else { - image_height = 768; - image_width = 1024; + int _level = (1 << ((int)level + 1)); + + ret = s->set_reg(s, 0x3A18, 0xFF, (_level >> 8) & 3) || s->set_reg(s, 0x3A19, 0xFF, _level & 0xFF); + + if (ret == 0) + { + // ESP_LOGD(TAG, "Set gainceiling to: %d", level); + s->status.gainceiling = level; + } } - else if (resol == FRAMESIZE_HD) + + return ret; +} + +// - It always zooms to the image center when offsets are zero +// - if imageSize = 0 then the image is not zoomed +// - if imageSize = max value, then the image is fully zoomed in +// - a zoom step is >>> Width + 32 px / Height + 24 px +void CCamera::SanitizeZoomParams(int imageSize, int frameSizeX, int frameSizeY, int &imageWidth, int &imageHeight, int &zoomOffsetX, int &zoomOffsetY) +{ + // for OV2640, This works only if the aspect ratio of 4:3 is preserved in the window size. + // use only values divisible by 8 without remainder + imageWidth = CCstatus.ImageWidth + (imageSize * 4 * 8); + imageHeight = CCstatus.ImageHeight + (imageSize * 3 * 8); + + int _maxX = frameSizeX - imageWidth; + int _maxY = frameSizeY - imageHeight; + + if ((abs(zoomOffsetX) * 2) > _maxX) { - image_height = 720; - image_width = 1280; + if (zoomOffsetX > 0) + { + zoomOffsetX = _maxX; + } + else + { + zoomOffsetX = 0; + } } - else if (resol == FRAMESIZE_SXGA) + else { - image_height = 1024; - image_width = 1280; + if (zoomOffsetX > 0) + { + zoomOffsetX = ((_maxX / 2) + zoomOffsetX); + } + else + { + zoomOffsetX = ((_maxX / 2) + zoomOffsetX); + } } - else if (resol == FRAMESIZE_UXGA) + + if ((abs(zoomOffsetY) * 2) > _maxY) { - image_height = 1200; - image_width = 1600; + if (zoomOffsetY > 0) + { + zoomOffsetY = _maxY; + } + else + { + zoomOffsetY = 0; + } + } + else + { + if (zoomOffsetY > 0) + { + zoomOffsetY = ((_maxY / 2) + zoomOffsetY); + } + else + { + zoomOffsetY = ((_maxY / 2) + zoomOffsetY); + } } } - -void CCamera::SetZoom(bool zoomEnabled, int zoomMode, int zoomOffsetX, int zoomOffsetY) +void CCamera::SetZoomSize(bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip) { - imageZoomEnabled = zoomEnabled; - imageZoomMode = zoomMode; - imageZoomOffsetX = zoomOffsetX; - imageZoomOffsetY = zoomOffsetY; - sensor_t *s = esp_camera_sensor_get(); - if (s) { - if (imageZoomEnabled) { - int z = imageZoomMode; - int x = imageZoomOffsetX; - int y = imageZoomOffsetY; - if (z > 1) - z = 1; - if (image_width >= 800 || image_height >= 600) { - z = 0; - } - int maxX = 1600 - image_width; - int maxY = 1200 - image_height; - if (z == 1) { - maxX = 800 - image_width; - maxY = 600 - image_height; + + if (s != NULL) + { + if (zoomEnabled) + { + int _imageSize_temp = 0; + int _imageWidth = CCstatus.ImageWidth; + int _imageHeight = CCstatus.ImageHeight; + int _offsetx = zoomOffsetX; + int _offsety = zoomOffsetY; + int frameSizeX; + int frameSizeY; + + switch (CCstatus.CamSensor_id) + { + case OV5640_PID: + frameSizeX = 2592; + frameSizeY = 1944; + // max imageSize = ((frameSizeX - CCstatus.ImageWidth) / 8 / 4) - 1 + // 59 = ((2560 - 640) / 8 / 4) - 1 + if (imageSize < 59) + { + _imageSize_temp = (59 - imageSize); + } + SanitizeZoomParams(_imageSize_temp, frameSizeX, frameSizeY, _imageWidth, _imageHeight, _offsetx, _offsety); + SetCamWindow(s, frameSizeX, frameSizeY, _offsetx, _offsety, _imageWidth, _imageHeight, CCstatus.ImageWidth, CCstatus.ImageHeight, imageVflip); + break; + + case OV3660_PID: + frameSizeX = 2048; + frameSizeY = 1536; + // max imageSize = ((frameSizeX - CCstatus.ImageWidth) / 8 / 4) -1 + // 43 = ((2048 - 640) / 8 / 4) - 1 + if (imageSize < 43) + { + _imageSize_temp = (43 - imageSize); + } + SanitizeZoomParams(_imageSize_temp, frameSizeX, frameSizeY, _imageWidth, _imageHeight, _offsetx, _offsety); + SetCamWindow(s, frameSizeX, frameSizeY, _offsetx, _offsety, _imageWidth, _imageHeight, CCstatus.ImageWidth, CCstatus.ImageHeight, imageVflip); + break; + + case OV2640_PID: + frameSizeX = 1600; + frameSizeY = 1200; + // max imageSize = ((frameSizeX - CCstatus.ImageWidth) / 8 / 4) -1 + // 29 = ((1600 - 640) / 8 / 4) - 1 + if (imageSize < 29) + { + _imageSize_temp = (29 - imageSize); + } + SanitizeZoomParams(_imageSize_temp, frameSizeX, frameSizeY, _imageWidth, _imageHeight, _offsetx, _offsety); + SetCamWindow(s, frameSizeX, frameSizeY, _offsetx, _offsety, _imageWidth, _imageHeight, CCstatus.ImageWidth, CCstatus.ImageHeight, imageVflip); + break; + + default: + // do nothing + break; } - if (x > maxX) - x = maxX; - if (y > maxY) - y = maxY; - SetCamWindow(s, z, x, y, image_width, image_height); - } else { - s->set_framesize(s, ActualResolution); + } + else + { + s->set_framesize(s, CCstatus.ImageFrameSize); } } } - -void CCamera::SetQualitySize(int qual, framesize_t resol, bool zoomEnabled, int zoomMode, int zoomOffsetX, int zoomOffsetY) +void CCamera::SetQualityZoomSize(int qual, framesize_t resol, bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip) { - qual = min(63, max(8, qual)); // Limit quality from 8..63 (values lower than 8 tent to be unstable) - - ActualResolution = resol; - ActualQuality = qual; + sensor_t *s = esp_camera_sensor_get(); - imageZoomEnabled = zoomEnabled; - imageZoomMode = zoomMode; - imageZoomOffsetX = zoomOffsetX; - imageZoomOffsetY = zoomOffsetY; + // OV2640 has no lower limit on jpeg quality + if (CCstatus.CamSensor_id == OV5640_PID) + { + qual = min(63, max(8, qual)); + } SetImageWidthHeightFromResolution(resol); - sensor_t * s = esp_camera_sensor_get(); - if (s) { + if (s != NULL) + { s->set_quality(s, qual); - SetZoom(zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); + SetZoomSize(zoomEnabled, zoomOffsetX, zoomOffsetY, imageSize, imageVflip); } - else { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SetQualitySize: Failed to get control structure"); + else + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SetQualityZoomSize, Failed to get Cam control structure"); } } +void CCamera::SetCamSharpness(bool _autoSharpnessEnabled, int _sharpnessLevel) +{ + sensor_t *s = esp_camera_sensor_get(); + + if (s != NULL) + { + if (CCstatus.CamSensor_id == OV2640_PID) + { + _sharpnessLevel = min(2, max(-2, _sharpnessLevel)); + // The OV2640 does not officially support sharpness, so the detour is made with the ov2640_sharpness.cpp. + if (_autoSharpnessEnabled) + { + ov2640_enable_auto_sharpness(s); + } + else + { + ov2640_set_sharpness(s, _sharpnessLevel); + } + } + else + { + _sharpnessLevel = min(3, max(-3, _sharpnessLevel)); + // for CAMERA_OV5640 and CAMERA_OV3660 + if (_autoSharpnessEnabled) + { + // autoSharpness is not supported, default to zero + s->set_sharpness(s, 0); + } + else + { + s->set_sharpness(s, _sharpnessLevel); + } + } + } + else + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SetCamSharpness, Failed to get Cam control structure"); + } +} -void CCamera::EnableAutoExposure(int flash_duration) +void CCamera::SetCamWindow(sensor_t *s, int frameSizeX, int frameSizeY, int xOffset, int yOffset, int xTotal, int yTotal, int xOutput, int yOutput, int imageVflip) { - ESP_LOGD(TAG, "EnableAutoExposure"); - - LEDOnOff(true); - if (flash_duration > 0) { - LightOnOff(true); - const TickType_t xDelay = flash_duration / portTICK_PERIOD_MS; - vTaskDelay( xDelay ); + if (CCstatus.CamSensor_id == OV2640_PID) + { + s->set_res_raw(s, 0, 0, 0, 0, xOffset, yOffset, xTotal, yTotal, xOutput, yOutput, false, false); } + else + { + // for CAMERA_OV5640 and CAMERA_OV3660 + bool scale = !(xOutput == xTotal && yOutput == yTotal); + bool binning = (xTotal >= (frameSizeX >> 1)); - camera_fb_t * fb = esp_camera_fb_get(); - esp_camera_fb_return(fb); - fb = esp_camera_fb_get(); - if (!fb) { - LEDOnOff(false); - LightOnOff(false); - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "EnableAutoExposure: Capture Failed. " - "Check camera module and/or proper electrical connection"); - //doReboot(); + if (imageVflip == true) + { + s->set_res_raw(s, xOffset, yOffset, xOffset + xTotal - 1, yOffset + yTotal - 1, 0, 0, frameSizeX, frameSizeY, xOutput, yOutput, scale, binning); + } + else + { + s->set_res_raw(s, xOffset, yOffset, xOffset + xTotal, yOffset + yTotal, 0, 0, frameSizeX, frameSizeY, xOutput, yOutput, scale, binning); + } } - esp_camera_fb_return(fb); +} + +static size_t jpg_encode_stream(void *arg, size_t index, const void *data, size_t len) +{ + jpg_chunking_t *j = (jpg_chunking_t *)arg; - sensor_t * s = esp_camera_sensor_get(); - if (s) { - s->set_gain_ctrl(s, 0); - s->set_exposure_ctrl(s, 0); + if (!index) + { + j->len = 0; } - else { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "EnableAutoExposure: Failed to get control structure to set gain+exposure"); + + if (httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK) + { + return 0; } - LEDOnOff(false); - LightOnOff(false); - isFixedExposure = true; - waitbeforepicture_org = flash_duration; -} + j->len += len; + return len; +} esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("CaptureToBasisImage - Start"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("CaptureToBasisImage - Start"); +#endif + + _Image->EmptyImage(); // Delete previous stored raw image -> black image - _Image->EmptyImage(); //Delete previous stored raw image -> black image - - LEDOnOff(true); + LEDOnOff(true); // Status-LED on - if (delay > 0) { - LightOnOff(true); + if (delay > 0) + { + LightOnOff(true); // Flash-LED on const TickType_t xDelay = delay / portTICK_PERIOD_MS; - vTaskDelay( xDelay ); + vTaskDelay(xDelay); } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("CaptureToBasisImage - After LightOn"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("CaptureToBasisImage - After LightOn"); +#endif - camera_fb_t * fb = esp_camera_fb_get(); + camera_fb_t *fb = esp_camera_fb_get(); esp_camera_fb_return(fb); fb = esp_camera_fb_get(); - if (!fb) { - LEDOnOff(false); - LightOnOff(false); + + if (!fb) + { + LEDOnOff(false); // Status-LED off + LightOnOff(false); // Flash-LED off LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "is not working anymore (CaptureToBasisImage) - most probably caused " "by a hardware problem (instablility, ...). System will reboot."); @@ -468,540 +631,532 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) return ESP_FAIL; } - if (demoMode) { // Use images stored on SD-Card instead of camera image + if (CCstatus.DemoMode) + { + // Use images stored on SD-Card instead of camera image /* Replace Framebuffer with image from SD-Card */ loadNextDemoImage(fb); } - CImageBasis* _zwImage = new CImageBasis("zwImage"); - if (_zwImage) { + CImageBasis *_zwImage = new CImageBasis("zwImage"); + + if (_zwImage) + { _zwImage->LoadFromMemory(fb->buf, fb->len); } - else { + else + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToBasisImage: Can't allocate _zwImage"); } - esp_camera_fb_return(fb); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("CaptureToBasisImage - After fb_get"); - #endif + esp_camera_fb_return(fb); - LEDOnOff(false); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("CaptureToBasisImage - After fb_get"); +#endif - if (delay > 0) - LightOnOff(false); - -// TickType_t xDelay = 1000 / portTICK_PERIOD_MS; -// vTaskDelay( xDelay ); // wait for power to recover - - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("CaptureToBasisImage - After LoadFromMemory"); - #endif + LEDOnOff(false); // Status-LED off - if (_zwImage == NULL) { - return ESP_OK; + if (delay > 0) + { + LightOnOff(false); // Flash-LED off } - if (imageNegative) { - _zwImage->Negative(); + // TickType_t xDelay = 1000 / portTICK_PERIOD_MS; + // vTaskDelay( xDelay ); // wait for power to recover + +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("CaptureToBasisImage - After LoadFromMemory"); +#endif + + if (_zwImage == NULL) + { + return ESP_OK; } - stbi_uc* p_target; - stbi_uc* p_source; + stbi_uc *p_target; + stbi_uc *p_source; int channels = 3; - int width = image_width; - int height = image_height; + int width = CCstatus.ImageWidth; + int height = CCstatus.ImageHeight; - #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); - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, _zw); - #endif +#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); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, _zw); +#endif for (int x = 0; x < width; ++x) + { for (int y = 0; y < height; ++y) { p_target = _Image->rgb_image + (channels * (y * width + x)); p_source = _zwImage->rgb_image + (channels * (y * width + x)); - for (int c = 0; c < channels; c++) { + + for (int c = 0; c < channels; c++) + { p_target[c] = p_source[c]; } } + } delete _zwImage; - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("CaptureToBasisImage - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("CaptureToBasisImage - Done"); +#endif return ESP_OK; } - esp_err_t CCamera::CaptureToFile(std::string nm, int delay) { string ftype; - LEDOnOff(true); // Switched off to save power ! + LEDOnOff(true); // Status-LED on - if (delay > 0) { - LightOnOff(true); + if (delay > 0) + { + LightOnOff(true); // Flash-LED on const TickType_t xDelay = delay / portTICK_PERIOD_MS; - vTaskDelay( xDelay ); + vTaskDelay(xDelay); } - camera_fb_t * fb = esp_camera_fb_get(); + camera_fb_t *fb = esp_camera_fb_get(); esp_camera_fb_return(fb); fb = esp_camera_fb_get(); - if (!fb) { - LEDOnOff(false); - LightOnOff(false); + + if (!fb) + { + LEDOnOff(false); // Status-LED off + LightOnOff(false); // Flash-LED off LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToFile: Capture Failed. " "Check camera module and/or proper electrical connection"); - //doReboot(); + // doReboot(); return ESP_FAIL; } - LEDOnOff(false); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "w %d, h %d, size %d", fb->width, fb->height, fb->len); - #endif + LEDOnOff(false); // Status-LED off + +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "w %d, h %d, size %d", fb->width, fb->height, fb->len); +#endif nm = FormatFileName(nm); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Save Camera to: %s", nm.c_str()); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Save Camera to: %s", nm.c_str()); +#endif ftype = toUpper(getFileType(nm)); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Filetype: %s", ftype.c_str()); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Filetype: %s", ftype.c_str()); +#endif - uint8_t * buf = NULL; - size_t buf_len = 0; - bool converted = false; + uint8_t *buf = NULL; + size_t buf_len = 0; + bool converted = false; if (ftype.compare("BMP") == 0) { frame2bmp(fb, &buf, &buf_len); converted = true; } + if (ftype.compare("JPG") == 0) { - if(fb->format != PIXFORMAT_JPEG){ - bool jpeg_converted = frame2jpg(fb, ActualQuality, &buf, &buf_len); + if (fb->format != PIXFORMAT_JPEG) + { + bool jpeg_converted = frame2jpg(fb, CCstatus.ImageQuality, &buf, &buf_len); converted = true; - if(!jpeg_converted){ + + if (!jpeg_converted) + { ESP_LOGE(TAG, "JPEG compression failed"); } - } else { + } + else + { buf_len = fb->len; buf = fb->buf; } } - FILE * fp = fopen(nm.c_str(), "wb"); - if (fp == NULL) { // If an error occurs during the file creation + FILE *fp = fopen(nm.c_str(), "wb"); + + if (fp == NULL) + { + // If an error occurs during the file creation LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToFile: Failed to open file " + nm); } - else { - fwrite(buf, sizeof(uint8_t), buf_len, fp); + else + { + fwrite(buf, sizeof(uint8_t), buf_len, fp); fclose(fp); - } + } if (converted) + { free(buf); + } esp_camera_fb_return(fb); - if (delay > 0) - LightOnOff(false); + if (delay > 0) + { + LightOnOff(false); // Flash-LED off + } - return ESP_OK; + return ESP_OK; } - esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay) { esp_err_t res = ESP_OK; size_t fb_len = 0; int64_t fr_start = esp_timer_get_time(); - LEDOnOff(true); + LEDOnOff(true); // Status-LED on - if (delay > 0) { - LightOnOff(true); + if (delay > 0) + { + LightOnOff(true); // Flash-LED on const TickType_t xDelay = delay / portTICK_PERIOD_MS; - vTaskDelay( xDelay ); + vTaskDelay(xDelay); } camera_fb_t *fb = esp_camera_fb_get(); esp_camera_fb_return(fb); fb = esp_camera_fb_get(); - if (!fb) { - LEDOnOff(false); - LightOnOff(false); + + if (!fb) + { + LEDOnOff(false); // Status-LED off + LightOnOff(false); // Flash-LED off LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToFile: Capture Failed. " - "Check camera module and/or proper electrical connection"); + "Check camera module and/or proper electrical connection"); httpd_resp_send_500(req); -// doReboot(); + // doReboot(); return ESP_FAIL; } - LEDOnOff(false); + LEDOnOff(false); // Status-LED off res = httpd_resp_set_type(req, "image/jpeg"); - if(res == ESP_OK){ + + if (res == ESP_OK) + { res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=raw.jpg"); } - if(res == ESP_OK){ - if (demoMode) { // Use images stored on SD-Card instead of camera image + if (res == ESP_OK) + { + if (CCstatus.DemoMode) + { + // Use images stored on SD-Card instead of camera image LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Using Demo image!"); /* Replace Framebuffer with image from SD-Card */ loadNextDemoImage(fb); res = httpd_resp_send(req, (const char *)fb->buf, fb->len); } - else { - if(fb->format == PIXFORMAT_JPEG){ + else + { + if (fb->format == PIXFORMAT_JPEG) + { fb_len = fb->len; res = httpd_resp_send(req, (const char *)fb->buf, fb->len); - } else { + } + else + { jpg_chunking_t jchunk = {req, 0}; - res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk)?ESP_OK:ESP_FAIL; + res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL; httpd_resp_send_chunk(req, NULL, 0); fb_len = jchunk.len; } } } + esp_camera_fb_return(fb); int64_t fr_end = esp_timer_get_time(); - - ESP_LOGI(TAG, "JPG: %dKB %dms", (int)(fb_len/1024), (int)((fr_end - fr_start)/1000)); - if (delay > 0) - LightOnOff(false); + ESP_LOGI(TAG, "JPG: %dKB %dms", (int)(fb_len / 1024), (int)((fr_end - fr_start) / 1000)); + + if (delay > 0) + { + LightOnOff(false); // Flash-LED off + } return res; } - esp_err_t CCamera::CaptureToStream(httpd_req_t *req, bool FlashlightOn) { esp_err_t res = ESP_OK; size_t fb_len = 0; int64_t fr_start; - char * part_buf[64]; + char *part_buf[64]; + + // wenn die Kameraeinstellungen durch Erstellen eines neuen Referenzbildes verändert wurden, müssen sie neu gesetzt werden + if (CFstatus.changedCameraSettings) + { + Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera + Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + CFstatus.changedCameraSettings = false; + } LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Live stream started"); - if (FlashlightOn) { - LEDOnOff(true); - LightOnOff(true); + if (FlashlightOn) + { + LEDOnOff(true); // Status-LED on + LightOnOff(true); // Flash-LED on } - //httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); //stream is blocking web interface, only serving to local + // httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); //stream is blocking web interface, only serving to local httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); - while(1) + while (1) { fr_start = esp_timer_get_time(); camera_fb_t *fb = esp_camera_fb_get(); esp_camera_fb_return(fb); fb = esp_camera_fb_get(); - if (!fb) { + + if (!fb) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToStream: Camera framebuffer not available"); break; } + fb_len = fb->len; - - if (res == ESP_OK){ + + if (res == ESP_OK) + { size_t hlen = snprintf((char *)part_buf, sizeof(part_buf), _STREAM_PART, fb_len); res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen); } - if (res == ESP_OK){ + + if (res == ESP_OK) + { res = httpd_resp_send_chunk(req, (const char *)fb->buf, fb_len); } - if (res == ESP_OK){ + + if (res == ESP_OK) + { res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); } - + esp_camera_fb_return(fb); int64_t fr_end = esp_timer_get_time(); - ESP_LOGD(TAG, "JPG: %dKB %dms", (int)(fb_len/1024), (int)((fr_end - fr_start)/1000)); + ESP_LOGD(TAG, "JPG: %dKB %dms", (int)(fb_len / 1024), (int)((fr_end - fr_start) / 1000)); - if (res != ESP_OK){ // Exit loop, e.g. also when closing the webpage + if (res != ESP_OK) + { + // Exit loop, e.g. also when closing the webpage break; } int64_t fr_delta_ms = (fr_end - fr_start) / 1000; - if (CAM_LIVESTREAM_REFRESHRATE > fr_delta_ms) { - const TickType_t xDelay = (CAM_LIVESTREAM_REFRESHRATE - fr_delta_ms) / portTICK_PERIOD_MS; - ESP_LOGD(TAG, "Stream: sleep for: %ldms", (long) xDelay*10); - vTaskDelay(xDelay); + + if (CAM_LIVESTREAM_REFRESHRATE > fr_delta_ms) + { + const TickType_t xDelay = (CAM_LIVESTREAM_REFRESHRATE - fr_delta_ms) / portTICK_PERIOD_MS; + ESP_LOGD(TAG, "Stream: sleep for: %ldms", (long)xDelay * 10); + vTaskDelay(xDelay); } } - LEDOnOff(false); - LightOnOff(false); + LEDOnOff(false); // Status-LED off + LightOnOff(false); // Flash-LED off LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Live stream stopped"); return res; } - void CCamera::LightOnOff(bool status) { - GpioHandler* gpioHandler = gpio_handler_get(); - if ((gpioHandler != NULL) && (gpioHandler->isEnabled())) { + GpioHandler *gpioHandler = gpio_handler_get(); + + if ((gpioHandler != NULL) && (gpioHandler->isEnabled())) + { ESP_LOGD(TAG, "Use gpioHandler to trigger flashlight"); gpioHandler->flashLightEnable(status); - } - else { - #ifdef USE_PWM_LEDFLASH - if (status) { - ESP_LOGD(TAG, "Internal Flash-LED turn on with PWM %d", led_intensity); - ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, led_intensity)); + } + else + { +#ifdef USE_PWM_LEDFLASH + if (status) + { + ESP_LOGD(TAG, "Internal Flash-LED turn on with PWM %d", CCstatus.ImageLedIntensity); + ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, CCstatus.ImageLedIntensity)); // Update duty to apply the new value ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); } - else { + else + { ESP_LOGD(TAG, "Internal Flash-LED turn off PWM"); ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0)); ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); } - #else +#else // Init the GPIO gpio_pad_select_gpio(FLASH_GPIO); - // Set the GPIO as a push/pull output - gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT); - if (status) + // Set the GPIO as a push/pull output + gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT); + + if (status) + { gpio_set_level(FLASH_GPIO, 1); + } else + { gpio_set_level(FLASH_GPIO, 0); - #endif + } +#endif } } - void CCamera::LEDOnOff(bool status) { - if (xHandle_task_StatusLED == NULL) { + if (xHandle_task_StatusLED == NULL) + { // Init the GPIO gpio_pad_select_gpio(BLINK_GPIO); + /* Set the GPIO as a push/pull output */ - gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); + gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); - if (!status) + if (!status) + { gpio_set_level(BLINK_GPIO, 1); + } else - gpio_set_level(BLINK_GPIO, 0); + { + gpio_set_level(BLINK_GPIO, 0); + } } } - -void CCamera::GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol, bool &zoomEnabled, int &zoomMode, int &zoomOffsetX, int &zoomOffsetY) +void CCamera::SetImageWidthHeightFromResolution(framesize_t resol) { - char _query[100]; - char _value[10]; - - resol = ActualResolution; - qual = ActualQuality; - zoomEnabled = imageZoomEnabled; - zoomMode = imageZoomMode; - zoomOffsetX = imageZoomOffsetX; - zoomOffsetY = imageZoomOffsetY; - - if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) + if (resol == FRAMESIZE_QVGA) { - ESP_LOGD(TAG, "Query: %s", _query); - if (httpd_query_key_value(_query, "size", _value, sizeof(_value)) == ESP_OK) - { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Size: %s", _size); - #endif - if (strcmp(_value, "QVGA") == 0) - resol = FRAMESIZE_QVGA; // 320x240 - else if (strcmp(_value, "VGA") == 0) - resol = FRAMESIZE_VGA; // 640x480 - else if (strcmp(_value, "SVGA") == 0) - resol = FRAMESIZE_SVGA; // 800x600 - else if (strcmp(_value, "XGA") == 0) - resol = FRAMESIZE_XGA; // 1024x768 - else if (strcmp(_value, "SXGA") == 0) - resol = FRAMESIZE_SXGA; // 1280x1024 - else if (strcmp(_value, "UXGA") == 0) - resol = FRAMESIZE_UXGA; // 1600x1200 - } - if (httpd_query_key_value(_query, "quality", _value, sizeof(_value)) == ESP_OK) - { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Quality: %s", _qual); - #endif - qual = atoi(_value); - if (qual > 63) // Limit to max. 63 - qual = 63; - else if (qual < 8) // Limit to min. 8 - qual = 8; - } - if (httpd_query_key_value(_query, "z", _value, sizeof(_value)) == ESP_OK) - { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Zoom: %s", _value); - #endif - if (atoi(_value) != 0) - zoomEnabled = true; - else - zoomEnabled = false; - } - if (httpd_query_key_value(_query, "zm", _value, sizeof(_value)) == ESP_OK) - { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Zoom mode: %s", _value); - #endif - zoomMode = atoi(_value); - if (zoomMode > 2) - zoomMode = 2; - else if (zoomMode < 0) - zoomMode = 0; - } - if (httpd_query_key_value(_query, "x", _value, sizeof(_value)) == ESP_OK) - { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "X offset: %s", _value); - #endif - zoomOffsetX = atoi(_value); - if (zoomOffsetX < 0) - zoomOffsetX = 0; - } - if (httpd_query_key_value(_query, "y", _value, sizeof(_value)) == ESP_OK) - { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Y offset: %s", _value); - #endif - zoomOffsetY = atoi(_value); - if (zoomOffsetY < 0) - zoomOffsetY = 0; - } + CCstatus.ImageHeight = 240; + CCstatus.ImageWidth = 320; + } + else if (resol == FRAMESIZE_VGA) + { + CCstatus.ImageHeight = 480; + CCstatus.ImageWidth = 640; + } + else if (resol == FRAMESIZE_SVGA) + { + CCstatus.ImageHeight = 600; + CCstatus.ImageWidth = 800; + } + else if (resol == FRAMESIZE_XGA) + { + CCstatus.ImageHeight = 768; + CCstatus.ImageWidth = 1024; + } + else if (resol == FRAMESIZE_HD) + { + CCstatus.ImageHeight = 720; + CCstatus.ImageWidth = 1280; + } + else if (resol == FRAMESIZE_SXGA) + { + CCstatus.ImageHeight = 1024; + CCstatus.ImageWidth = 1280; + } + else if (resol == FRAMESIZE_UXGA) + { + CCstatus.ImageHeight = 1200; + CCstatus.ImageWidth = 1600; } } - -framesize_t CCamera::TextToFramesize(const char * _size) +framesize_t CCamera::TextToFramesize(const char *_size) { if (strcmp(_size, "QVGA") == 0) - return FRAMESIZE_QVGA; // 320x240 + { + return FRAMESIZE_QVGA; // 320x240 + } else if (strcmp(_size, "VGA") == 0) - return FRAMESIZE_VGA; // 640x480 + { + return FRAMESIZE_VGA; // 640x480 + } else if (strcmp(_size, "SVGA") == 0) - return FRAMESIZE_SVGA; // 800x600 + { + return FRAMESIZE_SVGA; // 800x600 + } else if (strcmp(_size, "XGA") == 0) - return FRAMESIZE_XGA; // 1024x768 + { + return FRAMESIZE_XGA; // 1024x768 + } else if (strcmp(_size, "SXGA") == 0) - return FRAMESIZE_SXGA; // 1280x1024 + { + return FRAMESIZE_SXGA; // 1280x1024 + } else if (strcmp(_size, "UXGA") == 0) - return FRAMESIZE_UXGA; // 1600x1200 - - return ActualResolution; -} - - -CCamera::CCamera() -{ - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "CreateClassCamera"); - #endif - brightness = 0; - contrast = 0; - saturation = 0; - isFixedExposure = false; - - ledc_init(); -} - - -esp_err_t CCamera::InitCam() -{ - ESP_LOGD(TAG, "Init Camera"); - ActualQuality = camera_config.jpeg_quality; - ActualResolution = camera_config.frame_size; - //initialize the camera - esp_camera_deinit(); // De-init in case it was already initialized - esp_err_t err = esp_camera_init(&camera_config); - if (err != ESP_OK) { - ESP_LOGE(TAG, "Camera Init Failed"); - return err; + { + return FRAMESIZE_UXGA; // 1600x1200 } - CameraInitSuccessful = true; - return ESP_OK; -} - - -void CCamera::SetLEDIntensity(float _intrel) -{ - _intrel = min(_intrel, (float) 100); - _intrel = max(_intrel, (float) 0); - _intrel = _intrel / 100; - led_intensity = (int) (_intrel * 8191); - ESP_LOGD(TAG, "Set led_intensity to %d of 8191", led_intensity); - -} - - -bool CCamera::getCameraInitSuccessful() -{ - return CameraInitSuccessful; + return CCstatus.ImageFrameSize; } - std::vector demoFiles; -void CCamera::useDemoMode() +void CCamera::useDemoMode(void) { char line[50]; FILE *fd = fopen("/sdcard/demo/files.txt", "r"); - if (!fd) { + + if (!fd) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can not start Demo mode, the folder '/sdcard/demo/' does not contain the needed files!"); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "See Details on https://jomjol.github.io/AI-on-the-edge-device-docs/Demo-Mode!"); return; } - demoImage = (uint8_t*)malloc(DEMO_IMAGE_SIZE); - if (demoImage == NULL) { + demoImage = (uint8_t *)malloc(DEMO_IMAGE_SIZE); + + if (demoImage == NULL) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Unable to acquire required memory for demo image!"); return; } - while (fgets(line, sizeof(line), fd) != NULL) { + while (fgets(line, sizeof(line), fd) != NULL) + { line[strlen(line) - 1] = '\0'; demoFiles.push_back(line); } - + fclose(fd); - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Using Demo mode (" + std::to_string(demoFiles.size()) + - " files) instead of real camera image!"); + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Using Demo mode (" + std::to_string(demoFiles.size()) + " files) instead of real camera image!"); - for (auto file : demoFiles) { + for (auto file : demoFiles) + { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, file); } - demoMode = true; + CCstatus.DemoMode = true; } - -bool CCamera::loadNextDemoImage(camera_fb_t *fb) { +bool CCamera::loadNextDemoImage(camera_fb_t *fb) +{ char filename[50]; int readBytes; long fileSize; @@ -1012,17 +1167,20 @@ bool CCamera::loadNextDemoImage(camera_fb_t *fb) { /* Inject saved image */ - FILE * fp = fopen(filename, "rb"); - if (!fp) { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read file: " + std::string(filename) +"!"); + FILE *fp = fopen(filename, "rb"); + + if (!fp) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read file: " + std::string(filename) + "!"); return false; } fileSize = GetFileSize(filename); - if (fileSize > DEMO_IMAGE_SIZE) { + + if (fileSize > DEMO_IMAGE_SIZE) + { char buf[100]; - snprintf(buf, sizeof(buf), "Demo Image (%d bytes) is larger than provided buffer (%d bytes)!", - (int)fileSize, DEMO_IMAGE_SIZE); + snprintf(buf, sizeof(buf), "Demo Image (%d bytes) is larger than provided buffer (%d bytes)!", (int)fileSize, DEMO_IMAGE_SIZE); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, std::string(buf)); return false; } @@ -1038,7 +1196,6 @@ bool CCamera::loadNextDemoImage(camera_fb_t *fb) { return true; } - long CCamera::GetFileSize(std::string filename) { struct stat stat_buf; diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.h b/code/components/jomjol_controlcamera/ClassControllCamera.h index 064eefb91..cea057260 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.h +++ b/code/components/jomjol_controlcamera/ClassControllCamera.h @@ -15,66 +15,99 @@ #include "CImageBasis.h" #include "../../include/defines.h" -class CCamera { - protected: - int ActualQuality; - framesize_t ActualResolution; - int brightness, contrast, saturation, autoExposureLevel; - bool isFixedExposure; - int waitbeforepicture_org; - int led_intensity = 4095; - - void ledc_init(void); - bool CameraInitSuccessful = false; - bool demoMode = false; - - bool loadNextDemoImage(camera_fb_t *fb); - long GetFileSize(std::string filename); - - void SetCamWindow(sensor_t *s, int resolution, int xOffset, int yOffset, int xLength, int yLength); - void SetImageWidthHeightFromResolution(framesize_t resol); - - public: - int image_height, image_width; - bool imageZoomEnabled = false; - int imageZoomMode = 0; - int imageZoomOffsetX = 0; - int imageZoomOffsetY = 0; - bool imageNegative = false; - bool imageAec2 = false; - bool imageAutoSharpness = false; - int imageSharpnessLevel = 0; - #ifdef GRAYSCALE_AS_DEFAULT - bool imageGrayscale = true; - #else - bool imageGrayscale = false; - #endif - - CCamera(); - esp_err_t InitCam(); - - void LightOnOff(bool status); - void LEDOnOff(bool status); - esp_err_t CaptureToHTTP(httpd_req_t *req, int delay = 0); - esp_err_t CaptureToStream(httpd_req_t *req, bool FlashlightOn); - void SetQualitySize(int qual, framesize_t resol, bool zoomEnabled, int zoomMode, int zoomOffsetX, int zoomOffsetY); - bool SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation, int _autoExposureLevel, bool _grayscale, bool _negative, bool _aec2, int _sharpnessLevel); - void SetZoom(bool zoomEnabled, int zoomMode, int zoomOffsetX, int zoomOffsetY); - void GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol, bool &zoomEnabled, int &zoomMode, int &zoomOffsetX, int &zoomOffsetY); - void SetLEDIntensity(float _intrel); - bool testCamera(void); - void EnableAutoExposure(int flash_duration); - bool getCameraInitSuccessful(); - void useDemoMode(void); - - - framesize_t TextToFramesize(const char * text); - - esp_err_t CaptureToFile(std::string nm, int delay = 0); - esp_err_t CaptureToBasisImage(CImageBasis *_Image, int delay = 0); -}; +typedef struct +{ + uint16_t CamSensor_id; + framesize_t ImageFrameSize = FRAMESIZE_VGA; // 0 - 10 + gainceiling_t ImageGainceiling; // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) -extern CCamera Camera; + int ImageQuality; // 0 - 63 + int ImageBrightness; // (-2 to 2) - set brightness + int ImageContrast; //-2 - 2 + int ImageSaturation; //-2 - 2 + int ImageSharpness; //-2 - 2 + bool ImageAutoSharpness; + int ImageSpecialEffect; // 0 - 6 + int ImageWbMode; // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) + int ImageAwb; // white balance enable (0 or 1) + int ImageAwbGain; // Auto White Balance enable (0 or 1) + int ImageAec; // auto exposure off (1 or 0) + int ImageAec2; // automatic exposure sensor (0 or 1) + int ImageAeLevel; // auto exposure levels (-2 to 2) + int ImageAecValue; // set exposure manually (0-1200) + int ImageAgc; // auto gain off (1 or 0) + int ImageAgcGain; // set gain manually (0 - 30) + int ImageBpc; // black pixel correction + int ImageWpc; // white pixel correction + int ImageRawGma; // (1 or 0) + int ImageLenc; // lens correction (1 or 0) + int ImageHmirror; // (0 or 1) flip horizontally + int ImageVflip; // Invert image (0 or 1) + int ImageDcw; // downsize enable (1 or 0) + + int ImageDenoiseLevel; // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) + + int ImageWidth; + int ImageHeight; + + int ImageLedIntensity; + + bool ImageZoomEnabled; + int ImageZoomOffsetX; + int ImageZoomOffsetY; + int ImageZoomSize; + + int WaitBeforePicture; + bool isImageSize; + + bool CameraInitSuccessful; + bool changedCameraSettings; + bool DemoMode; + bool SaveAllFiles; +} camera_controll_config_temp_t; + +extern camera_controll_config_temp_t CCstatus; + +class CCamera +{ +protected: + void ledc_init(void); + bool loadNextDemoImage(camera_fb_t *fb); + long GetFileSize(std::string filename); + void SetCamWindow(sensor_t *s, int frameSizeX, int frameSizeY, int xOffset, int yOffset, int xTotal, int yTotal, int xOutput, int yOutput, int imageVflip); + void SetImageWidthHeightFromResolution(framesize_t resol); + void SanitizeZoomParams(int imageSize, int frameSizeX, int frameSizeY, int &imageWidth, int &imageHeight, int &zoomOffsetX, int &zoomOffsetY); + +public: + CCamera(void); + esp_err_t InitCam(void); + void LightOnOff(bool status); + void LEDOnOff(bool status); + + esp_err_t setSensorDatenFromCCstatus(void); + esp_err_t getSensorDatenToCCstatus(void); + + int ov5640_set_gainceiling(sensor_t *s, gainceiling_t level); + + esp_err_t CaptureToHTTP(httpd_req_t *req, int delay = 0); + esp_err_t CaptureToStream(httpd_req_t *req, bool FlashlightOn); + + void SetQualityZoomSize(int qual, framesize_t resol, bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip); + void SetZoomSize(bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip); + void SetCamSharpness(bool _autoSharpnessEnabled, int _sharpnessLevel); + + void SetLEDIntensity(float _intrel); + bool testCamera(void); + bool getCameraInitSuccessful(void); + void useDemoMode(void); + + framesize_t TextToFramesize(const char *text); + + esp_err_t CaptureToFile(std::string nm, int delay = 0); + esp_err_t CaptureToBasisImage(CImageBasis *_Image, int delay = 0); +}; + +extern CCamera Camera; #endif \ No newline at end of file diff --git a/code/components/jomjol_controlcamera/ov2640_sharpness.cpp b/code/components/jomjol_controlcamera/ov2640_sharpness.cpp index 6970b27c4..8e67bc789 100644 --- a/code/components/jomjol_controlcamera/ov2640_sharpness.cpp +++ b/code/components/jomjol_controlcamera/ov2640_sharpness.cpp @@ -3,71 +3,78 @@ #include "ov2640_sharpness.h" -#define OV2640_MAXLEVEL_SHARPNESS 6 - const static uint8_t OV2640_SHARPNESS_AUTO[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, 0x93, 0x20, 0x20, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_MANUAL[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, 0x93, 0x00, 0x20, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL0[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xc0, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xC0, 0x1F, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL1[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xc1, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xC1, 0x1F, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL2[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xc2, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xC2, 0x1F, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL3[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xc4, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xC4, 0x1F, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL4[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xc8, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xC8, 0x1F, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL5[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xd0, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xD0, 0x1F, 0x00, 0x00, 0x00 }; const static uint8_t OV2640_SHARPNESS_LEVEL6[]= { - 0xFF, 0x00, 0xff, - 0x92, 0x01, 0xff, - 0x93, 0xdf, 0x1f, + //reg, val, mask + 0xFF, 0x00, 0xFF, + 0x92, 0x01, 0xFF, + 0x93, 0xDF, 0x1F, 0x00, 0x00, 0x00 }; @@ -82,6 +89,9 @@ const static uint8_t *OV2640_SETTING_SHARPNESS[]= OV2640_SHARPNESS_LEVEL6 // +3 sharpness }; +#define OV2640_MAXLEVEL_SHARPNESS 6 + + static int table_mask_write(sensor_t *sensor, const uint8_t* ptab) { uint8_t address; @@ -91,34 +101,52 @@ static int table_mask_write(sensor_t *sensor, const uint8_t* ptab) const uint8_t *pdata = ptab; if (pdata == NULL) + { return -1; + } while (1) { address = *pdata++; value = *pdata++; mask = *pdata++; + if ((address == 0) && (value == 0) && (mask == 0)) + { break; + } + sensor->set_reg(sensor, address, mask, value); } return 0; } + int ov2640_enable_auto_sharpness(sensor_t *sensor) { table_mask_write(sensor, OV2640_SHARPNESS_AUTO); + return 0; } int ov2640_set_sharpness(sensor_t *sensor, int sharpness) { - if ((sharpness < -3) || (sharpness > OV2640_MAXLEVEL_SHARPNESS - 3)) - return -1; + int sharpness_temp = 0; + + if (sharpness < -3) + { + sharpness_temp = -3; + } + + if (sharpness > OV2640_MAXLEVEL_SHARPNESS - 3) + { + sharpness_temp = OV2640_MAXLEVEL_SHARPNESS - 3; + } table_mask_write(sensor, OV2640_SHARPNESS_MANUAL); - table_mask_write(sensor, OV2640_SETTING_SHARPNESS[sharpness + 3]); + table_mask_write(sensor, OV2640_SETTING_SHARPNESS[sharpness_temp + 3]); + return 0; } diff --git a/code/components/jomjol_controlcamera/server_camera.cpp b/code/components/jomjol_controlcamera/server_camera.cpp index dc37e2abb..fc8fd4bc1 100644 --- a/code/components/jomjol_controlcamera/server_camera.cpp +++ b/code/components/jomjol_controlcamera/server_camera.cpp @@ -5,6 +5,7 @@ #include "esp_camera.h" #include "ClassControllCamera.h" +#include "MainFlowControl.h" #include "ClassLogFile.h" #include "esp_log.h" @@ -13,191 +14,187 @@ static const char *TAG = "server_cam"; - -void PowerResetCamera(){ - - ESP_LOGD(TAG, "Resetting camera by power down line"); - gpio_config_t conf; - conf.intr_type = GPIO_INTR_DISABLE; - conf.pin_bit_mask = 1LL << GPIO_NUM_32; - conf.mode = GPIO_MODE_OUTPUT; - conf.pull_down_en = GPIO_PULLDOWN_DISABLE; - conf.pull_up_en = GPIO_PULLUP_DISABLE; - gpio_config(&conf); - - // carefull, logic is inverted compared to reset pin - gpio_set_level(GPIO_NUM_32, 1); - vTaskDelay(1000 / portTICK_PERIOD_MS); - gpio_set_level(GPIO_NUM_32, 0); - vTaskDelay(1000 / portTICK_PERIOD_MS); +void PowerResetCamera() +{ +#if CAM_PIN_PWDN == GPIO_NUM_NC // Use reset only if pin is available + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "No power down pin availbale to reset camera"); +#else + ESP_LOGD(TAG, "Resetting camera by power down line"); + gpio_config_t conf; + conf.intr_type = GPIO_INTR_DISABLE; + conf.pin_bit_mask = 1LL << CAM_PIN_PWDN; + conf.mode = GPIO_MODE_OUTPUT; + conf.pull_down_en = GPIO_PULLDOWN_DISABLE; + conf.pull_up_en = GPIO_PULLUP_DISABLE; + gpio_config(&conf); + + // carefull, logic is inverted compared to reset pin + gpio_set_level(CAM_PIN_PWDN, 1); + vTaskDelay(1000 / portTICK_PERIOD_MS); + gpio_set_level(CAM_PIN_PWDN, 0); + vTaskDelay(1000 / portTICK_PERIOD_MS); +#endif } - esp_err_t handler_lightOn(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_lightOn - Start"); - ESP_LOGD(TAG, "handler_lightOn uri: %s", req->uri); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_lightOn - Start"); + ESP_LOGD(TAG, "handler_lightOn uri: %s", req->uri); +#endif - if (Camera.getCameraInitSuccessful()) + if (Camera.getCameraInitSuccessful()) { Camera.LightOnOff(true); - const char* resp_str = (const char*) req->user_ctx; + const char *resp_str = (const char *)req->user_ctx; httpd_resp_send(req, resp_str, strlen(resp_str)); } - else + else { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /lighton not available!"); return ESP_ERR_NOT_FOUND; } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_lightOn - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_lightOn - Done"); +#endif return ESP_OK; } - esp_err_t handler_lightOff(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_lightOff - Start"); - ESP_LOGD(TAG, "handler_lightOff uri: %s", req->uri); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_lightOff - Start"); + ESP_LOGD(TAG, "handler_lightOff uri: %s", req->uri); +#endif - if (Camera.getCameraInitSuccessful()) + if (Camera.getCameraInitSuccessful()) { Camera.LightOnOff(false); - const char* resp_str = (const char*) req->user_ctx; - httpd_resp_send(req, resp_str, strlen(resp_str)); + const char *resp_str = (const char *)req->user_ctx; + httpd_resp_send(req, resp_str, strlen(resp_str)); } - else + else { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /lightoff not available!"); return ESP_ERR_NOT_FOUND; } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_lightOff - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_lightOff - Done"); +#endif return ESP_OK; } - esp_err_t handler_capture(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_capture - Start"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_capture - Start"); +#endif - if (Camera.getCameraInitSuccessful()) + if (Camera.getCameraInitSuccessful()) { - int quality; - framesize_t res; - bool zoomEnabled; - int zoomMode; - int zoomOffsetX; - int zoomOffsetY; - - Camera.GetCameraParameter(req, quality, res, zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); - - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality); - #endif + // If the camera settings were changed by creating a new reference image, they must be reset + if (CFstatus.changedCameraSettings) + { + Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera + Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + CFstatus.changedCameraSettings = false; + } - Camera.SetQualitySize(quality, res, zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Size: %d, Quality: %d", CCstatus.ImageFrameSize, CCstatus.ImageQuality); +#endif esp_err_t result; result = Camera.CaptureToHTTP(req); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_capture - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_capture - Done"); +#endif return result; } - else + else { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /capture not available!"); return ESP_ERR_NOT_FOUND; } } - esp_err_t handler_capture_with_light(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_capture_with_light - Start"); - #endif - - if (Camera.getCameraInitSuccessful()) +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_capture_with_light - Start"); +#endif + + if (Camera.getCameraInitSuccessful()) { char _query[100]; char _delay[10]; - - int quality; - framesize_t res; - bool zoomEnabled; - int zoomMode; - int zoomOffsetX; - int zoomOffsetY; int delay = 2500; if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { ESP_LOGD(TAG, "Query: %s", _query); + if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Delay: %s", _delay); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Delay: %s", _delay); +#endif delay = atoi(_delay); if (delay < 0) + { delay = 0; + } } } - Camera.GetCameraParameter(req, quality, res, zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); + // If the camera settings were changed by creating a new reference image, they must be reset + if (CFstatus.changedCameraSettings) + { + Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera + Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + CFstatus.changedCameraSettings = false; + } - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Size: %d, Quality: %d", CCstatus.ImageFrameSize, CCstatus.ImageQuality); +#endif - Camera.SetQualitySize(quality, res, zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); Camera.LightOnOff(true); const TickType_t xDelay = delay / portTICK_PERIOD_MS; - vTaskDelay( xDelay ); + vTaskDelay(xDelay); esp_err_t result; - result = Camera.CaptureToHTTP(req); + result = Camera.CaptureToHTTP(req); Camera.LightOnOff(false); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_capture_with_light - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_capture_with_light - Done"); +#endif return result; } - else + else { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /capture_with_flashlight not available!"); return ESP_ERR_NOT_FOUND; } } - esp_err_t handler_capture_save_to_file(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_capture_save_to_file - Start"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_capture_save_to_file - Start"); +#endif - if (Camera.getCameraInitSuccessful()) + if (Camera.getCameraInitSuccessful()) { char _query[100]; char _delay[10]; @@ -205,98 +202,102 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req) char filename[100]; std::string fn = "/sdcard/"; - - int quality; - framesize_t res; - bool zoomEnabled; - int zoomMode; - int zoomOffsetX; - int zoomOffsetY; - if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { ESP_LOGD(TAG, "Query: %s", _query); + if (httpd_query_key_value(_query, "filename", filename, 100) == ESP_OK) { fn.append(filename); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Filename: %s", fn.c_str()); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Filename: %s", fn.c_str()); +#endif } else + { fn.append("noname.jpg"); + } if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Delay: %s", _delay); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Delay: %s", _delay); +#endif delay = atoi(_delay); if (delay < 0) + { delay = 0; + } } } else + { fn.append("noname.jpg"); + } + + // If the camera settings were changed by creating a new reference image, they must be reset + if (CFstatus.changedCameraSettings) + { + Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera + Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + CFstatus.changedCameraSettings = false; + } - Camera.GetCameraParameter(req, quality, res, zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality); - #endif - Camera.SetQualitySize(quality, res, zoomEnabled, zoomMode, zoomOffsetX, zoomOffsetY); +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Size: %d, Quality: %d", CCstatus.ImageFrameSize, CCstatus.ImageQuality); +#endif esp_err_t result; - result = Camera.CaptureToFile(fn, delay); + result = Camera.CaptureToFile(fn, delay); - const char* resp_str = (const char*) fn.c_str(); + const char *resp_str = (const char *)fn.c_str(); httpd_resp_send(req, resp_str, strlen(resp_str)); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_capture_save_to_file - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_capture_save_to_file - Done"); +#endif return result; } - else + else { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /save not available!"); return ESP_ERR_NOT_FOUND; } } - void register_server_camera_uri(httpd_handle_t server) { -#ifdef DEBUG_DETAIL_ON +#ifdef DEBUG_DETAIL_ON ESP_LOGI(TAG, "server_part_camera - Registering URI handlers"); #endif - httpd_uri_t camuri = { }; - camuri.method = HTTP_GET; + httpd_uri_t camuri = {}; + camuri.method = HTTP_GET; - camuri.uri = "/lighton"; - camuri.handler = handler_lightOn; - camuri.user_ctx = (void*) "Light On"; + camuri.uri = "/lighton"; + camuri.handler = handler_lightOn; + camuri.user_ctx = (void *)"Light On"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/lightoff"; - camuri.handler = handler_lightOff; - camuri.user_ctx = (void*) "Light Off"; - httpd_register_uri_handler(server, &camuri); - - camuri.uri = "/capture"; - camuri.handler = handler_capture; - camuri.user_ctx = NULL; - httpd_register_uri_handler(server, &camuri); - - camuri.uri = "/capture_with_flashlight"; - camuri.handler = handler_capture_with_light; - camuri.user_ctx = NULL; - httpd_register_uri_handler(server, &camuri); - - camuri.uri = "/save"; - camuri.handler = handler_capture_save_to_file; - camuri.user_ctx = NULL; - httpd_register_uri_handler(server, &camuri); + camuri.uri = "/lightoff"; + camuri.handler = handler_lightOff; + camuri.user_ctx = (void *)"Light Off"; + httpd_register_uri_handler(server, &camuri); + + camuri.uri = "/capture"; + camuri.handler = handler_capture; + camuri.user_ctx = NULL; + httpd_register_uri_handler(server, &camuri); + + camuri.uri = "/capture_with_flashlight"; + camuri.handler = handler_capture_with_light; + camuri.user_ctx = NULL; + httpd_register_uri_handler(server, &camuri); + + camuri.uri = "/save"; + camuri.handler = handler_capture_save_to_file; + camuri.user_ctx = NULL; + httpd_register_uri_handler(server, &camuri); } diff --git a/code/components/jomjol_controlcamera/server_camera.h b/code/components/jomjol_controlcamera/server_camera.h index 7bd79b89c..656b99eb2 100644 --- a/code/components/jomjol_controlcamera/server_camera.h +++ b/code/components/jomjol_controlcamera/server_camera.h @@ -10,7 +10,6 @@ //#include "ClassControllCamera.h" void register_server_camera_uri(httpd_handle_t server); - void PowerResetCamera(); #endif \ No newline at end of file diff --git a/code/components/jomjol_fileserver_ota/miniz/readme2.md b/code/components/jomjol_fileserver_ota/miniz/readme2.md index da2b7ea1f..64c696103 100644 --- a/code/components/jomjol_fileserver_ota/miniz/readme2.md +++ b/code/components/jomjol_fileserver_ota/miniz/readme2.md @@ -4,5 +4,5 @@ It should be possible to include the repo directly as a submodule, how ever it c - https://github.com/richgel999/miniz/issues/145 - https://github.com/espressif/esptool/pull/500#issuecomment-574879468 - For sumplicity we therefore use the release files as suggested in the readme. - Additionally we added the CMakeLists.txt and this readme. \ No newline at end of file + For simplicity we therefore use the release files as suggested in the readme. + Additionally we added the CMakeLists.txt and this readme. diff --git a/code/components/jomjol_flowcontroll/CMakeLists.txt b/code/components/jomjol_flowcontroll/CMakeLists.txt index 2b58ada94..2df515fc7 100644 --- a/code/components/jomjol_flowcontroll/CMakeLists.txt +++ b/code/components/jomjol_flowcontroll/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES esp_timer esp_wifi jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_influxdb jomjol_fileserver_ota jomjol_image_proc jomjol_wlan) + REQUIRES esp_timer esp_wifi jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_influxdb jomjol_webhook jomjol_fileserver_ota jomjol_image_proc jomjol_wlan openmetrics) diff --git a/code/components/jomjol_flowcontroll/ClassFlow.cpp b/code/components/jomjol_flowcontroll/ClassFlow.cpp index 0de7428d8..858c95244 100644 --- a/code/components/jomjol_flowcontroll/ClassFlow.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlow.cpp @@ -67,11 +67,6 @@ string ClassFlow::getHTMLSingleStep(string host){ return ""; } -string ClassFlow::getReadout() -{ - return string(); -} - std::string ClassFlow::GetParameterName(std::string _input) { string _param; diff --git a/code/components/jomjol_flowcontroll/ClassFlow.h b/code/components/jomjol_flowcontroll/ClassFlow.h index 52f5c72c8..9c826c11a 100644 --- a/code/components/jomjol_flowcontroll/ClassFlow.h +++ b/code/components/jomjol_flowcontroll/ClassFlow.h @@ -46,7 +46,6 @@ class ClassFlow virtual bool ReadParameter(FILE* pfile, string &aktparamgraph); virtual bool doFlow(string time); virtual string getHTMLSingleStep(string host); - virtual string getReadout(); virtual string name(){return "ClassFlow";}; }; diff --git a/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp b/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp index 235e3df50..2324fd3cf 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp @@ -1,393 +1,374 @@ -#include "ClassFlowAlignment.h" -#include "ClassFlowTakeImage.h" -#include "ClassFlow.h" -#include "MainFlowControl.h" - -#include "CRotateImage.h" -#include "esp_log.h" - - -#include "ClassLogFile.h" -#include "psram.h" -#include "../../include/defines.h" - - -static const char *TAG = "ALIGN"; - -// #define DEBUG_DETAIL_ON - - -void ClassFlowAlignment::SetInitialParameter(void) -{ - initialrotate = 0; - anz_ref = 0; - initialmirror = false; - use_antialiasing = false; - initialflip = false; - SaveAllFiles = false; - namerawimage = "/sdcard/img_tmp/raw.jpg"; - FileStoreRefAlignment = "/sdcard/config/align.txt"; - ListFlowControll = NULL; - AlignAndCutImage = NULL; - ImageBasis = NULL; - ImageTMP = NULL; - #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG - AlgROI = (ImageData*)malloc_psram_heap(std::string(TAG) + "->AlgROI", sizeof(ImageData), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - #endif - previousElement = NULL; - disabled = false; - SAD_criteria = 0.05; -} - - -ClassFlowAlignment::ClassFlowAlignment(std::vector* lfc) -{ - SetInitialParameter(); - ListFlowControll = lfc; - - for (int i = 0; i < ListFlowControll->size(); ++i) - { - if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) - { - ImageBasis = ((ClassFlowTakeImage*) (*ListFlowControll)[i])->rawImage; - } - } - - if (!ImageBasis) // the function take pictures does not exist --> must be created first ONLY FOR TEST PURPOSES - { - ESP_LOGD(TAG, "CImageBasis had to be created"); - ImageBasis = new CImageBasis("ImageBasis", namerawimage); - } -} - - -bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph) -{ - std::vector splitted; - int suchex = 40; - int suchey = 40; - int alg_algo = 0; //default=0; 1 =HIGHACCURACY; 2= FAST; 3= OFF //add disable aligment algo |01.2023 - - - aktparamgraph = trim(aktparamgraph); - - if (aktparamgraph.size() == 0) - if (!this->GetNextParagraph(pfile, aktparamgraph)) - return false; - - if (aktparamgraph.compare("[Alignment]") != 0) //Paragraph does not fit Alignment - return false; - - while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) - { - splitted = ZerlegeZeile(aktparamgraph); - if ((toUpper(splitted[0]) == "FLIPIMAGESIZE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - initialflip = true; - } - if ((toUpper(splitted[0]) == "INITIALMIRROR") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - initialmirror = true; - } - if (((toUpper(splitted[0]) == "initialrotate") || (toUpper(splitted[0]) == "INITIALROTATE")) && (splitted.size() > 1)) - { - this->initialrotate = std::stod(splitted[1]); - } - if ((toUpper(splitted[0]) == "SEARCHFIELDX") && (splitted.size() > 1)) - { - suchex = std::stod(splitted[1]); - } - if ((toUpper(splitted[0]) == "SEARCHFIELDY") && (splitted.size() > 1)) - { - suchey = std::stod(splitted[1]); - } - if ((toUpper(splitted[0]) == "ANTIALIASING") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - use_antialiasing = true; - } - if ((splitted.size() == 3) && (anz_ref < 2)) - { - References[anz_ref].image_file = FormatFileName("/sdcard" + splitted[0]); - References[anz_ref].target_x = std::stod(splitted[1]); - References[anz_ref].target_y = std::stod(splitted[2]); - anz_ref++; - } - - if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - SaveAllFiles = true; - } - if ((toUpper(splitted[0]) == "ALIGNMENTALGO") && (splitted.size() > 1)) - { - #ifdef DEBUG_DETAIL_ON - std::string zw2 = "Alignment mode selected: " + splitted[1]; - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw2); - #endif - if (toUpper(splitted[1]) == "HIGHACCURACY") - alg_algo = 1; - if (toUpper(splitted[1]) == "FAST") - alg_algo = 2; - if (toUpper(splitted[1]) == "OFF") //no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 - alg_algo = 3; - } - } - - for (int i = 0; i < anz_ref; ++i) - { - References[i].search_x = suchex; - References[i].search_y = suchey; - References[i].fastalg_SAD_criteria = SAD_criteria; - References[i].alignment_algo = alg_algo; - #ifdef DEBUG_DETAIL_ON - std::string zw2 = "Alignment mode written: " + std::to_string(alg_algo); - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw2); - #endif - } - - //no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 - if(References[0].alignment_algo != 3){ - LoadReferenceAlignmentValues(); - } - - return true; - -} - - -string ClassFlowAlignment::getHTMLSingleStep(string host) -{ - string result; - - result = "

Rotated Image:

\n"; - result = result + "

Found Alignment:

\n"; - result = result + "

Aligned Image:

\n"; - return result; -} - - -bool ClassFlowAlignment::doFlow(string time) -{ - #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG - if (!AlgROI) // AlgROI needs to be allocated before ImageTMP to avoid heap fragmentation - { - AlgROI = (ImageData*)heap_caps_realloc(AlgROI, sizeof(ImageData), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - if (!AlgROI) - { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't allocate AlgROI"); - LogFile.WriteHeapInfo("ClassFlowAlignment-doFlow"); - } - } - - if (AlgROI) - { - ImageBasis->writeToMemoryAsJPG((ImageData*)AlgROI, 90); - } - #endif - - if (!ImageTMP) - { - ImageTMP = new CImageBasis("tmpImage", ImageBasis); // Make sure the name does not get change, it is relevant for the PSRAM allocation! - if (!ImageTMP) - { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't allocate tmpImage -> Exec this round aborted!"); - LogFile.WriteHeapInfo("ClassFlowAlignment-doFlow"); - return false; - } - } - - delete AlignAndCutImage; - AlignAndCutImage = new CAlignAndCutImage("AlignAndCutImage", ImageBasis, ImageTMP); - if (!AlignAndCutImage) - { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't allocate AlignAndCutImage -> Exec this round aborted!"); - LogFile.WriteHeapInfo("ClassFlowAlignment-doFlow"); - return false; - } - - CRotateImage rt("rawImage", AlignAndCutImage, ImageTMP, initialflip); - if (initialflip) - { - int _zw = ImageBasis->height; - ImageBasis->height = ImageBasis->width; - ImageBasis->width = _zw; - - _zw = ImageTMP->width; - ImageTMP->width = ImageTMP->height; - ImageTMP->height = _zw; - } - - if (initialmirror) - { - ESP_LOGD(TAG, "do mirror"); - rt.Mirror(); - - if (SaveAllFiles) - AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/mirror.jpg")); - } - - if ((initialrotate != 0) || initialflip) - { - if (use_antialiasing) - rt.RotateAntiAliasing(initialrotate); - else - rt.Rotate(initialrotate); - - if (SaveAllFiles) - AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/rot.jpg")); - } - - - //no align algo if set to 3 = off //add disable aligment algo |01.2023 - if(References[0].alignment_algo != 3){ - if (!AlignAndCutImage->Align(&References[0], &References[1])) - { - SaveReferenceAlignmentValues(); - } - }// no align - - - #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG - if (AlgROI) { - //no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 - if(References[0].alignment_algo != 3){ - DrawRef(ImageTMP); - } - flowctrl.DigitalDrawROI(ImageTMP); - flowctrl.AnalogDrawROI(ImageTMP); - ImageTMP->writeToMemoryAsJPG((ImageData*)AlgROI, 90); - } - #endif - - if (SaveAllFiles) - { - AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg")); - ImageTMP->SaveToFile(FormatFileName("/sdcard/img_tmp/alg_roi.jpg")); - } - - // must be deleted to have memory space for loading tflite - delete ImageTMP; - ImageTMP = NULL; - - //no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 - if(References[0].alignment_algo != 3){ - LoadReferenceAlignmentValues(); - } - - return true; -} - - -void ClassFlowAlignment::SaveReferenceAlignmentValues() -{ - FILE* pFile; - std::string zwtime, zwvalue; - - pFile = fopen(FileStoreRefAlignment.c_str(), "w"); - - if (strlen(zwtime.c_str()) == 0) - { - time_t rawtime; - struct tm* timeinfo; - char buffer[80]; - - time(&rawtime); - timeinfo = localtime(&rawtime); - - strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo); - zwtime = std::string(buffer); - } - - fputs(zwtime.c_str(), pFile); - fputs("\n", pFile); - - zwvalue = std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_y); - zwvalue = zwvalue + "\t" +std::to_string(References[0].fastalg_SAD)+ "\t" +std::to_string(References[0].fastalg_min); - zwvalue = zwvalue + "\t" +std::to_string(References[0].fastalg_max)+ "\t" +std::to_string(References[0].fastalg_avg); - fputs(zwvalue.c_str(), pFile); - fputs("\n", pFile); - - zwvalue = std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_y); - zwvalue = zwvalue + "\t" +std::to_string(References[1].fastalg_SAD)+ "\t" +std::to_string(References[1].fastalg_min); - zwvalue = zwvalue + "\t" +std::to_string(References[1].fastalg_max)+ "\t" +std::to_string(References[1].fastalg_avg); - fputs(zwvalue.c_str(), pFile); - fputs("\n", pFile); - - fclose(pFile); -} - - -bool ClassFlowAlignment::LoadReferenceAlignmentValues(void) -{ - FILE* pFile; - char zw[1024]; - string zwvalue; - std::vector splitted; - - - pFile = fopen(FileStoreRefAlignment.c_str(), "r"); - if (pFile == NULL) - return false; - - fgets(zw, 1024, pFile); - ESP_LOGD(TAG, "%s", zw); - - fgets(zw, 1024, pFile); - splitted = ZerlegeZeile(std::string(zw), " \t"); - if (splitted.size() < 6) - { - fclose(pFile); - return false; - } - - References[0].fastalg_x = stoi(splitted[0]); - References[0].fastalg_y = stoi(splitted[1]); - References[0].fastalg_SAD = stof(splitted[2]); - References[0].fastalg_min = stoi(splitted[3]); - References[0].fastalg_max = stoi(splitted[4]); - References[0].fastalg_avg = stof(splitted[5]); - - fgets(zw, 1024, pFile); - splitted = ZerlegeZeile(std::string(zw)); - if (splitted.size() < 6) - { - fclose(pFile); - return false; - } - - References[1].fastalg_x = stoi(splitted[0]); - References[1].fastalg_y = stoi(splitted[1]); - References[1].fastalg_SAD = stof(splitted[2]); - References[1].fastalg_min = stoi(splitted[3]); - References[1].fastalg_max = stoi(splitted[4]); - References[1].fastalg_avg = stof(splitted[5]); - - fclose(pFile); - - - /*#ifdef DEBUG_DETAIL_ON - std::string _zw = "\tLoadReferences[0]\tx,y:\t" + std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_x); - _zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[0].fastalg_SAD) + "\t" + std::to_string(References[0].fastalg_min); - _zw = _zw + "\t" + std::to_string(References[0].fastalg_max) + "\t" + std::to_string(References[0].fastalg_avg); - LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw); - _zw = "\tLoadReferences[1]\tx,y:\t" + std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_x); - _zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[1].fastalg_SAD) + "\t" + std::to_string(References[1].fastalg_min); - _zw = _zw + "\t" + std::to_string(References[1].fastalg_max) + "\t" + std::to_string(References[1].fastalg_avg); - LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw); - #endif*/ - - return true; -} - - -void ClassFlowAlignment::DrawRef(CImageBasis *_zw) -{ - if (_zw->ImageOkay()) - { - _zw->drawRect(References[0].target_x, References[0].target_y, References[0].width, References[0].height, 255, 0, 0, 2); - _zw->drawRect(References[1].target_x, References[1].target_y, References[1].width, References[1].height, 255, 0, 0, 2); - } -} +#include "ClassFlowAlignment.h" +#include "ClassFlowTakeImage.h" +#include "ClassFlow.h" +#include "MainFlowControl.h" + +#include "CRotateImage.h" +#include "esp_log.h" + +#include "ClassLogFile.h" +#include "psram.h" +#include "../../include/defines.h" + +static const char *TAG = "ALIGN"; + +// #define DEBUG_DETAIL_ON + +void ClassFlowAlignment::SetInitialParameter(void) +{ + initialrotate = 0; + anz_ref = 0; + use_antialiasing = false; + initialflip = false; + SaveAllFiles = false; + namerawimage = "/sdcard/img_tmp/raw.jpg"; + FileStoreRefAlignment = "/sdcard/config/align.txt"; + ListFlowControll = NULL; + AlignAndCutImage = NULL; + ImageBasis = NULL; + ImageTMP = NULL; +#ifdef ALGROI_LOAD_FROM_MEM_AS_JPG + AlgROI = (ImageData *)malloc_psram_heap(std::string(TAG) + "->AlgROI", sizeof(ImageData), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); +#endif + previousElement = NULL; + disabled = false; + SAD_criteria = 0.05; +} + +ClassFlowAlignment::ClassFlowAlignment(std::vector *lfc) +{ + SetInitialParameter(); + ListFlowControll = lfc; + + for (int i = 0; i < ListFlowControll->size(); ++i) { + if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) { + ImageBasis = ((ClassFlowTakeImage *)(*ListFlowControll)[i])->rawImage; + } + } + + // the function take pictures does not exist --> must be created first ONLY FOR TEST PURPOSES + if (!ImageBasis) { + ESP_LOGD(TAG, "CImageBasis had to be created"); + ImageBasis = new CImageBasis("ImageBasis", namerawimage); + } +} + +bool ClassFlowAlignment::ReadParameter(FILE *pfile, string &aktparamgraph) +{ + std::vector splitted; + int suchex = 40; + int suchey = 40; + int alg_algo = 0; // default=0; 1 =HIGHACCURACY; 2= FAST; 3= OFF //add disable aligment algo |01.2023 + + aktparamgraph = trim(aktparamgraph); + + if (aktparamgraph.size() == 0) + { + if (!this->GetNextParagraph(pfile, aktparamgraph)) { + return false; + } + } + + if (aktparamgraph.compare("[Alignment]") != 0) + { + // Paragraph does not fit Alignment + return false; + } + + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) + { + splitted = ZerlegeZeile(aktparamgraph); + + if ((toUpper(splitted[0]) == "FLIPIMAGESIZE") && (splitted.size() > 1)) { + initialflip = alphanumericToBoolean(splitted[1]); + } + else if (((toUpper(splitted[0]) == "initialrotate") || (toUpper(splitted[0]) == "INITIALROTATE")) && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) { + this->initialrotate = std::stod(splitted[1]); + } + } + else if ((toUpper(splitted[0]) == "SEARCHFIELDX") && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) { + suchex = std::stod(splitted[1]); + } + } + else if ((toUpper(splitted[0]) == "SEARCHFIELDY") && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) { + suchey = std::stod(splitted[1]); + } + } + else if ((toUpper(splitted[0]) == "ANTIALIASING") && (splitted.size() > 1)) { + use_antialiasing = alphanumericToBoolean(splitted[1]); + } + else if ((splitted.size() == 3) && (anz_ref < 2)) { + if ((isStringNumeric(splitted[1])) && (isStringNumeric(splitted[2]))) + { + References[anz_ref].image_file = FormatFileName("/sdcard" + splitted[0]); + References[anz_ref].target_x = std::stod(splitted[1]); + References[anz_ref].target_y = std::stod(splitted[2]); + anz_ref++; + } + else + { + References[anz_ref].image_file = FormatFileName("/sdcard" + splitted[0]); + References[anz_ref].target_x = 10; + References[anz_ref].target_y = 10; + anz_ref++; + } + } + + else if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) { + SaveAllFiles = alphanumericToBoolean(splitted[1]); + } + else if ((toUpper(splitted[0]) == "ALIGNMENTALGO") && (splitted.size() > 1)) { +#ifdef DEBUG_DETAIL_ON + std::string zw2 = "Alignment mode selected: " + splitted[1]; + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw2); +#endif + if (toUpper(splitted[1]) == "HIGHACCURACY") { + alg_algo = 1; + } + if (toUpper(splitted[1]) == "FAST") { + alg_algo = 2; + } + if (toUpper(splitted[1]) == "OFF") { + // no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 + alg_algo = 3; + } + } + } + + for (int i = 0; i < anz_ref; ++i) { + References[i].search_x = suchex; + References[i].search_y = suchey; + References[i].fastalg_SAD_criteria = SAD_criteria; + References[i].alignment_algo = alg_algo; +#ifdef DEBUG_DETAIL_ON + std::string zw2 = "Alignment mode written: " + std::to_string(alg_algo); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zw2); +#endif + } + + // no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 + if (References[0].alignment_algo != 3) { + return LoadReferenceAlignmentValues(); + } + + return true; +} + +string ClassFlowAlignment::getHTMLSingleStep(string host) +{ + string result; + + result = "

Rotated Image:

\n"; + result = result + "

Found Alignment:

\n"; + result = result + "

Aligned Image:

\n"; + return result; +} + +bool ClassFlowAlignment::doFlow(string time) +{ +#ifdef ALGROI_LOAD_FROM_MEM_AS_JPG + // AlgROI needs to be allocated before ImageTMP to avoid heap fragmentation + if (!AlgROI) { + AlgROI = (ImageData *)heap_caps_realloc(AlgROI, sizeof(ImageData), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + + if (!AlgROI) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't allocate AlgROI"); + LogFile.WriteHeapInfo("ClassFlowAlignment-doFlow"); + } + } + + if (AlgROI) { + ImageBasis->writeToMemoryAsJPG((ImageData *)AlgROI, 90); + } +#endif + + if (!ImageTMP) { + ImageTMP = new CImageBasis("tmpImage", ImageBasis); // Make sure the name does not get change, it is relevant for the PSRAM allocation! + + if (!ImageTMP) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't allocate tmpImage -> Exec this round aborted!"); + LogFile.WriteHeapInfo("ClassFlowAlignment-doFlow"); + return false; + } + } + + delete AlignAndCutImage; + AlignAndCutImage = new CAlignAndCutImage("AlignAndCutImage", ImageBasis, ImageTMP); + + if (!AlignAndCutImage) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't allocate AlignAndCutImage -> Exec this round aborted!"); + LogFile.WriteHeapInfo("ClassFlowAlignment-doFlow"); + return false; + } + + CRotateImage rt("rawImage", AlignAndCutImage, ImageTMP, initialflip); + + if (initialflip) { + int _zw = ImageBasis->height; + ImageBasis->height = ImageBasis->width; + ImageBasis->width = _zw; + + _zw = ImageTMP->width; + ImageTMP->width = ImageTMP->height; + ImageTMP->height = _zw; + } + + if ((initialrotate != 0) || initialflip) { + if (use_antialiasing) { + rt.RotateAntiAliasing(initialrotate); + } + else { + rt.Rotate(initialrotate); + } + + if (SaveAllFiles) { + AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/rot.jpg")); + } + } + + // no align algo if set to 3 = off //add disable aligment algo |01.2023 + if (References[0].alignment_algo != 3) { + if (!AlignAndCutImage->Align(&References[0], &References[1])) { + SaveReferenceAlignmentValues(); + } + } // no align + +#ifdef ALGROI_LOAD_FROM_MEM_AS_JPG + if (AlgROI) { + // no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 + if (References[0].alignment_algo != 3) { + DrawRef(ImageTMP); + } + + flowctrl.DigitDrawROI(ImageTMP); + flowctrl.AnalogDrawROI(ImageTMP); + ImageTMP->writeToMemoryAsJPG((ImageData *)AlgROI, 90); + } +#endif + + if (SaveAllFiles) { + AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg")); + ImageTMP->SaveToFile(FormatFileName("/sdcard/img_tmp/alg_roi.jpg")); + } + + // must be deleted to have memory space for loading tflite + delete ImageTMP; + ImageTMP = NULL; + + // no align algo if set to 3 = off => no draw ref //add disable aligment algo |01.2023 + if (References[0].alignment_algo != 3) { + return LoadReferenceAlignmentValues(); + } + + return true; +} + +void ClassFlowAlignment::SaveReferenceAlignmentValues() +{ + FILE *pFile; + std::string zwtime, zwvalue; + + pFile = fopen(FileStoreRefAlignment.c_str(), "w"); + + if (strlen(zwtime.c_str()) == 0) { + time_t rawtime; + struct tm *timeinfo; + char buffer[80]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo); + zwtime = std::string(buffer); + } + + fputs(zwtime.c_str(), pFile); + fputs("\n", pFile); + + zwvalue = std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_y); + zwvalue = zwvalue + "\t" + std::to_string(References[0].fastalg_SAD) + "\t" + std::to_string(References[0].fastalg_min); + zwvalue = zwvalue + "\t" + std::to_string(References[0].fastalg_max) + "\t" + std::to_string(References[0].fastalg_avg); + fputs(zwvalue.c_str(), pFile); + fputs("\n", pFile); + + zwvalue = std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_y); + zwvalue = zwvalue + "\t" + std::to_string(References[1].fastalg_SAD) + "\t" + std::to_string(References[1].fastalg_min); + zwvalue = zwvalue + "\t" + std::to_string(References[1].fastalg_max) + "\t" + std::to_string(References[1].fastalg_avg); + fputs(zwvalue.c_str(), pFile); + fputs("\n", pFile); + + fclose(pFile); +} + +bool ClassFlowAlignment::LoadReferenceAlignmentValues(void) +{ + FILE *pFile; + char zw[1024]; + string zwvalue; + std::vector splitted; + + pFile = fopen(FileStoreRefAlignment.c_str(), "r"); + + if (pFile == NULL) { + return false; + } + + fgets(zw, 1024, pFile); + ESP_LOGD(TAG, "%s", zw); + + fgets(zw, 1024, pFile); + splitted = ZerlegeZeile(std::string(zw), " \t"); + + if (splitted.size() < 6) { + fclose(pFile); + return false; + } + + References[0].fastalg_x = stoi(splitted[0]); + References[0].fastalg_y = stoi(splitted[1]); + References[0].fastalg_SAD = stof(splitted[2]); + References[0].fastalg_min = stoi(splitted[3]); + References[0].fastalg_max = stoi(splitted[4]); + References[0].fastalg_avg = stof(splitted[5]); + + fgets(zw, 1024, pFile); + splitted = ZerlegeZeile(std::string(zw)); + + if (splitted.size() < 6) { + fclose(pFile); + return false; + } + + References[1].fastalg_x = stoi(splitted[0]); + References[1].fastalg_y = stoi(splitted[1]); + References[1].fastalg_SAD = stof(splitted[2]); + References[1].fastalg_min = stoi(splitted[3]); + References[1].fastalg_max = stoi(splitted[4]); + References[1].fastalg_avg = stof(splitted[5]); + + fclose(pFile); + + /*#ifdef DEBUG_DETAIL_ON + std::string _zw = "\tLoadReferences[0]\tx,y:\t" + std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_x); + _zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[0].fastalg_SAD) + "\t" + std::to_string(References[0].fastalg_min); + _zw = _zw + "\t" + std::to_string(References[0].fastalg_max) + "\t" + std::to_string(References[0].fastalg_avg); + LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw); + _zw = "\tLoadReferences[1]\tx,y:\t" + std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_x); + _zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[1].fastalg_SAD) + "\t" + std::to_string(References[1].fastalg_min); + _zw = _zw + "\t" + std::to_string(References[1].fastalg_max) + "\t" + std::to_string(References[1].fastalg_avg); + LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw); + #endif*/ + + return true; +} + +void ClassFlowAlignment::DrawRef(CImageBasis *_zw) +{ + if (_zw->ImageOkay()) { + _zw->drawRect(References[0].target_x, References[0].target_y, References[0].width, References[0].height, 255, 0, 0, 2); + _zw->drawRect(References[1].target_x, References[1].target_y, References[1].width, References[1].height, 255, 0, 0, 2); + } +} diff --git a/code/components/jomjol_flowcontroll/ClassFlowAlignment.h b/code/components/jomjol_flowcontroll/ClassFlowAlignment.h index e7a1591fe..2d0944cbf 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowAlignment.h +++ b/code/components/jomjol_flowcontroll/ClassFlowAlignment.h @@ -1,54 +1,51 @@ -#pragma once - -#ifndef CLASSFLOWALIGNMENT_H -#define CLASSFLOWALIGNMENT_H - -#include "ClassFlow.h" -#include "Helper.h" -#include "CAlignAndCutImage.h" -#include "CFindTemplate.h" - -#include - -using namespace std; - -class ClassFlowAlignment : - public ClassFlow -{ -protected: - float initialrotate; - bool initialmirror; - bool initialflip; - bool use_antialiasing; - RefInfo References[2]; - int anz_ref; - string namerawimage; - bool SaveAllFiles; - CAlignAndCutImage *AlignAndCutImage; - std::string FileStoreRefAlignment; - float SAD_criteria; - - void SetInitialParameter(void); - bool LoadReferenceAlignmentValues(void); - void SaveReferenceAlignmentValues(); - -public: - CImageBasis *ImageBasis, *ImageTMP; - #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG - ImageData *AlgROI; - #endif - - ClassFlowAlignment(std::vector* lfc); - - CAlignAndCutImage* GetAlignAndCutImage(){return AlignAndCutImage;}; - - void DrawRef(CImageBasis *_zw); - - bool ReadParameter(FILE* pfile, string& aktparamgraph); - bool doFlow(string time); - string getHTMLSingleStep(string host); - string name(){return "ClassFlowAlignment";}; -}; - - -#endif //CLASSFLOWALIGNMENT_H +#pragma once + +#ifndef CLASSFLOWALIGNMENT_H +#define CLASSFLOWALIGNMENT_H + +#include "ClassFlow.h" +#include "Helper.h" +#include "CAlignAndCutImage.h" +#include "CFindTemplate.h" + +#include + +using namespace std; + +class ClassFlowAlignment : public ClassFlow +{ +protected: + float initialrotate; + bool initialflip; + bool use_antialiasing; + RefInfo References[2]; + int anz_ref; + string namerawimage; + bool SaveAllFiles; + CAlignAndCutImage *AlignAndCutImage; + std::string FileStoreRefAlignment; + float SAD_criteria; + + void SetInitialParameter(void); + bool LoadReferenceAlignmentValues(void); + void SaveReferenceAlignmentValues(); + +public: + CImageBasis *ImageBasis, *ImageTMP; +#ifdef ALGROI_LOAD_FROM_MEM_AS_JPG + ImageData *AlgROI; +#endif + + ClassFlowAlignment(std::vector *lfc); + + CAlignAndCutImage *GetAlignAndCutImage() { return AlignAndCutImage; }; + + void DrawRef(CImageBasis *_zw); + + bool ReadParameter(FILE *pfile, string &aktparamgraph); + bool doFlow(string time); + string getHTMLSingleStep(string host); + string name() { return "ClassFlowAlignment"; }; +}; + +#endif // CLASSFLOWALIGNMENT_H diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 4eb3544a2..146063f3d 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -19,7 +19,6 @@ static const char* TAG = "CNN"; static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM #endif - ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG) { string cnnmodelfile = ""; modelxsize = 1; @@ -36,8 +35,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy imagesRetention = 5; } - -string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _before_narrow_Analog, float analogDigitalTransitionStart) { +string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _before_narrow_Analog, float AnalogToDigitTransitionStart) { string result = ""; if (GENERAL[_analog]->ROI.size() == 0) { @@ -65,7 +63,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } - if (CNNType == Digital) { + if (CNNType == Digit) { for (int i = 0; i < GENERAL[_analog]->ROI.size(); ++i) { if (GENERAL[_analog]->ROI[i]->result_klasse >= 10) { result = result + "N"; @@ -77,7 +75,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } - if ((CNNType == DoubleHyprid10) || (CNNType == Digital100)) { + if ((CNNType == DoubleHyprid10) || (CNNType == Digit100)) { float number = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float; // NaN? if (number >= 0) { @@ -92,7 +90,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution } else { if (_before_narrow_Analog >= 0) { - prev = PointerEvalHybridNew(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _before_narrow_Analog, prev, true, analogDigitalTransitionStart); + prev = PointerEvalHybridNew(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _before_narrow_Analog, prev, true, AnalogToDigitTransitionStart); } else { prev = PointerEvalHybridNew(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev, prev); @@ -103,7 +101,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution } else { result = "N"; - if (_extendedResolution && (CNNType != Digital)) { + if (_extendedResolution && (CNNType != Digit)) { result = "NN"; } } @@ -137,13 +135,13 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution * 0.1 => 0 (eval_predecessors) * The 0 makes a 9.9 to 0 (eval_predecessors) * The 0 makes a 9.8 to 0 - * @param Analog_Predecessors false/true if the last ROI is an analog or digital ROI (default=false) + * @param Analog_Predecessors false/true if the last ROI is an analog or digit ROI (default=false) * runs in special handling because analog is much less precise - * @param digitalAnalogTransitionStart start of the transitionlogic begins on number_of_predecessor (default=9.2) + * @param digitAnalogTransitionStart start of the transitionlogic begins on number_of_predecessor (default=9.2) * * @return int the determined number of the current ROI */ -int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors, float digitalAnalogTransitionStart) { +int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors, float digitAnalogTransitionStart) { int result; int result_after_decimal_point = ((int) floor(number * 10)) % 10; int result_before_decimal_point = ((int) floor(number) + 10) % 10; @@ -155,21 +153,21 @@ int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_pred result = (int) ((int) trunc(round((number+10 % 10)*100)) ) / 100; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybridNew - No predecessor - Result = " + std::to_string(result) + - " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digital_Uncertainty = " + std::to_string(Digital_Uncertainty)); + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty)); return result; } if (Analog_Predecessors) { - result = PointerEvalAnalogToDigitNew(number, number_of_predecessors, eval_predecessors, digitalAnalogTransitionStart); + result = PointerEvalAnalogToDigitNew(number, number_of_predecessors, eval_predecessors, digitAnalogTransitionStart); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybridNew - Analog predecessor, evaluation over PointerEvalAnalogNew = " + std::to_string(result) + - " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digital_Uncertainty = " + std::to_string(Digital_Uncertainty)); + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty)); return result; } - if ((number_of_predecessors >= Digital_Transition_Area_Predecessor ) && (number_of_predecessors <= (10.0 - Digital_Transition_Area_Predecessor))) { - // no digit change, because predecessor is far enough away (0+/-DigitalTransitionRangePredecessor) --> number is rounded + if ((number_of_predecessors >= Digit_Transition_Area_Predecessor ) && (number_of_predecessors <= (10.0 - Digit_Transition_Area_Predecessor))) { + // no digit change, because predecessor is far enough away (0+/-DigitTransitionRangePredecessor) --> number is rounded // Band around the digit --> Round off, as digit reaches inaccuracy in the frame - if ((result_after_decimal_point <= DigitalBand) || (result_after_decimal_point >= (10-DigitalBand))) { + if ((result_after_decimal_point <= DigitBand) || (result_after_decimal_point >= (10-DigitBand))) { result = ((int) round(number) + 10) % 10; } else { @@ -177,7 +175,7 @@ int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_pred } LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybridNew - NO analogue predecessor, no change of digits, as pre-decimal point far enough away = " + std::to_string(result) + - " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digital_Uncertainty = " + std::to_string(Digital_Uncertainty)); + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty)); return result; } @@ -194,17 +192,16 @@ int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_pred result = result_before_decimal_point % 10; } LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybridNew - NO analogue predecessor, zero crossing has taken placen = " + std::to_string(result) + - " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digital_Uncertainty = " + std::to_string(Digital_Uncertainty)); + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty)); return result; } - // remains only >= 9.x --> no zero crossing yet --> 2.8 --> 2, - // and from 9.7(DigitalTransitionRangeLead) 3.1 --> 2 + // and from 9.7(DigitTransitionRangeLead) 3.1 --> 2 // everything >=x.4 can be considered as current number in transition. With 9.x predecessor the current // number can still be x.6 - x.7. // Preceding (else - branch) does not already happen from 9. - if (Digital_Transition_Area_Forward>=number_of_predecessors || result_after_decimal_point >= 4) { + if (Digit_Transition_Area_Forward>=number_of_predecessors || result_after_decimal_point >= 4) { // The current digit, like the previous digit, does not yet have a zero crossing. result = result_before_decimal_point % 10; } @@ -215,40 +212,39 @@ int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_pred } LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybridNew - O analogue predecessor, >= 9.5 --> no zero crossing yet = " + std::to_string(result) + - " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digital_Uncertainty = " + std::to_string(Digital_Uncertainty) + " result_after_decimal_point = " + std::to_string(result_after_decimal_point)); + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors)+ " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty) + " result_after_decimal_point = " + std::to_string(result_after_decimal_point)); return result; } - -int ClassFlowCNNGeneral::PointerEvalAnalogToDigitNew(float number, float numeral_preceder, int eval_predecessors, float analogDigitalTransitionStart) { +int ClassFlowCNNGeneral::PointerEvalAnalogToDigitNew(float number, float numeral_preceder, int eval_predecessors, float AnalogToDigitTransitionStart) { int result; int result_after_decimal_point = ((int) floor(number * 10)) % 10; int result_before_decimal_point = ((int) floor(number) + 10) % 10; bool roundedUp = false; - // Within the digital inequalities - if ((result_after_decimal_point >= (10-Digital_Uncertainty * 10)) // Band around the digit --> Round off, as digit reaches inaccuracy in the frame + // Within the digit inequalities + if ((result_after_decimal_point >= (10-Digit_Uncertainty * 10)) // Band around the digit --> Round off, as digit reaches inaccuracy in the frame || (eval_predecessors <= 4 && result_after_decimal_point>=6)) { // or digit runs after (analogue =0..4, digit >=6) result = (int) (round(number) + 10) % 10; roundedUp = true; // before/ after decimal point, because we adjust the number based on the uncertainty. result_after_decimal_point = ((int) floor(result * 10)) % 10; result_before_decimal_point = ((int) floor(result) + 10) % 10; - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigitNew - Digital Uncertainty - Result = " + std::to_string(result) + + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigitNew - Digit Uncertainty - Result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder: " + std::to_string(numeral_preceder) + " erg before comma: " + std::to_string(result_before_decimal_point) + " erg after comma: " + std::to_string(result_after_decimal_point)); } else { result = (int) ((int) trunc(number) + 10) % 10; - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigitNew - NO digital Uncertainty - Result = " + std::to_string(result) + + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigitNew - NO digit Uncertainty - Result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder)); } // No zero crossing has taken place. // Only eval_predecessors used because numeral_preceder could be wrong here. // numeral_preceder<=0.1 & eval_predecessors=9 corresponds to analogue was reset because of previous analogue that are not yet at 0. - if ((eval_predecessors>=6 && (numeral_preceder>analogDigitalTransitionStart || numeral_preceder<=0.2) && roundedUp)) { + if ((eval_predecessors>=6 && (numeral_preceder>AnalogToDigitTransitionStart || numeral_preceder<=0.2) && roundedUp)) { result = ((result_before_decimal_point+10) - 1) % 10; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigitNew - Nulldurchgang noch nicht stattgefunden = " + std::to_string(result) + " number: " + std::to_string(number) + @@ -259,7 +255,6 @@ int ClassFlowCNNGeneral::PointerEvalAnalogToDigitNew(float number, float numeral return result; } - int ClassFlowCNNGeneral::PointerEvalAnalogNew(float number, int numeral_preceder) { float number_min, number_max; int result; @@ -296,7 +291,6 @@ int ClassFlowCNNGeneral::PointerEvalAnalogNew(float number, int numeral_preceder return result; } - bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { std::vector splitted; @@ -322,7 +316,6 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { return true; } - while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { splitted = ZerlegeZeile(aktparamgraph); if ((toUpper(splitted[0]) == "ROIIMAGESLOCATION") && (splitted.size() > 1)) { @@ -336,7 +329,9 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { } if ((toUpper(splitted[0]) == "ROIIMAGESRETENTION") && (splitted.size() > 1)) { - this->imagesRetention = std::stoi(splitted[1]); + if (isStringNumeric(splitted[1])) { + this->imagesRetention = std::stoi(splitted[1]); + } } if ((toUpper(splitted[0]) == "MODEL") && (splitted.size() > 1)) { @@ -344,7 +339,9 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { } if ((toUpper(splitted[0]) == "CNNGOODTHRESHOLD") && (splitted.size() > 1)) { - CNNGoodThreshold = std::stof(splitted[1]); + if (isStringNumeric(splitted[1])) { + CNNGoodThreshold = std::stof(splitted[1]); + } } if (splitted.size() >= 5) { @@ -366,9 +363,7 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { } if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") { - SaveAllFiles = true; - } + SaveAllFiles = alphanumericToBoolean(splitted[1]); } } @@ -378,7 +373,6 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { return false; } - for (int _ana = 0; _ana < GENERAL.size(); ++_ana) { for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i) { GENERAL[_ana]->ROI[i]->image = new CImageBasis("ROI " + GENERAL[_ana]->ROI[i]->name, @@ -391,7 +385,6 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { return true; } - general* ClassFlowCNNGeneral::FindGENERAL(string _name_number) { for (int i = 0; i < GENERAL.size(); ++i) { if (GENERAL[i]->name == _name_number) { @@ -402,7 +395,6 @@ general* ClassFlowCNNGeneral::FindGENERAL(string _name_number) { return NULL; } - general* ClassFlowCNNGeneral::GetGENERAL(string _name, bool _create = true) { string _analog, _roi; int _pospunkt = _name.find_first_of("."); @@ -445,7 +437,6 @@ general* ClassFlowCNNGeneral::GetGENERAL(string _name, bool _create = true) { return _ret; } - string ClassFlowCNNGeneral::getHTMLSingleStep(string host) { string result, zw; std::vector htmlinfo; @@ -469,7 +460,6 @@ string ClassFlowCNNGeneral::getHTMLSingleStep(string host) { return result; } - bool ClassFlowCNNGeneral::doFlow(string time) { #ifdef HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT //register a buffer to record the memory trace @@ -500,7 +490,6 @@ bool ClassFlowCNNGeneral::doFlow(string time) { return true; } - bool ClassFlowCNNGeneral::doAlignAndCut(string time) { if (disabled) { return true; @@ -537,7 +526,6 @@ bool ClassFlowCNNGeneral::doAlignAndCut(string time) { return true; } - void ClassFlowCNNGeneral::DrawROI(CImageBasis *_zw) { if (_zw->ImageOkay()) { if (CNNType == Analogue || CNNType == Analogue100) { @@ -564,7 +552,6 @@ void ClassFlowCNNGeneral::DrawROI(CImageBasis *_zw) { } } - bool ClassFlowCNNGeneral::getNetworkParameter() { if (disabled) { return true; @@ -606,17 +593,17 @@ bool ClassFlowCNNGeneral::getNetworkParameter() { ESP_LOGD(TAG, "TFlite-Type set to DoubleHyprid10"); break; case 11: - CNNType = Digital; - ESP_LOGD(TAG, "TFlite-Type set to Digital"); + CNNType = Digit; + ESP_LOGD(TAG, "TFlite-Type set to Digit"); break; /* case 20: - CNNType = DigitalHyprid10; - ESP_LOGD(TAG, "TFlite-Type set to DigitalHyprid10"); + CNNType = DigitHyprid10; + ESP_LOGD(TAG, "TFlite-Type set to DigitHyprid10"); break; */ // case 22: -// CNNType = DigitalHyprid; -// ESP_LOGD(TAG, "TFlite-Type set to DigitalHyprid"); +// CNNType = DigitHyprid; +// ESP_LOGD(TAG, "TFlite-Type set to DigitHyprid"); // break; case 100: if (modelxsize==32 && modelysize == 32) { @@ -624,8 +611,8 @@ bool ClassFlowCNNGeneral::getNetworkParameter() { ESP_LOGD(TAG, "TFlite-Type set to Analogue100"); } else { - CNNType = Digital100; - ESP_LOGD(TAG, "TFlite-Type set to Digital"); + CNNType = Digit100; + ESP_LOGD(TAG, "TFlite-Type set to Digit"); } break; default: @@ -637,7 +624,6 @@ bool ClassFlowCNNGeneral::getNetworkParameter() { return true; } - bool ClassFlowCNNGeneral::doNeuralNetwork(string time) { if (disabled) { return true; @@ -700,8 +686,8 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) { } } break; - case Digital: - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Digital"); + case Digit: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Digit"); { GENERAL[n]->ROI[roi]->result_klasse = 0; GENERAL[n]->ROI[roi]->result_klasse = tflite->GetClassFromImageBasis(GENERAL[n]->ROI[roi]->image); @@ -792,10 +778,10 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) { } } } break; - case Digital100: + case Digit100: case Analogue100: { - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Digital100 or Analogue100"); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Digit100 or Analogue100"); int _num; float _result_save_file; @@ -842,16 +828,14 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) { return true; } - bool ClassFlowCNNGeneral::isExtendedResolution(int _number) { - if (CNNType == Digital) { + if (CNNType == Digit) { return false; } return true; } - std::vector ClassFlowCNNGeneral::GetHTMLInfo() { std::vector result; @@ -877,7 +861,7 @@ std::vector ClassFlowCNNGeneral::GetHTMLInfo() { zw->filename_org = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"; } - if (CNNType == Digital) { + if (CNNType == Digit) { zw->val = GENERAL[_ana]->ROI[i]->result_klasse; } else { @@ -894,12 +878,10 @@ std::vector ClassFlowCNNGeneral::GetHTMLInfo() { return result; } - int ClassFlowCNNGeneral::getNumberGENERAL() { return GENERAL.size(); } - string ClassFlowCNNGeneral::getNameGENERAL(int _analog) { if (_analog < GENERAL.size()) { return GENERAL[_analog]->name; @@ -908,7 +890,6 @@ string ClassFlowCNNGeneral::getNameGENERAL(int _analog) { return "GENERAL DOES NOT EXIST"; } - general* ClassFlowCNNGeneral::GetGENERAL(int _analog) { if (_analog < GENERAL.size()) { return GENERAL[_analog]; @@ -917,7 +898,6 @@ general* ClassFlowCNNGeneral::GetGENERAL(int _analog) { return NULL; } - void ClassFlowCNNGeneral::UpdateNameNumbers(std::vector *_name_numbers) { for (int _dig = 0; _dig < GENERAL.size(); _dig++) { std::string _name = GENERAL[_dig]->name; @@ -934,7 +914,6 @@ void ClassFlowCNNGeneral::UpdateNameNumbers(std::vector *_name_numb } } - string ClassFlowCNNGeneral::getReadoutRawString(int _analog) { string rt = ""; @@ -948,7 +927,7 @@ string ClassFlowCNNGeneral::getReadoutRawString(int _analog) rt = rt + "," + RundeOutput(GENERAL[_analog]->ROI[i]->result_float, 1); } - if (CNNType == Digital) { + if (CNNType == Digit) { if (GENERAL[_analog]->ROI[i]->result_klasse >= 10) { rt = rt + ",N"; } @@ -957,10 +936,9 @@ string ClassFlowCNNGeneral::getReadoutRawString(int _analog) } } - if ((CNNType == DoubleHyprid10) || (CNNType == Digital100)) { + if ((CNNType == DoubleHyprid10) || (CNNType == Digit100)) { rt = rt + "," + RundeOutput(GENERAL[_analog]->ROI[i]->result_float, 1); } } return rt; } - diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 8c3baac6a..9946d551a 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -11,10 +11,10 @@ enum t_CNNType { AutoDetect, Analogue, Analogue100, - Digital, - DigitalHyprid10, + Digit, + DigitHyprid10, DoubleHyprid10, - Digital100, + Digit100, None }; @@ -26,15 +26,6 @@ class ClassFlowCNNGeneral : std::vector GENERAL; float CNNGoodThreshold; - //moved to define.h - //float Analog_error = 3.0; - //float AnalogToDigtalFehler = 0.8; - //float Digital_Uncertainty = 0.2; - //int DigitalBand = 3; - //float Digital_Transition_Range_Predecessor = 2; - //float Digital_Transition_Area_Predecessor = 0.7; // 9.3 - 0.7 - //float Digital_Transition_Area_Forward = 9.7; // Pre-run zero crossing only happens from approx. 9.7 onwards - string cnnmodelfile; int modelxsize, modelysize, modelchannel; bool isLogImageSelect; @@ -44,8 +35,8 @@ class ClassFlowCNNGeneral : bool SaveAllFiles; int PointerEvalAnalogNew(float zahl, int numeral_preceder); - int PointerEvalAnalogToDigitNew(float zahl, float numeral_preceder, int eval_predecessors, float analogDigitalTransitionStart); - int PointerEvalHybridNew(float zahl, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors = false, float analogDigitalTransitionStart=9.2); + int PointerEvalAnalogToDigitNew(float zahl, float numeral_preceder, int eval_predecessors, float AnalogToDigitTransitionStart); + int PointerEvalHybridNew(float zahl, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors = false, float AnalogToDigitTransitionStart=9.2); @@ -61,7 +52,7 @@ class ClassFlowCNNGeneral : bool doFlow(string time); string getHTMLSingleStep(string host); - string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _before_narrow_Analog = -1, float analogDigitalTransitionStart=9.2); + string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _before_narrow_Analog = -1, float AnalogToDigitTransitionStart=9.2); string getReadoutRawString(int _analog); diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index f54df869d..474a86ec8 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -32,7 +32,6 @@ static const char* TAG = "FLOWCTRL"; //#define DEBUG_DETAIL_ON - std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){ std::string _classname = ""; std::string result = ""; @@ -65,11 +64,19 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _ _classname = "ClassFlowInfluxDBv2"; } #endif //ENABLE_INFLUXDB + #ifdef ENABLE_WEBHOOK + if ((_stepname.compare("[Webhook]") == 0) || (_stepname.compare(";[Webhook]") == 0)){ + _classname = "ClassFlowWebhook"; + } + #endif //ENABLE_WEBHOOK for (int i = 0; i < FlowControll.size(); ++i) if (FlowControll[i]->name().compare(_classname) == 0){ - if (!(FlowControll[i]->name().compare("ClassFlowTakeImage") == 0)) // if it is a TakeImage, the image does not need to be included, this happens automatically with the html query. + if (!(FlowControll[i]->name().compare("ClassFlowTakeImage") == 0)) { + // if it is a TakeImage, the image does not need to be included, this happens automatically with the html query. FlowControll[i]->doFlow(""); + } + result = FlowControll[i]->getHTMLSingleStep(_host); } @@ -78,37 +85,51 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _ return result; } - std::string ClassFlowControll::TranslateAktstatus(std::string _input) { - if (_input.compare("ClassFlowTakeImage") == 0) + if (_input.compare("ClassFlowTakeImage") == 0) { return ("Take Image"); - if (_input.compare("ClassFlowAlignment") == 0) + } + + if (_input.compare("ClassFlowAlignment") == 0) { return ("Aligning"); - if (_input.compare("ClassFlowCNNGeneral") == 0) - return ("Digitalization of ROIs"); + } + + if (_input.compare("ClassFlowCNNGeneral") == 0) { + return ("Digitization of ROIs"); + } + #ifdef ENABLE_MQTT - if (_input.compare("ClassFlowMQTT") == 0) + if (_input.compare("ClassFlowMQTT") == 0) { return ("Sending MQTT"); + } #endif //ENABLE_MQTT + #ifdef ENABLE_INFLUXDB - if (_input.compare("ClassFlowInfluxDB") == 0) + if (_input.compare("ClassFlowInfluxDB") == 0) { return ("Sending InfluxDB"); - if (_input.compare("ClassFlowInfluxDBv2") == 0) + } + + if (_input.compare("ClassFlowInfluxDBv2") == 0) { return ("Sending InfluxDBv2"); + } #endif //ENABLE_INFLUXDB - if (_input.compare("ClassFlowPostProcessing") == 0) + #ifdef ENABLE_WEBHOOK + if (_input.compare("ClassFlowWebhook") == 0) { + return ("Sending Webhook"); + } + #endif //ENABLE_WEBHOOK + if (_input.compare("ClassFlowPostProcessing") == 0) { return ("Post-Processing"); + } return "Unkown Status"; } - -std::vector ClassFlowControll::GetAllDigital() +std::vector ClassFlowControll::GetAllDigit() { - if (flowdigit) - { - ESP_LOGD(TAG, "ClassFlowControll::GetAllDigital - flowdigit != NULL"); + if (flowdigit) { + ESP_LOGD(TAG, "ClassFlowControll::GetAllDigit - flowdigit != NULL"); return flowdigit->GetHTMLInfo(); } @@ -116,65 +137,63 @@ std::vector ClassFlowControll::GetAllDigital() return empty; } - std::vector ClassFlowControll::GetAllAnalog() { - if (flowanalog) + if (flowanalog) { return flowanalog->GetHTMLInfo(); + } std::vector empty; return empty; } - -t_CNNType ClassFlowControll::GetTypeDigital() +t_CNNType ClassFlowControll::GetTypeDigit() { - if (flowdigit) + if (flowdigit) { return flowdigit->getCNNType(); + } return t_CNNType::None; } - t_CNNType ClassFlowControll::GetTypeAnalog() { - if (flowanalog) + if (flowanalog) { return flowanalog->getCNNType(); + } return t_CNNType::None; } - #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG -void ClassFlowControll::DigitalDrawROI(CImageBasis *_zw) +void ClassFlowControll::DigitDrawROI(CImageBasis *_zw) { - if (flowdigit) + if (flowdigit) { flowdigit->DrawROI(_zw); + } } - void ClassFlowControll::AnalogDrawROI(CImageBasis *_zw) { - if (flowanalog) + if (flowanalog) { flowanalog->DrawROI(_zw); + } } #endif - #ifdef ENABLE_MQTT bool ClassFlowControll::StartMQTTService() { /* Start the MQTT service */ - for (int i = 0; i < FlowControll.size(); ++i) { - if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0) { - return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoInterval); - } - } + for (int i = 0; i < FlowControll.size(); ++i) { + if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0) { + return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoInterval); + } + } return false; } #endif //ENABLE_MQTT - void ClassFlowControll::SetInitialParameter(void) { AutoStart = false; @@ -189,7 +208,6 @@ void ClassFlowControll::SetInitialParameter(void) aktstatusWithTime = aktstatus; } - bool ClassFlowControll::getIsAutoStart(void) { return AutoStart; @@ -201,69 +219,81 @@ void ClassFlowControll::setAutoStartInterval(long &_interval) _interval = AutoInterval * 60 * 1000; // AutoInterval: minutes -> ms } - ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type) { ClassFlow* cfc = NULL; _type = trim(_type); - if (toUpper(_type).compare("[TAKEIMAGE]") == 0) - { + if (toUpper(_type).compare("[TAKEIMAGE]") == 0) { cfc = new ClassFlowTakeImage(&FlowControll); flowtakeimage = (ClassFlowTakeImage*) cfc; } - if (toUpper(_type).compare("[ALIGNMENT]") == 0) - { + + if (toUpper(_type).compare("[ALIGNMENT]") == 0) { cfc = new ClassFlowAlignment(&FlowControll); flowalignment = (ClassFlowAlignment*) cfc; } - if (toUpper(_type).compare("[ANALOG]") == 0) - { + + if (toUpper(_type).compare("[ANALOG]") == 0) { cfc = new ClassFlowCNNGeneral(flowalignment); flowanalog = (ClassFlowCNNGeneral*) cfc; } - if (toUpper(_type).compare(0, 7, "[DIGITS") == 0) - { + + if (toUpper(_type).compare(0, 7, "[DIGITS") == 0) { cfc = new ClassFlowCNNGeneral(flowalignment); flowdigit = (ClassFlowCNNGeneral*) cfc; } + #ifdef ENABLE_MQTT - if (toUpper(_type).compare("[MQTT]") == 0) + if (toUpper(_type).compare("[MQTT]") == 0) { cfc = new ClassFlowMQTT(&FlowControll); + } #endif //ENABLE_MQTT + #ifdef ENABLE_INFLUXDB - if (toUpper(_type).compare("[INFLUXDB]") == 0) + if (toUpper(_type).compare("[INFLUXDB]") == 0) { cfc = new ClassFlowInfluxDB(&FlowControll); - if (toUpper(_type).compare("[INFLUXDBV2]") == 0) + } + + if (toUpper(_type).compare("[INFLUXDBV2]") == 0) { cfc = new ClassFlowInfluxDBv2(&FlowControll); + } #endif //ENABLE_INFLUXDB + #ifdef ENABLE_WEBHOOK + if (toUpper(_type).compare("[WEBHOOK]") == 0) + cfc = new ClassFlowWebhook(&FlowControll); + #endif //ENABLE_WEBHOOK - if (toUpper(_type).compare("[POSTPROCESSING]") == 0) - { + if (toUpper(_type).compare("[POSTPROCESSING]") == 0) { cfc = new ClassFlowPostProcessing(&FlowControll, flowanalog, flowdigit); flowpostprocessing = (ClassFlowPostProcessing*) cfc; } - if (cfc) // Attached only if it is not [AutoTimer], because this is for FlowControll + if (cfc) { + // Attached only if it is not [AutoTimer], because this is for FlowControll FlowControll.push_back(cfc); + } - if (toUpper(_type).compare("[AUTOTIMER]") == 0) - cfc = this; + if (toUpper(_type).compare("[AUTOTIMER]") == 0) { + cfc = this; + } - if (toUpper(_type).compare("[DATALOGGING]") == 0) - cfc = this; + if (toUpper(_type).compare("[DATALOGGING]") == 0) { + cfc = this; + } - if (toUpper(_type).compare("[DEBUG]") == 0) - cfc = this; + if (toUpper(_type).compare("[DEBUG]") == 0) { + cfc = this; + } - if (toUpper(_type).compare("[SYSTEM]") == 0) - cfc = this; + if (toUpper(_type).compare("[SYSTEM]") == 0) { + cfc = this; + } return cfc; } - void ClassFlowControll::InitFlow(std::string config) { aktstatus = "Initialization"; @@ -284,62 +314,55 @@ void ClassFlowControll::InitFlow(std::string config) line = ""; char zw[1024]; - if (pFile != NULL) - { + + if (pFile != NULL) { fgets(zw, 1024, pFile); ESP_LOGD(TAG, "%s", zw); line = std::string(zw); } - while ((line.size() > 0) && !(feof(pFile))) - { + while ((line.size() > 0) && !(feof(pFile))) { cfc = CreateClassFlow(line); -// printf("Name: %s\n", cfc->name().c_str()); - if (cfc) - { - ESP_LOGD(TAG, "Start ReadParameter (%s)", line.c_str()); + // printf("Name: %s\n", cfc->name().c_str()); + + if (cfc) { + ESP_LOGE(TAG, "Start ReadParameter (%s)", line.c_str()); cfc->ReadParameter(pFile, line); } - else - { + else { line = ""; - if (fgets(zw, 1024, pFile) && !feof(pFile)) - { - ESP_LOGD(TAG, "Read: %s", zw); - line = std::string(zw); - } + + if (fgets(zw, 1024, pFile) && !feof(pFile)) { + ESP_LOGD(TAG, "Read: %s", zw); + line = std::string(zw); + } } } fclose(pFile); } - std::string* ClassFlowControll::getActStatusWithTime() { return &aktstatusWithTime; } - std::string* ClassFlowControll::getActStatus() { return &aktstatus; } - void ClassFlowControll::setActStatus(std::string _aktstatus) { aktstatus = _aktstatus; aktstatusWithTime = aktstatus; } - void ClassFlowControll::doFlowTakeImageOnly(string time) { std::string zw_time; - for (int i = 0; i < FlowControll.size(); ++i) - { + for (int i = 0; i < FlowControll.size(); ++i) { if (FlowControll[i]->name() == "ClassFlowTakeImage") { zw_time = getCurrentTimeString("%H:%M:%S"); aktstatus = TranslateAktstatus(FlowControll[i]->name()); @@ -353,7 +376,6 @@ void ClassFlowControll::doFlowTakeImageOnly(string time) } } - bool ClassFlowControll::doFlow(string time) { bool result = true; @@ -373,8 +395,7 @@ bool ClassFlowControll::doFlow(string time) //checkNtpStatus(0); - for (int i = 0; i < FlowControll.size(); ++i) - { + for (int i = 0; i < FlowControll.size(); ++i) { zw_time = getCurrentTimeString("%H:%M:%S"); aktstatus = TranslateAktstatus(FlowControll[i]->name()); aktstatusWithTime = aktstatus + " (" + zw_time + ")"; @@ -391,7 +412,7 @@ bool ClassFlowControll::doFlow(string time) if (!FlowControll[i]->doFlow(time)){ repeat++; LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt"); - if (i) i -= 1; // vPrevious step must be repeated (probably take pictures) + if (i) { i -= 1; } // vPrevious step must be repeated (probably take pictures) result = false; if (repeat > 5) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Wiederholung 5x nicht erfolgreich --> reboot"); @@ -399,8 +420,7 @@ bool ClassFlowControll::doFlow(string time) //Step was repeated 5x --> reboot } } - else - { + else { result = true; } @@ -424,27 +444,29 @@ bool ClassFlowControll::doFlow(string time) string ClassFlowControll::getReadoutAll(int _type) { std::string out = ""; - if (flowpostprocessing) - { + + if (flowpostprocessing) { std::vector *numbers = flowpostprocessing->GetNumbers(); - for (int i = 0; i < (*numbers).size(); ++i) - { + for (int i = 0; i < (*numbers).size(); ++i) { out = out + (*numbers)[i]->name + "\t"; + switch (_type) { case READOUT_TYPE_VALUE: out = out + (*numbers)[i]->ReturnValue; break; case READOUT_TYPE_PREVALUE: - if (flowpostprocessing->PreValueUse) - { - if ((*numbers)[i]->PreValueOkay) + if (flowpostprocessing->PreValueUse) { + if ((*numbers)[i]->PreValueOkay) { out = out + (*numbers)[i]->ReturnPreValue; - else - out = out + "PreValue too old"; + } + else { + out = out + "PreValue too old"; + } } - else + else { out = out + "PreValue deactivated"; + } break; case READOUT_TYPE_RAWVALUE: out = out + (*numbers)[i]->ReturnRawValue; @@ -453,8 +475,10 @@ string ClassFlowControll::getReadoutAll(int _type) out = out + (*numbers)[i]->ErrorMessageText; break; } - if (i < (*numbers).size()-1) + + if (i < (*numbers).size()-1) { out = out + "\r\n"; + } } // ESP_LOGD(TAG, "OUT: %s", out.c_str()); } @@ -462,43 +486,24 @@ string ClassFlowControll::getReadoutAll(int _type) return out; } - string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false, int _number = 0) { - if (flowpostprocessing) + if (flowpostprocessing) { return flowpostprocessing->getReadoutParam(_rawvalue, _noerror, _number); - - string zw = ""; - string result = ""; - - for (int i = 0; i < FlowControll.size(); ++i) - { - zw = FlowControll[i]->getReadout(); - if (zw.length() > 0) - { - if (result.length() == 0) - result = zw; - else - result = result + "\t" + zw; - } } - return result; + return std::string(""); } - string ClassFlowControll::GetPrevalue(std::string _number) { - if (flowpostprocessing) - { + if (flowpostprocessing) { return flowpostprocessing->GetPreValue(_number); } - return std::string(""); } - bool ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbers, bool _extern) { double newvalueAsDouble; @@ -519,10 +524,12 @@ bool ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbe } if (flowpostprocessing) { - if (flowpostprocessing->SetPreValue(newvalueAsDouble, _numbers, _extern)) + if (flowpostprocessing->SetPreValue(newvalueAsDouble, _numbers, _extern)) { return true; - else + } + else { return false; + } } else { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "UpdatePrevalue: ERROR - Class Post-Processing not initialized"); @@ -530,93 +537,85 @@ bool ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbe } } - bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) { std::vector splitted; aktparamgraph = trim(aktparamgraph); - if (aktparamgraph.size() == 0) - if (!this->GetNextParagraph(pfile, aktparamgraph)) + if (aktparamgraph.size() == 0) { + if (!this->GetNextParagraph(pfile, aktparamgraph)) { return false; - + } + } if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) && - (toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu Debug oder DataLogging + (toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) { + // Paragraph passt nicht zu Debug oder DataLogging return false; + } - while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) - { + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { splitted = ZerlegeZeile(aktparamgraph, " ="); - if ((toUpper(splitted[0]) == "AUTOSTART") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") + + if ((toUpper(splitted[0]) == "AUTOSTART") && (splitted.size() > 1)) { + AutoStart = alphanumericToBoolean(splitted[1]); + } + + if ((toUpper(splitted[0]) == "INTERVAL") && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) { - AutoStart = true; + AutoInterval = std::stof(splitted[1]); } } - if ((toUpper(splitted[0]) == "INTERVAL") && (splitted.size() > 1)) - { - AutoInterval = std::stof(splitted[1]); + if ((toUpper(splitted[0]) == "DATALOGACTIVE") && (splitted.size() > 1)) { + LogFile.SetDataLogToSD(alphanumericToBoolean(splitted[1])); } - if ((toUpper(splitted[0]) == "DATALOGACTIVE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") + if ((toUpper(splitted[0]) == "DATAFILESRETENTION") && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) { - LogFile.SetDataLogToSD(true); - } - else { - LogFile.SetDataLogToSD(false); + LogFile.SetDataLogRetention(std::stoi(splitted[1])); } } - if ((toUpper(splitted[0]) == "DATAFILESRETENTION") && (splitted.size() > 1)) - { - LogFile.SetDataLogRetention(std::stoi(splitted[1])); - } - - if ((toUpper(splitted[0]) == "LOGLEVEL") && (splitted.size() > 1)) - { + if ((toUpper(splitted[0]) == "LOGLEVEL") && (splitted.size() > 1)) { /* matches esp_log_level_t */ - if ((toUpper(splitted[1]) == "TRUE") || (toUpper(splitted[1]) == "2")) - { + if ((toUpper(splitted[1]) == "TRUE") || (toUpper(splitted[1]) == "2")) { LogFile.setLogLevel(ESP_LOG_WARN); } - else if ((toUpper(splitted[1]) == "FALSE") || (toUpper(splitted[1]) == "0") || (toUpper(splitted[1]) == "1")) - { + else if ((toUpper(splitted[1]) == "FALSE") || (toUpper(splitted[1]) == "0") || (toUpper(splitted[1]) == "1")) { LogFile.setLogLevel(ESP_LOG_ERROR); } - else if (toUpper(splitted[1]) == "3") - { + else if (toUpper(splitted[1]) == "3") { LogFile.setLogLevel(ESP_LOG_INFO); } - else if (toUpper(splitted[1]) == "4") - { + else if (toUpper(splitted[1]) == "4") { LogFile.setLogLevel(ESP_LOG_DEBUG); } /* If system reboot was not triggered by user and reboot was caused by execption -> keep log level to DEBUG */ - if (!getIsPlannedReboot() && (esp_reset_reason() == ESP_RST_PANIC)) + if (!getIsPlannedReboot() && (esp_reset_reason() == ESP_RST_PANIC)) { LogFile.setLogLevel(ESP_LOG_DEBUG); + } } - if ((toUpper(splitted[0]) == "LOGFILESRETENTION") && (splitted.size() > 1)) - { - LogFile.SetLogFileRetention(std::stoi(splitted[1])); + + if ((toUpper(splitted[0]) == "LOGFILESRETENTION") && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) + { + LogFile.SetLogFileRetention(std::stoi(splitted[1])); + } } /* TimeServer and TimeZone got already read from the config, see setupTime () */ #if (defined WLAN_USE_ROAMING_BY_SCANNING || (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES)) - if ((toUpper(splitted[0]) == "RSSITHRESHOLD") && (splitted.size() > 1)) - { + if ((toUpper(splitted[0]) == "RSSITHRESHOLD") && (splitted.size() > 1)) { int RSSIThresholdTMP = atoi(splitted[1].c_str()); RSSIThresholdTMP = min(0, max(-100, RSSIThresholdTMP)); // Verify input limits (-100 - 0) - if (ChangeRSSIThreshold(WLAN_CONFIG_FILE, RSSIThresholdTMP)) - { + if (ChangeRSSIThreshold(WLAN_CONFIG_FILE, RSSIThresholdTMP)) { // reboot necessary so that the new wlan.ini is also used !!! fclose(pfile); LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Rebooting to activate new RSSITHRESHOLD ..."); @@ -625,10 +624,8 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) } #endif - if ((toUpper(splitted[0]) == "HOSTNAME") && (splitted.size() > 1)) - { - if (ChangeHostName(WLAN_CONFIG_FILE, splitted[1])) - { + if ((toUpper(splitted[0]) == "HOSTNAME") && (splitted.size() > 1)) { + if (ChangeHostName(WLAN_CONFIG_FILE, splitted[1])) { // reboot necessary so that the new wlan.ini is also used !!! fclose(pfile); LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Rebooting to activate new HOSTNAME..."); @@ -636,23 +633,19 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) } } - if ((toUpper(splitted[0]) == "SETUPMODE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - { - SetupModeActive = true; - } + if ((toUpper(splitted[0]) == "SETUPMODE") && (splitted.size() > 1)) { + SetupModeActive = alphanumericToBoolean(splitted[1]); } } return true; } - int ClassFlowControll::CleanTempFolder() { const char* folderPath = "/sdcard/img_tmp"; ESP_LOGD(TAG, "Clean up temporary folder to avoid damage of sdcard sectors: %s", folderPath); DIR *dir = opendir(folderPath); + if (!dir) { ESP_LOGE(TAG, "Failed to stat dir: %s", folderPath); return -1; @@ -660,31 +653,33 @@ int ClassFlowControll::CleanTempFolder() { struct dirent *entry; int deleted = 0; + while ((entry = readdir(dir)) != NULL) { std::string path = string(folderPath) + "/" + entry->d_name; - if (entry->d_type == DT_REG) { - if (unlink(path.c_str()) == 0) { - deleted ++; - } else { - ESP_LOGE(TAG, "can't delete file: %s", path.c_str()); - } - } else if (entry->d_type == DT_DIR) { - deleted += removeFolder(path.c_str(), TAG); - } + if (entry->d_type == DT_REG) { + if (unlink(path.c_str()) == 0) { + deleted ++; + } + else { + ESP_LOGE(TAG, "can't delete file: %s", path.c_str()); + } + } + else if (entry->d_type == DT_DIR) { + deleted += removeFolder(path.c_str(), TAG); + } } + closedir(dir); ESP_LOGD(TAG, "%d files deleted", deleted); return 0; } - esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req) { return flowtakeimage != NULL ? flowtakeimage->SendRawJPG(req) : ESP_FAIL; } - esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req) { ESP_LOGD(TAG, "ClassFlowControll::GetJPGStream %s", _fn.c_str()); @@ -846,8 +841,8 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req) else { std::vector htmlinfo; - htmlinfo = GetAllDigital(); - ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigital"); + htmlinfo = GetAllDigit(); + ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigit"); for (int i = 0; i < htmlinfo.size(); ++i) { @@ -916,14 +911,20 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req) return result; } - string ClassFlowControll::getNumbersName() { return flowpostprocessing->getNumbersName(); } - string ClassFlowControll::getJSON() { return flowpostprocessing->GetJSON(); } + +/** + * @returns a vector of all current sequences + **/ +const std::vector &ClassFlowControll::getNumbers() +{ + return *flowpostprocessing->GetNumbers(); +} diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.h b/code/components/jomjol_flowcontroll/ClassFlowControll.h index e0d5f74e2..40b5ba112 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.h +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.h @@ -17,6 +17,9 @@ #include "ClassFlowInfluxDB.h" #include "ClassFlowInfluxDBv2.h" #endif //ENABLE_INFLUXDB +#ifdef ENABLE_WEBHOOK + #include "ClassFlowWebhook.h" +#endif //ENABLE_WEBHOOK #include "ClassFlowCNNGeneral.h" class ClassFlowControll : @@ -52,12 +55,13 @@ class ClassFlowControll : string GetPrevalue(std::string _number = ""); bool ReadParameter(FILE* pfile, string& aktparamgraph); string getJSON(); + const std::vector &getNumbers(); string getNumbersName(); string TranslateAktstatus(std::string _input); #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG - void DigitalDrawROI(CImageBasis *_zw); + void DigitDrawROI(CImageBasis *_zw); void AnalogDrawROI(CImageBasis *_zw); #endif @@ -73,10 +77,10 @@ class ClassFlowControll : std::string* getActStatus(); void setActStatus(std::string _aktstatus); - std::vector GetAllDigital(); + std::vector GetAllDigit(); std::vector GetAllAnalog(); - t_CNNType GetTypeDigital(); + t_CNNType GetTypeDigit(); t_CNNType GetTypeAnalog(); #ifdef ENABLE_MQTT diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h index 059a55b8f..63e8afe16 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h +++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h @@ -5,6 +5,10 @@ #include "ClassFlowImage.h" +/** + * Properties of one ROI + * FIXME: naming of members could use some refactoring to comply with common C++ coding style guidelines + */ struct roi { int posx, posy, deltax, deltay; float result_float; @@ -14,56 +18,66 @@ struct roi { CImageBasis *image, *image_org; }; +/** + * FIXME: Why is this additional layer needed? + */ struct general { string name; std::vector ROI; }; enum t_RateType { - AbsoluteChange, - RateChange + AbsoluteChange, // ignores the time difference; only the value difference is used comparison with NumberPost.maxRate + RateChange // time difference is considered and a normalized rate is used for comparison with NumberPost.maxRate }; +/** + * Holds all properties and settings of a sequence. A sequence is a set of digit and/or analog ROIs that are combined to + * provide one meter reading (value). + * FIXME: can be renamed to `Sequence` + */ struct NumberPost { - float MaxRateValue; - bool useMaxRateValue; - t_RateType RateType; - bool ErrorMessage; - bool PreValueOkay; - bool AllowNegativeRates; - bool checkDigitIncreaseConsistency; - time_t lastvalue; - time_t timeStampTimeUTC; - string timeStamp; - double FlowRateAct; // m3 / min - double PreValue; // last value that was read out well - double Value; // last value read out, incl. corrections - string ReturnRateValue; // return value rate - string ReturnChangeAbsolute; // return value rate - string ReturnRawValue; // Raw value (with N & leading 0) - string ReturnValue; // corrected return value, if necessary with error message - string ReturnPreValue; // corrected return value without error message - string ErrorMessageText; // Error message for consistency check - int AnzahlAnalog; - int AnzahlDigital; - int DecimalShift; - int DecimalShiftInitial; - float AnalogDigitalTransitionStart; // When is the digit > x.1, i.e. when does it start to tilt? - int Nachkomma; + float MaxRateValue; // maxRate; upper bound for the difference between two consecutive readings; affected by maxRateType; + bool useMaxRateValue; // consistencyChecksEnabled; enables consistency checks; uses maxRate and maxRateType + t_RateType MaxRateType; // maxRateType; affects how the value of maxRate is used for comparing the current and previous value + bool ErrorMessage; // FIXME: not used; can be removed + int ChangeRateThreshold; // threshold parameter for negative rate detection + bool PreValueOkay; // previousValueValid; indicates that the reading of the previous round has no errors + bool AllowNegativeRates; // allowNegativeRate; defines if the consistency checks allow negative rates between consecutive meter readings. + bool checkDigitIncreaseConsistency; // extendedConsistencyCheck; performs an additional consistency check to avoid wrong readings + time_t timeStampLastValue; // Timestamp for the last read value; is used for the log + time_t timeStampLastPreValue; // Timestamp for the last PreValue set; is used for useMaxRateValue + time_t timeStampTimeUTC; // FIXME: not used; can be removed. + string timeStamp; // localTimeStr; timestamp of last valid reading formatted as local time + double FlowRateAct; // currentRate; ΔValue/min; since usage is not limited to water meters, the physical unit is not known. + double PreValue; // lastValidValue; most recent value that could be read w/o any errors + double Value; // value; most recent readout; may include corrections + string ReturnRateValue; // currentRateStr; current normalized rate; ΔValue/min + string ReturnChangeAbsolute; // currentChangeStr; absolute difference between current and previous measurement + string ReturnRawValue; // rawValueStr; Raw value (with N & leading 0) + string ReturnValue; // valueStr; corrected return value, if necessary with error message + string ReturnPreValue; // lastValidValueStr; corrected return value without error message + string ErrorMessageText; // errorMessage; Error message for consistency checks + int AnzahlAnalog; // numAnalogRoi; number of analog ROIs used in this sequence + int AnzahlDigit; // numDigitRoi; number of digit ROIs used in this sequence + int DecimalShift; // decimalShift; each increment shifts the decimal separator by one digit; value=value*10^decimalShift; pos. value shifts to the right + int DecimalShiftInitial; // decimalShiftInitial; same as decimalShift but is a const to reset decimalShift after calculations + float AnalogToDigitTransitionStart; // AnalogToDigitTransitionStartValue; FIXME: need a better description; When is the digit > x.1, i.e. when does it start to tilt? + int Nachkomma; // decimalPlaces; usually defined by the number of analog ROIs; affected by DecimalShift - string FieldV1; // Fieldname in InfluxDBv1 - string MeasurementV1; // Measurement in InfluxDBv1 + string FieldV1; // influxdbFieldName_v1; Name of the Field in InfluxDBv1 + string MeasurementV1; // influxdbMeasurementName_v1; Name of the Measurement in InfluxDBv1 - string FieldV2; // Fieldname in InfluxDBv2 - string MeasurementV2; // Measurement in InfluxDBv2 + string FieldV2; // influxdbFieldName_v2; Name of the Field in InfluxDBv2 + string MeasurementV2; // influxdbMeasurementName_v2; Name of the Measurement in InfluxDBv2 - bool isExtendedResolution; + bool isExtendedResolution; // extendResolution; Adds the decimal place of the least significant analog ROI to the value - general *digit_roi; - general *analog_roi; + general *digit_roi; // digitRoi; set of digit ROIs for the sequence + general *analog_roi; // analogRoi; set of analog ROIs for the sequence - string name; + string name; // name; Designation for the sequence }; #endif diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 797491f6e..b1162f837 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -286,7 +286,7 @@ bool ClassFlowMQTT::doFlow(string zwtime) if (resultchangabs.length() > 0) { success |= MQTTPublish(namenumber + "changeabsolut", resultchangabs, qos, SetRetainFlag); // Legacy API - success |= MQTTPublish(namenumber + "rate_per_digitalization_round", resultchangabs, qos, SetRetainFlag); + success |= MQTTPublish(namenumber + "rate_per_Digitization_round", resultchangabs, qos, SetRetainFlag); } if (resultraw.length() > 0) diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 7e19c22c3..db4a3778b 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -15,124 +15,129 @@ static const char* TAG = "POSTPROC"; -std::string ClassFlowPostProcessing::getNumbersName() -{ +std::string ClassFlowPostProcessing::getNumbersName() { std::string ret=""; - for (int i = 0; i < NUMBERS.size(); ++i) - { + for (int i = 0; i < NUMBERS.size(); ++i) { ret += NUMBERS[i]->name; - if (i < NUMBERS.size()-1) + + if (i < NUMBERS.size()-1) { ret = ret + "\t"; + } } -// ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str()); + // ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str()); return ret; } -std::string ClassFlowPostProcessing::GetJSON(std::string _lineend) -{ +std::string ClassFlowPostProcessing::GetJSON(std::string _lineend) { std::string json="{" + _lineend; - for (int i = 0; i < NUMBERS.size(); ++i) - { + for (int i = 0; i < NUMBERS.size(); ++i) { json += "\"" + NUMBERS[i]->name + "\":" + _lineend; - json += getJsonFromNumber(i, _lineend) + _lineend; - if ((i+1) < NUMBERS.size()) + if ((i+1) < NUMBERS.size()) { json += "," + _lineend; + } } + json += "}"; return json; } - string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _lineend) { - std::string json = ""; + std::string json = ""; - json += " {" + _lineend; + json += " {" + _lineend; - if (NUMBERS[i]->ReturnValue.length() > 0) - json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend; - else - json += " \"value\": \"\"," + _lineend; + if (NUMBERS[i]->ReturnValue.length() > 0) { + json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend; + } + else { + json += " \"value\": \"\"," + _lineend; + } - json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend; - json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend; - json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend; + json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend; + json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend; + json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend; - if (NUMBERS[i]->ReturnRateValue.length() > 0) - json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend; - else - json += " \"rate\": \"\"," + _lineend; + if (NUMBERS[i]->ReturnRateValue.length() > 0) { + json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend; + } + else { + json += " \"rate\": \"\"," + _lineend; + } - json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend; - json += " }" + _lineend; + json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend; + json += " }" + _lineend; - return json; + return json; } - -string ClassFlowPostProcessing::GetPreValue(std::string _number) -{ +string ClassFlowPostProcessing::GetPreValue(std::string _number) { std::string result; int index = -1; - if (_number == "") - _number = "default"; + if (_number == "") { + _number = "default"; + } - for (int i = 0; i < NUMBERS.size(); ++i) - if (NUMBERS[i]->name == _number) + for (int i = 0; i < NUMBERS.size(); ++i) { + if (NUMBERS[i]->name == _number) { index = i; + } + } - if (index == -1) + if (index == -1) { return std::string(""); + } result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma); return result; } - -bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern) -{ +bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern) { //ESP_LOGD(TAG, "SetPrevalue: %f, %s", zw, _numbers.c_str()); for (int j = 0; j < NUMBERS.size(); ++j) { //ESP_LOGD(TAG, "Number %d, %s", j, NUMBERS[j]->name.c_str()); + if (NUMBERS[j]->name == _numbers) { - if (_newvalue >= 0) { // if new value posivive, use provided value to preset PreValue + if (_newvalue >= 0) { + // if new value posivive, use provided value to preset PreValue NUMBERS[j]->PreValue = _newvalue; } - else { // if new value negative, use last raw value to preset PreValue + else { + // if new value negative, use last raw value to preset PreValue char* p; double ReturnRawValueAsDouble = strtod(NUMBERS[j]->ReturnRawValue.c_str(), &p); + if (ReturnRawValueAsDouble == 0) { - LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: " - + NUMBERS[j]->ReturnRawValue); + LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: " + NUMBERS[j]->ReturnRawValue); return false; } + NUMBERS[j]->PreValue = ReturnRawValueAsDouble; } NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue); NUMBERS[j]->PreValueOkay = true; - if (_extern) - { - time(&(NUMBERS[j]->lastvalue)); - localtime(&(NUMBERS[j]->lastvalue)); + if (_extern) { + time(&(NUMBERS[j]->timeStampLastPreValue)); + localtime(&(NUMBERS[j]->timeStampLastPreValue)); } + //ESP_LOGD(TAG, "Found %d! - set to %.8f", j, NUMBERS[j]->PreValue); UpdatePreValueINI = true; // Only update prevalue file if a new value is set SavePreValue(); - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " + - std::to_string(NUMBERS[j]->PreValue)); + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " + std::to_string(NUMBERS[j]->PreValue)); return true; } } @@ -141,9 +146,7 @@ bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, boo return false; // No new value was set (e.g. wrong numbersname, no numbers at all) } - -bool ClassFlowPostProcessing::LoadPreValue(void) -{ +bool ClassFlowPostProcessing::LoadPreValue(void) { std::vector splitted; FILE* pFile; char zw[1024]; @@ -152,30 +155,34 @@ bool ClassFlowPostProcessing::LoadPreValue(void) UpdatePreValueINI = false; // Conversion to the new format - pFile = fopen(FilePreValue.c_str(), "r"); - if (pFile == NULL) + + if (pFile == NULL) { return false; + } + + // Makes sure that an empty file is treated as such. + zw[0] = '\0'; fgets(zw, 1024, pFile); ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw); zwtime = trim(std::string(zw)); - if (zwtime.length() == 0) + + if (zwtime.length() == 0) { return false; + } splitted = HelperZerlegeZeile(zwtime, "\t"); - if (splitted.size() > 1) // Conversion to the new format - { - while ((splitted.size() > 1) && !_done) - { + + // Conversion to the new format + if (splitted.size() > 1) { + while ((splitted.size() > 1) && !_done) { name = trim(splitted[0]); zwtime = trim(splitted[1]); zwvalue = trim(splitted[2]); - for (int j = 0; j < NUMBERS.size(); ++j) - { - if (NUMBERS[j]->name == name) - { + for (int j = 0; j < NUMBERS.size(); ++j) { + if (NUMBERS[j]->name == name) { NUMBERS[j]->PreValue = stod(zwvalue.c_str()); NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // To be on the safe side, 1 digit more, as Exgtended Resolution may be on (will only be set during the first run). @@ -192,27 +199,30 @@ bool ClassFlowPostProcessing::LoadPreValue(void) whenStart.tm_sec = ss; whenStart.tm_isdst = -1; - NUMBERS[j]->lastvalue = mktime(&whenStart); + NUMBERS[j]->timeStampLastPreValue = mktime(&whenStart); time(&tStart); localtime(&tStart); - double difference = difftime(tStart, NUMBERS[j]->lastvalue); + double difference = difftime(tStart, NUMBERS[j]->timeStampLastPreValue); difference /= 60; - if (difference > PreValueAgeStartup) + + if (difference > PreValueAgeStartup) { NUMBERS[j]->PreValueOkay = false; - else + } + else { NUMBERS[j]->PreValueOkay = true; + } } } - if (!fgets(zw, 1024, pFile)) + if (!fgets(zw, 1024, pFile)) { _done = true; - else - { + } + else { ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw); splitted = HelperZerlegeZeile(trim(std::string(zw)), "\t"); - if (splitted.size() > 1) - { + + if (splitted.size() > 1) { name = trim(splitted[0]); zwtime = trim(splitted[1]); zwvalue = trim(splitted[2]); @@ -221,8 +231,8 @@ bool ClassFlowPostProcessing::LoadPreValue(void) } fclose(pFile); } - else // Old Format - { + else { + // Old Format fgets(zw, 1024, pFile); fclose(pFile); ESP_LOGD(TAG, "%s", zw); @@ -244,20 +254,21 @@ bool ClassFlowPostProcessing::LoadPreValue(void) ESP_LOGD(TAG, "TIME: %d, %d, %d, %d, %d, %d", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec); - NUMBERS[0]->lastvalue = mktime(&whenStart); + NUMBERS[0]->timeStampLastPreValue = mktime(&whenStart); time(&tStart); localtime(&tStart); - double difference = difftime(tStart, NUMBERS[0]->lastvalue); + double difference = difftime(tStart, NUMBERS[0]->timeStampLastPreValue); difference /= 60; - if (difference > PreValueAgeStartup) + + if (difference > PreValueAgeStartup) { return false; + } NUMBERS[0]->Value = NUMBERS[0]->PreValue; NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value); - if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi) - { + if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi) { NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma); } @@ -268,27 +279,28 @@ bool ClassFlowPostProcessing::LoadPreValue(void) return true; } -void ClassFlowPostProcessing::SavePreValue() -{ +void ClassFlowPostProcessing::SavePreValue() { FILE* pFile; string _zw; - if (!UpdatePreValueINI) // PreValues unchanged --> File does not have to be rewritten + // PreValues unchanged --> File does not have to be rewritten + if (!UpdatePreValueINI) { return; + } pFile = fopen(FilePreValue.c_str(), "w"); - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { char buffer[80]; - struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue); + struct tm* timeinfo = localtime(&NUMBERS[j]->timeStampLastPreValue); strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); NUMBERS[j]->timeStamp = std::string(buffer); - NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->lastvalue; -// ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); + NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->timeStampLastPreValue; + // ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n"; ESP_LOGD(TAG, "Write PreValue line: %s", _zw.c_str()); + if (pFile) { fputs(_zw.c_str(), pFile); } @@ -299,9 +311,7 @@ void ClassFlowPostProcessing::SavePreValue() fclose(pFile); } - -ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) -{ +ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) { PreValueUse = false; PreValueAgeStartup = 30; ErrorMessage = false; @@ -314,76 +324,56 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, C flowAnalog = _analog; flowDigit = _digit; - for (int i = 0; i < ListFlowControll->size(); ++i) - { - if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) - { + for (int i = 0; i < ListFlowControll->size(); ++i) { + if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) { flowTakeImage = (ClassFlowTakeImage*) (*ListFlowControll)[i]; } } } -void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { - bool _zwdc = false; - - if (toUpper(_value) == "TRUE") - _zwdc = true; - - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->isExtendedResolution = _zwdc; - } + for (int j = 0; j < NUMBERS.size(); ++j) { + bool _zwdc = alphanumericToBoolean(_value); - if (NUMBERS[j]->name == _digit) - { + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->isExtendedResolution = _zwdc; } } } - -void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { int _zwdc = 0; - -// try - { - _zwdc = stoi(_value); - } -/* catch(const std::exception& e) - { - ESP_LOGD(TAG, "ERROR - Decimalshift is not a number: %s", _value.c_str()); - } -*/ - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->DecimalShift = _zwdc; - NUMBERS[j]->DecimalShiftInitial = _zwdc; + + if (isStringNumeric(_value)) { + _zwdc = std::stoi(_value); } - if (NUMBERS[j]->name == _digit) - { + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->DecimalShift = _zwdc; NUMBERS[j]->DecimalShiftInitial = _zwdc; } @@ -392,285 +382,309 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val } } -void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleAnalogToDigitTransitionStart(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { float _zwdc = 9.2; - { - _zwdc = stof(_value); + + if (isStringNumeric(_value)) { + _zwdc = std::stof(_value); } - if (_digit == "default" || NUMBERS[j]->name == _digit) // Set to default first (if nothing else is set) - { - NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc; + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { + NUMBERS[j]->AnalogToDigitTransitionStart = _zwdc; } } } -void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { - bool _rt = false; - - if (toUpper(_value) == "TRUE") - _rt = true; - - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->AllowNegativeRates = _rt; - } + for (int j = 0; j < NUMBERS.size(); ++j) { + bool _zwdc = alphanumericToBoolean(_value); - if (NUMBERS[j]->name == _digit) - { - NUMBERS[j]->AllowNegativeRates = _rt; + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { + NUMBERS[j]->AllowNegativeRates = _zwdc; } } } - - -void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { - t_RateType _rt = AbsoluteChange; - - if (toUpper(_value) == "RATECHANGE") - _rt = RateChange; + for (int j = 0; j < NUMBERS.size(); ++j) { + t_RateType _zwdc = AbsoluteChange; - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->RateType = _rt; + if (toUpper(_value) == "RATECHANGE") { + _zwdc = RateChange; } - if (NUMBERS[j]->name == _digit) - { - NUMBERS[j]->RateType = _rt; + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { + NUMBERS[j]->MaxRateType = _zwdc; } } } - - - -void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; - for (int j = 0; j < NUMBERS.size(); ++j) - { + } + + for (int j = 0; j < NUMBERS.size(); ++j) { float _zwdc = 1; -// try - { - _zwdc = stof(_value); - } -/* catch(const std::exception& e) - { - ESP_LOGD(TAG, "ERROR - MaxRateValue is not a number: %s", _value.c_str()); - } -*/ - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->useMaxRateValue = true; - NUMBERS[j]->MaxRateValue = _zwdc; + + if (isStringNumeric(_value)) { + _zwdc = std::stof(_value); } - if (NUMBERS[j]->name == _digit) - { + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->useMaxRateValue = true; NUMBERS[j]->MaxRateValue = _zwdc; } } } +void ClassFlowPostProcessing::handleChangeRateThreshold(string _decsep, string _value) { + string _digit, _decpos; + int _pospunkt = _decsep.find_first_of("."); + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { + _digit = _decsep.substr(0, _pospunkt); + } + else { + _digit = "default"; + } + + for (int j = 0; j < NUMBERS.size(); ++j) { + int _zwdc = 2; -bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) + if (isStringNumeric(_value)) { + _zwdc = std::stof(_value); + } + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { + NUMBERS[j]->ChangeRateThreshold = _zwdc; + } + } +} +/* +void ClassFlowPostProcessing::handlecheckDigitIncreaseConsistency(std::string _decsep, std::string _value) { + std::string _digit; + int _pospunkt = _decsep.find_first_of("."); + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { + _digit = _decsep.substr(0, _pospunkt); + } + else { + _digit = "default"; + } + + for (int j = 0; j < NUMBERS.size(); ++j) { + bool _rt = alphanumericToBoolean(_value); + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { + NUMBERS[j]->checkDigitIncreaseConsistency = _rt; + } + } +} +*/ +bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { std::vector splitted; int _n; aktparamgraph = trim(aktparamgraph); - if (aktparamgraph.size() == 0) - if (!this->GetNextParagraph(pfile, aktparamgraph)) + if (aktparamgraph.size() == 0) { + if (!this->GetNextParagraph(pfile, aktparamgraph)) { return false; + } + } - - if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph does not fit PostProcessing + // Paragraph does not fit PostProcessing + if (aktparamgraph.compare("[PostProcessing]") != 0) { return false; + } InitNUMBERS(); - - while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) - { + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { splitted = ZerlegeZeile(aktparamgraph); std::string _param = GetParameterName(splitted[0]); - if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (splitted.size() > 1)) - { + if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (splitted.size() > 1)) { handleDecimalExtendedResolution(splitted[0], splitted[1]); } - if ((toUpper(_param) == "DECIMALSHIFT") && (splitted.size() > 1)) - { + if ((toUpper(_param) == "DECIMALSHIFT") && (splitted.size() > 1)) { handleDecimalSeparator(splitted[0], splitted[1]); } - if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (splitted.size() > 1)) - { - handleAnalogDigitalTransitionStart(splitted[0], splitted[1]); + + if ((toUpper(_param) == "AnalogToDigitTransitionStart") && (splitted.size() > 1)) { + handleAnalogToDigitTransitionStart(splitted[0], splitted[1]); } - if ((toUpper(_param) == "MAXRATEVALUE") && (splitted.size() > 1)) - { + + if ((toUpper(_param) == "MAXRATEVALUE") && (splitted.size() > 1)) { handleMaxRateValue(splitted[0], splitted[1]); } - if ((toUpper(_param) == "MAXRATETYPE") && (splitted.size() > 1)) - { + + if ((toUpper(_param) == "MAXRATETYPE") && (splitted.size() > 1)) { handleMaxRateType(splitted[0], splitted[1]); } - - if ((toUpper(_param) == "PREVALUEUSE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - { - PreValueUse = true; - } + + if ((toUpper(_param) == "PREVALUEUSE") && (splitted.size() > 1)) { + PreValueUse = alphanumericToBoolean(splitted[1]); + } + + if ((toUpper(_param) == "CHANGERATETHRESHOLD") && (splitted.size() > 1)) { + handleChangeRateThreshold(splitted[0], splitted[1]); } - if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - for (_n = 0; _n < NUMBERS.size(); ++_n) + + if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1)) { + // handlecheckDigitIncreaseConsistency(splitted[0], splitted[1]); + if (alphanumericToBoolean(splitted[1])) { + for (_n = 0; _n < NUMBERS.size(); ++_n) { NUMBERS[_n]->checkDigitIncreaseConsistency = true; - } - if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1)) - { + } + } + } + + if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1)) { handleAllowNegativeRate(splitted[0], splitted[1]); -/* Updated to allow individual Settings - if (toUpper(splitted[1]) == "TRUE") - for (_n = 0; _n < NUMBERS.size(); ++_n) - NUMBERS[_n]->AllowNegativeRates = true; -*/ } - if ((toUpper(_param) == "ERRORMESSAGE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - ErrorMessage = true; + + if ((toUpper(_param) == "ERRORMESSAGE") && (splitted.size() > 1)) { + ErrorMessage = alphanumericToBoolean(splitted[1]); } - if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - IgnoreLeadingNaN = true; + + if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1)) { + IgnoreLeadingNaN = alphanumericToBoolean(splitted[1]); } - - if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1)) - { - PreValueAgeStartup = std::stoi(splitted[1]); + if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1)) { + if (isStringNumeric(splitted[1])) { + PreValueAgeStartup = std::stoi(splitted[1]); + } } } if (PreValueUse) { - LoadPreValue(); + return LoadPreValue(); } return true; } -void ClassFlowPostProcessing::InitNUMBERS() -{ +void ClassFlowPostProcessing::InitNUMBERS() { int anzDIGIT = 0; int anzANALOG = 0; std::vector name_numbers; - if (flowDigit) - { + if (flowDigit) { anzDIGIT = flowDigit->getNumberGENERAL(); flowDigit->UpdateNameNumbers(&name_numbers); } - if (flowAnalog) - { + + if (flowAnalog) { anzANALOG = flowAnalog->getNumberGENERAL(); flowAnalog->UpdateNameNumbers(&name_numbers); } ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG); - for (int _num = 0; _num < name_numbers.size(); ++_num) - { + for (int _num = 0; _num < name_numbers.size(); ++_num) { NumberPost *_number = new NumberPost; _number->name = name_numbers[_num]; _number->digit_roi = NULL; - if (flowDigit) + + if (flowDigit) { _number->digit_roi = flowDigit->FindGENERAL(name_numbers[_num]); + } - if (_number->digit_roi) - _number->AnzahlDigital = _number->digit_roi->ROI.size(); - else - _number->AnzahlDigital = 0; + if (_number->digit_roi) { + _number->AnzahlDigit = _number->digit_roi->ROI.size(); + } + else { + _number->AnzahlDigit = 0; + } _number->analog_roi = NULL; - if (flowAnalog) + + if (flowAnalog) { _number->analog_roi = flowAnalog->FindGENERAL(name_numbers[_num]); + } - - if (_number->analog_roi) + if (_number->analog_roi) { _number->AnzahlAnalog = _number->analog_roi->ROI.size(); - else + } + else { _number->AnzahlAnalog = 0; + } - _number->ReturnRawValue = ""; // Raw value (with N & leading 0). - _number->ReturnValue = ""; // corrected return value, possibly with error message - _number->ErrorMessageText = ""; // Error message for consistency check - _number->ReturnPreValue = ""; + _number->FlowRateAct = 0; // m3 / min _number->PreValueOkay = false; _number->AllowNegativeRates = false; _number->MaxRateValue = 0.1; - _number->RateType = AbsoluteChange; + _number->MaxRateType = AbsoluteChange; _number->useMaxRateValue = false; _number->checkDigitIncreaseConsistency = false; _number->DecimalShift = 0; _number->DecimalShiftInitial = 0; _number->isExtendedResolution = false; - _number->AnalogDigitalTransitionStart=9.2; + _number->AnalogToDigitTransitionStart=9.2; + _number->ChangeRateThreshold = 2; - - _number->FlowRateAct = 0; // m3 / min - _number->PreValue = 0; // last value read out well _number->Value = 0; // last value read out, incl. corrections - _number->ReturnRawValue = ""; // raw value (with N & leading 0) _number->ReturnValue = ""; // corrected return value, possibly with error message + _number->ReturnRawValue = ""; // raw value (with N & leading 0) + _number->PreValue = 0; // last value read out well + _number->ReturnPreValue = ""; _number->ErrorMessageText = ""; // Error message for consistency check _number->Nachkomma = _number->AnzahlAnalog; @@ -679,40 +693,41 @@ void ClassFlowPostProcessing::InitNUMBERS() } for (int i = 0; i < NUMBERS.size(); ++i) { - ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog); + ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigit, NUMBERS[i]->AnzahlAnalog); } - } -string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){ - - if (_decShift == 0){ +string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift) { + if (_decShift == 0) { return in; } int _pos_dec_org, _pos_dec_neu; _pos_dec_org = findDelimiterPos(in, "."); + if (_pos_dec_org == std::string::npos) { _pos_dec_org = in.length(); } - else - { + else { in = in.erase(_pos_dec_org, 1); } _pos_dec_neu = _pos_dec_org + _decShift; - if (_pos_dec_neu <= 0) { // comma is before the first digit - for (int i = 0; i > _pos_dec_neu; --i){ + // comma is before the first digit + if (_pos_dec_neu <= 0) { + for (int i = 0; i > _pos_dec_neu; --i) { in = in.insert(0, "0"); } + in = "0." + in; return in; } - if (_pos_dec_neu > in.length()){ // Comma should be after string (123 --> 1230) - for (int i = in.length(); i < _pos_dec_neu; ++i){ + // Comma should be after string (123 --> 1230) + if (_pos_dec_neu > in.length()) { + for (int i = in.length(); i < _pos_dec_neu; ++i) { in = in.insert(in.length(), "0"); } return in; @@ -726,8 +741,7 @@ string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){ return zw; } -bool ClassFlowPostProcessing::doFlow(string zwtime) -{ +bool ClassFlowPostProcessing::doFlow(string zwtime) { string result = ""; string digit = ""; string analog = ""; @@ -739,8 +753,10 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) // Update decimal point, as the decimal places can also change when changing from CNNType Auto --> xyz: imagetime = flowTakeImage->getTimeImageTaken(); - if (imagetime == 0) + + if (imagetime == 0) { time(&imagetime); + } struct tm* timeinfo; timeinfo = localtime(&imagetime); @@ -750,110 +766,118 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) ESP_LOGD(TAG, "Quantity NUMBERS: %d", NUMBERS.size()); - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { NUMBERS[j]->ReturnRawValue = ""; NUMBERS[j]->ReturnRateValue = ""; NUMBERS[j]->ReturnValue = ""; + NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(0.0, NUMBERS[j]->Nachkomma); // always reset change absolute NUMBERS[j]->ErrorMessageText = ""; NUMBERS[j]->Value = -1; - /* calculate time difference BEFORE we overwrite the 'lastvalue' */ - double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in seconds - - /* TODO: - * We could call `NUMBERS[j]->lastvalue = imagetime;` here and remove all other such calls further down. - * But we should check nothing breaks! */ + // calculate time difference + // double LastValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastValue); // in seconds + double LastPreValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastPreValue); // in seconds UpdateNachkommaDecimalShift(); int previous_value = -1; - if (NUMBERS[j]->analog_roi) - { - NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution); - if (NUMBERS[j]->ReturnRawValue.length() > 0) - { + if (NUMBERS[j]->analog_roi) { + NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution); + + if (NUMBERS[j]->ReturnRawValue.length() > 0) { char zw = NUMBERS[j]->ReturnRawValue[0]; - if (zw >= 48 && zw <=57) + + if (zw >= 48 && zw <=57) { previous_value = zw - 48; + } } } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After analog->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif - if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) + + if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) { NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue; + } - if (NUMBERS[j]->digit_roi) - { - if (NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue; - else + if (NUMBERS[j]->digit_roi) { + if (NUMBERS[j]->analog_roi) { + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogToDigitTransitionStart) + NUMBERS[j]->ReturnRawValue; + } + else { NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits + } } + #ifdef SERIAL_DEBUG - ESP_LOGD(TAG, "After digital->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After digit->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift); #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif - if (IgnoreLeadingNaN) - while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) + if (IgnoreLeadingNaN) { + while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) { NUMBERS[j]->ReturnRawValue.erase(0, 1); + } + } #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After IgnoreLeadingNaN: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue; - if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos) - { - if (PreValueUse && NUMBERS[j]->PreValueOkay) - { + if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos) { + if (PreValueUse && NUMBERS[j]->PreValueOkay) { NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue); } - else - { + else { string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText; LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw); - /* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */ - NUMBERS[j]->lastvalue = imagetime; - + NUMBERS[j]->ReturnValue = ""; + NUMBERS[j]->timeStampLastValue = imagetime; WriteDataLog(j); continue; // there is no number because there is still an N. } } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After findDelimiterPos: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + // Delete leading zeros (unless there is only one 0 left) - while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0')) + while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0')) { NUMBERS[j]->ReturnValue.erase(0, 1); + } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After removeLeadingZeros: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue); + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After setting the Value: Value %f and as double is %f", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue)); #endif - if (NUMBERS[j]->checkDigitIncreaseConsistency) - { - if (flowDigit) - { - if (flowDigit->getCNNType() != Digital) - ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)"); - else + if (NUMBERS[j]->checkDigitIncreaseConsistency) { + if (flowDigit) { + if (flowDigit->getCNNType() != Digit) { + ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digit Classification)"); + } + else { NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue); + } } - else - { + else { #ifdef SERIAL_DEBUG - ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digital numbers defined!"); + ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digit numbers defined!"); #endif } } @@ -862,79 +886,88 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) ESP_LOGD(TAG, "After checkDigitIncreaseConsistency: Value %f", NUMBERS[j]->Value); #endif - if (!NUMBERS[j]->AllowNegativeRates) - { - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name); - if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue)) - { - // more debug if extended resolution is on, see #2447 - if (NUMBERS[j]->isExtendedResolution) { - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value) + if (PreValueUse && NUMBERS[j]->PreValueOkay) { + if (NUMBERS[j]->Nachkomma > 0) { + double _difference1 = (NUMBERS[j]->PreValue - (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma))); + double _difference2 = (NUMBERS[j]->PreValue + (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma))); + + if ((NUMBERS[j]->Value >= _difference1) && (NUMBERS[j]->Value <= _difference2)) { + NUMBERS[j]->Value = NUMBERS[j]->PreValue; + NUMBERS[j]->ReturnValue = std::to_string(NUMBERS[j]->PreValue); + } + } + + if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue)) { + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name); + + if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue)) { + // more debug if extended resolution is on, see #2447 + if (NUMBERS[j]->isExtendedResolution) { + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value) + ", preValue=" + std::to_string(NUMBERS[j]->PreValue) + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma)))); - } - - // Include inaccuracy of 0.2 for isExtendedResolution. - if ((NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution) - // not extended resolution allows -1 on the lowest digit - || (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(1/pow(10, NUMBERS[j]->Nachkomma))) && !NUMBERS[j]->isExtendedResolution)) { - NUMBERS[j]->Value = NUMBERS[j]->PreValue; - NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue); - } - else { + } + NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " "; NUMBERS[j]->Value = NUMBERS[j]->PreValue; NUMBERS[j]->ReturnValue = ""; - NUMBERS[j]->lastvalue = imagetime; + NUMBERS[j]->timeStampLastValue = imagetime; string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText; LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw); WriteDataLog(j); continue; } - } - } - #ifdef SERIAL_DEBUG - ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value); - #endif + #ifdef SERIAL_DEBUG + ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value); + #endif - difference /= 60; - NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference; - NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct); - - if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay) - { - double _ratedifference; - if (NUMBERS[j]->RateType == RateChange) - _ratedifference = NUMBERS[j]->FlowRateAct; - else - _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue); - - if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue)) - { - NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + RundeOutput(_ratedifference, NUMBERS[j]->Nachkomma); - NUMBERS[j]->Value = NUMBERS[j]->PreValue; - NUMBERS[j]->ReturnValue = ""; - NUMBERS[j]->ReturnRateValue = ""; - NUMBERS[j]->lastvalue = imagetime; + // LastValueTimeDifference = LastValueTimeDifference / 60; // in minutes + LastPreValueTimeDifference = LastPreValueTimeDifference / 60; // in minutes + NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / LastPreValueTimeDifference; + NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct); - string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText; - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw); - WriteDataLog(j); - continue; + if ((NUMBERS[j]->useMaxRateValue) && (NUMBERS[j]->Value != NUMBERS[j]->PreValue)) { + double _ratedifference; + + if (NUMBERS[j]->MaxRateType == RateChange) { + _ratedifference = NUMBERS[j]->FlowRateAct; + } + else { + // TODO: + // Since I don't know if this is desired, I'll comment it out first. + // int roundDifference = (int)(round(LastPreValueTimeDifference / LastValueTimeDifference)); // calculate how many rounds have passed since NUMBERS[j]->timeLastPreValue was set + // _ratedifference = ((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / ((int)(round(LastPreValueTimeDifference / LastValueTimeDifference)))); // Difference per round, as a safeguard in case a reading error(Neg. Rate - Read: or Rate too high - Read:) occurs in the meantime + _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue); + } + + if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue)) { + NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + RundeOutput(_ratedifference, NUMBERS[j]->Nachkomma); + NUMBERS[j]->Value = NUMBERS[j]->PreValue; + NUMBERS[j]->ReturnValue = ""; + NUMBERS[j]->ReturnRateValue = ""; + NUMBERS[j]->timeStampLastValue = imagetime; + + string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText; + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw); + WriteDataLog(j); + continue; + } } - } #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value); #endif + } NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); NUMBERS[j]->PreValue = NUMBERS[j]->Value; NUMBERS[j]->PreValueOkay = true; - NUMBERS[j]->lastvalue = imagetime; + + NUMBERS[j]->timeStampLastValue = imagetime; + NUMBERS[j]->timeStampLastPreValue = imagetime; NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma); NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); @@ -951,104 +984,105 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) return true; } -void ClassFlowPostProcessing::WriteDataLog(int _index) -{ - if (!LogFile.GetDataLogToSD()){ +void ClassFlowPostProcessing::WriteDataLog(int _index) { + if (!LogFile.GetDataLogToSD()) { return; } string analog = ""; - string digital = ""; + string digit = ""; string timezw = ""; char buffer[80]; - struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue); + struct tm* timeinfo = localtime(&NUMBERS[_index]->timeStampLastValue); strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); timezw = std::string(buffer); - if (flowAnalog) + if (flowAnalog) { analog = flowAnalog->getReadoutRawString(_index); - if (flowDigit) - digital = flowDigit->getReadoutRawString(_index); - LogFile.WriteToData(timezw, NUMBERS[_index]->name, - NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue, - NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute, - NUMBERS[_index]->ErrorMessageText, - digital, analog); - ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digital.c_str(), analog.c_str()); -} + } + if (flowDigit) { + digit = flowDigit->getReadoutRawString(_index); + } + + LogFile.WriteToData(timezw, NUMBERS[_index]->name, NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue, + NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute, NUMBERS[_index]->ErrorMessageText, digit, analog); -void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() -{ - for (int j = 0; j < NUMBERS.size(); ++j) - { - if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits - { -// ESP_LOGD(TAG, "Nurdigital"); + ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digit.c_str(), analog.c_str()); +} + +void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() { + for (int j = 0; j < NUMBERS.size(); ++j) { + // There are only digits + if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) { + // ESP_LOGD(TAG, "Nurdigit"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; - if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit. + // Extended resolution is on and should also be used for this digit. + if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) { NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1; + } NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift; } - if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) - { -// ESP_LOGD(TAG, "Nur analog"); + if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) { + // ESP_LOGD(TAG, "Nur analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; - if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) + + if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) { NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1; + } NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift; } - if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog - { -// ESP_LOGD(TAG, "Nur digital + analog"); + // digit + analog + if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) { + // ESP_LOGD(TAG, "Nur digit + analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift; - if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit. + // Extended resolution is on and should also be used for this digit. + if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) { NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1; - + } } ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift); } } - -string ClassFlowPostProcessing::getReadout(int _number) -{ +string ClassFlowPostProcessing::getReadout(int _number) { return NUMBERS[_number]->ReturnValue; } -string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number) -{ - if (_rawValue) +string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number) { + if (_rawValue) { return NUMBERS[_number]->ReturnRawValue; - if (_noerror) + } + + if (_noerror) { return NUMBERS[_number]->ReturnValue; + } + return NUMBERS[_number]->ReturnValue; } - -string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) -{ +string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) { int posN, posPunkt; int pot, ziffer; float zw; posN = findDelimiterPos(input, "N"); posPunkt = findDelimiterPos(input, "."); - if (posPunkt == std::string::npos){ + + if (posPunkt == std::string::npos) { posPunkt = input.length(); } - while (posN != std::string::npos) - { + while (posN != std::string::npos) { if (posN < posPunkt) { pot = posPunkt - posN - 1; } @@ -1066,7 +1100,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) return input; } -float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){ +float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue) { int aktdigit, olddigit; int aktdigit_before, olddigit_before; int pot, pot_max; @@ -1074,16 +1108,19 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams bool no_nulldurchgang = false; pot = _decilamshift; - if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated - { + + // if there are no analogue values, the last one cannot be evaluated + if (!_isanalog) { pot++; } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift); #endif + pot_max = ((int) log10(input)) + 1; - while (pot <= pot_max) - { + + while (pot <= pot_max) { zw = input / pow(10, pot-1); aktdigit_before = ((int) zw) % 10; zw = _preValue / pow(10, pot-1); @@ -1096,43 +1133,36 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams no_nulldurchgang = (olddigit_before <= aktdigit_before); - if (no_nulldurchgang) - { - if (aktdigit != olddigit) - { + if (no_nulldurchgang) { + if (aktdigit != olddigit) { input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit; } } - else - { - if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1 - { + else { + // despite zero crossing, digit was not incremented --> add 1 + if (aktdigit == olddigit) { input = input + ((float) (1)) * pow(10, pot); // add 1 at the point } } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input); #endif + pot++; } return input; } -string ClassFlowPostProcessing::getReadoutRate(int _number) -{ +string ClassFlowPostProcessing::getReadoutRate(int _number) { return std::to_string(NUMBERS[_number]->FlowRateAct); } -string ClassFlowPostProcessing::getReadoutTimeStamp(int _number) -{ +string ClassFlowPostProcessing::getReadoutTimeStamp(int _number) { return NUMBERS[_number]->timeStamp; } - -string ClassFlowPostProcessing::getReadoutError(int _number) -{ +string ClassFlowPostProcessing::getReadoutError(int _number) { return NUMBERS[_number]->ErrorMessageText; } - - diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index aae28e6a3..e16aa618c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -21,11 +21,9 @@ class ClassFlowPostProcessing : bool ErrorMessage; bool IgnoreLeadingNaN; // SPECIAL CASE for User Gustl ??? - ClassFlowCNNGeneral* flowAnalog; ClassFlowCNNGeneral* flowDigit; - string FilePreValue; ClassFlowTakeImage *flowTakeImage; @@ -41,21 +39,18 @@ class ClassFlowPostProcessing : void handleMaxRateValue(string _decsep, string _value); void handleDecimalExtendedResolution(string _decsep, string _value); void handleMaxRateType(string _decsep, string _value); - void handleAnalogDigitalTransitionStart(string _decsep, string _value); + void handleAnalogToDigitTransitionStart(string _decsep, string _value); void handleAllowNegativeRate(string _decsep, string _value); + void handleChangeRateThreshold(string _decsep, string _value); std::string GetStringReadouts(general); void WriteDataLog(int _index); - - - public: bool PreValueUse; std::vector NUMBERS; - ClassFlowPostProcessing(std::vector* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit); virtual ~ClassFlowPostProcessing(){}; bool ReadParameter(FILE* pfile, string& aktparamgraph); diff --git a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp index 5d6d9ed74..f83829064 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp @@ -1,9 +1,15 @@ +#include +#include +#include +#include + #include "ClassFlowTakeImage.h" #include "Helper.h" #include "ClassLogFile.h" #include "CImageBasis.h" #include "ClassControllCamera.h" +#include "MainFlowControl.h" #include "esp_wifi.h" #include "esp_log.h" @@ -12,14 +18,14 @@ #include -// #define DEBUG_DETAIL_ON - +// #define DEBUG_DETAIL_ON // #define WIFITURNOFF -static const char* TAG = "TAKEIMAGE"; +static const char *TAG = "TAKEIMAGE"; -esp_err_t ClassFlowTakeImage::camera_capture(){ - string nm = namerawimage; +esp_err_t ClassFlowTakeImage::camera_capture(void) +{ + string nm = namerawimage; Camera.CaptureToFile(nm); time(&TimeImageTaken); localtime(&TimeImageTaken); @@ -30,204 +36,499 @@ esp_err_t ClassFlowTakeImage::camera_capture(){ void ClassFlowTakeImage::takePictureWithFlash(int flash_duration) { // in case the image is flipped, it must be reset here // - rawImage->width = image_width; - rawImage->height = image_height; - ///////////////////////////////////////////////////////////////////////////////////// + rawImage->width = CCstatus.ImageWidth; + rawImage->height = CCstatus.ImageHeight; + ESP_LOGD(TAG, "flash_duration: %d", flash_duration); + Camera.CaptureToBasisImage(rawImage, flash_duration); + time(&TimeImageTaken); localtime(&TimeImageTaken); - if (SaveAllFiles) rawImage->SaveToFile(namerawimage); + if (CCstatus.SaveAllFiles) + { + rawImage->SaveToFile(namerawimage); + } } void ClassFlowTakeImage::SetInitialParameter(void) { - waitbeforepicture = 5; - isImageSize = false; - ImageQuality = -1; TimeImageTaken = 0; - ImageQuality = 5; rawImage = NULL; - ImageSize = FRAMESIZE_VGA; - ZoomEnabled = false; - ZoomMode = 0; - zoomOffsetX = 0; - zoomOffsetY = 0; - ImageNegative = false; - ImageAec2 = false; -#ifdef GRAYSCALE_AS_DEFAULT - ImageGrayscale = true; -#else - ImageGrayscale = false; -#endif - SaveAllFiles = false; disabled = false; - FixedExposure = false; namerawimage = "/sdcard/img_tmp/raw.jpg"; -} - - -ClassFlowTakeImage::ClassFlowTakeImage(std::vector* lfc) : ClassFlowImage(lfc, TAG) -{ - imagesLocation = "/log/source"; - imagesRetention = 5; - SetInitialParameter(); } - -bool ClassFlowTakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) +// auslesen der Kameraeinstellungen aus der config.ini +// wird beim Start aufgerufen +bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph) { + Camera.getSensorDatenToCCstatus(); // Kamera >>> CCstatus + std::vector splitted; aktparamgraph = trim(aktparamgraph); - int _brightness = 0; - int _contrast = 0; - int _saturation = 0; - int _sharpness = 0; - int _autoExposureLevel = 0; if (aktparamgraph.size() == 0) + { if (!this->GetNextParagraph(pfile, aktparamgraph)) + { return false; + } + } - if (aktparamgraph.compare("[TakeImage]") != 0) // Paragraph does not fit TakeImage + if (aktparamgraph.compare("[TakeImage]") != 0) + { + // Paragraph does not fit TakeImage return false; + } while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { splitted = ZerlegeZeile(aktparamgraph); - if ((toUpper(splitted[0]) == "RAWIMAGESLOCATION") && (splitted.size() > 1)) + + if ((toUpper(splitted[0]) == "RAWIMAGESLOCATION") && (splitted.size() > 1)) { imagesLocation = "/sdcard" + splitted[1]; isLogImage = true; } - if ((toUpper(splitted[0]) == "IMAGEQUALITY") && (splitted.size() > 1)) - ImageQuality = std::stod(splitted[1]); - if ((toUpper(splitted[0]) == "ZOOM") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "RAWIMAGESRETENTION") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + this->imagesRetention = std::stod(splitted[1]); + } + } + + else if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) + { + CCstatus.SaveAllFiles = alphanumericToBoolean(splitted[1]); + } + + else if ((toUpper(splitted[0]) == "WAITBEFORETAKINGPICTURE") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _WaitBeforePicture = std::stoi(splitted[1]); + if (_WaitBeforePicture != 0) + { + CCstatus.WaitBeforePicture = _WaitBeforePicture; + } + else + { + CCstatus.WaitBeforePicture = 2; + } + } + } + + else if ((toUpper(splitted[0]) == "CAMGAINCEILING") && (splitted.size() > 1)) + { + std::string _ImageGainceiling = toUpper(splitted[1]); + + if (isStringNumeric(_ImageGainceiling)) + { + int _ImageGainceiling_ = std::stoi(_ImageGainceiling); + switch (_ImageGainceiling_) + { + case 1: + CFstatus.ImageGainceiling = GAINCEILING_4X; + break; + case 2: + CFstatus.ImageGainceiling = GAINCEILING_8X; + break; + case 3: + CFstatus.ImageGainceiling = GAINCEILING_16X; + break; + case 4: + CFstatus.ImageGainceiling = GAINCEILING_32X; + break; + case 5: + CFstatus.ImageGainceiling = GAINCEILING_64X; + break; + case 6: + CFstatus.ImageGainceiling = GAINCEILING_128X; + break; + default: + CFstatus.ImageGainceiling = GAINCEILING_2X; + } + } + else + { + if (_ImageGainceiling == "X4") + { + CCstatus.ImageGainceiling = GAINCEILING_4X; + } + else if (_ImageGainceiling == "X8") + { + CCstatus.ImageGainceiling = GAINCEILING_8X; + } + else if (_ImageGainceiling == "X16") + { + CCstatus.ImageGainceiling = GAINCEILING_16X; + } + else if (_ImageGainceiling == "X32") + { + CCstatus.ImageGainceiling = GAINCEILING_32X; + } + else if (_ImageGainceiling == "X64") + { + CCstatus.ImageGainceiling = GAINCEILING_64X; + } + else if (_ImageGainceiling == "X128") + { + CCstatus.ImageGainceiling = GAINCEILING_128X; + } + else + { + CCstatus.ImageGainceiling = GAINCEILING_2X; + } + } + } + + else if ((toUpper(splitted[0]) == "CAMQUALITY") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageQuality = std::stoi(splitted[1]); + CCstatus.ImageQuality = clipInt(_ImageQuality, 63, 6); + } + } + + else if ((toUpper(splitted[0]) == "CAMBRIGHTNESS") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageBrightness = std::stoi(splitted[1]); + CCstatus.ImageBrightness = clipInt(_ImageBrightness, 2, -2); + } + } + + else if ((toUpper(splitted[0]) == "CAMCONTRAST") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageContrast = std::stoi(splitted[1]); + CCstatus.ImageContrast = clipInt(_ImageContrast, 2, -2); + } + } + + else if ((toUpper(splitted[0]) == "CAMSATURATION") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageSaturation = std::stoi(splitted[1]); + CCstatus.ImageSaturation = clipInt(_ImageSaturation, 2, -2); + } + } + + else if ((toUpper(splitted[0]) == "CAMSHARPNESS") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageSharpness = std::stoi(splitted[1]); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageSharpness = clipInt(_ImageSharpness, 2, -2); + } + else + { + CCstatus.ImageSharpness = clipInt(_ImageSharpness, 3, -3); + } + } + } + + else if ((toUpper(splitted[0]) == "CAMAUTOSHARPNESS") && (splitted.size() > 1)) + { + CCstatus.ImageAutoSharpness = alphanumericToBoolean(splitted[1]); + } + + else if ((toUpper(splitted[0]) == "CAMSPECIALEFFECT") && (splitted.size() > 1)) + { + std::string _ImageSpecialEffect = toUpper(splitted[1]); + + if (isStringNumeric(_ImageSpecialEffect)) + { + int _ImageSpecialEffect_ = std::stoi(_ImageSpecialEffect); + CFstatus.ImageSpecialEffect = clipInt(_ImageSpecialEffect_, 6, 0); + } + else + { + if (_ImageSpecialEffect == "NEGATIVE") + { + CCstatus.ImageSpecialEffect = 1; + } + else if (_ImageSpecialEffect == "GRAYSCALE") + { + CCstatus.ImageSpecialEffect = 2; + } + else if (_ImageSpecialEffect == "RED") + { + CCstatus.ImageSpecialEffect = 3; + } + else if (_ImageSpecialEffect == "GREEN") + { + CCstatus.ImageSpecialEffect = 4; + } + else if (_ImageSpecialEffect == "BLUE") + { + CCstatus.ImageSpecialEffect = 5; + } + else if (_ImageSpecialEffect == "RETRO") + { + CCstatus.ImageSpecialEffect = 6; + } + else + { + CCstatus.ImageSpecialEffect = 0; + } + } + } + + else if ((toUpper(splitted[0]) == "CAMWBMODE") && (splitted.size() > 1)) + { + std::string _ImageWbMode = toUpper(splitted[1]); + + if (isStringNumeric(_ImageWbMode)) + { + int _ImageWbMode_ = std::stoi(_ImageWbMode); + CFstatus.ImageWbMode = clipInt(_ImageWbMode_, 4, 0); + } + else + { + if (_ImageWbMode == "SUNNY") + { + CCstatus.ImageWbMode = 1; + } + else if (_ImageWbMode == "CLOUDY") + { + CCstatus.ImageWbMode = 2; + } + else if (_ImageWbMode == "OFFICE") + { + CCstatus.ImageWbMode = 3; + } + else if (_ImageWbMode == "HOME") + { + CCstatus.ImageWbMode = 4; + } + else + { + CCstatus.ImageWbMode = 0; + } + } + } + + else if ((toUpper(splitted[0]) == "CAMAWB") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") - ZoomEnabled = true; - else if (toUpper(splitted[1]) == "FALSE") - ZoomEnabled = false; + CCstatus.ImageAwb = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "ZOOMMODE") && (splitted.size() > 1)) - ZoomMode = std::stod(splitted[1]); - if ((toUpper(splitted[0]) == "ZOOMOFFSETX") && (splitted.size() > 1)) - zoomOffsetX = std::stod(splitted[1]); - if ((toUpper(splitted[0]) == "ZOOMOFFSETY") && (splitted.size() > 1)) - zoomOffsetY = std::stod(splitted[1]); - if ((toUpper(splitted[0]) == "GRAYSCALE") && (splitted.size() > 1)) + + else if ((toUpper(splitted[0]) == "CAMAWBGAIN") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") - ImageGrayscale = true; - else if (toUpper(splitted[1]) == "FALSE") - ImageGrayscale = false; + CCstatus.ImageAwbGain = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "NEGATIVE") && (splitted.size() > 1)) + + else if ((toUpper(splitted[0]) == "CAMAEC") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") - ImageNegative = true; - else if (toUpper(splitted[1]) == "FALSE") - ImageNegative = false; + CCstatus.ImageAec = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "AEC2") && (splitted.size() > 1)) + + else if ((toUpper(splitted[0]) == "CAMAEC2") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") - ImageAec2 = true; - else if (toUpper(splitted[1]) == "FALSE") - ImageAec2 = false; + CCstatus.ImageAec2 = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "AUTOEXPOSURELEVEL") && (splitted.size() > 1)) - _autoExposureLevel = std::stod(splitted[1]); - if ((toUpper(splitted[0]) == "IMAGESIZE") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMAELEVEL") && (splitted.size() > 1)) { - ImageSize = Camera.TextToFramesize(splitted[1].c_str()); - isImageSize = true; + if (isStringNumeric(splitted[1])) + { + int _ImageAeLevel = std::stoi(splitted[1]); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 2, -2); + } + else + { + CCstatus.ImageAeLevel = clipInt(_ImageAeLevel, 5, -5); + } + } } - if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMAECVALUE") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") - SaveAllFiles = true; + if (isStringNumeric(splitted[1])) + { + int _ImageAecValue = std::stoi(splitted[1]); + CCstatus.ImageAecValue = clipInt(_ImageAecValue, 1200, 0); + } } - - if ((toUpper(splitted[0]) == "WAITBEFORETAKINGPICTURE") && (splitted.size() > 1)) + + else if ((toUpper(splitted[0]) == "CAMAGC") && (splitted.size() > 1)) + { + CCstatus.ImageAgc = alphanumericToBoolean(splitted[1]); + } + + else if ((toUpper(splitted[0]) == "CAMAGCGAIN") && (splitted.size() > 1)) { - waitbeforepicture = stoi(splitted[1]); + if (isStringNumeric(splitted[1])) + { + int _ImageAgcGain = std::stoi(splitted[1]); + CCstatus.ImageAgcGain = clipInt(_ImageAgcGain, 30, 0); + } } - if ((toUpper(splitted[0]) == "RAWIMAGESRETENTION") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMBPC") && (splitted.size() > 1)) { - this->imagesRetention = std::stoi(splitted[1]); + CCstatus.ImageBpc = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "BRIGHTNESS") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMWPC") && (splitted.size() > 1)) { - _brightness = stoi(splitted[1]); + CCstatus.ImageWpc = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "CONTRAST") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMRAWGMA") && (splitted.size() > 1)) { - _contrast = stoi(splitted[1]); + CCstatus.ImageRawGma = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "SATURATION") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMLENC") && (splitted.size() > 1)) { - _saturation = stoi(splitted[1]); + CCstatus.ImageLenc = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "SHARPNESS") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMHMIRROR") && (splitted.size() > 1)) { - _sharpness = stoi(splitted[1]); + CCstatus.ImageHmirror = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "FIXEDEXPOSURE") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMVFLIP") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") - FixedExposure = true; + CCstatus.ImageVflip = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "LEDINTENSITY") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMDCW") && (splitted.size() > 1)) { - float ledintensity = stof(splitted[1]); - ledintensity = min((float) 100, ledintensity); - ledintensity = max((float) 0, ledintensity); - Camera.SetLEDIntensity(ledintensity); + CCstatus.ImageDcw = alphanumericToBoolean(splitted[1]); } - if ((toUpper(splitted[0]) == "DEMO") && (splitted.size() > 1)) + else if ((toUpper(splitted[0]) == "CAMDENOISE") && (splitted.size() > 1)) { - if (toUpper(splitted[1]) == "TRUE") + if (isStringNumeric(splitted[1])) + { + int _ImageDenoiseLevel = std::stoi(splitted[1]); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageDenoiseLevel = 0; + } + else + { + CCstatus.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0); + } + } + } + + else if ((toUpper(splitted[0]) == "CAMZOOM") && (splitted.size() > 1)) + { + CCstatus.ImageZoomEnabled = alphanumericToBoolean(splitted[1]); + } + + else if ((toUpper(splitted[0]) == "CAMZOOMOFFSETX") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageZoomOffsetX = std::stoi(splitted[1]); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480); + } + else if (CCstatus.CamSensor_id == OV3660_PID) + { + CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704); + } + else if (CCstatus.CamSensor_id == OV5640_PID) + { + CCstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960); + } + } + } + + else if ((toUpper(splitted[0]) == "CAMZOOMOFFSETY") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageZoomOffsetY = std::stoi(splitted[1]); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360); + } + else if (CCstatus.CamSensor_id == OV3660_PID) + { + CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528); + } + else if (CCstatus.CamSensor_id == OV5640_PID) + { + CCstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720); + } + } + } + + else if ((toUpper(splitted[0]) == "CAMZOOMSIZE") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + int _ImageZoomSize = std::stoi(splitted[1]); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0); + } + else if (CCstatus.CamSensor_id == OV3660_PID) + { + CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0); + } + else if (CCstatus.CamSensor_id == OV5640_PID) + { + CCstatus.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0); + } + } + } + + else if ((toUpper(splitted[0]) == "LEDINTENSITY") && (splitted.size() > 1)) + { + if (isStringNumeric(splitted[1])) + { + float ledintensity = std::stof(splitted[1]); + Camera.SetLEDIntensity(ledintensity); + } + } + + else if ((toUpper(splitted[0]) == "DEMO") && (splitted.size() > 1)) + { + CCstatus.DemoMode = alphanumericToBoolean(splitted[1]); + if (CCstatus.DemoMode == true) + { Camera.useDemoMode(); + } } } - Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation, _autoExposureLevel, ImageGrayscale, ImageNegative, ImageAec2, _sharpness); - Camera.SetQualitySize(ImageQuality, ImageSize, ZoomEnabled, ZoomMode, zoomOffsetX, zoomOffsetY); + Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera + Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); - image_width = Camera.image_width; - image_height = Camera.image_height; rawImage = new CImageBasis("rawImage"); - rawImage->CreateEmptyImage(image_width, image_height, 3); - - waitbeforepicture_store = waitbeforepicture; - if (FixedExposure && (waitbeforepicture > 0)) - { -// ESP_LOGD(TAG, "Fixed Exposure enabled!"); - int flash_duration = (int) (waitbeforepicture * 1000); - Camera.EnableAutoExposure(flash_duration); - waitbeforepicture = 0.2; -// flash_duration = (int) (waitbeforepicture * 1000); -// takePictureWithFlash(flash_duration); -// rawImage->SaveToFile("/sdcard/init2.jpg"); - } + rawImage->CreateEmptyImage(CCstatus.ImageWidth, CCstatus.ImageHeight, 3); return true; } +ClassFlowTakeImage::ClassFlowTakeImage(std::vector *lfc) : ClassFlowImage(lfc, TAG) +{ + imagesLocation = "/log/source"; + imagesRetention = 5; + SetInitialParameter(); +} string ClassFlowTakeImage::getHTMLSingleStep(string host) { @@ -236,74 +537,78 @@ string ClassFlowTakeImage::getHTMLSingleStep(string host) return result; } - +// wird bei jeder Auswertrunde aufgerufen bool ClassFlowTakeImage::doFlow(string zwtime) { psram_init_shared_memory_for_take_image_step(); string logPath = CreateLogFolder(zwtime); - int flash_duration = (int) (waitbeforepicture * 1000); - - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - Before takePictureWithFlash"); - #endif + int flash_duration = (int)(CCstatus.WaitBeforePicture * 1000); +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - Before takePictureWithFlash"); +#endif - #ifdef WIFITURNOFF - esp_wifi_stop(); // to save power usage and - #endif +#ifdef WIFITURNOFF + esp_wifi_stop(); // to save power usage and +#endif - takePictureWithFlash(flash_duration); + // wenn die Kameraeinstellungen durch Erstellen eines neuen Referenzbildes verändert wurden, müssen sie neu gesetzt werden + if (CFstatus.changedCameraSettings) + { + Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera + Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + CFstatus.changedCameraSettings = false; + } - #ifdef WIFITURNOFF - esp_wifi_start(); - #endif + takePictureWithFlash(flash_duration); +#ifdef WIFITURNOFF + esp_wifi_start(); +#endif - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After takePictureWithFlash"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After takePictureWithFlash"); +#endif LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage); RemoveOldLogs(); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After RemoveOldLogs"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After RemoveOldLogs"); +#endif psram_deinit_shared_memory_for_take_image_step(); return true; } - esp_err_t ClassFlowTakeImage::SendRawJPG(httpd_req_t *req) { - int flash_duration = (int) (waitbeforepicture * 1000); + int flash_duration = (int)(CCstatus.WaitBeforePicture * 1000); time(&TimeImageTaken); localtime(&TimeImageTaken); return Camera.CaptureToHTTP(req, flash_duration); } - -ImageData* ClassFlowTakeImage::SendRawImage() +ImageData *ClassFlowTakeImage::SendRawImage(void) { CImageBasis *zw = new CImageBasis("SendRawImage", rawImage); ImageData *id; - int flash_duration = (int) (waitbeforepicture * 1000); + int flash_duration = (int)(CCstatus.WaitBeforePicture * 1000); Camera.CaptureToBasisImage(zw, flash_duration); time(&TimeImageTaken); localtime(&TimeImageTaken); - id = zw->writeToMemoryAsJPG(); + id = zw->writeToMemoryAsJPG(); delete zw; - return id; + return id; } -time_t ClassFlowTakeImage::getTimeImageTaken() +time_t ClassFlowTakeImage::getTimeImageTaken(void) { return TimeImageTaken; } @@ -312,4 +617,3 @@ ClassFlowTakeImage::~ClassFlowTakeImage(void) { delete rawImage; } - diff --git a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h index d83f393e1..0be4f3af8 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h @@ -9,54 +9,32 @@ #include -class ClassFlowTakeImage : - public ClassFlowImage +class ClassFlowTakeImage : public ClassFlowImage { protected: - float waitbeforepicture; - float waitbeforepicture_store; - framesize_t ImageSize; - bool isImageSize; - bool ZoomEnabled = false; - int ZoomMode = 0; - int zoomOffsetX = 0; - int zoomOffsetY = 0; - bool ImageGrayscale; - bool ImageNegative; - bool ImageAec2; - int ImageQuality; time_t TimeImageTaken; string namerawimage; - int image_height, image_width; - bool SaveAllFiles; - bool FixedExposure; - - - void CopyFile(string input, string output); - - esp_err_t camera_capture(); + esp_err_t camera_capture(void); void takePictureWithFlash(int flash_duration); - - void SetInitialParameter(void); + void SetInitialParameter(void); public: CImageBasis *rawImage; - ClassFlowTakeImage(std::vector* lfc); + ClassFlowTakeImage(std::vector *lfc); - bool ReadParameter(FILE* pfile, string& aktparamgraph); + bool ReadParameter(FILE *pfile, string &aktparamgraph); bool doFlow(string time); string getHTMLSingleStep(string host); - time_t getTimeImageTaken(); - string name(){return "ClassFlowTakeImage";}; + time_t getTimeImageTaken(void); + string name() { return "ClassFlowTakeImage"; }; - ImageData* SendRawImage(); + ImageData *SendRawImage(void); esp_err_t SendRawJPG(httpd_req_t *req); ~ClassFlowTakeImage(void); }; - -#endif //CLASSFFLOWTAKEIMAGE_H \ No newline at end of file +#endif // CLASSFFLOWTAKEIMAGE_H \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/ClassFlowWebhook.cpp b/code/components/jomjol_flowcontroll/ClassFlowWebhook.cpp new file mode 100644 index 000000000..5194c82b4 --- /dev/null +++ b/code/components/jomjol_flowcontroll/ClassFlowWebhook.cpp @@ -0,0 +1,171 @@ +#ifdef ENABLE_WEBHOOK +#include +#include "ClassFlowWebhook.h" +#include "Helper.h" +#include "connect_wlan.h" + +#include "time_sntp.h" +#include "interface_webhook.h" + +#include "ClassFlowPostProcessing.h" +#include "ClassFlowAlignment.h" +#include "esp_log.h" +#include "../../include/defines.h" + +#include "ClassLogFile.h" + +#include + +static const char* TAG = "WEBHOOK"; + +void ClassFlowWebhook::SetInitialParameter(void) +{ + uri = ""; + flowpostprocessing = NULL; + flowAlignment = NULL; + previousElement = NULL; + ListFlowControll = NULL; + disabled = false; + WebhookEnable = false; + WebhookUploadImg = 0; +} + +ClassFlowWebhook::ClassFlowWebhook() +{ + SetInitialParameter(); +} + +ClassFlowWebhook::ClassFlowWebhook(std::vector* lfc) +{ + SetInitialParameter(); + + ListFlowControll = lfc; + for (int i = 0; i < ListFlowControll->size(); ++i) + { + if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0) + { + flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i]; + } + if (((*ListFlowControll)[i])->name().compare("ClassFlowAlignment") == 0) + { + flowAlignment = (ClassFlowAlignment*) (*ListFlowControll)[i]; + } + + } +} + +ClassFlowWebhook::ClassFlowWebhook(std::vector* lfc, ClassFlow *_prev) +{ + SetInitialParameter(); + + previousElement = _prev; + ListFlowControll = lfc; + + for (int i = 0; i < ListFlowControll->size(); ++i) + { + if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0) + { + flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i]; + } + if (((*ListFlowControll)[i])->name().compare("ClassFlowAlignment") == 0) + { + flowAlignment = (ClassFlowAlignment*) (*ListFlowControll)[i]; + } + } +} + + +bool ClassFlowWebhook::ReadParameter(FILE* pfile, string& aktparamgraph) +{ + std::vector splitted; + + aktparamgraph = trim(aktparamgraph); + printf("akt param: %s\n", aktparamgraph.c_str()); + + if (aktparamgraph.size() == 0) + if (!this->GetNextParagraph(pfile, aktparamgraph)) + return false; + + if (toUpper(aktparamgraph).compare("[WEBHOOK]") != 0) + return false; + + + + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) + { + ESP_LOGD(TAG, "while loop reading line: %s", aktparamgraph.c_str()); + splitted = ZerlegeZeile(aktparamgraph); + std::string _param = GetParameterName(splitted[0]); + + if ((toUpper(_param) == "URI") && (splitted.size() > 1)) + { + this->uri = splitted[1]; + } + if (((toUpper(_param) == "APIKEY")) && (splitted.size() > 1)) + { + this->apikey = splitted[1]; + } + if (((toUpper(_param) == "UPLOADIMG")) && (splitted.size() > 1)) + { + if (toUpper(splitted[1]) == "1") + { + this->WebhookUploadImg = 1; + } else if (toUpper(splitted[1]) == "2") + { + this->WebhookUploadImg = 2; + } + } + } + + WebhookInit(uri,apikey); + WebhookEnable = true; + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Webhook Enabled for Uri " + uri); + + printf("uri: %s\n", uri.c_str()); + return true; +} + + +void ClassFlowWebhook::handleMeasurement(string _decsep, string _value) +{ + string _digit, _decpos; + int _pospunkt = _decsep.find_first_of("."); +// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + if (_pospunkt > -1) + _digit = _decsep.substr(0, _pospunkt); + else + _digit = "default"; + for (int j = 0; j < flowpostprocessing->NUMBERS.size(); ++j) + { + if (_digit == "default") // Set to default first (if nothing else is set) + { + flowpostprocessing->NUMBERS[j]->MeasurementV2 = _value; + } + if (flowpostprocessing->NUMBERS[j]->name == _digit) + { + flowpostprocessing->NUMBERS[j]->MeasurementV2 = _value; + } + } +} + + +bool ClassFlowWebhook::doFlow(string zwtime) +{ + if (!WebhookEnable) + return true; + + if (flowpostprocessing) + { + printf("vor sende WebHook"); + bool numbersWithError = WebhookPublish(flowpostprocessing->GetNumbers()); + + #ifdef ALGROI_LOAD_FROM_MEM_AS_JPG + if ((WebhookUploadImg == 1 || (WebhookUploadImg != 0 && numbersWithError)) && flowAlignment && flowAlignment->AlgROI) { + WebhookUploadPic(flowAlignment->AlgROI); + } + #endif + } + + return true; +} +#endif //ENABLE_WEBHOOK \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/ClassFlowWebhook.h b/code/components/jomjol_flowcontroll/ClassFlowWebhook.h new file mode 100644 index 000000000..8f679d42f --- /dev/null +++ b/code/components/jomjol_flowcontroll/ClassFlowWebhook.h @@ -0,0 +1,43 @@ +#ifdef ENABLE_WEBHOOK + +#pragma once + +#ifndef CLASSFWEBHOOK_H +#define CLASSFWEBHOOK_H + +#include "ClassFlow.h" + +#include "ClassFlowPostProcessing.h" +#include "ClassFlowAlignment.h" + +#include + +class ClassFlowWebhook : + public ClassFlow +{ +protected: + std::string uri, apikey; + ClassFlowPostProcessing* flowpostprocessing; + ClassFlowAlignment* flowAlignment; + + bool WebhookEnable; + int WebhookUploadImg; + + void SetInitialParameter(void); + + void handleFieldname(string _decsep, string _value); + void handleMeasurement(string _decsep, string _value); + + +public: + ClassFlowWebhook(); + ClassFlowWebhook(std::vector* lfc); + ClassFlowWebhook(std::vector* lfc, ClassFlow *_prev); + + bool ReadParameter(FILE* pfile, string& aktparamgraph); + bool doFlow(string time); + string name(){return "ClassFlowWebhook";}; +}; + +#endif //CLASSFWEBHOOK_H +#endif //ENABLE_WEBHOOK \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/MainFlowControl.cpp b/code/components/jomjol_flowcontroll/MainFlowControl.cpp index 85ed30674..e80f69eb3 100644 --- a/code/components/jomjol_flowcontroll/MainFlowControl.cpp +++ b/code/components/jomjol_flowcontroll/MainFlowControl.cpp @@ -34,6 +34,7 @@ #endif ClassFlowControll flowctrl; +camera_flow_config_temp_t CFstatus; TaskHandle_t xHandletask_autodoFlow = NULL; @@ -48,177 +49,329 @@ bool isPlannedReboot = false; static const char *TAG = "MAINCTRL"; -//#define DEBUG_DETAIL_ON +// #define DEBUG_DETAIL_ON - -void CheckIsPlannedReboot() { +void CheckIsPlannedReboot(void) +{ FILE *pfile; - - if ((pfile = fopen("/sdcard/reboot.txt", "r")) == NULL) { - //LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Initial boot or not a planned reboot"); + + if ((pfile = fopen("/sdcard/reboot.txt", "r")) == NULL) + { + // LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Initial boot or not a planned reboot"); isPlannedReboot = false; } - else { + else + { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Planned reboot"); - DeleteFile("/sdcard/reboot.txt"); // Prevent Boot Loop!!! + DeleteFile("/sdcard/reboot.txt"); // Prevent Boot Loop!!! isPlannedReboot = true; } } - -bool getIsPlannedReboot() { +bool getIsPlannedReboot(void) +{ return isPlannedReboot; } - -int getCountFlowRounds() { +int getCountFlowRounds(void) +{ return countRounds; } - -esp_err_t GetJPG(std::string _filename, httpd_req_t *req) { +esp_err_t GetJPG(std::string _filename, httpd_req_t *req) +{ return flowctrl.GetJPGStream(_filename, req); } - -esp_err_t GetRawJPG(httpd_req_t *req) { +esp_err_t GetRawJPG(httpd_req_t *req) +{ return flowctrl.SendRawJPG(req); } - -bool isSetupModusActive() { +bool isSetupModusActive(void) +{ return flowctrl.getStatusSetupModus(); } - -void DeleteMainFlowTask() +void DeleteMainFlowTask(void) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "DeleteMainFlowTask: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow); - #endif - - if( xHandletask_autodoFlow != NULL ) { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "DeleteMainFlowTask: xHandletask_autodoFlow: %ld", (long)xHandletask_autodoFlow); +#endif + + if (xHandletask_autodoFlow != NULL) + { vTaskDelete(xHandletask_autodoFlow); xHandletask_autodoFlow = NULL; } - - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow"); - #endif -} +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow"); +#endif +} -void doInit() { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Start flowctrl.InitFlow(config);"); - #endif +void doInit(void) +{ +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Start flowctrl.InitFlow(config);"); +#endif flowctrl.InitFlow(CONFIG_FILE); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Finished flowctrl.InitFlow(config);"); - #endif - +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Finished flowctrl.InitFlow(config);"); +#endif + /* GPIO handler has to be initialized before MQTT init to ensure proper topic subscription */ gpio_handler_init(); - #ifdef ENABLE_MQTT - flowctrl.StartMQTTService(); - #endif //ENABLE_MQTT +#ifdef ENABLE_MQTT + flowctrl.StartMQTTService(); +#endif // ENABLE_MQTT } - -bool doflow() { +bool doflow(void) +{ std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT); ESP_LOGD(TAG, "doflow - start %s", zw_time.c_str()); flowisrunning = true; flowctrl.doFlow(zw_time); flowisrunning = false; - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str()); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str()); +#endif return true; } +esp_err_t setCCstatusToCFstatus(void) +{ + CFstatus.CamSensor_id = CCstatus.CamSensor_id; + + CFstatus.ImageFrameSize = CCstatus.ImageFrameSize; + CFstatus.ImageGainceiling = CCstatus.ImageGainceiling; + + CFstatus.ImageQuality = CCstatus.ImageQuality; + CFstatus.ImageBrightness = CCstatus.ImageBrightness; + CFstatus.ImageContrast = CCstatus.ImageContrast; + CFstatus.ImageSaturation = CCstatus.ImageSaturation; + CFstatus.ImageSharpness = CCstatus.ImageSharpness; + CFstatus.ImageAutoSharpness = CCstatus.ImageAutoSharpness; + CFstatus.ImageWbMode = CCstatus.ImageWbMode; + CFstatus.ImageAwb = CCstatus.ImageAwb; + CFstatus.ImageAwbGain = CCstatus.ImageAwbGain; + CFstatus.ImageAec = CCstatus.ImageAec; + CFstatus.ImageAec2 = CCstatus.ImageAec2; + CFstatus.ImageAeLevel = CCstatus.ImageAeLevel; + CFstatus.ImageAecValue = CCstatus.ImageAecValue; + CFstatus.ImageAgc = CCstatus.ImageAgc; + CFstatus.ImageAgcGain = CCstatus.ImageAgcGain; + CFstatus.ImageBpc = CCstatus.ImageBpc; + CFstatus.ImageWpc = CCstatus.ImageWpc; + CFstatus.ImageRawGma = CCstatus.ImageRawGma; + CFstatus.ImageLenc = CCstatus.ImageLenc; + CFstatus.ImageSpecialEffect = CCstatus.ImageSpecialEffect; + CFstatus.ImageHmirror = CCstatus.ImageHmirror; + CFstatus.ImageVflip = CCstatus.ImageVflip; + CFstatus.ImageDcw = CCstatus.ImageDcw; + CFstatus.ImageDenoiseLevel = CCstatus.ImageDenoiseLevel; + + CFstatus.ImageLedIntensity = CCstatus.ImageLedIntensity; + + CFstatus.ImageZoomEnabled = CCstatus.ImageZoomEnabled; + CFstatus.ImageZoomOffsetX = CCstatus.ImageZoomOffsetX; + CFstatus.ImageZoomOffsetY = CCstatus.ImageZoomOffsetY; + CFstatus.ImageZoomSize = CCstatus.ImageZoomSize; + + CFstatus.WaitBeforePicture = CCstatus.WaitBeforePicture; + + return ESP_OK; +} + +esp_err_t setCFstatusToCCstatus(void) +{ + // CCstatus.CamSensor_id = CFstatus.CamSensor_id; + + CCstatus.ImageFrameSize = CFstatus.ImageFrameSize; + CCstatus.ImageGainceiling = CFstatus.ImageGainceiling; + + CCstatus.ImageQuality = CFstatus.ImageQuality; + CCstatus.ImageBrightness = CFstatus.ImageBrightness; + CCstatus.ImageContrast = CFstatus.ImageContrast; + CCstatus.ImageSaturation = CFstatus.ImageSaturation; + CCstatus.ImageSharpness = CFstatus.ImageSharpness; + CCstatus.ImageAutoSharpness = CFstatus.ImageAutoSharpness; + CCstatus.ImageWbMode = CFstatus.ImageWbMode; + CCstatus.ImageAwb = CFstatus.ImageAwb; + CCstatus.ImageAwbGain = CFstatus.ImageAwbGain; + CCstatus.ImageAec = CFstatus.ImageAec; + CCstatus.ImageAec2 = CFstatus.ImageAec2; + CCstatus.ImageAeLevel = CFstatus.ImageAeLevel; + CCstatus.ImageAecValue = CFstatus.ImageAecValue; + CCstatus.ImageAgc = CFstatus.ImageAgc; + CCstatus.ImageAgcGain = CFstatus.ImageAgcGain; + CCstatus.ImageBpc = CFstatus.ImageBpc; + CCstatus.ImageWpc = CFstatus.ImageWpc; + CCstatus.ImageRawGma = CFstatus.ImageRawGma; + CCstatus.ImageLenc = CFstatus.ImageLenc; + CCstatus.ImageSpecialEffect = CFstatus.ImageSpecialEffect; + CCstatus.ImageHmirror = CFstatus.ImageHmirror; + CCstatus.ImageVflip = CFstatus.ImageVflip; + CCstatus.ImageDcw = CFstatus.ImageDcw; + CCstatus.ImageDenoiseLevel = CFstatus.ImageDenoiseLevel; + + CCstatus.ImageLedIntensity = CFstatus.ImageLedIntensity; + + CCstatus.ImageZoomEnabled = CFstatus.ImageZoomEnabled; + CCstatus.ImageZoomOffsetX = CFstatus.ImageZoomOffsetX; + CCstatus.ImageZoomOffsetY = CFstatus.ImageZoomOffsetY; + CCstatus.ImageZoomSize = CFstatus.ImageZoomSize; + + CCstatus.WaitBeforePicture = CFstatus.WaitBeforePicture; + + return ESP_OK; +} + +esp_err_t setCFstatusToCam(void) +{ + sensor_t *s = esp_camera_sensor_get(); + + if (s != NULL) + { + s->set_framesize(s, CFstatus.ImageFrameSize); + s->set_quality(s, CFstatus.ImageQuality); // 0 - 63 + + s->set_brightness(s, CFstatus.ImageBrightness); // -2 to 2 + s->set_contrast(s, CFstatus.ImageContrast); // -2 to 2 + s->set_saturation(s, CFstatus.ImageSaturation); // -2 to 2 + // s->set_sharpness(s, CFstatus.ImageSharpness); // auto-sharpness is not officially supported, default to 0 + Camera.SetCamSharpness(CFstatus.ImageAutoSharpness, CFstatus.ImageSharpness); + + s->set_denoise(s, CFstatus.ImageDenoiseLevel); // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) + + s->set_special_effect(s, CFstatus.ImageSpecialEffect); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia) + s->set_wb_mode(s, CFstatus.ImageWbMode); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) + + s->set_ae_level(s, CFstatus.ImageAeLevel); // -2 to 2 + s->set_aec_value(s, CFstatus.ImageAecValue); // 0 to 1200 + s->set_agc_gain(s, CFstatus.ImageAgcGain); // 0 to 30 + + // s->set_gainceiling(s, CFstatus.ImageGainceiling); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) + Camera.ov5640_set_gainceiling(s, CFstatus.ImageGainceiling); + + s->set_lenc(s, CFstatus.ImageLenc); // 0 = disable , 1 = enable + s->set_gain_ctrl(s, CFstatus.ImageAgc); // 0 = disable , 1 = enable + s->set_exposure_ctrl(s, CFstatus.ImageAec); // 0 = disable , 1 = enable + + s->set_hmirror(s, CFstatus.ImageHmirror); // 0 = disable , 1 = enable + s->set_vflip(s, CFstatus.ImageVflip); // 0 = disable , 1 = enable + s->set_aec2(s, CFstatus.ImageAec2); // 0 = disable , 1 = enable + + s->set_bpc(s, CFstatus.ImageBpc); // 0 = disable , 1 = enable + s->set_wpc(s, CFstatus.ImageWpc); // 0 = disable , 1 = enable + + s->set_raw_gma(s, CFstatus.ImageRawGma); // 0 = disable , 1 = enable + + s->set_awb_gain(s, CFstatus.ImageAwbGain); // 0 = disable , 1 = enable + s->set_whitebal(s, CFstatus.ImageAwb); // 0 = disable , 1 = enable -esp_err_t handler_get_heap(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_get_heap - Start"); - ESP_LOGD(TAG, "handler_get_heap uri: %s", req->uri); - #endif + s->set_dcw(s, CFstatus.ImageDcw); // 0 = disable , 1 = enable + + TickType_t xDelay2 = 100 / portTICK_PERIOD_MS; + vTaskDelay(xDelay2); + + return ESP_OK; + } + else + { + return ESP_FAIL; + } +} + +esp_err_t handler_get_heap(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_get_heap - Start"); + ESP_LOGD(TAG, "handler_get_heap uri: %s", req->uri); +#endif std::string zw = "Heap info:
" + getESPHeapInfo(); - #ifdef TASK_ANALYSIS_ON - char* pcTaskList = (char*) calloc_psram_heap(std::string(TAG) + "->pcTaskList", 1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - if (pcTaskList) { - vTaskList(pcTaskList); - zw = zw + "

Task info:
Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)
" - + std::string(pcTaskList) + "
"; - free_psram_heap(std::string(TAG) + "->pcTaskList", pcTaskList); - } - else { - zw = zw + "

Task info:
ERROR - Allocation of TaskList buffer in PSRAM failed"; - } - #endif +#ifdef TASK_ANALYSIS_ON + char *pcTaskList = (char *)calloc_psram_heap(std::string(TAG) + "->pcTaskList", 1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + if (pcTaskList) + { + vTaskList(pcTaskList); + zw = zw + "

Task info:
Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)
" + std::string(pcTaskList) + "
"; + free_psram_heap(std::string(TAG) + "->pcTaskList", pcTaskList); + } + else + { + zw = zw + "

Task info:
ERROR - Allocation of TaskList buffer in PSRAM failed"; + } +#endif httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - if (zw.length() > 0) { + if (zw.length() > 0) + { httpd_resp_send(req, zw.c_str(), zw.length()); } - else { + else + { httpd_resp_send(req, NULL, 0); } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_get_heap - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_get_heap - Done"); +#endif return ESP_OK; } - -esp_err_t handler_init(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_init - Start"); - ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri); - #endif +esp_err_t handler_init(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_init - Start"); + ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri); +#endif httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - const char* resp_str = "Init started
"; - httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); + const char *resp_str = "Init started
"; + httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); doInit(); resp_str = "Init done
"; - httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); + httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_init - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_init - Done"); +#endif return ESP_OK; } - -esp_err_t handler_stream(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_stream - Start"); - ESP_LOGD(TAG, "handler_stream uri: %s", req->uri); - #endif +esp_err_t handler_stream(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_stream - Start"); + ESP_LOGD(TAG, "handler_stream uri: %s", req->uri); +#endif char _query[50]; char _value[10]; bool flashlightOn = false; - if (httpd_req_get_url_query_str(req, _query, 50) == ESP_OK) { -// ESP_LOGD(TAG, "Query: %s", _query); - if (httpd_query_key_value(_query, "flashlight", _value, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "flashlight is found%s", _value); - #endif - if (strlen(_value) > 0) { + if (httpd_req_get_url_query_str(req, _query, 50) == ESP_OK) + { + // ESP_LOGD(TAG, "Query: %s", _query); + if (httpd_query_key_value(_query, "flashlight", _value, 10) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "flashlight is found%s", _value); +#endif + if (strlen(_value) > 0) + { flashlightOn = true; } } @@ -226,190 +379,277 @@ esp_err_t handler_stream(httpd_req_t *req) { Camera.CaptureToStream(req, flashlightOn); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_stream - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_stream - Done"); +#endif return ESP_OK; } - -esp_err_t handler_flow_start(httpd_req_t *req) { - - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_flow_start - Start"); - #endif +esp_err_t handler_flow_start(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_flow_start - Start"); +#endif ESP_LOGD(TAG, "handler_flow_start uri: %s", req->uri); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - if (autostartIsEnabled) { + if (autostartIsEnabled) + { xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by REST API /flow_start"); - const char* resp_str = "The flow is going to be started immediately or is already running"; - httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); + const char *resp_str = "The flow is going to be started immediately or is already running"; + httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); } - else { + else + { LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by REST API, but flow is not active!"); - const char* resp_str = "WARNING: Flow start triggered by REST API, but flow is not active"; - httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); + const char *resp_str = "WARNING: Flow start triggered by REST API, but flow is not active"; + httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_flow_start - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_flow_start - Done"); +#endif return ESP_OK; } - #ifdef ENABLE_MQTT -esp_err_t MQTTCtrlFlowStart(std::string _topic) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Start"); - #endif +esp_err_t MQTTCtrlFlowStart(std::string _topic) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Start"); +#endif ESP_LOGD(TAG, "MQTTCtrlFlowStart: topic %s", _topic.c_str()); - if (autostartIsEnabled) { + if (autostartIsEnabled) + { xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by MQTT topic " + _topic); } - else { + else + { LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by MQTT topic " + _topic + ", but flow is not active!"); - } + } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Done"); +#endif return ESP_OK; } -#endif //ENABLE_MQTT - +#endif // ENABLE_MQTT -esp_err_t handler_json(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_json - Start"); - #endif +esp_err_t handler_json(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_json - Start"); +#endif ESP_LOGD(TAG, "handler_JSON uri: %s", req->uri); - - if (bTaskAutoFlowCreated) { + + if (bTaskAutoFlowCreated) + { httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_type(req, "application/json"); std::string zw = flowctrl.getJSON(); - if (zw.length() > 0) { + if (zw.length() > 0) + { httpd_resp_send(req, zw.c_str(), zw.length()); } - else { + else + { httpd_resp_send(req, NULL, 0); } } - else { + else + { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /json not yet available!"); return ESP_ERR_NOT_FOUND; } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_JSON - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_JSON - Done"); +#endif return ESP_OK; } +/** + * Generates a http response containing the OpenMetrics (https://openmetrics.io/) text wire format + * according to https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#text-format. + * + * A MetricFamily with a Metric for each Sequence is provided. If no valid value is available, the metric is not provided. + * MetricPoints are provided without a timestamp. Additional metrics with some device information is also provided. + * + * The metric name prefix is 'ai_on_the_edge_device_'. + * + * example configuration for Prometheus (`prometheus.yml`): + * + * - job_name: watermeter + * static_configs: + * - targets: ['watermeter.fritz.box'] + * +*/ +esp_err_t handler_openmetrics(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_openmetrics - Start"); +#endif + + ESP_LOGD(TAG, "handler_openmetrics uri: %s", req->uri); + + if (bTaskAutoFlowCreated) + { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_set_type(req, "text/plain"); // application/openmetrics-text is not yet supported by prometheus so we use text/plain for now + + const string metricNamePrefix = "ai_on_the_edge_device"; -esp_err_t handler_wasserzaehler(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler water counter - Start"); - #endif + // get current measurement (flow) + string response = createSequenceMetrics(metricNamePrefix, flowctrl.getNumbers()); - if (bTaskAutoFlowCreated) { + // CPU Temperature + response += createMetric(metricNamePrefix + "_cpu_temperature_celsius", "current cpu temperature in celsius", "gauge", std::to_string((int)temperatureRead())); + + // WiFi signal strength + response += createMetric(metricNamePrefix + "_rssi_dbm", "current WiFi signal strength in dBm", "gauge", std::to_string(get_WIFI_RSSI())); + + // memory info + response += createMetric(metricNamePrefix + "_memory_heap_free_bytes", "available heap memory", "gauge", std::to_string(getESPHeapSize())); + + // device uptime + response += createMetric(metricNamePrefix + "_uptime_seconds", "device uptime in seconds", "gauge", std::to_string((long)getUpTime())); + + // data aquisition round + response += createMetric(metricNamePrefix + "_rounds_total", "data aquisition rounds since device startup", "counter", std::to_string(countRounds)); + + // the response always contains at least the metadata (HELP, TYPE) for the MetricFamily so no length check is needed + httpd_resp_send(req, response.c_str(), response.length()); + } + else + { + httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /metrics not yet available!"); + return ESP_ERR_NOT_FOUND; + } + +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_openmetrics - Done"); +#endif + + return ESP_OK; +} + +esp_err_t handler_wasserzaehler(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler water counter - Start"); +#endif + + if (bTaskAutoFlowCreated) + { bool _rawValue = false; bool _noerror = false; bool _all = false; std::string _type = "value"; - string zw; + std::string zw; - ESP_LOGD(TAG, "handler water counter uri: %s", req->uri); + ESP_LOGD(TAG, "handler water counter uri: %s", req->uri); char _query[100]; char _size[10]; - if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { - // ESP_LOGD(TAG, "Query: %s", _query); - if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "all is found%s", _size); - #endif + if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) + { + // ESP_LOGD(TAG, "Query: %s", _query); + if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "all is found%s", _size); +#endif _all = true; } - if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "all is found: %s", _size); - #endif + if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "all is found: %s", _size); +#endif _type = std::string(_size); } - if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "rawvalue is found: %s", _size); - #endif + if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "rawvalue is found: %s", _size); +#endif _rawValue = true; } - - if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "noerror is found: %s", _size); - #endif + + if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "noerror is found: %s", _size); +#endif _noerror = true; - } - } + } + } httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - if (_all) { + if (_all) + { httpd_resp_set_type(req, "text/plain"); ESP_LOGD(TAG, "TYPE: %s", _type.c_str()); int _intype = READOUT_TYPE_VALUE; - - if (_type == "prevalue") { + + if (_type == "prevalue") + { _intype = READOUT_TYPE_PREVALUE; } - - if (_type == "raw") { + + if (_type == "raw") + { _intype = READOUT_TYPE_RAWVALUE; } - - if (_type == "error") { + + if (_type == "error") + { _intype = READOUT_TYPE_ERROR; } zw = flowctrl.getReadoutAll(_intype); ESP_LOGD(TAG, "ZW: %s", zw.c_str()); - - if (zw.length() > 0) { + + if (zw.length() > 0) + { httpd_resp_send(req, zw.c_str(), zw.length()); } - + return ESP_OK; } std::string *status = flowctrl.getActStatus(); - string query = std::string(_query); - // ESP_LOGD(TAG, "Query: %s, query.c_str()); - if (query.find("full") != std::string::npos) { - string txt; + std::string query = std::string(_query); + // ESP_LOGD(TAG, "Query: %s, query.c_str()); + + if (query.find("full") != std::string::npos) + { + std::string txt; txt = ""; - if ((countRounds <= 1) && (*status != std::string("Flow finished"))) { + if ((countRounds <= 1) && (*status != std::string("Flow finished"))) + { // First round not completed yet txt += "

Please wait for the first round to complete!

Current state: " + *status + "

\n"; } - else { + else + { txt += "

Value

"; } @@ -417,161 +657,185 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) { } zw = flowctrl.getReadout(_rawValue, _noerror, 0); - - if (zw.length() > 0) { - httpd_resp_sendstr_chunk(req, zw.c_str()); + + if (zw.length() > 0) + { + httpd_resp_sendstr_chunk(req, zw.c_str()); } - if (query.find("full") != std::string::npos) { - string txt, zw; + if (query.find("full") != std::string::npos) + { + std::string txt, zw; - if ((countRounds <= 1) && (*status != std::string("Flow finished"))) { + if ((countRounds <= 1) && (*status != std::string("Flow finished"))) + { // First round not completed yet // Nothing to do } - else { - /* Digital ROIs */ + else + { + /* Digit ROIs */ txt = ""; txt += "

Recognized Digit ROIs (previous round)

\n"; txt += "\n"; - std::vector htmlinfodig; - htmlinfodig = flowctrl.GetAllDigital(); + std::vector htmlinfodig; + htmlinfodig = flowctrl.GetAllDigit(); - for (int i = 0; i < htmlinfodig.size(); ++i) { - if (flowctrl.GetTypeDigital() == Digital) { - if (htmlinfodig[i]->val >= 10) { + for (int i = 0; i < htmlinfodig.size(); ++i) + { + if (flowctrl.GetTypeDigit() == Digit) + { + // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values ​​from 0 to 9. + if ((htmlinfodig[i]->val >= 10) || (htmlinfodig[i]->val < 0)) + { zw = "NaN"; } - else { - zw = to_string((int) htmlinfodig[i]->val); + else + { + zw = std::to_string((int)htmlinfodig[i]->val); } - txt += "\n"; + txt += "\n"; } - else { + else + { std::stringstream stream; stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val; zw = stream.str(); - if (std::stod(zw) >= 10) { + // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values ​​from 0 to 9. + if ((std::stod(zw) >= 10) || (std::stod(zw) < 0)) + { zw = "NaN"; } - txt += "\n"; + txt += "\n"; } delete htmlinfodig[i]; } htmlinfodig.clear(); - + txt += "

" + zw + "

filename + "\">

" + zw + "

filename + "\">

" + zw + "

filename + "\">

" + zw + "

filename + "\">

\n"; - httpd_resp_sendstr_chunk(req, txt.c_str()); + httpd_resp_sendstr_chunk(req, txt.c_str()); /* Analog ROIs */ txt = "

Recognized Analog ROIs (previous round)

\n"; txt += "\n"; - - std::vector htmlinfoana; + + std::vector htmlinfoana; htmlinfoana = flowctrl.GetAllAnalog(); - - for (int i = 0; i < htmlinfoana.size(); ++i) { + + for (int i = 0; i < htmlinfoana.size(); ++i) + { std::stringstream stream; stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val; zw = stream.str(); - - if (std::stod(zw) >= 10) { + + // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values ​​from 0 to 9. + if ((std::stod(zw) >= 10) || (std::stod(zw) < 0)) + { zw = "NaN"; - } + } - txt += "\n"; + txt += "\n"; delete htmlinfoana[i]; } - - htmlinfoana.clear(); + + htmlinfoana.clear(); txt += "\n

" + zw + "

filename + "\">

" + zw + "

filename + "\">

\n"; - httpd_resp_sendstr_chunk(req, txt.c_str()); - - /* Full Image - * Only show it after the image got taken and aligned */ - txt = "

Aligned Image (current round)

\n"; - - if ((*status == std::string("Initialization")) || - (*status == std::string("Initialization (delayed)")) || - (*status == std::string("Take Image"))) { + httpd_resp_sendstr_chunk(req, txt.c_str()); + + /* Full Image + * Only show it after the image got taken */ + txt = "

Full Image (current round)

\n"; + + if ((*status == std::string("Initialization")) || + (*status == std::string("Initialization (delayed)")) || + (*status == std::string("Take Image"))) + { txt += "

Current state: " + *status + "

\n"; } - else { + else + { txt += "\n"; } - httpd_resp_sendstr_chunk(req, txt.c_str()); + httpd_resp_sendstr_chunk(req, txt.c_str()); } - } + } /* Respond with an empty chunk to signal HTTP response completion */ - httpd_resp_sendstr_chunk(req, NULL); + httpd_resp_sendstr_chunk(req, NULL); } - else { + else + { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /value not available!"); return ESP_ERR_NOT_FOUND; } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_wasserzaehler - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_wasserzaehler - Done"); +#endif return ESP_OK; } - -esp_err_t handler_editflow(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_editflow - Start"); - #endif +esp_err_t handler_editflow(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_editflow - Start"); +#endif ESP_LOGD(TAG, "handler_editflow uri: %s", req->uri); - char _query[200]; + char _query[512]; char _valuechar[30]; - string _task; - - if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) { - if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "task is found: %s", _valuechar); - #endif - _task = string(_valuechar); + std::string _task; + + if (httpd_req_get_url_query_str(req, _query, 512) == ESP_OK) + { + if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "task is found: %s", _valuechar); +#endif + _task = std::string(_valuechar); } - } + } - if (_task.compare("namenumbers") == 0) { + if (_task.compare("namenumbers") == 0) + { ESP_LOGD(TAG, "Get NUMBER list"); return get_numbers_file_handler(req); } - if (_task.compare("data") == 0) { + if (_task.compare("data") == 0) + { ESP_LOGD(TAG, "Get data list"); return get_data_file_handler(req); } - if (_task.compare("tflite") == 0) { + if (_task.compare("tflite") == 0) + { ESP_LOGD(TAG, "Get tflite list"); return get_tflite_file_handler(req); } - if (_task.compare("copy") == 0) { - string in, out, zw; + if (_task.compare("copy") == 0) + { + std::string in, out, zw; httpd_query_key_value(_query, "in", _valuechar, 30); - in = string(_valuechar); - httpd_query_key_value(_query, "out", _valuechar, 30); - out = string(_valuechar); + in = std::string(_valuechar); + httpd_query_key_value(_query, "out", _valuechar, 30); + out = std::string(_valuechar); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "in: %s", in.c_str()); - ESP_LOGD(TAG, "out: %s", out.c_str()); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "in: %s", in.c_str()); + ESP_LOGD(TAG, "out: %s", out.c_str()); +#endif in = "/sdcard" + in; out = "/sdcard" + out; @@ -579,48 +843,64 @@ esp_err_t handler_editflow(httpd_req_t *req) { CopyFile(in, out); zw = "Copy Done"; httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - httpd_resp_send(req, zw.c_str(), zw.length()); + httpd_resp_send(req, zw.c_str(), zw.length()); } - if (_task.compare("cutref") == 0) { - string in, out, zw; - int x, y, dx, dy; + if (_task.compare("cutref") == 0) + { + std::string in, out, zw; + int x = 0, y = 0, dx = 20, dy = 20; bool enhance = false; httpd_query_key_value(_query, "in", _valuechar, 30); - in = string(_valuechar); + in = std::string(_valuechar); - httpd_query_key_value(_query, "out", _valuechar, 30); - out = string(_valuechar); + httpd_query_key_value(_query, "out", _valuechar, 30); + out = std::string(_valuechar); httpd_query_key_value(_query, "x", _valuechar, 30); - zw = string(_valuechar); - x = stoi(zw); + std::string _x = std::string(_valuechar); + if (isStringNumeric(_x)) + { + x = std::stoi(_x); + } httpd_query_key_value(_query, "y", _valuechar, 30); - zw = string(_valuechar); - y = stoi(zw); + std::string _y = std::string(_valuechar); + if (isStringNumeric(_y)) + { + y = std::stoi(_y); + } httpd_query_key_value(_query, "dx", _valuechar, 30); - zw = string(_valuechar); - dx = stoi(zw); + std::string _dx = std::string(_valuechar); + if (isStringNumeric(_dx)) + { + dx = std::stoi(_dx); + } httpd_query_key_value(_query, "dy", _valuechar, 30); - zw = string(_valuechar); - dy = stoi(zw); - - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "in: %s", in.c_str()); - ESP_LOGD(TAG, "out: %s", out.c_str()); - ESP_LOGD(TAG, "x: %s", zw.c_str()); - ESP_LOGD(TAG, "y: %s", zw.c_str()); - ESP_LOGD(TAG, "dx: %s", zw.c_str()); - ESP_LOGD(TAG, "dy: %s", zw.c_str()); - #endif - - if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK) { - zw = string(_valuechar); - if (zw.compare("true") == 0) { + std::string _dy = std::string(_valuechar); + if (isStringNumeric(_dy)) + { + dy = std::stoi(_dy); + } + +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "in: %s", in.c_str()); + ESP_LOGD(TAG, "out: %s", out.c_str()); + ESP_LOGD(TAG, "x: %s", _x.c_str()); + ESP_LOGD(TAG, "y: %s", _y.c_str()); + ESP_LOGD(TAG, "dx: %s", _dx.c_str()); + ESP_LOGD(TAG, "dy: %s", _dy.c_str()); +#endif + + if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK) + { + string _enhance = std::string(_valuechar); + + if (_enhance.compare("true") == 0) + { enhance = true; } } @@ -628,271 +908,612 @@ esp_err_t handler_editflow(httpd_req_t *req) { in = "/sdcard" + in; out = "/sdcard" + out; - string out2 = out.substr(0, out.length() - 4) + "_org.jpg"; + std::string out2 = out.substr(0, out.length() - 4) + "_org.jpg"; - if ((flowctrl.SetupModeActive || (*flowctrl.getActStatus() == "Flow finished")) && psram_init_shared_memory_for_take_image_step()) { + if ((flowctrl.SetupModeActive || (*flowctrl.getActStatus() == std::string("Flow finished"))) && psram_init_shared_memory_for_take_image_step()) + { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Taking image for Alignment Mark Update..."); CAlignAndCutImage *caic = new CAlignAndCutImage("cutref", in); caic->CutAndSave(out2, x, y, dx, dy); - delete caic; + delete caic; CImageBasis *cim = new CImageBasis("cutref", out2); - if (enhance) { + + if (enhance) + { cim->Contrast(90); } cim->SaveToFile(out); - delete cim; + delete cim; psram_deinit_shared_memory_for_take_image_step(); zw = "CutImage Done"; } - else { - LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Taking image for Alignment Mark not possible while device") + - " is busy with a round (Current State: '" + *flowctrl.getActStatus() + "')!"); + else + { + LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Taking image for Alignment Mark not possible while device") + " is busy with a round (Current State: '" + *flowctrl.getActStatus() + "')!"); zw = "Device Busy"; } httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - httpd_resp_send(req, zw.c_str(), zw.length()); + httpd_resp_send(req, zw.c_str(), zw.length()); } - if ((_task.compare("test_take") == 0) || (_task.compare("cam_settings") == 0)) { - std::string _zw = ""; - std::string _host = ""; - int bri = -100; - int sat = -100; - int con = -100; - int intens = -100; - int aelevel = 0; - int zoommode = 0; - int zoomoffsetx = 0; - int zoomoffsety = 0; - bool zoom = false; - bool negative = false; - bool aec2 = false; - int sharpnessLevel = 0; - #ifdef GRAYSCALE_AS_DEFAULT - bool grayscale = true; - #else - bool grayscale = false; - #endif - - if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) { - _host = std::string(_valuechar); - } - if (httpd_query_key_value(_query, "int", _valuechar, 30) == ESP_OK) { - std::string _int = std::string(_valuechar); - intens = stoi(_int); - } - if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK) { - std::string _bri = std::string(_valuechar); - bri = stoi(_bri); - } - if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK) { - std::string _con = std::string(_valuechar); - con = stoi(_con); - } - if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK) { - std::string _sat = std::string(_valuechar); - sat = stoi(_sat); - } - if (httpd_query_key_value(_query, "ae", _valuechar, 30) == ESP_OK) { - std::string _ae = std::string(_valuechar); - aelevel = stoi(_ae); - } - if (httpd_query_key_value(_query, "sh", _valuechar, 30) == ESP_OK) { - std::string _sh = std::string(_valuechar); - sharpnessLevel = stoi(_sh); - } - if (httpd_query_key_value(_query, "gs", _valuechar, 30) == ESP_OK) { - std::string _gr = std::string(_valuechar); - if (stoi(_gr) != 0) { - grayscale = true; + // wird beim Erstellen eines neuen Referenzbildes aufgerufen + std::string *sys_status = flowctrl.getActStatus(); + + if ((sys_status->c_str() != std::string("Take Image")) && (sys_status->c_str() != std::string("Aligning"))) + { + if ((_task.compare("test_take") == 0) || (_task.compare("cam_settings") == 0)) + { + std::string _host = ""; + + // laden der aktuellen Kameraeinstellungen(CCstatus) in den Zwischenspeicher(CFstatus) + setCCstatusToCFstatus(); // CCstatus >>> CFstatus + + if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) + { + _host = std::string(_valuechar); } - else { - grayscale = false; + + if (httpd_query_key_value(_query, "waitb", _valuechar, 30) == ESP_OK) + { + std::string _waitb = std::string(_valuechar); + if (isStringNumeric(_waitb)) + { + CFstatus.WaitBeforePicture = std::stoi(_valuechar); + } } - } - if (httpd_query_key_value(_query, "ne", _valuechar, 30) == ESP_OK) { - std::string _ne = std::string(_valuechar); - if (stoi(_ne) != 0) { - negative = true; + + if (httpd_query_key_value(_query, "aecgc", _valuechar, 30) == ESP_OK) + { + std::string _aecgc = std::string(_valuechar); + if (isStringNumeric(_aecgc)) + { + int _aecgc_ = std::stoi(_valuechar); + switch (_aecgc_) + { + case 1: + CFstatus.ImageGainceiling = GAINCEILING_4X; + break; + case 2: + CFstatus.ImageGainceiling = GAINCEILING_8X; + break; + case 3: + CFstatus.ImageGainceiling = GAINCEILING_16X; + break; + case 4: + CFstatus.ImageGainceiling = GAINCEILING_32X; + break; + case 5: + CFstatus.ImageGainceiling = GAINCEILING_64X; + break; + case 6: + CFstatus.ImageGainceiling = GAINCEILING_128X; + break; + default: + CFstatus.ImageGainceiling = GAINCEILING_2X; + } + } + else + { + if (_aecgc == "X4") { + CFstatus.ImageGainceiling = GAINCEILING_4X; + } + else if (_aecgc == "X8") { + CFstatus.ImageGainceiling = GAINCEILING_8X; + } + else if (_aecgc == "X16") { + CFstatus.ImageGainceiling = GAINCEILING_16X; + } + else if (_aecgc == "X32") { + CFstatus.ImageGainceiling = GAINCEILING_32X; + } + else if (_aecgc == "X64") { + CFstatus.ImageGainceiling = GAINCEILING_64X; + } + else if (_aecgc == "X128") { + CFstatus.ImageGainceiling = GAINCEILING_128X; + } + else { + CFstatus.ImageGainceiling = GAINCEILING_2X; + } + } } - else { - negative = false; - } - } - if (httpd_query_key_value(_query, "a2", _valuechar, 30) == ESP_OK) { - std::string _a2 = std::string(_valuechar); - if (stoi(_a2) != 0) { - aec2 = true; - } - else { - aec2 = false; - } - } - if (httpd_query_key_value(_query, "z", _valuechar, 30) == ESP_OK) { - std::string _zoom = std::string(_valuechar); - if (stoi(_zoom) != 0) { - zoom = true; - } - else { - zoom = false; - } - } - if (httpd_query_key_value(_query, "zm", _valuechar, 30) == ESP_OK) { - std::string _zm = std::string(_valuechar); - zoommode = stoi(_zm); - } - if (httpd_query_key_value(_query, "x", _valuechar, 30) == ESP_OK) { - std::string _x = std::string(_valuechar); - zoomoffsetx = stoi(_x); - } - if (httpd_query_key_value(_query, "y", _valuechar, 30) == ESP_OK) { - std::string _y = std::string(_valuechar); - zoomoffsety = stoi(_y); - } -// ESP_LOGD(TAG, "Parameter host: %s", _host.c_str()); -// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str()); - Camera.SetZoom(zoom, zoommode, zoomoffsetx, zoomoffsety); - Camera.SetBrightnessContrastSaturation(bri, con, sat, aelevel, grayscale, negative, aec2, sharpnessLevel); - Camera.SetLEDIntensity(intens); + if (httpd_query_key_value(_query, "qual", _valuechar, 30) == ESP_OK) + { + std::string _qual = std::string(_valuechar); + if (isStringNumeric(_qual)) + { + int _qual_ = std::stoi(_valuechar); + CFstatus.ImageQuality = clipInt(_qual_, 63, 6); + } + } - if (_task.compare("cam_settings") == 0) - { - ESP_LOGD(TAG, "Cam Settings set"); - _zw = "Cam Settings set"; + if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK) + { + std::string _bri = std::string(_valuechar); + if (isStringNumeric(_bri)) + { + int _bri_ = std::stoi(_valuechar); + CFstatus.ImageBrightness = clipInt(_bri_, 2, -2); + } + } + + if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK) + { + std::string _con = std::string(_valuechar); + if (isStringNumeric(_con)) + { + int _con_ = std::stoi(_valuechar); + CFstatus.ImageContrast = clipInt(_con_, 2, -2); + } + } + + if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK) + { + std::string _sat = std::string(_valuechar); + if (isStringNumeric(_sat)) + { + int _sat_ = std::stoi(_valuechar); + CFstatus.ImageSaturation = clipInt(_sat_, 2, -2); + } + } + + if (httpd_query_key_value(_query, "shp", _valuechar, 30) == ESP_OK) + { + std::string _shp = std::string(_valuechar); + if (isStringNumeric(_shp)) + { + int _shp_ = std::stoi(_valuechar); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CFstatus.ImageSharpness = clipInt(_shp_, 2, -2); + } + else + { + CFstatus.ImageSharpness = clipInt(_shp_, 3, -3); + } + } + } + + if (httpd_query_key_value(_query, "ashp", _valuechar, 30) == ESP_OK) + { + std::string _ashp = std::string(_valuechar); + CFstatus.ImageAutoSharpness = alphanumericToBoolean(_ashp); + } + + if (httpd_query_key_value(_query, "spe", _valuechar, 30) == ESP_OK) + { + std::string _spe = std::string(_valuechar); + if (isStringNumeric(_spe)) + { + int _spe_ = std::stoi(_valuechar); + CFstatus.ImageSpecialEffect = clipInt(_spe_, 6, 0); + } + else + { + if (_spe == "negative") { + CFstatus.ImageSpecialEffect = 1; + } + else if (_spe == "grayscale") { + CFstatus.ImageSpecialEffect = 2; + } + else if (_spe == "red") { + CFstatus.ImageSpecialEffect = 3; + } + else if (_spe == "green") { + CFstatus.ImageSpecialEffect = 4; + } + else if (_spe == "blue") { + CFstatus.ImageSpecialEffect = 5; + } + else if (_spe == "retro") { + CFstatus.ImageSpecialEffect = 6; + } + else { + CFstatus.ImageSpecialEffect = 0; + } + } + } + + if (httpd_query_key_value(_query, "wbm", _valuechar, 30) == ESP_OK) + { + std::string _wbm = std::string(_valuechar); + if (isStringNumeric(_wbm)) + { + int _wbm_ = std::stoi(_valuechar); + CFstatus.ImageWbMode = clipInt(_wbm_, 4, 0); + } + else + { + if (_wbm == "sunny") { + CFstatus.ImageWbMode = 1; + } + else if (_wbm == "cloudy") { + CFstatus.ImageWbMode = 2; + } + else if (_wbm == "office") { + CFstatus.ImageWbMode = 3; + } + else if (_wbm == "home") { + CFstatus.ImageWbMode = 4; + } + else { + CFstatus.ImageWbMode = 0; + } + } + } + + if (httpd_query_key_value(_query, "awb", _valuechar, 30) == ESP_OK) + { + std::string _awb = std::string(_valuechar); + CFstatus.ImageAwb = alphanumericToBoolean(_awb); + } + + if (httpd_query_key_value(_query, "awbg", _valuechar, 30) == ESP_OK) + { + std::string _awbg = std::string(_valuechar); + CFstatus.ImageAwbGain = alphanumericToBoolean(_awbg); + } + + if (httpd_query_key_value(_query, "aec", _valuechar, 30) == ESP_OK) + { + std::string _aec = std::string(_valuechar); + CFstatus.ImageAec = alphanumericToBoolean(_aec); + } + + if (httpd_query_key_value(_query, "aec2", _valuechar, 30) == ESP_OK) + { + std::string _aec2 = std::string(_valuechar); + CFstatus.ImageAec2 = alphanumericToBoolean(_aec2); + } + + if (httpd_query_key_value(_query, "ael", _valuechar, 30) == ESP_OK) + { + std::string _ael = std::string(_valuechar); + if (isStringNumeric(_ael)) + { + int _ael_ = std::stoi(_valuechar); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CFstatus.ImageAeLevel = clipInt(_ael_, 2, -2); + } + else + { + CFstatus.ImageAeLevel = clipInt(_ael_, 5, -5); + } + } + } + + if (httpd_query_key_value(_query, "aecv", _valuechar, 30) == ESP_OK) + { + std::string _aecv = std::string(_valuechar); + if (isStringNumeric(_aecv)) + { + int _aecv_ = std::stoi(_valuechar); + CFstatus.ImageAecValue = clipInt(_aecv_, 1200, 0); + } + } + + if (httpd_query_key_value(_query, "agc", _valuechar, 30) == ESP_OK) + { + std::string _agc = std::string(_valuechar); + CFstatus.ImageAgc = alphanumericToBoolean(_agc); + } + + if (httpd_query_key_value(_query, "agcg", _valuechar, 30) == ESP_OK) + { + std::string _agcg = std::string(_valuechar); + if (isStringNumeric(_agcg)) + { + int _agcg_ = std::stoi(_valuechar); + CFstatus.ImageAgcGain = clipInt(_agcg_, 30, 0); + } + } + + if (httpd_query_key_value(_query, "bpc", _valuechar, 30) == ESP_OK) + { + std::string _bpc = std::string(_valuechar); + CFstatus.ImageBpc = alphanumericToBoolean(_bpc); + } + + if (httpd_query_key_value(_query, "wpc", _valuechar, 30) == ESP_OK) + { + std::string _wpc = std::string(_valuechar); + CFstatus.ImageWpc = alphanumericToBoolean(_wpc); + } + + if (httpd_query_key_value(_query, "rgma", _valuechar, 30) == ESP_OK) + { + std::string _rgma = std::string(_valuechar); + CFstatus.ImageRawGma = alphanumericToBoolean(_rgma); + } + + if (httpd_query_key_value(_query, "lenc", _valuechar, 30) == ESP_OK) + { + std::string _lenc = std::string(_valuechar); + CFstatus.ImageLenc = alphanumericToBoolean(_lenc); + } + + if (httpd_query_key_value(_query, "mirror", _valuechar, 30) == ESP_OK) + { + std::string _mirror = std::string(_valuechar); + CFstatus.ImageHmirror = alphanumericToBoolean(_mirror); + } + + if (httpd_query_key_value(_query, "flip", _valuechar, 30) == ESP_OK) + { + std::string _flip = std::string(_valuechar); + CFstatus.ImageVflip = alphanumericToBoolean(_flip); + } + + if (httpd_query_key_value(_query, "dcw", _valuechar, 30) == ESP_OK) + { + std::string _dcw = std::string(_valuechar); + CFstatus.ImageDcw = alphanumericToBoolean(_dcw); + } + + if (httpd_query_key_value(_query, "den", _valuechar, 30) == ESP_OK) + { + std::string _idlv = std::string(_valuechar); + if (isStringNumeric(_idlv)) + { + int _ImageDenoiseLevel = std::stoi(_valuechar); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CCstatus.ImageDenoiseLevel = 0; + } + else + { + CFstatus.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0); + } + } + } + + if (httpd_query_key_value(_query, "zoom", _valuechar, 30) == ESP_OK) + { + std::string _zoom = std::string(_valuechar); + CFstatus.ImageZoomEnabled = alphanumericToBoolean(_zoom); + } + + if (httpd_query_key_value(_query, "zoomx", _valuechar, 30) == ESP_OK) + { + std::string _zoomx = std::string(_valuechar); + if (isStringNumeric(_zoomx)) + { + int _ImageZoomOffsetX = std::stoi(_valuechar); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480); + } + else if (CCstatus.CamSensor_id == OV3660_PID) + { + CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704); + } + else if (CCstatus.CamSensor_id == OV5640_PID) + { + CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960); + } + } + } + + if (httpd_query_key_value(_query, "zoomy", _valuechar, 30) == ESP_OK) + { + std::string _zoomy = std::string(_valuechar); + if (isStringNumeric(_zoomy)) + { + int _ImageZoomOffsetY = std::stoi(_valuechar); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360); + } + else if (CCstatus.CamSensor_id == OV3660_PID) + { + CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528); + } + else if (CCstatus.CamSensor_id == OV5640_PID) + { + CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720); + } + } + } + + if (httpd_query_key_value(_query, "zooms", _valuechar, 30) == ESP_OK) + { + std::string _zooms = std::string(_valuechar); + if (isStringNumeric(_zooms)) + { + int _ImageZoomSize = std::stoi(_valuechar); + if (CCstatus.CamSensor_id == OV2640_PID) + { + CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0); + } + else if (CCstatus.CamSensor_id == OV3660_PID) + { + CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0); + } + else if (CCstatus.CamSensor_id == OV5640_PID) + { + CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0); + } + } + } + + if (httpd_query_key_value(_query, "ledi", _valuechar, 30) == ESP_OK) + { + std::string _ledi = std::string(_valuechar); + if (isStringNumeric(_ledi)) + { + float _ImageLedIntensity = std::stof(_valuechar); + Camera.SetLEDIntensity(_ImageLedIntensity); + CFstatus.ImageLedIntensity = CCstatus.ImageLedIntensity; + } + } + + if (_task.compare("cam_settings") == 0) + { + // wird aufgerufen, wenn das Referenzbild + Kameraeinstellungen gespeichert wurden + setCFstatusToCCstatus(); // CFstatus >>> CCstatus + + // Kameraeinstellungen wurden verädert + CFstatus.changedCameraSettings = true; + + ESP_LOGD(TAG, "Cam Settings set"); + std::string _zw = "CamSettingsSet"; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_send(req, _zw.c_str(), _zw.length()); + } + else + { + // wird aufgerufen, wenn ein neues Referenzbild erstellt oder aktualisiert wurde + // CFstatus >>> Kamera + setCFstatusToCam(); + + Camera.SetQualityZoomSize(CFstatus.ImageQuality, CFstatus.ImageFrameSize, CFstatus.ImageZoomEnabled, CFstatus.ImageZoomOffsetX, CFstatus.ImageZoomOffsetY, CFstatus.ImageZoomSize, CFstatus.ImageVflip); + // Camera.SetZoomSize(CFstatus.ImageZoomEnabled, CFstatus.ImageZoomOffsetX, CFstatus.ImageZoomOffsetY, CFstatus.ImageZoomSize, CFstatus.ImageVflip); + + // Kameraeinstellungen wurden verädert + CFstatus.changedCameraSettings = true; + + ESP_LOGD(TAG, "test_take - vor TakeImage"); + std::string image_temp = flowctrl.doSingleStep("[TakeImage]", _host); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_send(req, image_temp.c_str(), image_temp.length()); + } } - else + if (_task.compare("test_align") == 0) { - ESP_LOGD(TAG, "test_take - vor TakeImage"); - _zw = flowctrl.doSingleStep("[TakeImage]", _host); - } - - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - httpd_resp_send(req, _zw.c_str(), _zw.length()); - } - - if (_task.compare("test_align") == 0) { - std::string _host = ""; - if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) { - _host = std::string(_valuechar); - } -// ESP_LOGD(TAG, "Parameter host: %s", _host.c_str()); + std::string _host = ""; -// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str()); - std::string zw = flowctrl.doSingleStep("[Alignment]", _host); + if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) + { + _host = std::string(_valuechar); + } + + std::string zw = flowctrl.doSingleStep("[Alignment]", _host); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_send(req, zw.c_str(), zw.length()); + } + } + else + { + std::string _zw = "DeviceIsBusy"; httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - httpd_resp_send(req, zw.c_str(), zw.length()); + httpd_resp_send(req, _zw.c_str(), _zw.length()); } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_editflow - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_editflow - Done"); +#endif return ESP_OK; } +esp_err_t handler_statusflow(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_statusflow - Start"); +#endif -esp_err_t handler_statusflow(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_statusflow - Start"); - #endif - - const char* resp_str; + const char *resp_str; httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - if (bTaskAutoFlowCreated) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "handler_statusflow: %s", req->uri); - #endif + if (bTaskAutoFlowCreated) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "handler_statusflow: %s", req->uri); +#endif - string* zw = flowctrl.getActStatusWithTime(); + string *zw = flowctrl.getActStatusWithTime(); resp_str = zw->c_str(); - httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); + httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); } - else { + else + { resp_str = "Flow task not yet created"; - httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); + httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_statusflow - Done"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_statusflow - Done"); +#endif return ESP_OK; } - -esp_err_t handler_cputemp(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_cputemp - Start"); - #endif +esp_err_t handler_cputemp(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_cputemp - Start"); +#endif httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, std::to_string((int)temperatureRead()).c_str(), HTTPD_RESP_USE_STRLEN); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_cputemp - End"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_cputemp - End"); +#endif return ESP_OK; } +esp_err_t handler_rssi(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_rssi - Start"); +#endif -esp_err_t handler_rssi(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_rssi - Start"); - #endif - - if (getWIFIisConnected()) { + if (getWIFIisConnected()) + { httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, std::to_string(get_WIFI_RSSI()).c_str(), HTTPD_RESP_USE_STRLEN); } - else { + else + { httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "WIFI not (yet) connected: REST API /rssi not available!"); return ESP_ERR_NOT_FOUND; - } + } - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_rssi - End"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_rssi - End"); +#endif return ESP_OK; } +esp_err_t handler_uptime(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_uptime - Start"); +#endif -esp_err_t handler_uptime(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_uptime - Start"); - #endif - std::string formatedUptime = getFormatedUptime(false); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length()); + httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length()); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_uptime - End"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_uptime - End"); +#endif return ESP_OK; } - -esp_err_t handler_prevalue(httpd_req_t *req) { - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_prevalue - Start"); - ESP_LOGD(TAG, "handler_prevalue: %s", req->uri); - #endif +esp_err_t handler_prevalue(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_prevalue - Start"); + ESP_LOGD(TAG, "handler_prevalue: %s", req->uri); +#endif // Default usage message when handler gets called without any parameter - const std::string RESTUsageInfo = + const std::string RESTUsageInfo = "00: Handler usage:
" "- To retrieve actual PreValue, please provide only a numbersname, e.g. /setPreValue?numbers=main
" "- To set PreValue to a new value, please provide a numbersname and a value, e.g. /setPreValue?numbers=main&value=1234.5678
" @@ -909,82 +1530,92 @@ esp_err_t handler_prevalue(httpd_req_t *req) { httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Query: %s", _query); - #endif + if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Query: %s", _query); +#endif - if (httpd_query_key_value(_query, "numbers", _numbersname, 50) != ESP_OK) { + if (httpd_query_key_value(_query, "numbers", _numbersname, 50) != ESP_OK) + { // If request is incomplete sReturnMessage = "E91: Query parameter incomplete or not valid!
" "Call /setPreValue to show REST API usage info and/or check documentation"; httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); - return ESP_FAIL; + return ESP_FAIL; } - if (httpd_query_key_value(_query, "value", _value, 20) == ESP_OK) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Value: %s", _value); - #endif + if (httpd_query_key_value(_query, "value", _value, 20) == ESP_OK) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Value: %s", _value); +#endif } } - else { + else + { // if no parameter is provided, print handler usage httpd_resp_send(req, RESTUsageInfo.c_str(), RESTUsageInfo.length()); - return ESP_OK; - } + return ESP_OK; + } - if (strlen(_value) == 0) { + if (strlen(_value) == 0) + { // If no value is povided --> return actual PreValue sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname)); - if (sReturnMessage.empty()) { + if (sReturnMessage.empty()) + { sReturnMessage = "E92: Numbers name not found"; httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); return ESP_FAIL; } } - else { + else + { // New value is positive: Set PreValue to provided value and return value // New value is negative and actual RAW value is a valid number: Set PreValue to RAW value and return value - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) + - ", value: " + std::string(_value)); - if (!flowctrl.UpdatePrevalue(_value, _numbersname, true)) { + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) + ", value: " + std::string(_value)); + + if (!flowctrl.UpdatePrevalue(_value, _numbersname, true)) + { sReturnMessage = "E93: Update request rejected. Please check device logs for more details"; - httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); + httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); return ESP_FAIL; } sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname)); - if (sReturnMessage.empty()) { + if (sReturnMessage.empty()) + { sReturnMessage = "E94: Numbers name not found"; httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); return ESP_FAIL; } } - httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); + httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length()); - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("handler_prevalue - End"); - #endif +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_prevalue - End"); +#endif return ESP_OK; } - -void task_autodoFlow(void *pvParameter) { +void task_autodoFlow(void *pvParameter) +{ int64_t fr_start, fr_delta_ms; bTaskAutoFlowCreated = true; - if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC)) { + if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC)) + { flowctrl.setActStatus("Initialization (delayed)"); - //#ifdef ENABLE_MQTT - //MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later - //#endif //ENABLE_MQTT - vTaskDelay(60*5000 / portTICK_PERIOD_MS); // Wait 5 minutes to give time to do an OTA update or fetch the log + // #ifdef ENABLE_MQTT + // MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later + // #endif //ENABLE_MQTT + vTaskDelay(60 * 5000 / portTICK_PERIOD_MS); // Wait 5 minutes to give time to do an OTA update or fetch the log } ESP_LOGD(TAG, "task_autodoFlow: start"); @@ -993,206 +1624,227 @@ void task_autodoFlow(void *pvParameter) { flowctrl.setAutoStartInterval(auto_interval); autostartIsEnabled = flowctrl.getIsAutoStart(); - if (isSetupModusActive()) { + if (isSetupModusActive()) + { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "We are in Setup Mode -> Not starting Auto Flow!"); autostartIsEnabled = false; - std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT); - flowctrl.doFlowTakeImageOnly(zw_time); + // 15.7.0 Setup Wizard cannot take a Reference Picture #2953 + // std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT); + // flowctrl.doFlowTakeImageOnly(zw_time); } - if (autostartIsEnabled) { + if (autostartIsEnabled) + { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Starting Flow..."); } - else { + else + { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Autostart is not enabled -> Not starting Flow"); } - - while (autostartIsEnabled) { + + while (autostartIsEnabled) + { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs - std::string _zw = "Round #" + std::to_string(++countRounds) + " started"; time_t roundStartTime = getUpTime(); - LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw); + + std::string _zw = "Round #" + std::to_string(++countRounds) + " started"; + LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw); + fr_start = esp_timer_get_time(); - if (flowisrunning) { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Autoflow: doFlow is already running!"); - #endif + if (flowisrunning) + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Autoflow: doFlow is already running!"); +#endif } - else { - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Autoflow: doFlow is started"); - #endif + else + { +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Autoflow: doFlow is started"); +#endif flowisrunning = true; doflow(); - #ifdef DEBUG_DETAIL_ON - ESP_LOGD(TAG, "Remove older log files"); - #endif +#ifdef DEBUG_DETAIL_ON + ESP_LOGD(TAG, "Remove older log files"); +#endif LogFile.RemoveOldLogFile(); LogFile.RemoveOldDataLog(); } // Round finished -> Logfile - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) + - " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)"); - + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) + " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)"); + // CPU Temp -> Logfile LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C"); - + // WIFI Signal Strength (RSSI) -> Logfile LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm"); // Check if time is synchronized (if NTP is configured) - if (getUseNtp() && !getTimeIsSet()) { + if (getUseNtp() && !getTimeIsSet()) + { LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time server is configured, but time is not yet set!"); StatusLED(TIME_CHECK, 1, false); } - #if (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES) - wifiRoamingQuery(); - #endif - - // Scan channels and check if an AP with better RSSI is available, then disconnect and try to reconnect to AP with better RSSI - // NOTE: Keep this direct before the following task delay, because scan is done in blocking mode and this takes ca. 1,5 - 2s. - #ifdef WLAN_USE_ROAMING_BY_SCANNING - wifiRoamByScanning(); - #endif - +#if (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES) + wifiRoamingQuery(); +#endif + +// Scan channels and check if an AP with better RSSI is available, then disconnect and try to reconnect to AP with better RSSI +// NOTE: Keep this direct before the following task delay, because scan is done in blocking mode and this takes ca. 1,5 - 2s. +#ifdef WLAN_USE_ROAMING_BY_SCANNING + wifiRoamByScanning(); +#endif + fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000; - - if (auto_interval > fr_delta_ms) { - const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS; - ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long) xDelay); - vTaskDelay( xDelay ); + + if (auto_interval > fr_delta_ms) + { + const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS; + ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long)xDelay); + vTaskDelay(xDelay); } } - while(1) { + while (1) + { // Keep flow task running to handle necessary sub tasks like reboot handler, etc.. - vTaskDelay(2000 / portTICK_PERIOD_MS); + vTaskDelay(2000 / portTICK_PERIOD_MS); } - vTaskDelete(NULL); //Delete this task if it exits from the loop above + vTaskDelete(NULL); // Delete this task if it exits from the loop above xHandletask_autodoFlow = NULL; + ESP_LOGD(TAG, "task_autodoFlow: end"); } - -void InitializeFlowTask() { +void InitializeFlowTask(void) +{ BaseType_t xReturned; ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str()); uint32_t stackSize = 16 * 1024; - xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", stackSize, NULL, tskIDLE_PRIORITY+2, &xHandletask_autodoFlow, 0); - - if( xReturned != pdPASS ) { + xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", stackSize, NULL, tskIDLE_PRIORITY + 2, &xHandletask_autodoFlow, 0); + + if (xReturned != pdPASS) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Creation task_autodoFlow failed. Requested stack size:" + std::to_string(stackSize)); LogFile.WriteHeapInfo("Creation task_autodoFlow failed"); } - + ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str()); } - -void register_server_main_flow_task_uri(httpd_handle_t server) { +void register_server_main_flow_task_uri(httpd_handle_t server) +{ ESP_LOGI(TAG, "server_main_flow_task - Registering URI handlers"); - - httpd_uri_t camuri = { }; - camuri.method = HTTP_GET; - camuri.uri = "/doinit"; - camuri.handler = handler_init; - camuri.user_ctx = (void*) "Light On"; + httpd_uri_t camuri = {}; + camuri.method = HTTP_GET; + + camuri.uri = "/doinit"; + camuri.handler = handler_init; + camuri.user_ctx = (void *)"Light On"; httpd_register_uri_handler(server, &camuri); // Legacy API => New: "/setPreValue" - camuri.uri = "/setPreValue.html"; - camuri.handler = handler_prevalue; - camuri.user_ctx = (void*) "Prevalue"; + camuri.uri = "/setPreValue.html"; + camuri.handler = handler_prevalue; + camuri.user_ctx = (void *)"Prevalue"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/setPreValue"; - camuri.handler = handler_prevalue; - camuri.user_ctx = (void*) "Prevalue"; + camuri.uri = "/setPreValue"; + camuri.handler = handler_prevalue; + camuri.user_ctx = (void *)"Prevalue"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/flow_start"; - camuri.handler = handler_flow_start; - camuri.user_ctx = (void*) "Flow Start"; + camuri.uri = "/flow_start"; + camuri.handler = handler_flow_start; + camuri.user_ctx = (void *)"Flow Start"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/statusflow.html"; - camuri.handler = handler_statusflow; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/statusflow.html"; + camuri.handler = handler_statusflow; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/statusflow"; - camuri.handler = handler_statusflow; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/statusflow"; + camuri.handler = handler_statusflow; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); // Legacy API => New: "/cpu_temperature" - camuri.uri = "/cputemp.html"; - camuri.handler = handler_cputemp; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/cputemp.html"; + camuri.handler = handler_cputemp; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/cpu_temperature"; - camuri.handler = handler_cputemp; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/cpu_temperature"; + camuri.handler = handler_cputemp; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); // Legacy API => New: "/rssi" - camuri.uri = "/rssi.html"; - camuri.handler = handler_rssi; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/rssi.html"; + camuri.handler = handler_rssi; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/rssi"; - camuri.handler = handler_rssi; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/rssi"; + camuri.handler = handler_rssi; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/uptime"; - camuri.handler = handler_uptime; - camuri.user_ctx = (void*) "Light Off"; + camuri.uri = "/uptime"; + camuri.handler = handler_uptime; + camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/editflow"; - camuri.handler = handler_editflow; - camuri.user_ctx = (void*) "EditFlow"; - httpd_register_uri_handler(server, &camuri); + camuri.uri = "/editflow"; + camuri.handler = handler_editflow; + camuri.user_ctx = (void *)"EditFlow"; + httpd_register_uri_handler(server, &camuri); // Legacy API => New: "/value" - camuri.uri = "/value.html"; - camuri.handler = handler_wasserzaehler; - camuri.user_ctx = (void*) "Value"; + camuri.uri = "/value.html"; + camuri.handler = handler_wasserzaehler; + camuri.user_ctx = (void *)"Value"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/value"; - camuri.handler = handler_wasserzaehler; - camuri.user_ctx = (void*) "Value"; + camuri.uri = "/value"; + camuri.handler = handler_wasserzaehler; + camuri.user_ctx = (void *)"Value"; httpd_register_uri_handler(server, &camuri); // Legacy API => New: "/value" - camuri.uri = "/wasserzaehler.html"; - camuri.handler = handler_wasserzaehler; - camuri.user_ctx = (void*) "Wasserzaehler"; + camuri.uri = "/wasserzaehler.html"; + camuri.handler = handler_wasserzaehler; + camuri.user_ctx = (void *)"Wasserzaehler"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/json"; - camuri.handler = handler_json; - camuri.user_ctx = (void*) "JSON"; + camuri.uri = "/json"; + camuri.handler = handler_json; + camuri.user_ctx = (void *)"JSON"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/heap"; - camuri.handler = handler_get_heap; - camuri.user_ctx = (void*) "Heap"; + camuri.uri = "/heap"; + camuri.handler = handler_get_heap; + camuri.user_ctx = (void *)"Heap"; httpd_register_uri_handler(server, &camuri); - camuri.uri = "/stream"; - camuri.handler = handler_stream; - camuri.user_ctx = (void*) "stream"; + camuri.uri = "/stream"; + camuri.handler = handler_stream; + camuri.user_ctx = (void *)"stream"; httpd_register_uri_handler(server, &camuri); + + /** will handle metrics requests */ + camuri.uri = "/metrics"; + camuri.handler = handler_openmetrics; + camuri.user_ctx = (void *)"metrics"; + httpd_register_uri_handler(server, &camuri); + + /** when adding a new handler, make sure to increment the value for config.max_uri_handlers in `main/server_main.cpp` */ } diff --git a/code/components/jomjol_flowcontroll/MainFlowControl.h b/code/components/jomjol_flowcontroll/MainFlowControl.h index 8ede3be07..a2c2047e3 100644 --- a/code/components/jomjol_flowcontroll/MainFlowControl.h +++ b/code/components/jomjol_flowcontroll/MainFlowControl.h @@ -9,26 +9,83 @@ #include #include "CImageBasis.h" #include "ClassFlowControll.h" +#include "openmetrics.h" +typedef struct +{ + uint16_t CamSensor_id; + + framesize_t ImageFrameSize = FRAMESIZE_VGA; // 0 - 10 + gainceiling_t ImageGainceiling; // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) + + int ImageQuality; // 0 - 63 + int ImageBrightness; // (-2 to 2) - set brightness + int ImageContrast; //-2 - 2 + int ImageSaturation; //-2 - 2 + int ImageSharpness; //-2 - 2 + bool ImageAutoSharpness; + int ImageSpecialEffect; // 0 - 6 + int ImageWbMode; // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) + int ImageAwb; // white balance enable (0 or 1) + int ImageAwbGain; // Auto White Balance enable (0 or 1) + int ImageAec; // auto exposure off (1 or 0) + int ImageAec2; // automatic exposure sensor (0 or 1) + int ImageAeLevel; // auto exposure levels (-2 to 2) + int ImageAecValue; // set exposure manually (0-1200) + int ImageAgc; // auto gain off (1 or 0) + int ImageAgcGain; // set gain manually (0 - 30) + int ImageBpc; // black pixel correction + int ImageWpc; // white pixel correction + int ImageRawGma; // (1 or 0) + int ImageLenc; // lens correction (1 or 0) + int ImageHmirror; // (0 or 1) flip horizontally + int ImageVflip; // Invert image (0 or 1) + int ImageDcw; // downsize enable (1 or 0) + + int ImageDenoiseLevel; // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) + + int ImageWidth; + int ImageHeight; + + int ImageLedIntensity; + + bool ImageZoomEnabled; + int ImageZoomOffsetX; + int ImageZoomOffsetY; + int ImageZoomSize; + + int WaitBeforePicture; + bool isImageSize; + + bool CameraInitSuccessful; + bool changedCameraSettings; + bool DemoMode; + bool SaveAllFiles; +} camera_flow_config_temp_t; + +extern camera_flow_config_temp_t CFstatus; extern ClassFlowControll flowctrl; +esp_err_t setCCstatusToCFstatus(void); // CCstatus >>> CFstatus +esp_err_t setCFstatusToCCstatus(void); // CFstatus >>> CCstatus +esp_err_t setCFstatusToCam(void); // CFstatus >>> Kamera void register_server_main_flow_task_uri(httpd_handle_t server); -void CheckIsPlannedReboot(); -bool getIsPlannedReboot(); +void CheckIsPlannedReboot(void); +bool getIsPlannedReboot(void); -void InitializeFlowTask(); -void DeleteMainFlowTask(); -bool isSetupModusActive(); +void InitializeFlowTask(void); +void DeleteMainFlowTask(void); +bool isSetupModusActive(void); -int getCountFlowRounds(); +int getCountFlowRounds(void); #ifdef ENABLE_MQTT esp_err_t MQTTCtrlFlowStart(std::string _topic); -#endif //ENABLE_MQTT +#endif // ENABLE_MQTT esp_err_t GetRawJPG(httpd_req_t *req); esp_err_t GetJPG(std::string _filename, httpd_req_t *req); -#endif //MAINFLOWCONTROL_H +#endif // MAINFLOWCONTROL_H diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index ed2c9524e..78d359e38 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -1,4 +1,4 @@ -//#pragma warning(disable : 4996) +// #pragma warning(disable : 4996) #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -14,7 +14,8 @@ #include #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include #ifdef __cplusplus @@ -32,7 +33,7 @@ extern "C" { #include "esp_vfs_fat.h" #include "../sdmmc_common.h" -static const char* TAG = "HELPER"; +static const char *TAG = "HELPER"; using namespace std; @@ -42,190 +43,205 @@ sdmmc_cid_t SDCardCid; sdmmc_csd_t SDCardCsd; bool SDCardIsMMC; -// #define DEBUG_DETAIL_ON +// #define DEBUG_DETAIL_ON ///////////////////////////////////////////////////////////////////////////////////////////// -string getESPHeapInfo(){ +string getESPHeapInfo() +{ string espInfoResultStr = ""; char aMsgBuf[80]; - size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT); - size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); size_t aHeapIntLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); - size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); - + size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); - sprintf(aMsgBuf,"Heap Total: %ld", (long) aFreeHeapSize); + sprintf(aMsgBuf, "Heap Total: %ld", (long)aFreeHeapSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," | SPI Free: %ld", (long) aFreeSPIHeapSize); + sprintf(aMsgBuf, " | SPI Free: %ld", (long)aFreeSPIHeapSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," | SPI Large Block: %ld", (long) aHeapLargestFreeBlockSize); + sprintf(aMsgBuf, " | SPI Large Block: %ld", (long)aHeapLargestFreeBlockSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," | SPI Min Free: %ld", (long) aMinFreeHeapSize); + sprintf(aMsgBuf, " | SPI Min Free: %ld", (long)aMinFreeHeapSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," | Int Free: %ld", (long) (aFreeInternalHeapSize)); + sprintf(aMsgBuf, " | Int Free: %ld", (long)(aFreeInternalHeapSize)); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," | Int Large Block: %ld", (long) aHeapIntLargestFreeBlockSize); + sprintf(aMsgBuf, " | Int Large Block: %ld", (long)aHeapIntLargestFreeBlockSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," | Int Min Free: %ld", (long) (aMinFreeInternalHeapSize)); + sprintf(aMsgBuf, " | Int Min Free: %ld", (long)(aMinFreeInternalHeapSize)); espInfoResultStr += string(aMsgBuf); - - return espInfoResultStr; -} + return espInfoResultStr; +} size_t getESPHeapSize() { - return heap_caps_get_free_size(MALLOC_CAP_8BIT); + return heap_caps_get_free_size(MALLOC_CAP_8BIT); } - -size_t getInternalESPHeapSize() +size_t getInternalESPHeapSize() { - return heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); + return heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); } - -string getSDCardPartitionSize(){ +string getSDCardPartitionSize() +{ FATFS *fs; - uint32_t fre_clust, tot_sect; + uint32_t fre_clust, tot_sect; - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + tot_sect = ((fs->n_fatent - 2) * fs->csize) / 1024 / (1024 / SDCardCsd.sector_size); // corrected by SD Card sector size (usually 512 bytes) and convert to MB - //ESP_LOGD(TAG, "%d MB total drive space (Sector size [bytes]: %d)", (int)tot_sect, (int)fs->ssize); + // ESP_LOGD(TAG, "%d MB total drive space (Sector size [bytes]: %d)", (int)tot_sect, (int)fs->ssize); return std::to_string(tot_sect); } - -string getSDCardFreePartitionSpace(){ +string getSDCardFreePartitionSpace() +{ FATFS *fs; - uint32_t fre_clust, fre_sect; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + uint32_t fre_clust, fre_sect; - //ESP_LOGD(TAG, "%d MB free drive space (Sector size [bytes]: %d)", (int)fre_sect, (int)fs->ssize); + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + fre_sect = (fre_clust * fs->csize) / 1024 / (1024 / SDCardCsd.sector_size); // corrected by SD Card sector size (usually 512 bytes) and convert to MB + + // ESP_LOGD(TAG, "%d MB free drive space (Sector size [bytes]: %d)", (int)fre_sect, (int)fs->ssize); return std::to_string(fre_sect); } - -string getSDCardPartitionAllocationSize(){ +string getSDCardPartitionAllocationSize() +{ FATFS *fs; - uint32_t fre_clust, allocation_size; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - allocation_size = fs->ssize; + uint32_t fre_clust, allocation_size; - //ESP_LOGD(TAG, "SD Card Partition Allocation Size: %d bytes", allocation_size); + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + allocation_size = fs->ssize; + + // ESP_LOGD(TAG, "SD Card Partition Allocation Size: %d bytes", allocation_size); return std::to_string(allocation_size); } - -void SaveSDCardInfo(sdmmc_card_t* card) { +void SaveSDCardInfo(sdmmc_card_t *card) +{ SDCardCid = card->cid; - SDCardCsd = card->csd; + SDCardCsd = card->csd; SDCardIsMMC = card->is_mmc; } - -string getSDCardManufacturer(){ +string getSDCardManufacturer() +{ string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); - //ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str()); - + // ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str()); + return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); } - -string getSDCardName(){ +string getSDCardName() +{ char *SDCardName = SDCardCid.name; - //ESP_LOGD(TAG, "SD Card Name: %s", SDCardName); + // ESP_LOGD(TAG, "SD Card Name: %s", SDCardName); return std::string(SDCardName); } - -string getSDCardCapacity(){ - int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - //ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str()); +string getSDCardCapacity() +{ + int SDCardCapacity = SDCardCsd.capacity / (1024 / SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + // ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str()); return std::to_string(SDCardCapacity); } - -string getSDCardSectorSize(){ +string getSDCardSectorSize() +{ int SDCardSectorSize = SDCardCsd.sector_size; - //ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str()); + // ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str()); return std::to_string(SDCardSectorSize); } /////////////////////////////////////////////////////////////////////////////////////////////// -void memCopyGen(uint8_t* _source, uint8_t* _target, int _size) +void memCopyGen(uint8_t *_source, uint8_t *_target, int _size) { - for (int i = 0; i < _size; ++i) - *(_target + i) = *(_source + i); + for (int i = 0; i < _size; ++i) + { + *(_target + i) = *(_source + i); + } } - std::string FormatFileName(std::string input) { #ifdef ISWINDOWS_TRUE - input.erase(0, 1); - std::string os = "/"; - std::string ns = "\\"; - FindReplace(input, os, ns); + input.erase(0, 1); + std::string os = "/"; + std::string ns = "\\"; + FindReplace(input, os, ns); #endif - return input; + return input; } +std::size_t file_size(const std::string &file_name) +{ + std::ifstream file(file_name.c_str(), std::ios::in | std::ios::binary); -std::size_t file_size(const std::string& file_name) { - std::ifstream file(file_name.c_str(),std::ios::in | std::ios::binary); - if (!file) return 0; - file.seekg (0, std::ios::end); - return static_cast(file.tellg()); + if (!file) + { + return 0; + } + + file.seekg(0, std::ios::end); + return static_cast(file.tellg()); } +void FindReplace(std::string &line, std::string &oldString, std::string &newString) +{ + const size_t oldSize = oldString.length(); -void FindReplace(std::string& line, std::string& oldString, std::string& newString) { - const size_t oldSize = oldString.length(); - - // do nothing if line is shorter than the string to find - if (oldSize > line.length()) return; - - const size_t newSize = newString.length(); - for (size_t pos = 0; ; pos += newSize) { - // Locate the substring to replace - pos = line.find(oldString, pos); - if (pos == std::string::npos) return; - if (oldSize == newSize) { - // if they're same size, use std::string::replace - line.replace(pos, oldSize, newString); - } - else { - // if not same size, replace by erasing and inserting - line.erase(pos, oldSize); - line.insert(pos, newString); - } - } -} + // do nothing if line is shorter than the string to find + if (oldSize > line.length()) + { + return; + } + + const size_t newSize = newString.length(); + + for (size_t pos = 0;; pos += newSize) + { + // Locate the substring to replace + pos = line.find(oldString, pos); + + if (pos == std::string::npos) + { + return; + } + if (oldSize == newSize) + { + // if they're same size, use std::string::replace + line.replace(pos, oldSize, newString); + } + else + { + // if not same size, replace by erasing and inserting + line.erase(pos, oldSize); + line.insert(pos, newString); + } + } +} /** * Create a folder and its parent folders as needed @@ -237,56 +253,63 @@ bool MakeDir(std::string path) LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Creating folder " + path + "..."); bool bSuccess = false; - int nRC = ::mkdir( path.c_str(), 0775 ); - if( nRC == -1 ) - { - switch( errno ) { - case ENOENT: - //parent didn't exist, try to create it - parent = path.substr(0, path.find_last_of('/')); - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Need to create parent folder first: " + parent); - if(MakeDir(parent)) { - //Now, try to create again. - bSuccess = 0 == ::mkdir( path.c_str(), 0775 ); - } - else { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create parent folder: " + parent); - bSuccess = false; - } - break; - - case EEXIST: - //Done! - bSuccess = true; - break; - - default: - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create folder: " + path + " (errno: " + std::to_string(errno) + ")"); - bSuccess = false; - break; - } - } - else { - bSuccess = true; + int nRC = ::mkdir(path.c_str(), 0775); + + if (nRC == -1) + { + switch (errno) + { + case ENOENT: + // parent didn't exist, try to create it + parent = path.substr(0, path.find_last_of('/')); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Need to create parent folder first: " + parent); + + if (MakeDir(parent)) + { + // Now, try to create again. + bSuccess = 0 == ::mkdir(path.c_str(), 0775); + } + else + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create parent folder: " + parent); + bSuccess = false; + } + break; + + case EEXIST: + // Done! + bSuccess = true; + break; + + default: + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create folder: " + path + " (errno: " + std::to_string(errno) + ")"); + bSuccess = false; + break; + } + } + else + { + bSuccess = true; } - return bSuccess; + return bSuccess; } - bool ctype_space(const char c, string adddelimiter) { if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 11) { return true; } + if (adddelimiter.find(c) != string::npos) + { return true; + } return false; } - string trim(string istring, string adddelimiter) { bool trimmed = false; @@ -313,76 +336,87 @@ string trim(string istring, string adddelimiter) } } - size_t findDelimiterPos(string input, string delimiter) { size_t pos = std::string::npos; - size_t zw; + // size_t zw; string akt_del; for (int anz = 0; anz < delimiter.length(); ++anz) { akt_del = delimiter[anz]; - if ((zw = input.find(akt_del)) != std::string::npos) + size_t zw = input.find(akt_del); + + if (zw != std::string::npos) { - if (pos != std::string::npos) + if ((pos != std::string::npos) && (zw < pos)) { - if (zw < pos) - pos = zw; + pos = zw; } else + { pos = zw; + } } } + return pos; } - bool RenameFile(string from, string to) { -// ESP_LOGI(logTag, "Deleting file: %s", fn.c_str()); + // ESP_LOGI(logTag, "Deleting file: %s", fn.c_str()); /* Delete file */ - FILE* fpSourceFile = fopen(from.c_str(), "rb"); - if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + FILE *fpSourceFile = fopen(from.c_str(), "rb"); + + // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + if (!fpSourceFile) { ESP_LOGE(TAG, "DeleteFile: File %s existiert nicht!", from.c_str()); return false; } + fclose(fpSourceFile); rename(from.c_str(), to.c_str()); + return true; } - bool FileExists(string filename) { - FILE* fpSourceFile = fopen(filename.c_str(), "rb"); - if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + FILE *fpSourceFile = fopen(filename.c_str(), "rb"); + + // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + if (!fpSourceFile) { return false; } + fclose(fpSourceFile); - return true; -} + return true; +} bool DeleteFile(string fn) { -// ESP_LOGI(logTag, "Deleting file: %s", fn.c_str()); + // ESP_LOGI(logTag, "Deleting file: %s", fn.c_str()); /* Delete file */ - FILE* fpSourceFile = fopen(fn.c_str(), "rb"); - if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + FILE *fpSourceFile = fopen(fn.c_str(), "rb"); + + // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + if (!fpSourceFile) { ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str()); return false; } + fclose(fpSourceFile); unlink(fn.c_str()); - return true; -} + return true; +} bool CopyFile(string input, string output) { @@ -396,14 +430,16 @@ bool CopyFile(string input, string output) } char cTemp; - FILE* fpSourceFile = fopen(input.c_str(), "rb"); - if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + FILE *fpSourceFile = fopen(input.c_str(), "rb"); + + // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! + if (!fpSourceFile) { ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str()); return false; } - FILE* fpTargetFile = fopen(output.c_str(), "wb"); + FILE *fpTargetFile = fopen(output.c_str(), "wb"); // Code Section @@ -418,53 +454,60 @@ bool CopyFile(string input, string output) fclose(fpSourceFile); fclose(fpTargetFile); ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str()); + return true; } - string getFileFullFileName(string filename) { size_t lastpos = filename.find_last_of('/'); if (lastpos == string::npos) + { return ""; + } -// ESP_LOGD(TAG, "Last position: %d", lastpos); + // ESP_LOGD(TAG, "Last position: %d", lastpos); string zw = filename.substr(lastpos + 1, filename.size() - lastpos); return zw; } - string getDirectory(string filename) { size_t lastpos = filename.find('/'); if (lastpos == string::npos) + { lastpos = filename.find('\\'); + } if (lastpos == string::npos) + { return ""; + } -// ESP_LOGD(TAG, "Directory: %d", lastpos); + // ESP_LOGD(TAG, "Directory: %d", lastpos); string zw = filename.substr(0, lastpos - 1); return zw; } - string getFileType(string filename) { size_t lastpos = filename.rfind(".", filename.length()); size_t neu_pos; + while ((neu_pos = filename.find(".", lastpos + 1)) > -1) { lastpos = neu_pos; } if (lastpos == string::npos) + { return ""; + } string zw = filename.substr(lastpos + 1, filename.size() - lastpos); zw = toUpper(zw); @@ -472,172 +515,213 @@ string getFileType(string filename) return zw; } - /* recursive mkdir */ -int mkdir_r(const char *dir, const mode_t mode) { - char tmp[FILE_PATH_MAX]; - char *p = NULL; - struct stat sb; - size_t len; - - /* copy path */ - len = strnlen (dir, FILE_PATH_MAX); - if (len == 0 || len == FILE_PATH_MAX) { - return -1; - } - memcpy (tmp, dir, len); - tmp[len] = '\0'; - - /* remove trailing slash */ - if(tmp[len - 1] == '/') { - tmp[len - 1] = '\0'; - } - - /* check if path exists and is a directory */ - if (stat (tmp, &sb) == 0) { - if (S_ISDIR (sb.st_mode)) { - return 0; - } - } - - /* recursive mkdir */ - for(p = tmp + 1; *p; p++) { - if(*p == '/') { - *p = 0; - /* test path */ - if (stat(tmp, &sb) != 0) { - /* path does not exist - create directory */ - if (mkdir(tmp, mode) < 0) { - return -1; - } - } else if (!S_ISDIR(sb.st_mode)) { - /* not a directory */ - return -1; - } - *p = '/'; - } - } - /* test path */ - if (stat(tmp, &sb) != 0) { - /* path does not exist - create directory */ - if (mkdir(tmp, mode) < 0) { - return -1; - } - } else if (!S_ISDIR(sb.st_mode)) { - /* not a directory */ - return -1; - } - return 0; -} +int mkdir_r(const char *dir, const mode_t mode) +{ + char tmp[FILE_PATH_MAX]; + char *p = NULL; + struct stat sb; + size_t len; + + /* copy path */ + len = strnlen(dir, FILE_PATH_MAX); + if (len == 0 || len == FILE_PATH_MAX) + { + return -1; + } + + memcpy(tmp, dir, len); + tmp[len] = '\0'; + + /* remove trailing slash */ + if (tmp[len - 1] == '/') + { + tmp[len - 1] = '\0'; + } + + /* check if path exists and is a directory */ + if (stat(tmp, &sb) == 0) + { + if (S_ISDIR(sb.st_mode)) + { + return 0; + } + } + + /* recursive mkdir */ + for (p = tmp + 1; *p; p++) + { + if (*p == '/') + { + *p = 0; + + /* test path */ + if (stat(tmp, &sb) != 0) + { + /* path does not exist - create directory */ + if (mkdir(tmp, mode) < 0) + { + return -1; + } + } + else if (!S_ISDIR(sb.st_mode)) + { + /* not a directory */ + return -1; + } + + *p = '/'; + } + } + + /* test path */ + if (stat(tmp, &sb) != 0) + { + /* path does not exist - create directory */ + if (mkdir(tmp, mode) < 0) + { + return -1; + } + } + else if (!S_ISDIR(sb.st_mode)) + { + /* not a directory */ + return -1; + } + + return 0; +} string toUpper(string in) { for (int i = 0; i < in.length(); ++i) + { in[i] = toupper(in[i]); - + } + return in; } - string toLower(string in) { for (int i = 0; i < in.length(); ++i) + { in[i] = tolower(in[i]); - + } + return in; } - // CPU Temp extern "C" uint8_t temprature_sens_read(); float temperatureRead() { - return (temprature_sens_read() - 32) / 1.8; + return (temprature_sens_read() - 32) / 1.8; } - -time_t addDays(time_t startTime, int days) { - struct tm* tm = localtime(&startTime); +time_t addDays(time_t startTime, int days) +{ + struct tm *tm = localtime(&startTime); tm->tm_mday += days; return mktime(tm); } - -int removeFolder(const char* folderPath, const char* logTag) { - //ESP_LOGD(logTag, "Delete content in path %s", folderPath); +int removeFolder(const char *folderPath, const char *logTag) +{ + // ESP_LOGD(logTag, "Delete content in path %s", folderPath); DIR *dir = opendir(folderPath); - if (!dir) { - ESP_LOGE(logTag, "Failed to stat dir: %s", folderPath); - return -1; - } - - struct dirent *entry; - int deleted = 0; - while ((entry = readdir(dir)) != NULL) { - std::string path = string(folderPath) + "/" + entry->d_name; - if (entry->d_type == DT_REG) { - //ESP_LOGD(logTag, "Delete file %s", path.c_str()); - if (unlink(path.c_str()) == 0) { - deleted ++; - } else { + + if (!dir) + { + ESP_LOGE(logTag, "Failed to stat dir: %s", folderPath); + return -1; + } + + struct dirent *entry; + int deleted = 0; + + while ((entry = readdir(dir)) != NULL) + { + std::string path = string(folderPath) + "/" + entry->d_name; + + if (entry->d_type == DT_REG) + { + // ESP_LOGD(logTag, "Delete file %s", path.c_str()); + if (unlink(path.c_str()) == 0) + { + deleted++; + } + else + { ESP_LOGE(logTag, "can't delete file: %s", path.c_str()); } - } else if (entry->d_type == DT_DIR) { + } + else if (entry->d_type == DT_DIR) + { deleted += removeFolder(path.c_str(), logTag); } - } - - closedir(dir); - if (rmdir(folderPath) != 0) { + } + + closedir(dir); + + if (rmdir(folderPath) != 0) + { ESP_LOGE(logTag, "can't delete folder: %s", folderPath); } + ESP_LOGD(logTag, "%d files in folder %s deleted.", deleted, folderPath); return deleted; } - std::vector HelperZerlegeZeile(std::string input, std::string _delimiter = "") { std::vector Output; std::string delimiter = " =,"; - if (_delimiter.length() > 0){ - delimiter = _delimiter; - } + + if (_delimiter.length() > 0) + { + delimiter = _delimiter; + } return ZerlegeZeile(input, delimiter); } - std::vector ZerlegeZeile(std::string input, std::string delimiter) { std::vector Output; - /* The input can have multiple formats: + /* The input can have multiple formats: * - key = value - * - key = value1 value2 value3 ... - * - key value1 value2 value3 ... - * + * - key = value1 value2 value3 ... + * - key value1 value2 value3 ... + * * Examples: * - ImageSize = VGA - * - IO0 = input disabled 10 false false + * - IO0 = input disabled 10 false false * - main.dig1 28 144 55 100 false - * + * * This causes issues eg. if a password key has a whitespace or equal sign in its value. * As a workaround and to not break any legacy usage, we enforce to only use the * equal sign, if the key is "password" - */ - if ((input.find("password") != string::npos) || (input.find("Token") != string::npos)) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence + */ + if ((input.find("password") != string::npos) || (input.find("Token") != string::npos)) + { + // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence size_t pos = input.find("="); Output.push_back(trim(input.substr(0, pos), "")); - Output.push_back(trim(input.substr(pos +1, string::npos), "")); + Output.push_back(trim(input.substr(pos + 1, string::npos), "")); } - else { // Legacy Mode - input = trim(input, delimiter); // sonst werden delimiter am Ende (z.B. == im Token) gelöscht) + else + { + // Legacy Mode + input = trim(input, delimiter); // sonst werden delimiter am Ende (z.B. == im Token) gelöscht) size_t pos = findDelimiterPos(input, delimiter); std::string token; - while (pos != std::string::npos) { + + while (pos != std::string::npos) + { token = input.substr(0, pos); token = trim(token, delimiter); Output.push_back(token); @@ -645,34 +729,35 @@ std::vector ZerlegeZeile(std::string input, std::string delimiter) input = trim(input, delimiter); pos = findDelimiterPos(input, delimiter); } + Output.push_back(input); } return Output; - } +std::string ReplaceString(std::string subject, const std::string &search, const std::string &replace) +{ + size_t pos = 0; -std::string ReplaceString(std::string subject, const std::string& search, - const std::string& replace) { - size_t pos = 0; - while ((pos = subject.find(search, pos)) != std::string::npos) { - subject.replace(pos, search.length(), replace); - pos += replace.length(); - } - return subject; -} + while ((pos = subject.find(search, pos)) != std::string::npos) + { + subject.replace(pos, search.length(), replace); + pos += replace.length(); + } + return subject; +} /* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ /* SD Card Manufacturer Database */ -struct SDCard_Manufacturer_database { +struct SDCard_Manufacturer_database +{ string type; int id; string manufacturer; }; - /* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ /* SD Card Manufacturer Database */ struct SDCard_Manufacturer_database sd_database[] = { @@ -857,242 +942,376 @@ struct SDCard_Manufacturer_database mmc_database[] = { }; /* Parse SD Card Manufacturer Database */ -string SDCardParseManufacturerIDs(int id) +string SDCardParseManufacturerIDs(int id) { - if (SDCardIsMMC) - { - unsigned int id_cnt = sizeof(mmc_database) / sizeof(struct SDCard_Manufacturer_database); - string ret_val = ""; - - for (int i = 0; i < id_cnt; i++) - { - if (mmc_database[i].id == id) - { - return mmc_database[i].manufacturer; - } - else - { - ret_val = "ID unknown (not in DB)"; - } - } + if (SDCardIsMMC) + { + unsigned int id_cnt = sizeof(mmc_database) / sizeof(struct SDCard_Manufacturer_database); + string ret_val = ""; - return ret_val; - } + for (int i = 0; i < id_cnt; i++) + { + if (mmc_database[i].id == id) + { + return mmc_database[i].manufacturer; + } + else + { + ret_val = "ID unknown (not in DB)"; + } + } - else - { - unsigned int id_cnt = sizeof(sd_database) / sizeof(struct SDCard_Manufacturer_database); - string ret_val = ""; + return ret_val; + } - for (int i = 0; i < id_cnt; i++) + else { - if (sd_database[i].id == id) - { - return sd_database[i].manufacturer; - } - else - { - ret_val = "ID unknown (not in DB)"; - } - } + unsigned int id_cnt = sizeof(sd_database) / sizeof(struct SDCard_Manufacturer_database); + string ret_val = ""; - return ret_val; - } -} + for (int i = 0; i < id_cnt; i++) + { + if (sd_database[i].id == id) + { + return sd_database[i].manufacturer; + } + else + { + ret_val = "ID unknown (not in DB)"; + } + } + return ret_val; + } +} string RundeOutput(double _in, int _anzNachkomma) { - std::stringstream stream; - int _zw = _in; -// ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma); - - if (_anzNachkomma < 0) { - _anzNachkomma = 0; - } - - if (_anzNachkomma > 0) - { - stream << std::fixed << std::setprecision(_anzNachkomma) << _in; - return stream.str(); - } - else - { - stream << _zw; - } - - - return stream.str(); -} + std::stringstream stream; + int _zw = _in; + // ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma); + + if (_anzNachkomma > 0) + { + stream << std::fixed << std::setprecision(_anzNachkomma) << _in; + } + else + { + stream << _zw; + } + return stream.str(); +} -string getMac(void) { - uint8_t macInt[6]; - char macFormated[6*2 + 5 + 1]; // AA:BB:CC:DD:EE:FF +string getMac(void) +{ + uint8_t macInt[6]; + char macFormated[6 * 2 + 5 + 1]; // AA:BB:CC:DD:EE:FF - esp_read_mac(macInt, ESP_MAC_WIFI_STA); - sprintf(macFormated, "%02X:%02X:%02X:%02X:%02X:%02X", macInt[0], macInt[1], macInt[2], macInt[3], macInt[4], macInt[5]); + esp_read_mac(macInt, ESP_MAC_WIFI_STA); + sprintf(macFormated, "%02X:%02X:%02X:%02X:%02X:%02X", macInt[0], macInt[1], macInt[2], macInt[3], macInt[4], macInt[5]); - return macFormated; + return macFormated; } - -void setSystemStatusFlag(SystemStatusFlag_t flag) { +void setSystemStatusFlag(SystemStatusFlag_t flag) +{ systemStatus = systemStatus | flag; // set bit char buf[20]; snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus()); - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf)); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf)); } - -void clearSystemStatusFlag(SystemStatusFlag_t flag) { +void clearSystemStatusFlag(SystemStatusFlag_t flag) +{ systemStatus = systemStatus | ~flag; // clear bit char buf[20]; snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus()); - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf)); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf)); } - -int getSystemStatus(void) { - return systemStatus; +int getSystemStatus(void) +{ + return systemStatus; } +bool isSetSystemStatusFlag(SystemStatusFlag_t flag) +{ + // ESP_LOGE(TAG, "Flag (0x%08X) is set (0x%08X): %d", flag, systemStatus , ((systemStatus & flag) == flag)); -bool isSetSystemStatusFlag(SystemStatusFlag_t flag) { - //ESP_LOGE(TAG, "Flag (0x%08X) is set (0x%08X): %d", flag, systemStatus , ((systemStatus & flag) == flag)); - - if ((systemStatus & flag) == flag) { + if ((systemStatus & flag) == flag) + { return true; } - else { + else + { return false; } } - -time_t getUpTime(void) { - return (uint32_t)(esp_timer_get_time()/1000/1000); // in seconds +time_t getUpTime(void) +{ + return (uint32_t)(esp_timer_get_time() / 1000 / 1000); // in seconds } - -string getResetReason(void) { +string getResetReason(void) +{ std::string reasonText; - switch(esp_reset_reason()) { - case ESP_RST_POWERON: reasonText = "Power-on event (or reset button)"; break; //!< Reset due to power-on event - case ESP_RST_EXT: reasonText = "External pin"; break; //!< Reset by external pin (not applicable for ESP32) - case ESP_RST_SW: reasonText = "Via esp_restart"; break; //!< Software reset via esp_restart - case ESP_RST_PANIC: reasonText = "Exception/panic"; break; //!< Software reset due to exception/panic - case ESP_RST_INT_WDT: reasonText = "Interrupt watchdog"; break; //!< Reset (software or hardware) due to interrupt watchdog - case ESP_RST_TASK_WDT: reasonText = "Task watchdog"; break; //!< Reset due to task watchdog - case ESP_RST_WDT: reasonText = "Other watchdogs"; break; //!< Reset due to other watchdogs - case ESP_RST_DEEPSLEEP: reasonText = "Exiting deep sleep mode"; break; //!< Reset after exiting deep sleep mode - case ESP_RST_BROWNOUT: reasonText = "Brownout"; break; //!< Brownout reset (software or hardware) - case ESP_RST_SDIO: reasonText = "SDIO"; break; //!< Reset over SDIO - - case ESP_RST_UNKNOWN: //!< Reset reason can not be determined - default: - reasonText = "Unknown"; + switch (esp_reset_reason()) + { + case ESP_RST_POWERON: + reasonText = "Power-on event (or reset button)"; + break; //!< Reset due to power-on event + case ESP_RST_EXT: + reasonText = "External pin"; + break; //!< Reset by external pin (not applicable for ESP32) + case ESP_RST_SW: + reasonText = "Via esp_restart"; + break; //!< Software reset via esp_restart + case ESP_RST_PANIC: + reasonText = "Exception/panic"; + break; //!< Software reset due to exception/panic + case ESP_RST_INT_WDT: + reasonText = "Interrupt watchdog"; + break; //!< Reset (software or hardware) due to interrupt watchdog + case ESP_RST_TASK_WDT: + reasonText = "Task watchdog"; + break; //!< Reset due to task watchdog + case ESP_RST_WDT: + reasonText = "Other watchdogs"; + break; //!< Reset due to other watchdogs + case ESP_RST_DEEPSLEEP: + reasonText = "Exiting deep sleep mode"; + break; //!< Reset after exiting deep sleep mode + case ESP_RST_BROWNOUT: + reasonText = "Brownout"; + break; //!< Brownout reset (software or hardware) + case ESP_RST_SDIO: + reasonText = "SDIO"; + break; //!< Reset over SDIO + + case ESP_RST_UNKNOWN: //!< Reset reason can not be determined + default: + reasonText = "Unknown"; } - return reasonText; -} + return reasonText; +} /** * Returns the current uptime formated ad xxf xxh xxm [xxs] */ -std::string getFormatedUptime(bool compact) { +std::string getFormatedUptime(bool compact) +{ char buf[20]; - #pragma GCC diagnostic ignored "-Wformat-truncation" +#pragma GCC diagnostic ignored "-Wformat-truncation" - int uptime = getUpTime(); // in seconds + int uptime = getUpTime(); // in seconds - int days = int(floor(uptime / (3600*24))); - int hours = int(floor((uptime - days * 3600*24) / (3600))); - int minutes = int(floor((uptime - days * 3600*24 - hours * 3600) / (60))); - int seconds = uptime - days * 3600*24 - hours * 3600 - minutes * 60; - - if (compact) { + int days = int(floor(uptime / (3600 * 24))); + int hours = int(floor((uptime - days * 3600 * 24) / (3600))); + int minutes = int(floor((uptime - days * 3600 * 24 - hours * 3600) / (60))); + int seconds = uptime - days * 3600 * 24 - hours * 3600 - minutes * 60; + + if (compact) + { snprintf(buf, sizeof(buf), "%dd%02dh%02dm%02ds", days, hours, minutes, seconds); } - else { + else + { snprintf(buf, sizeof(buf), "%3dd %02dh %02dm %02ds", days, hours, minutes, seconds); } return std::string(buf); } +const char *get404(void) +{ + return "
\n\n\n\n"
+		   "        _\n"
+		   "    .__(.)< ( oh oh! This page does not exist! )\n"
+		   "    \\___)\n"
+		   "\n\n"
+		   "                You could try your luck here!
\n" + ""; // Make sure we load the overview page +} + +std::string UrlDecode(const std::string &value) +{ + std::string result; + result.reserve(value.size()); -const char* get404(void) { - return -"
\n\n\n\n"
-"        _\n"
-"    .__(.)< ( oh oh! This page does not exist! )\n"
-"    \\___)\n"
-"\n\n"
-"                You could try your luck here!
\n" -""; // Make sure we load the overview page + for (std::size_t i = 0; i < value.size(); ++i) + { + auto ch = value[i]; + + if (ch == '%' && (i + 2) < value.size()) + { + auto hex = value.substr(i + 1, 2); + auto dec = static_cast(std::strtol(hex.c_str(), nullptr, 16)); + result.push_back(dec); + i += 2; + } + else if (ch == '+') + { + result.push_back(' '); + } + else + { + result.push_back(ch); + } + } + + return result; } +bool replaceString(std::string &s, std::string const &toReplace, std::string const &replaceWith) +{ + return replaceString(s, toReplace, replaceWith, true); +} -std::string UrlDecode(const std::string& value) +bool replaceString(std::string &s, std::string const &toReplace, std::string const &replaceWith, bool logIt) { - std::string result; - result.reserve(value.size()); - - for (std::size_t i = 0; i < value.size(); ++i) - { - auto ch = value[i]; - - if (ch == '%' && (i + 2) < value.size()) - { - auto hex = value.substr(i + 1, 2); - auto dec = static_cast(std::strtol(hex.c_str(), nullptr, 16)); - result.push_back(dec); - i += 2; - } - else if (ch == '+') - { - result.push_back(' '); - } - else - { - result.push_back(ch); - } - } - - return result; + std::size_t pos = s.find(toReplace); + + if (pos == std::string::npos) + { + // Not found + return false; + } + + std::string old = s; + s.replace(pos, toReplace.length(), replaceWith); + + if (logIt) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Migrated Configfile line '" + old + "' to '" + s + "'"); + } + + return true; } +bool isInString(std::string &s, std::string const &toFind) +{ + std::size_t pos = s.find(toFind); + + if (pos == std::string::npos) + { + // Not found + return false; + } -bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith) { - return replaceString(s, toReplace, replaceWith, true); + return true; } +// from https://stackoverflow.com/a/14678800 +void replaceAll(std::string& s, const std::string& toReplace, const std::string& replaceWith) +{ + size_t pos = 0; + + while ((pos = s.find(toReplace, pos)) != std::string::npos) + { + s.replace(pos, toReplace.length(), replaceWith); + pos += replaceWith.length(); + } +} -bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt) { - std::size_t pos = s.find(toReplace); +bool isStringNumeric(std::string &input) +{ + if (input.size() <= 0) + { + return false; + } + + // Replace comma with a dot + replaceString(input, ",", ".", false); + + int start = 0; + int punkt_existiert_schon = 0; - if (pos == std::string::npos) { // Not found - return false; - } + if (input[0] == '-') + { + start = 1; + } - std::string old = s; - s.replace(pos, toReplace.length(), replaceWith); - if (logIt) { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Migrated Configfile line '" + old + "' to '" + s + "'"); - } - return true; + for (int i = start; i < input.size(); i++) + { + if ((input[i] == '.') && (i > 0) && (punkt_existiert_schon == 0)) + { + punkt_existiert_schon = 1; + i++; + } + else if (!isdigit(input[i])) + { + return false; + } + } + + return true; +} + +bool isStringAlphabetic(std::string &input) +{ + for (int i = 0; i < input.size(); i++) + { + if (!isalpha(input[i])) + { + return false; + } + } + + return true; +} + +bool isStringAlphanumeric(std::string &input) +{ + for (int i = 0; i < input.size(); i++) + { + if (!isalnum(input[i])) + { + return false; + } + } + + return true; } +bool alphanumericToBoolean(std::string &input) +{ + if (isStringAlphabetic(input)) + { + return stringToBoolean(toUpper(input)); + } + else if (isStringNumeric(input)) + { + return numericStrToBool(input); + } -bool isInString(std::string& s, std::string const& toFind) { - std::size_t pos = s.find(toFind); + return false; +} - if (pos == std::string::npos) { // Not found - return false; - } - return true; +int clipInt(int input, int high, int low) +{ + if (input < low) + { + input = low; + } + else if (input > high) + { + input = high; + } + return input; +} + +bool numericStrToBool(std::string input) +{ + return (std::stoi(input) != 0); +} + +bool stringToBoolean(std::string input) +{ + return (input == "TRUE"); } diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index 9cfdf702e..6403fea80 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -21,7 +21,6 @@ bool RenameFile(string from, string to); bool MakeDir(std::string _what); bool FileExists(string filename); - string RundeOutput(double _in, int _anzNachkomma); size_t findDelimiterPos(string input, string delimiter); @@ -33,7 +32,6 @@ string getFileType(string filename); string getFileFullFileName(string filename); string getDirectory(string filename); - int mkdir_r(const char *dir, const mode_t mode); int removeFolder(const char* folderPath, const char* logTag); @@ -68,7 +66,6 @@ string getSDCardSectorSize(); string getMac(void); - /* Error bit fields One bit per error Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */ @@ -98,8 +95,18 @@ const char* get404(void); std::string UrlDecode(const std::string& value); +void replaceAll(std::string& s, const std::string& toReplace, const std::string& replaceWith); bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith); bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt); bool isInString(std::string& s, std::string const& toFind); +bool isStringNumeric(std::string &input); +bool isStringAlphabetic(std::string &input); +bool isStringAlphanumeric(std::string &input); +bool alphanumericToBoolean(std::string &input); + +int clipInt(int input, int high, int low); +bool numericStrToBool(std::string input); +bool stringToBoolean(std::string input); + #endif //HELPER_H diff --git a/code/components/jomjol_helper/psram.cpp b/code/components/jomjol_helper/psram.cpp index ce6c1c032..d2caf8565 100644 --- a/code/components/jomjol_helper/psram.cpp +++ b/code/components/jomjol_helper/psram.cpp @@ -120,15 +120,15 @@ void psram_free_shared_temp_image_memory(void) { /******************************************************************* - * Memory used in Digitalization Steps + * Memory used in Digitization Steps * During this step we only use the shared part of the PSRAM for the * Tensor Arena and one of the Models. * The shared memory is large enough for the largest model and the * Tensor Arena. Therefore we do not need to monitor the usage. *******************************************************************/ void *psram_get_shared_tensor_arena_memory(void) { - if ((sharedMemoryInUseFor == "") || (sharedMemoryInUseFor == "Digitalization_Model")) { - sharedMemoryInUseFor = "Digitalization_Tensor"; + if ((sharedMemoryInUseFor == "") || (sharedMemoryInUseFor == "Digitization_Model")) { + sharedMemoryInUseFor = "Digitization_Tensor"; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Allocating Tensor Arena (" + std::to_string(TENSOR_ARENA_SIZE) + " bytes, use shared memory in PSRAM)..."); return shared_region; // Use 1th part of the shared memory for Tensor } @@ -140,8 +140,8 @@ void *psram_get_shared_tensor_arena_memory(void) { void *psram_get_shared_model_memory(void) { - if ((sharedMemoryInUseFor == "") || (sharedMemoryInUseFor == "Digitalization_Tensor")) { - sharedMemoryInUseFor = "Digitalization_Model"; + if ((sharedMemoryInUseFor == "") || (sharedMemoryInUseFor == "Digitization_Tensor")) { + sharedMemoryInUseFor = "Digitization_Model"; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Allocating Model memory (" + std::to_string(MAX_MODEL_SIZE) + " bytes, use shared memory in PSRAM)..."); return (uint8_t *)shared_region + TENSOR_ARENA_SIZE; // Use 2nd part of the shared memory (after Tensor Arena) for the model } diff --git a/code/components/jomjol_helper/psram.h b/code/components/jomjol_helper/psram.h index 880e883ac..71a5436f2 100644 --- a/code/components/jomjol_helper/psram.h +++ b/code/components/jomjol_helper/psram.h @@ -20,7 +20,7 @@ void psram_free_shared_stbi_memory(void *p); void *psram_reserve_shared_tmp_image_memory(void); void psram_free_shared_temp_image_memory(void); -/* Memory used in Digitalization Steps */ +/* Memory used in Digitization Steps */ void *psram_get_shared_tensor_arena_memory(void); void *psram_get_shared_model_memory(void); void psram_free_shared_tensor_arena_and_model_memory(void); diff --git a/code/components/jomjol_helper/sdcard_init.c b/code/components/jomjol_helper/sdcard_init.c index 02bac5cb5..1c306ac94 100644 --- a/code/components/jomjol_helper/sdcard_init.c +++ b/code/components/jomjol_helper/sdcard_init.c @@ -35,15 +35,15 @@ static const char* TAG = "sdcard_init"; } \ } while(0) -typedef struct vfs_fat_sd_ctx_t { +typedef struct mh_vfs_fat_sd_ctx_t { BYTE pdrv; //Drive number that is mounted esp_vfs_fat_mount_config_t mount_config; //Mount configuration FATFS *fs; //FAT structure pointer that is registered sdmmc_card_t *card; //Card info char *base_path; //Path where partition is registered -} vfs_fat_sd_ctx_t; +} mh_vfs_fat_sd_ctx_t; -static vfs_fat_sd_ctx_t *s_ctx[FF_VOLUMES] = {}; +static mh_vfs_fat_sd_ctx_t *s_ctx[FF_VOLUMES] = {}; /** * This `s_saved_ctx_id` is only used by `esp_vfs_fat_sdmmc_unmount`, which is deprecated. @@ -185,14 +185,9 @@ BYTE ff_diskio_get_pdrv_card_mh(const sdmmc_card_t* card) return 0xff; } - - - - - static bool s_get_context_id_by_card_mh(const sdmmc_card_t *card, uint32_t *out_id) { - vfs_fat_sd_ctx_t *p_ctx = NULL; + mh_vfs_fat_sd_ctx_t *p_ctx = NULL; for (int i = 0; i < FF_VOLUMES; i++) { p_ctx = s_ctx[i]; if (p_ctx) { @@ -378,7 +373,7 @@ static esp_err_t init_sdmmc_host_mh(int slot, const void *slot_config, int *out_ esp_err_t esp_vfs_fat_sdmmc_mount_mh(const char* base_path, const sdmmc_host_t* host_config, const void* slot_config, const esp_vfs_fat_mount_config_t* mount_config, sdmmc_card_t** out_card) { esp_err_t err; - vfs_fat_sd_ctx_t *ctx = NULL; + mh_vfs_fat_sd_ctx_t *ctx = NULL; uint32_t ctx_id = FF_VOLUMES; FATFS *fs = NULL; int card_handle = -1; //uninitialized @@ -419,7 +414,7 @@ esp_err_t esp_vfs_fat_sdmmc_mount_mh(const char* base_path, const sdmmc_host_t* s_saved_ctx_id = 0; } - ctx = calloc(sizeof(vfs_fat_sd_ctx_t), 1); + ctx = calloc(sizeof(mh_vfs_fat_sd_ctx_t), 1); if (!ctx) { CHECK_EXECUTE_RESULT(ESP_ERR_NO_MEM, "no mem"); @@ -462,7 +457,7 @@ esp_err_t esp_vfs_fat_sdspi_mount_mh(const char* base_path, const sdmmc_host_t* { const sdmmc_host_t* host_config = host_config_input; esp_err_t err; - vfs_fat_sd_ctx_t *ctx = NULL; + mh_vfs_fat_sd_ctx_t *ctx = NULL; uint32_t ctx_id = FF_VOLUMES; FATFS *fs = NULL; int card_handle = -1; //uninitialized @@ -514,7 +509,7 @@ esp_err_t esp_vfs_fat_sdspi_mount_mh(const char* base_path, const sdmmc_host_t* s_saved_ctx_id = 0; } - ctx = calloc(sizeof(vfs_fat_sd_ctx_t), 1); + ctx = calloc(sizeof(mh_vfs_fat_sd_ctx_t), 1); if (!ctx) { CHECK_EXECUTE_RESULT(ESP_ERR_NO_MEM, "no mem"); diff --git a/code/components/jomjol_image_proc/CRotateImage.cpp b/code/components/jomjol_image_proc/CRotateImage.cpp index 12d441540..bd1c91e77 100644 --- a/code/components/jomjol_image_proc/CRotateImage.cpp +++ b/code/components/jomjol_image_proc/CRotateImage.cpp @@ -1,353 +1,309 @@ -#include -#include "CRotateImage.h" -#include "psram.h" - -static const char *TAG = "C ROTATE IMG"; - -CRotateImage::CRotateImage(std::string _name, CImageBasis *_org, CImageBasis *_temp, bool _flip) : CImageBasis(_name) -{ - rgb_image = _org->rgb_image; - channels = _org->channels; - width = _org->width; - height = _org->height; - bpp = _org->bpp; - externalImage = true; - ImageTMP = _temp; - ImageOrg = _org; - islocked = false; - doflip = _flip; -} - - -void CRotateImage::Mirror(){ - int memsize = width * height * channels; - uint8_t* odata; - if (ImageTMP) - { - odata = ImageTMP->RGBImageLock(); - } - else - { - odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); - } - - - int x_source, y_source; - stbi_uc* p_target; - stbi_uc* p_source; - - RGBImageLock(); - - for (int x = 0; x < width; ++x) - for (int y = 0; y < height; ++y) - { - p_target = odata + (channels * (y * width + x)); - - x_source = width - x; - y_source = y; - - p_source = rgb_image + (channels * (y_source * width + x_source)); - for (int _channels = 0; _channels < channels; ++_channels) - p_target[_channels] = p_source[_channels]; - } - - // memcpy(rgb_image, odata, memsize); - memCopy(odata, rgb_image, memsize); - if (!ImageTMP) - free_psram_heap(std::string(TAG) + "->odata", odata); - - if (ImageTMP) - ImageTMP->RGBImageRelease(); - - RGBImageRelease(); -} - -void CRotateImage::Rotate(float _angle, int _centerx, int _centery) -{ - int org_width, org_height; - float m[2][3]; - - float x_center = _centerx; - float y_center = _centery; - _angle = _angle / 180 * M_PI; - - if (doflip) - { - org_width = width; - org_height = height; - height = org_width; - width = org_height; - x_center = x_center - (org_width/2) + (org_height/2); - y_center = y_center + (org_width/2) - (org_height/2); - if (ImageOrg) - { - ImageOrg->height = height; - ImageOrg->width = width; - } - } - else - { - org_width = width; - org_height = height; - } - - m[0][0] = cos(_angle); - m[0][1] = sin(_angle); - m[0][2] = (1 - m[0][0]) * x_center - m[0][1] * y_center; - - m[1][0] = -m[0][1]; - m[1][1] = m[0][0]; - m[1][2] = m[0][1] * x_center + (1 - m[0][0]) * y_center; - - if (doflip) - { - m[0][2] = m[0][2] + (org_width/2) - (org_height/2); - m[1][2] = m[1][2] - (org_width/2) + (org_height/2); - } - - int memsize = width * height * channels; - uint8_t* odata; - if (ImageTMP) - { - odata = ImageTMP->RGBImageLock(); - } - else - { - odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); - } - - - int x_source, y_source; - stbi_uc* p_target; - stbi_uc* p_source; - - RGBImageLock(); - - for (int x = 0; x < width; ++x) - for (int y = 0; y < height; ++y) - { - p_target = odata + (channels * (y * width + x)); - - x_source = int(m[0][0] * x + m[0][1] * y); - y_source = int(m[1][0] * x + m[1][1] * y); - - x_source += int(m[0][2]); - y_source += int(m[1][2]); - - if ((x_source >= 0) && (x_source < org_width) && (y_source >= 0) && (y_source < org_height)) - { - p_source = rgb_image + (channels * (y_source * org_width + x_source)); - for (int _channels = 0; _channels < channels; ++_channels) - p_target[_channels] = p_source[_channels]; - } - else - { - for (int _channels = 0; _channels < channels; ++_channels) - p_target[_channels] = 255; - } - } - - // memcpy(rgb_image, odata, memsize); - memCopy(odata, rgb_image, memsize); - - if (!ImageTMP) - { - free_psram_heap(std::string(TAG) + "->odata", odata); - } - if (ImageTMP) - ImageTMP->RGBImageRelease(); - - RGBImageRelease(); -} - - - -void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery) -{ - int org_width, org_height; - float m[2][3]; - - float x_center = _centerx; - float y_center = _centery; - _angle = _angle / 180 * M_PI; - - if (doflip) - { - org_width = width; - org_height = height; - height = org_width; - width = org_height; - x_center = x_center - (org_width/2) + (org_height/2); - y_center = y_center + (org_width/2) - (org_height/2); - if (ImageOrg) - { - ImageOrg->height = height; - ImageOrg->width = width; - } - } - else - { - org_width = width; - org_height = height; - } - - m[0][0] = cos(_angle); - m[0][1] = sin(_angle); - m[0][2] = (1 - m[0][0]) * x_center - m[0][1] * y_center; - - m[1][0] = -m[0][1]; - m[1][1] = m[0][0]; - m[1][2] = m[0][1] * x_center + (1 - m[0][0]) * y_center; - - if (doflip) - { - m[0][2] = m[0][2] + (org_width/2) - (org_height/2); - m[1][2] = m[1][2] - (org_width/2) + (org_height/2); - } - - int memsize = width * height * channels; - uint8_t* odata; - if (ImageTMP) - { - odata = ImageTMP->RGBImageLock(); - } - else - { - odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); - } - - - int x_source_1, y_source_1, x_source_2, y_source_2; - float x_source, y_source; - float quad_ul, quad_ur, quad_ol, quad_or; - stbi_uc* p_target; - stbi_uc *p_source_ul, *p_source_ur, *p_source_ol, *p_source_or; - - RGBImageLock(); - - for (int x = 0; x < width; ++x) - for (int y = 0; y < height; ++y) - { - p_target = odata + (channels * (y * width + x)); - - x_source = (m[0][0] * x + m[0][1] * y); - y_source = (m[1][0] * x + m[1][1] * y); - - x_source += (m[0][2]); - y_source += (m[1][2]); - - x_source_1 = (int)x_source; - x_source_2 = x_source_1 + 1; - y_source_1 = (int)y_source; - y_source_2 = y_source_1 + 1; - - quad_ul = (x_source_2 - x_source) * (y_source_2 - y_source); - quad_ur = (1- (x_source_2 - x_source)) * (y_source_2 - y_source); - quad_or = (x_source_2 - x_source) * (1-(y_source_2 - y_source)); - quad_ol = (1- (x_source_2 - x_source)) * (1-(y_source_2 - y_source)); - - - if ((x_source_1 >= 0) && (x_source_2 < org_width) && (y_source_1 >= 0) && (y_source_2 < org_height)) - { - p_source_ul = rgb_image + (channels * (y_source_1 * org_width + x_source_1)); - p_source_ur = rgb_image + (channels * (y_source_1 * org_width + x_source_2)); - p_source_or = rgb_image + (channels * (y_source_2 * org_width + x_source_1)); - p_source_ol = rgb_image + (channels * (y_source_2 * org_width + x_source_2)); - for (int _channels = 0; _channels < channels; ++_channels) - { - p_target[_channels] = (int)((float)p_source_ul[_channels] * quad_ul - + (float)p_source_ur[_channels] * quad_ur - + (float)p_source_or[_channels] * quad_or - + (float)p_source_ol[_channels] * quad_ol); - } - } - else - { - for (int _channels = 0; _channels < channels; ++_channels) - p_target[_channels] = 255; - } - } - - // memcpy(rgb_image, odata, memsize); - memCopy(odata, rgb_image, memsize); - - if (!ImageTMP) - { - free_psram_heap(std::string(TAG) + "->odata", odata); - } - if (ImageTMP) - ImageTMP->RGBImageRelease(); - - RGBImageRelease(); -} - - -void CRotateImage::Rotate(float _angle) -{ -// ESP_LOGD(TAG, "width %d, height %d", width, height); - Rotate(_angle, width / 2, height / 2); -} - -void CRotateImage::RotateAntiAliasing(float _angle) -{ -// ESP_LOGD(TAG, "width %d, height %d", width, height); - RotateAntiAliasing(_angle, width / 2, height / 2); -} - -void CRotateImage::Translate(int _dx, int _dy) -{ - int memsize = width * height * channels; - uint8_t* odata; - if (ImageTMP) - { - odata = ImageTMP->RGBImageLock(); - } - else - { - odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); - } - - - - int x_source, y_source; - stbi_uc* p_target; - stbi_uc* p_source; - - RGBImageLock(); - - for (int x = 0; x < width; ++x) - for (int y = 0; y < height; ++y) - { - p_target = odata + (channels * (y * width + x)); - - x_source = x - _dx; - y_source = y - _dy; - - if ((x_source >= 0) && (x_source < width) && (y_source >= 0) && (y_source < height)) - { - p_source = rgb_image + (channels * (y_source * width + x_source)); - for (int _channels = 0; _channels < channels; ++_channels) - p_target[_channels] = p_source[_channels]; - } - else - { - for (int _channels = 0; _channels < channels; ++_channels) - p_target[_channels] = 255; - } - } - - // memcpy(rgb_image, odata, memsize); - memCopy(odata, rgb_image, memsize); - if (!ImageTMP) - { - free_psram_heap(std::string(TAG) + "->odata", odata); - } - - if (ImageTMP) - { - ImageTMP->RGBImageRelease(); - } - RGBImageRelease(); - -} - +#include +#include "CRotateImage.h" +#include "psram.h" + +static const char *TAG = "C ROTATE IMG"; + +CRotateImage::CRotateImage(std::string _name, CImageBasis *_org, CImageBasis *_temp, bool _flip) : CImageBasis(_name) +{ + rgb_image = _org->rgb_image; + channels = _org->channels; + width = _org->width; + height = _org->height; + bpp = _org->bpp; + externalImage = true; + ImageTMP = _temp; + ImageOrg = _org; + islocked = false; + doflip = _flip; +} + +void CRotateImage::Rotate(float _angle, int _centerx, int _centery) +{ + int org_width, org_height; + float m[2][3]; + + float x_center = _centerx; + float y_center = _centery; + _angle = _angle / 180 * M_PI; + + if (doflip) + { + org_width = width; + org_height = height; + height = org_width; + width = org_height; + x_center = x_center - (org_width/2) + (org_height/2); + y_center = y_center + (org_width/2) - (org_height/2); + if (ImageOrg) + { + ImageOrg->height = height; + ImageOrg->width = width; + } + } + else + { + org_width = width; + org_height = height; + } + + m[0][0] = cos(_angle); + m[0][1] = sin(_angle); + m[0][2] = (1 - m[0][0]) * x_center - m[0][1] * y_center; + + m[1][0] = -m[0][1]; + m[1][1] = m[0][0]; + m[1][2] = m[0][1] * x_center + (1 - m[0][0]) * y_center; + + if (doflip) + { + m[0][2] = m[0][2] + (org_width/2) - (org_height/2); + m[1][2] = m[1][2] - (org_width/2) + (org_height/2); + } + + int memsize = width * height * channels; + uint8_t* odata; + if (ImageTMP) + { + odata = ImageTMP->RGBImageLock(); + } + else + { + odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); + } + + + int x_source, y_source; + stbi_uc* p_target; + stbi_uc* p_source; + + RGBImageLock(); + + for (int x = 0; x < width; ++x) + for (int y = 0; y < height; ++y) + { + p_target = odata + (channels * (y * width + x)); + + x_source = int(m[0][0] * x + m[0][1] * y); + y_source = int(m[1][0] * x + m[1][1] * y); + + x_source += int(m[0][2]); + y_source += int(m[1][2]); + + if ((x_source >= 0) && (x_source < org_width) && (y_source >= 0) && (y_source < org_height)) + { + p_source = rgb_image + (channels * (y_source * org_width + x_source)); + for (int _channels = 0; _channels < channels; ++_channels) + p_target[_channels] = p_source[_channels]; + } + else + { + for (int _channels = 0; _channels < channels; ++_channels) + p_target[_channels] = 255; + } + } + + // memcpy(rgb_image, odata, memsize); + memCopy(odata, rgb_image, memsize); + + if (!ImageTMP) + { + free_psram_heap(std::string(TAG) + "->odata", odata); + } + if (ImageTMP) + ImageTMP->RGBImageRelease(); + + RGBImageRelease(); +} + + + +void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery) +{ + int org_width, org_height; + float m[2][3]; + + float x_center = _centerx; + float y_center = _centery; + _angle = _angle / 180 * M_PI; + + if (doflip) + { + org_width = width; + org_height = height; + height = org_width; + width = org_height; + x_center = x_center - (org_width/2) + (org_height/2); + y_center = y_center + (org_width/2) - (org_height/2); + if (ImageOrg) + { + ImageOrg->height = height; + ImageOrg->width = width; + } + } + else + { + org_width = width; + org_height = height; + } + + m[0][0] = cos(_angle); + m[0][1] = sin(_angle); + m[0][2] = (1 - m[0][0]) * x_center - m[0][1] * y_center; + + m[1][0] = -m[0][1]; + m[1][1] = m[0][0]; + m[1][2] = m[0][1] * x_center + (1 - m[0][0]) * y_center; + + if (doflip) + { + m[0][2] = m[0][2] + (org_width/2) - (org_height/2); + m[1][2] = m[1][2] - (org_width/2) + (org_height/2); + } + + int memsize = width * height * channels; + uint8_t* odata; + if (ImageTMP) + { + odata = ImageTMP->RGBImageLock(); + } + else + { + odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); + } + + + int x_source_1, y_source_1, x_source_2, y_source_2; + float x_source, y_source; + float quad_ul, quad_ur, quad_ol, quad_or; + stbi_uc* p_target; + stbi_uc *p_source_ul, *p_source_ur, *p_source_ol, *p_source_or; + + RGBImageLock(); + + for (int x = 0; x < width; ++x) + for (int y = 0; y < height; ++y) + { + p_target = odata + (channels * (y * width + x)); + + x_source = (m[0][0] * x + m[0][1] * y); + y_source = (m[1][0] * x + m[1][1] * y); + + x_source += (m[0][2]); + y_source += (m[1][2]); + + x_source_1 = (int)x_source; + x_source_2 = x_source_1 + 1; + y_source_1 = (int)y_source; + y_source_2 = y_source_1 + 1; + + quad_ul = (x_source_2 - x_source) * (y_source_2 - y_source); + quad_ur = (1- (x_source_2 - x_source)) * (y_source_2 - y_source); + quad_or = (x_source_2 - x_source) * (1-(y_source_2 - y_source)); + quad_ol = (1- (x_source_2 - x_source)) * (1-(y_source_2 - y_source)); + + + if ((x_source_1 >= 0) && (x_source_2 < org_width) && (y_source_1 >= 0) && (y_source_2 < org_height)) + { + p_source_ul = rgb_image + (channels * (y_source_1 * org_width + x_source_1)); + p_source_ur = rgb_image + (channels * (y_source_1 * org_width + x_source_2)); + p_source_or = rgb_image + (channels * (y_source_2 * org_width + x_source_1)); + p_source_ol = rgb_image + (channels * (y_source_2 * org_width + x_source_2)); + for (int _channels = 0; _channels < channels; ++_channels) + { + p_target[_channels] = (int)((float)p_source_ul[_channels] * quad_ul + + (float)p_source_ur[_channels] * quad_ur + + (float)p_source_or[_channels] * quad_or + + (float)p_source_ol[_channels] * quad_ol); + } + } + else + { + for (int _channels = 0; _channels < channels; ++_channels) + p_target[_channels] = 255; + } + } + + // memcpy(rgb_image, odata, memsize); + memCopy(odata, rgb_image, memsize); + + if (!ImageTMP) + { + free_psram_heap(std::string(TAG) + "->odata", odata); + } + if (ImageTMP) + ImageTMP->RGBImageRelease(); + + RGBImageRelease(); +} + + +void CRotateImage::Rotate(float _angle) +{ +// ESP_LOGD(TAG, "width %d, height %d", width, height); + Rotate(_angle, width / 2, height / 2); +} + +void CRotateImage::RotateAntiAliasing(float _angle) +{ +// ESP_LOGD(TAG, "width %d, height %d", width, height); + RotateAntiAliasing(_angle, width / 2, height / 2); +} + +void CRotateImage::Translate(int _dx, int _dy) +{ + int memsize = width * height * channels; + uint8_t* odata; + if (ImageTMP) + { + odata = ImageTMP->RGBImageLock(); + } + else + { + odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM); + } + + + + int x_source, y_source; + stbi_uc* p_target; + stbi_uc* p_source; + + RGBImageLock(); + + for (int x = 0; x < width; ++x) + for (int y = 0; y < height; ++y) + { + p_target = odata + (channels * (y * width + x)); + + x_source = x - _dx; + y_source = y - _dy; + + if ((x_source >= 0) && (x_source < width) && (y_source >= 0) && (y_source < height)) + { + p_source = rgb_image + (channels * (y_source * width + x_source)); + for (int _channels = 0; _channels < channels; ++_channels) + p_target[_channels] = p_source[_channels]; + } + else + { + for (int _channels = 0; _channels < channels; ++_channels) + p_target[_channels] = 255; + } + } + + // memcpy(rgb_image, odata, memsize); + memCopy(odata, rgb_image, memsize); + if (!ImageTMP) + { + free_psram_heap(std::string(TAG) + "->odata", odata); + } + + if (ImageTMP) + { + ImageTMP->RGBImageRelease(); + } + RGBImageRelease(); + +} + diff --git a/code/components/jomjol_image_proc/CRotateImage.h b/code/components/jomjol_image_proc/CRotateImage.h index 30c758d3d..6b7b542ed 100644 --- a/code/components/jomjol_image_proc/CRotateImage.h +++ b/code/components/jomjol_image_proc/CRotateImage.h @@ -1,29 +1,28 @@ -#pragma once - -#ifndef CROTATEIMAGE_H -#define CROTATEIMAGE_H - -#include "CImageBasis.h" - - -class CRotateImage: public CImageBasis -{ - - public: - CImageBasis *ImageTMP, *ImageOrg; - bool doflip; - CRotateImage(std::string name, std::string _image, bool _flip = false) : CImageBasis(name, _image) {ImageTMP = NULL; ImageOrg = NULL; doflip = _flip;}; - CRotateImage(std::string name, uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp, bool _flip = false) : CImageBasis(name, _rgb_image, _channels, _width, _height, _bpp) {ImageTMP = NULL; ImageOrg = NULL; doflip = _flip;}; - CRotateImage(std::string name, CImageBasis *_org, CImageBasis *_temp, bool _flip = false); - - void Rotate(float _angle); - void RotateAntiAliasing(float _angle); - - void Rotate(float _angle, int _centerx, int _centery); - void RotateAntiAliasing(float _angle, int _centerx, int _centery); - - void Translate(int _dx, int _dy); - void Mirror(); -}; - +#pragma once + +#ifndef CROTATEIMAGE_H +#define CROTATEIMAGE_H + +#include "CImageBasis.h" + + +class CRotateImage: public CImageBasis +{ + + public: + CImageBasis *ImageTMP, *ImageOrg; + bool doflip; + CRotateImage(std::string name, std::string _image, bool _flip = false) : CImageBasis(name, _image) {ImageTMP = NULL; ImageOrg = NULL; doflip = _flip;}; + CRotateImage(std::string name, uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp, bool _flip = false) : CImageBasis(name, _rgb_image, _channels, _width, _height, _bpp) {ImageTMP = NULL; ImageOrg = NULL; doflip = _flip;}; + CRotateImage(std::string name, CImageBasis *_org, CImageBasis *_temp, bool _flip = false); + + void Rotate(float _angle); + void RotateAntiAliasing(float _angle); + + void Rotate(float _angle, int _centerx, int _centery); + void RotateAntiAliasing(float _angle, int _centerx, int _centery); + + void Translate(int _dx, int _dy); +}; + #endif //CROTATEIMAGE_H \ No newline at end of file diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index b4ec02c9b..3420e6a9a 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -32,7 +32,7 @@ void ClassLogFile::WriteHeapInfo(std::string _id) } -void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digital, std::string _analog) +void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digit, std::string _analog) { ESP_LOGD(TAG, "Start WriteToData"); time_t rawtime; @@ -67,7 +67,7 @@ void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::s fputs(_ReturnChangeAbsolute.c_str(), pFile); fputs(",", pFile); fputs(_ErrorMessageText.c_str(), pFile); - fputs(_digital.c_str(), pFile); + fputs(_digit.c_str(), pFile); fputs(_analog.c_str(), pFile); fputs("\n", pFile); diff --git a/code/components/jomjol_logfile/ClassLogFile.h b/code/components/jomjol_logfile/ClassLogFile.h index b3ade1cd7..7ce4058e1 100644 --- a/code/components/jomjol_logfile/ClassLogFile.h +++ b/code/components/jomjol_logfile/ClassLogFile.h @@ -39,8 +39,8 @@ class ClassLogFile void RemoveOldLogFile(); void RemoveOldDataLog(); -// void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog); - void WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digital, std::string _analog); +// void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digit, std::string _analog); + void WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digit, std::string _analog); std::string GetCurrentFileName(); diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index c95affd24..adc68e211 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -49,6 +49,15 @@ void mqttServer_setMeterType(std::string _meterType, std::string _valueUnit, std rateUnit = _rateUnit; } +/** + * Takes any multi-level MQTT-topic and returns the last topic level as nodeId + * see https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/ for details about MQTT topics +*/ +std::string createNodeId(std::string &topic) { + auto splitPos = topic.find_last_of('/'); + return (splitPos == std::string::npos) ? topic : topic.substr(splitPos + 1); +} + bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, std::string name, std::string icon, std::string unit, std::string deviceClass, std::string stateClass, std::string entityCategory, int qos) { @@ -69,11 +78,18 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, name = group + " " + name; } + /** + * homeassistant needs the MQTT discovery topic according to the following structure: + * //[/]/config + * if the main topic is embedded in a nested structure, we just use the last part as node_id + * This means a maintopic "home/test/watermeter" is transformed to the discovery topic "homeassistant/sensor/watermeter/..." + */ + std::string node_id = createNodeId(maintopic); if (field == "problem") { // Special binary sensor which is based on error topic - topicFull = "homeassistant/binary_sensor/" + maintopic + "/" + configTopic + "/config"; + topicFull = "homeassistant/binary_sensor/" + node_id + "/" + configTopic + "/config"; } else { - topicFull = "homeassistant/sensor/" + maintopic + "/" + configTopic + "/config"; + topicFull = "homeassistant/sensor/" + node_id + "/" + configTopic + "/config"; } /* See https://www.home-assistant.io/docs/mqtt/discovery/ */ @@ -172,10 +188,10 @@ bool MQTThomeassistantDiscovery(int qos) { allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "value", "Value", "gauge", valueUnit, meterType, "total_increasing", "", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "raw", "Raw Value", "raw", "", "", "", "diagnostic", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "error", "Error", "alert-circle-outline", "", "", "", "diagnostic", qos); - /* Not announcing "rate" as it is better to use rate_per_time_unit resp. rate_per_digitalization_round */ + /* Not announcing "rate" as it is better to use rate_per_time_unit resp. rate_per_Digitization_round */ // allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate", "Rate (Unit/Minute)", "swap-vertical", "", "", "", ""); // Legacy, always Unit per Minute allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate_per_time_unit", "Rate (" + rateUnit + ")", "swap-vertical", rateUnit, "", "measurement", "", qos); - allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate_per_digitalization_round", "Change since last digitalization round", "arrow-expand-vertical", valueUnit, "", "measurement", "", qos); // correctly the Unit is Unit/Interval! + allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate_per_Digitization_round", "Change since last Digitization round", "arrow-expand-vertical", valueUnit, "", "measurement", "", qos); // correctly the Unit is Unit/Interval! allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "timestamp", "Timestamp", "clock-time-eight-outline", "", "timestamp", "", "diagnostic", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "json", "JSON", "code-json", "", "", "", "diagnostic", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "problem", "Problem", "alert-outline", "", "problem", "", "", qos); // Special binary sensor which is based on error topic diff --git a/code/components/jomjol_mqtt/server_mqtt.h b/code/components/jomjol_mqtt/server_mqtt.h index 925358e35..41c359c98 100644 --- a/code/components/jomjol_mqtt/server_mqtt.h +++ b/code/components/jomjol_mqtt/server_mqtt.h @@ -22,6 +22,7 @@ std::string getTimeUnit(void); void GotConnected(std::string maintopic, bool SetRetainFlag); esp_err_t sendDiscovery_and_static_Topics(void); +std::string createNodeId(std::string &topic); #endif //SERVERMQTT_H #endif //ENABLE_MQTT \ No newline at end of file diff --git a/code/components/jomjol_tfliteclass/CTfLiteClass.cpp b/code/components/jomjol_tfliteclass/CTfLiteClass.cpp index 2f9ead86a..c6703ef59 100644 --- a/code/components/jomjol_tfliteclass/CTfLiteClass.cpp +++ b/code/components/jomjol_tfliteclass/CTfLiteClass.cpp @@ -206,6 +206,7 @@ bool CTfLiteClass::MakeAllocate() LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CTfLiteClass::MakeAllocate"); this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize); + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trying to load the model. If it crashes here, it ist most likely due to a corrupted model!"); if (this->interpreter) { diff --git a/code/components/jomjol_webhook/CMakeLists.txt b/code/components/jomjol_webhook/CMakeLists.txt new file mode 100644 index 000000000..10271c118 --- /dev/null +++ b/code/components/jomjol_webhook/CMakeLists.txt @@ -0,0 +1,7 @@ +FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) + +idf_component_register(SRCS ${app_sources} + INCLUDE_DIRS "." + REQUIRES esp_http_client jomjol_logfile jomjol_flowcontroll json) + + diff --git a/code/components/jomjol_webhook/interface_webhook.cpp b/code/components/jomjol_webhook/interface_webhook.cpp new file mode 100644 index 000000000..54d4c48ed --- /dev/null +++ b/code/components/jomjol_webhook/interface_webhook.cpp @@ -0,0 +1,170 @@ +#ifdef ENABLE_WEBHOOK +#include "interface_webhook.h" + +#include "esp_log.h" +#include +#include "ClassLogFile.h" +#include "esp_http_client.h" +#include "time_sntp.h" +#include "../../include/defines.h" +#include +#include + + +static const char *TAG = "WEBHOOK"; + +std::string _webhookURI; +std::string _webhookApiKey; +long _lastTimestamp; + +static esp_err_t http_event_handler(esp_http_client_event_t *evt); + +void WebhookInit(std::string _uri, std::string _apiKey) +{ + _webhookURI = _uri; + _webhookApiKey = _apiKey; + _lastTimestamp = 0L; +} + +bool WebhookPublish(std::vector* numbers) +{ + bool numbersWithError = false; + cJSON *jsonArray = cJSON_CreateArray(); + + for (int i = 0; i < (*numbers).size(); ++i) + { + string timezw = ""; + char buffer[80]; + time_t &lastPreValue = (*numbers)[i]->timeStampLastPreValue; + struct tm* timeinfo = localtime(&lastPreValue); + _lastTimestamp = static_cast(lastPreValue); + strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); + timezw = std::string(buffer); + + cJSON *json = cJSON_CreateObject(); + cJSON_AddStringToObject(json, "timestamp", timezw.c_str()); + cJSON_AddStringToObject(json, "timestampLong", std::to_string(_lastTimestamp).c_str()); + cJSON_AddStringToObject(json, "name", (*numbers)[i]->name.c_str()); + cJSON_AddStringToObject(json, "rawValue", (*numbers)[i]->ReturnRawValue.c_str()); + cJSON_AddStringToObject(json, "value", (*numbers)[i]->ReturnValue.c_str()); + cJSON_AddStringToObject(json, "preValue", (*numbers)[i]->ReturnPreValue.c_str()); + cJSON_AddStringToObject(json, "rate", (*numbers)[i]->ReturnRateValue.c_str()); + cJSON_AddStringToObject(json, "changeAbsolute", (*numbers)[i]->ReturnChangeAbsolute.c_str()); + cJSON_AddStringToObject(json, "error", (*numbers)[i]->ErrorMessageText.c_str()); + + cJSON_AddItemToArray(jsonArray, json); + + if ((*numbers)[i]->ErrorMessage) { + numbersWithError = true; + } + } + + char *jsonString = cJSON_PrintUnformatted(jsonArray); + + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "sending webhook"); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "sending JSON: " + std::string(jsonString)); + + char response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; + esp_http_client_config_t http_config = { + .url = _webhookURI.c_str(), + .user_agent = "ESP32 Meter reader", + .method = HTTP_METHOD_POST, + .event_handler = http_event_handler, + .buffer_size = MAX_HTTP_OUTPUT_BUFFER, + .user_data = response_buffer + }; + + esp_http_client_handle_t http_client = esp_http_client_init(&http_config); + + esp_http_client_set_header(http_client, "Content-Type", "application/json"); + esp_http_client_set_header(http_client, "APIKEY", _webhookApiKey.c_str()); + + ESP_ERROR_CHECK(esp_http_client_set_post_field(http_client, jsonString, strlen(jsonString))); + + esp_err_t err = ESP_ERROR_CHECK_WITHOUT_ABORT(esp_http_client_perform(http_client)); + + if(err == ESP_OK) { + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP request was performed"); + int status_code = esp_http_client_get_status_code(http_client); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP status code: " + std::to_string(status_code)); + } else { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "HTTP request failed"); + } + + esp_http_client_cleanup(http_client); + cJSON_Delete(jsonArray); + free(jsonString); + return numbersWithError; +} + +void WebhookUploadPic(ImageData *Img) { + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Starting WebhookUploadPic"); + + std::string fullURI = _webhookURI + "?timestamp=" + std::to_string(_lastTimestamp); + char response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; + esp_http_client_config_t http_config = { + .url = fullURI.c_str(), + .user_agent = "ESP32 Meter reader", + .method = HTTP_METHOD_PUT, + .event_handler = http_event_handler, + .buffer_size = MAX_HTTP_OUTPUT_BUFFER, + .user_data = response_buffer + }; + + esp_http_client_handle_t http_client = esp_http_client_init(&http_config); + + esp_http_client_set_header(http_client, "Content-Type", "image/jpeg"); + esp_http_client_set_header(http_client, "APIKEY", _webhookApiKey.c_str()); + + esp_err_t err = ESP_ERROR_CHECK_WITHOUT_ABORT(esp_http_client_set_post_field(http_client, (const char *)Img->data, Img->size)); + + err = ESP_ERROR_CHECK_WITHOUT_ABORT(esp_http_client_perform(http_client)); + + if (err == ESP_OK) { + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP PUT request was performed successfully"); + int status_code = esp_http_client_get_status_code(http_client); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP status code: " + std::to_string(status_code)); + } else { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "HTTP PUT request failed"); + } + + esp_http_client_cleanup(http_client); + + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "WebhookUploadPic finished"); +} + + +static esp_err_t http_event_handler(esp_http_client_event_t *evt) +{ + switch(evt->event_id) + { + case HTTP_EVENT_ERROR: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Client Error encountered"); + break; + case HTTP_EVENT_ON_CONNECTED: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Client connected"); + ESP_LOGI(TAG, "HTTP Client Connected"); + break; + case HTTP_EVENT_HEADERS_SENT: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Client sent all request headers"); + break; + case HTTP_EVENT_ON_HEADER: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Header: key=" + std::string(evt->header_key) + ", value=" + std::string(evt->header_value)); + break; + case HTTP_EVENT_ON_DATA: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Client data recevied: len=" + std::to_string(evt->data_len)); + break; + case HTTP_EVENT_ON_FINISH: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Client finished"); + break; + case HTTP_EVENT_DISCONNECTED: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Client Disconnected"); + break; + case HTTP_EVENT_REDIRECT: + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "HTTP Redirect"); + break; + } + return ESP_OK; +} + +#endif //ENABLE_WEBHOOK diff --git a/code/components/jomjol_webhook/interface_webhook.h b/code/components/jomjol_webhook/interface_webhook.h new file mode 100644 index 000000000..d7033be09 --- /dev/null +++ b/code/components/jomjol_webhook/interface_webhook.h @@ -0,0 +1,17 @@ +#ifdef ENABLE_WEBHOOK + +#pragma once +#ifndef INTERFACE_WEBHOOK_H +#define INTERFACE_WEBHOOK_H + +#include +#include +#include +#include + +void WebhookInit(std::string _webhookURI, std::string _apiKey); +bool WebhookPublish(std::vector* numbers); +void WebhookUploadPic(ImageData *Img); + +#endif //INTERFACE_WEBHOOK_H +#endif //ENABLE_WEBHOOK \ No newline at end of file diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index 603751265..03a4cd756 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -480,7 +480,8 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_ if (WIFIReconnectCnt >= 10) { WIFIReconnectCnt = 0; LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Disconnected, multiple reconnect attempts failed (" + - std::to_string(disconn->reason) + "), still retrying..."); + std::to_string(disconn->reason) + "), retrying after 5s"); + vTaskDelay(5000 / portTICK_PERIOD_MS); // Delay between the reconnections } } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) diff --git a/code/components/openmetrics/CMakeLists.txt b/code/components/openmetrics/CMakeLists.txt new file mode 100644 index 000000000..e25439394 --- /dev/null +++ b/code/components/openmetrics/CMakeLists.txt @@ -0,0 +1,7 @@ +FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) + +idf_component_register(SRCS ${app_sources} + INCLUDE_DIRS "." + REQUIRES jomjol_image_proc) + + diff --git a/code/components/openmetrics/openmetrics.cpp b/code/components/openmetrics/openmetrics.cpp new file mode 100644 index 000000000..c90100e87 --- /dev/null +++ b/code/components/openmetrics/openmetrics.cpp @@ -0,0 +1,43 @@ +#include "openmetrics.h" + +/** + * create a singe metric from the given input + **/ +std::string createMetric(const std::string &metricName, const std::string &help, const std::string &type, const std::string &value) +{ + return "# HELP " + metricName + " " + help + "\n" + + "# TYPE " + metricName + " " + type + "\n" + + metricName + " " + value + "\n"; +} + +/** + * Generate the MetricFamily from all available sequences + * @returns the string containing the text wire format of the MetricFamily + **/ +std::string createSequenceMetrics(std::string prefix, const std::vector &numbers) +{ + std::string res; + + for (const auto &number : numbers) + { + // only valid data is reported (https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#missing-data) + if (number->ReturnValue.length() > 0) + { + auto label = number->name; + + // except newline, double quote, and backslash (https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#abnf) + // to keep it simple, these characters are just removed from the label + replaceAll(label, "\\", ""); + replaceAll(label, "\"", ""); + replaceAll(label, "\n", ""); + res += prefix + "_flow_value{sequence=\"" + label + "\"} " + number->ReturnValue + "\n"; + } + } + + // prepend metadata if a valid metric was created + if (res.length() > 0) + { + res = "# HELP " + prefix + "_flow_value current value of meter readout\n# TYPE " + prefix + "_flow_value gauge\n" + res; + } + return res; +} diff --git a/code/components/openmetrics/openmetrics.h b/code/components/openmetrics/openmetrics.h new file mode 100644 index 000000000..b75e98cd4 --- /dev/null +++ b/code/components/openmetrics/openmetrics.h @@ -0,0 +1,15 @@ +#pragma once + +#ifndef OPENMETRICS_H +#define OPENMETRICS_H + +#include +#include +#include + +#include "ClassFlowDefineTypes.h" + +std::string createMetric(const std::string &metricName, const std::string &help, const std::string &type, const std::string &value); +std::string createSequenceMetrics(std::string prefix, const std::vector &numbers); + +#endif // OPENMETRICS_H diff --git a/code/dependencies.lock b/code/dependencies.lock index 6e49cb194..8ce5d9338 100644 --- a/code/dependencies.lock +++ b/code/dependencies.lock @@ -1,3 +1,16 @@ -manifest_hash: 63f5c6c9f0bcebc7b9ca12d2aa8b26b2c5f5218d377dc4b2375d9b9ca1df7815 +dependencies: + espressif/esp-nn: + component_hash: b32869798bdb40dec6bc99caca48cd65d42f8a9f506b9ab9c598a076f891ede9 + source: + pre_release: true + service_url: https://api.components.espressif.com/ + type: service + version: 1.0.2 + idf: + component_hash: null + source: + type: idf + version: 5.3.0 +manifest_hash: 6995555b9b41e897235448c868ca92c0c3401fd2ff90df084be9bb8629958f2c target: esp32 -version: 1.0.0 \ No newline at end of file +version: 1.0.0 diff --git a/code/include/defines.h b/code/include/defines.h index e7f9166da..e41178957 100644 --- a/code/include/defines.h +++ b/code/include/defines.h @@ -58,22 +58,11 @@ //#define CONFIG_IDF_TARGET_ARCH_XTENSA //not needed with platformio/espressif32 @ 5.2.0 - //Statusled + ClassControllCamera - #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED - - //ClassControllCamera - #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED - #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new #define CAM_LIVESTREAM_REFRESHRATE 500 // Camera livestream feature: Waiting time in milliseconds to refresh image // #define GRAYSCALE_AS_DEFAULT - //ClassControllCamera + ClassFlowTakeImage - #define CAMERA_MODEL_AI_THINKER - #define BOARD_ESP32CAM_AITHINKER - - //server_GPIO #define __LEDGLOBAL @@ -105,7 +94,7 @@ #define LOGFILE_LAST_PART_BYTES 80 * 1024 // 80 kBytes // Size of partial log file to return #define SERVER_FILER_SCRATCH_BUFSIZE 4096 - #define SERVER_HELPER_SCRATCH_BUFSIZE 8192 + #define SERVER_HELPER_SCRATCH_BUFSIZE 4096 #define SERVER_OTA_SCRATCH_BUFSIZE 1024 @@ -187,15 +176,13 @@ //ClassFlowCNNGeneral #define Analog_error 3 - #define AnalogToDigtalFehler 0.8 - #define Digital_Uncertainty 0.2 - #define DigitalBand 3 - #define Digital_Transition_Range_Predecessor 2 - #define Digital_Transition_Area_Predecessor 0.7 // 9.3 - 0.7 - #define Digital_Transition_Area_Forward 9.7 // Pre-run zero crossing only happens from approx. 9.7 onwards - - + #define AnalogToDigtalFehler 0.8 + #define Digit_Uncertainty 0.2 + #define DigitBand 3 + #define Digit_Transition_Range_Predecessor 2 + #define Digit_Transition_Area_Predecessor 0.7 // 9.3 - 0.7 + #define Digit_Transition_Area_Forward 9.7 // Pre-run zero crossing only happens from approx. 9.7 onwards //#define DEBUG_DETAIL_ON @@ -210,117 +197,124 @@ //// Conditionnal definitions //// ///////////////////////////////////////////// -//******* camera model -#if defined(CAMERA_MODEL_WROVER_KIT) - #define PWDN_GPIO_NUM -1 - #define RESET_GPIO_NUM -1 - #define XCLK_GPIO_NUM 21 - #define SIOD_GPIO_NUM 26 - #define SIOC_GPIO_NUM 27 - - #define Y9_GPIO_NUM 35 - #define Y8_GPIO_NUM 34 - #define Y7_GPIO_NUM 39 - #define Y6_GPIO_NUM 36 - #define Y5_GPIO_NUM 19 - #define Y4_GPIO_NUM 18 - #define Y3_GPIO_NUM 5 - #define Y2_GPIO_NUM 4 - #define VSYNC_GPIO_NUM 25 - #define HREF_GPIO_NUM 23 - #define PCLK_GPIO_NUM 22 - -#elif defined(CAMERA_MODEL_M5STACK_PSRAM) - #define PWDN_GPIO_NUM -1 - #define RESET_GPIO_NUM 15 - #define XCLK_GPIO_NUM 27 - #define SIOD_GPIO_NUM 25 - #define SIOC_GPIO_NUM 23 - - #define Y9_GPIO_NUM 19 - #define Y8_GPIO_NUM 36 - #define Y7_GPIO_NUM 18 - #define Y6_GPIO_NUM 39 - #define Y5_GPIO_NUM 5 - #define Y4_GPIO_NUM 34 - #define Y3_GPIO_NUM 35 - #define Y2_GPIO_NUM 32 - #define VSYNC_GPIO_NUM 22 - #define HREF_GPIO_NUM 26 - #define PCLK_GPIO_NUM 21 - -#elif defined(CAMERA_MODEL_AI_THINKER) - #define PWDN_GPIO_NUM GPIO_NUM_32 - #define RESET_GPIO_NUM -1 - #define XCLK_GPIO_NUM GPIO_NUM_0 - #define SIOD_GPIO_NUM GPIO_NUM_26 - #define SIOC_GPIO_NUM GPIO_NUM_27 - - #define Y9_GPIO_NUM GPIO_NUM_35 - #define Y8_GPIO_NUM GPIO_NUM_34 - #define Y7_GPIO_NUM GPIO_NUM_39 - #define Y6_GPIO_NUM GPIO_NUM_36 - #define Y5_GPIO_NUM GPIO_NUM_21 - #define Y4_GPIO_NUM GPIO_NUM_19 - #define Y3_GPIO_NUM GPIO_NUM_18 - #define Y2_GPIO_NUM GPIO_NUM_5 - #define VSYNC_GPIO_NUM GPIO_NUM_25 - #define HREF_GPIO_NUM GPIO_NUM_23 - #define PCLK_GPIO_NUM GPIO_NUM_22 - -#else - #error "Camera model not selected" -#endif //camera model // ******* Board type -#ifdef BOARD_WROVER_KIT // WROVER-KIT PIN Map - - #define CAM_PIN_PWDN -1 //power down is not used - #define CAM_PIN_RESET -1 //software reset will be performed - #define CAM_PIN_XCLK 21 - #define CAM_PIN_SIOD 26 - #define CAM_PIN_SIOC 27 - - #define CAM_PIN_D7 35 - #define CAM_PIN_D6 34 - #define CAM_PIN_D5 39 - #define CAM_PIN_D4 36 - #define CAM_PIN_D3 19 - #define CAM_PIN_D2 18 - #define CAM_PIN_D1 5 - #define CAM_PIN_D0 4 - #define CAM_PIN_VSYNC 25 - #define CAM_PIN_HREF 23 - #define CAM_PIN_PCLK 22 - -#endif //// WROVER-KIT PIN Map +#if defined(BOARD_WROVER_KIT) // WROVER-KIT PIN Map + // SD card (operated with SDMMC peripheral) + //------------------------------------------------- + #define GPIO_SDCARD_CLK GPIO_NUM_14 + #define GPIO_SDCARD_CMD GPIO_NUM_15 + #define GPIO_SDCARD_D0 GPIO_NUM_2 + #ifndef __SD_USE_ONE_LINE_MODE__ + #define GPIO_SDCARD_D1 GPIO_NUM_4 + #define GPIO_SDCARD_D2 GPIO_NUM_12 + #define GPIO_SDCARD_D3 GPIO_NUM_13 + #else + #define GPIO_SDCARD_D1 GPIO_NUM_NC + #define GPIO_SDCARD_D2 GPIO_NUM_NC + #define GPIO_SDCARD_D3 GPIO_NUM_13 + #endif + + #define CAM_PIN_PWDN GPIO_NUM_NC //power down is not used + #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed + #define CAM_PIN_XCLK GPIO_NUM_21 + #define CAM_PIN_SIOD GPIO_NUM_26 + #define CAM_PIN_SIOC GPIO_NUM_27 + + #define CAM_PIN_D7 GPIO_NUM_35 + #define CAM_PIN_D6 GPIO_NUM_34 + #define CAM_PIN_D5 GPIO_NUM_39 + #define CAM_PIN_D4 GPIO_NUM_36 + #define CAM_PIN_D3 GPIO_NUM_19 + #define CAM_PIN_D2 GPIO_NUM_18 + #define CAM_PIN_D1 GPIO_NUM_5 + #define CAM_PIN_D0 GPIO_NUM_4 + #define CAM_PIN_VSYNC GPIO_NUM_25 + #define CAM_PIN_HREF GPIO_NUM_23 + #define CAM_PIN_PCLK GPIO_NUM_22 + + //Statusled + ClassControllCamera + #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED, On the board the LED is on the IO2, but it is used for the SD + + //ClassControllCamera + #define FLASH_GPIO GPIO_NUM_12 // PIN for flashlight LED + #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new + +#elif defined(BOARD_M5STACK_PSRAM) // M5STACK PSRAM PIN Map + #define CAM_PIN_PWDN GPIO_NUM_NC + #define CAM_PIN_RESET GPIO_NUM_15 + #define CAM_PIN_XCLK GPIO_NUM_27 + #define CAM_PIN_SIOD GPIO_NUM_25 + #define CAM_PIN_SIOC GPIO_NUM_23 + + #define CAM_PIN_D7 GPIO_NUM_19 + #define CAM_PIN_D6 GPIO_NUM_36 + #define CAM_PIN_D5 GPIO_NUM_18 + #define CAM_PIN_D4 GPIO_NUM_39 + #define CAM_PIN_D3 GPIO_NUM_5 + #define CAM_PIN_D2 GPIO_NUM_34 + #define CAM_PIN_D1 GPIO_NUM_35 + #define CAM_PIN_D0 GPIO_NUM_32 + #define CAM_PIN_VSYNC GPIO_NUM_22 + #define CAM_PIN_HREF GPIO_NUM_26 + #define CAM_PIN_PCLK GPIO_NUM_21 + + //Statusled + ClassControllCamera + #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED + + //ClassControllCamera + #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED + #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new + + +#elif defined(BOARD_ESP32CAM_AITHINKER) // ESP32Cam (AiThinker) PIN Map + // SD card (operated with SDMMC peripheral) + //------------------------------------------------- + #define GPIO_SDCARD_CLK GPIO_NUM_14 + #define GPIO_SDCARD_CMD GPIO_NUM_15 + #define GPIO_SDCARD_D0 GPIO_NUM_2 + #ifndef __SD_USE_ONE_LINE_MODE__ + #define GPIO_SDCARD_D1 GPIO_NUM_4 + #define GPIO_SDCARD_D2 GPIO_NUM_12 + #define GPIO_SDCARD_D3 GPIO_NUM_13 + #else + #define GPIO_SDCARD_D1 GPIO_NUM_NC + #define GPIO_SDCARD_D2 GPIO_NUM_NC + #define GPIO_SDCARD_D3 GPIO_NUM_13 + #endif + + #define CAM_PIN_PWDN GPIO_NUM_32 + #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed + #define CAM_PIN_XCLK GPIO_NUM_0 + #define CAM_PIN_SIOD GPIO_NUM_26 + #define CAM_PIN_SIOC GPIO_NUM_27 + + #define CAM_PIN_D7 GPIO_NUM_35 + #define CAM_PIN_D6 GPIO_NUM_34 + #define CAM_PIN_D5 GPIO_NUM_39 + #define CAM_PIN_D4 GPIO_NUM_36 + #define CAM_PIN_D3 GPIO_NUM_21 + #define CAM_PIN_D2 GPIO_NUM_19 + #define CAM_PIN_D1 GPIO_NUM_18 + #define CAM_PIN_D0 GPIO_NUM_5 + #define CAM_PIN_VSYNC GPIO_NUM_25 + #define CAM_PIN_HREF GPIO_NUM_23 + #define CAM_PIN_PCLK GPIO_NUM_22 + + //Statusled + ClassControllCamera + #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED + + //ClassControllCamera + #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED + #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new + +#else + #error "Board not selected" +#endif //Board PIN Map - -#ifdef BOARD_ESP32CAM_AITHINKER // ESP32Cam (AiThinker) PIN Map - - #define CAM_PIN_PWDN 32 - #define CAM_PIN_RESET -1 //software reset will be performed - #define CAM_PIN_XCLK 0 - #define CAM_PIN_SIOD 26 - #define CAM_PIN_SIOC 27 - - #define CAM_PIN_D7 35 - #define CAM_PIN_D6 34 - #define CAM_PIN_D5 39 - #define CAM_PIN_D4 36 - #define CAM_PIN_D3 21 - #define CAM_PIN_D2 19 - #define CAM_PIN_D1 18 - #define CAM_PIN_D0 5 - #define CAM_PIN_VSYNC 25 - #define CAM_PIN_HREF 23 - #define CAM_PIN_PCLK 22 - -#endif // ESP32Cam (AiThinker) PIN Map // ******* LED definition #ifdef USE_PWM_LEDFLASH - //// PWM für Flash-LED #define LEDC_TIMER LEDC_TIMER_1 // LEDC_TIMER_0 #define LEDC_MODE LEDC_LOW_SPEED_MODE @@ -332,6 +326,7 @@ #endif //USE_PWM_LEDFLASH + //softAP #ifdef ENABLE_SOFTAP #define EXAMPLE_ESP_WIFI_SSID "AI-on-the-Edge" diff --git a/code/main/main.cpp b/code/main/main.cpp index a0ef0ea20..0340e50f6 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -11,10 +11,13 @@ #include "esp_chip_info.h" // SD-Card //////////////////// -#include "sdcard_init.h" #include "esp_vfs_fat.h" #include "ffconf.h" #include "driver/sdmmc_host.h" + +#if (ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5, 1, 2)) +#include "sdcard_init.h" +#endif /////////////////////////////// #include "ClassLogFile.h" @@ -91,10 +94,10 @@ static const char *TAG = "MAIN"; #define MOUNT_POINT "/sdcard" - bool Init_NVS_SDCard() { esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); @@ -108,12 +111,23 @@ bool Init_NVS_SDCard() // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); - // Set bus width to use: - #ifdef __SD_USE_ONE_LINE_MODE__ - slot_config.width = 1; - #else - slot_config.width = 4; - #endif + // Set bus width to use: +#ifdef __SD_USE_ONE_LINE_MODE__ + slot_config.width = 1; +#ifdef SOC_SDMMC_USE_GPIO_MATRIX + slot_config.clk = GPIO_SDCARD_CLK; + slot_config.cmd = GPIO_SDCARD_CMD; + slot_config.d0 = GPIO_SDCARD_D0; +#endif + +#else + slot_config.width = 4; +#ifdef SOC_SDMMC_USE_GPIO_MATRIX + slot_config.d1 = GPIO_SDCARD_D1; + slot_config.d2 = GPIO_SDCARD_D2; + slot_config.d3 = GPIO_SDCARD_D3; +#endif +#endif // Enable internal pullups on enabled pins. The internal pullups // are insufficient however, please make sure 10k external pullups are @@ -125,7 +139,7 @@ bool Init_NVS_SDCard() // dies führt jedoch bei schlechten Kopien des AI_THINKER Boards // zu Problemen mit der SD Initialisierung und eventuell sogar zur reboot-loops. // Um diese Probleme zu kompensieren, wird der PullUp manuel gesetzt. - gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // HS2_D3 + gpio_set_pull_mode(GPIO_SDCARD_D3, GPIO_PULLUP_ONLY); // HS2_D3 // Options for mounting the filesystem. // If format_if_mount_failed is set to true, SD card will be partitioned and @@ -144,7 +158,11 @@ bool Init_NVS_SDCard() // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function. // Please check its source code and implement error recovery when developing // production applications. +#if (ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5, 1, 2)) ret = esp_vfs_fat_sdmmc_mount_mh(mount_point, &host, &slot_config, &mount_config, &card); +#else + ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card); +#endif if (ret != ESP_OK) { if (ret == ESP_FAIL) { @@ -167,7 +185,6 @@ bool Init_NVS_SDCard() return true; } - extern "C" void app_main(void) { //#ifdef CONFIG_HEAP_TRACING_STANDALONE @@ -191,7 +208,6 @@ extern "C" void app_main(void) // ******************************************** ESP_LOGI(TAG, "\n\n\n\n================ Start app_main ================="); - // Init SD card // ******************************************** if (!Init_NVS_SDCard()) @@ -212,7 +228,6 @@ extern "C" void app_main(void) LogFile.WriteToFile(ESP_LOG_INFO, TAG, "==================== Start ======================"); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "================================================="); - // Init external PSRAM // ******************************************** esp_err_t PSRAMStatus = esp_psram_init(); @@ -261,7 +276,6 @@ extern "C" void app_main(void) ESP_LOGD(TAG, "After camera initialization: sleep for: %ldms", (long) xDelay * CONFIG_FREERTOS_HZ/portTICK_PERIOD_MS); vTaskDelay( xDelay ); - // Check camera init // ******************************************** if (camStatus != ESP_OK) { // Camera init failed, retry to init @@ -310,7 +324,6 @@ extern "C" void app_main(void) } } - // SD card: basic R/W check // ******************************************** int iSDCardStatus = SDCardCheckRW(); @@ -335,12 +348,10 @@ extern "C" void app_main(void) // ******************************************** setupTime(); // NTP time service: Status of time synchronization will be checked after every round (server_tflite.cpp) - // Set CPU Frequency // ******************************************** setCpuFrequency(); - // SD card: Create further mandatory directories (if not already existing) // Correct creation of these folders will be checked with function "SDCardCheckFolderFilePresence" // ******************************************** @@ -432,7 +443,6 @@ extern "C" void app_main(void) ESP_LOGD(TAG, "main: sleep for: %ldms", (long) xDelay * CONFIG_FREERTOS_HZ/portTICK_PERIOD_MS); vTaskDelay( xDelay ); - // manual reset the time // ******************************************** if (!time_manual_reset_sync()) @@ -440,8 +450,6 @@ extern "C" void app_main(void) LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Manual Time Sync failed during startup" ); } - - // Set log level for wifi component to WARN level (default: INFO; only relevant for serial console) // ******************************************** esp_log_level_set("wifi", ESP_LOG_WARN); @@ -465,8 +473,6 @@ extern "C" void app_main(void) #endif #endif - - // Print Device info // ******************************************** esp_chip_info_t chipInfo; @@ -522,7 +528,7 @@ extern "C" void app_main(void) } } - +// FIXME: needs to be revised or removed!!! void migrateConfiguration(void) { bool migrated = false; @@ -569,16 +575,19 @@ void migrateConfiguration(void) { migrated = migrated | replaceString(configLines[i], ";Demo = true", ";Demo = false"); // Set it to its default value migrated = migrated | replaceString(configLines[i], ";Demo", "Demo"); // Enable it - migrated = migrated | replaceString(configLines[i], ";FixedExposure = true", ";FixedExposure = false"); // Set it to its default value - migrated = migrated | replaceString(configLines[i], ";FixedExposure", "FixedExposure"); // Enable it + // Parameter is no longer used + // migrated = migrated | replaceString(configLines[i], ";FixedExposure = true", ";FixedExposure = false"); // Set it to its default value + // migrated = migrated | replaceString(configLines[i], ";FixedExposure", "FixedExposure"); // Enable it } if (section == "[Alignment]") { - migrated = migrated | replaceString(configLines[i], ";InitialMirror = true", ";InitialMirror = false"); // Set it to its default value - migrated = migrated | replaceString(configLines[i], ";InitialMirror", "InitialMirror"); // Enable it - - migrated = migrated | replaceString(configLines[i], ";FlipImageSize = true", ";FlipImageSize = false"); // Set it to its default value - migrated = migrated | replaceString(configLines[i], ";FlipImageSize", "FlipImageSize"); // Enable it + // Parameter is no longer used + // migrated = migrated | replaceString(configLines[i], ";InitialMirror = true", ";InitialMirror = false"); // Set it to its default value + // migrated = migrated | replaceString(configLines[i], ";InitialMirror", "InitialMirror"); // Enable it + + // Parameter is no longer used + // migrated = migrated | replaceString(configLines[i], ";FlipImageSize = true", ";FlipImageSize = false"); // Set it to its default value + // migrated = migrated | replaceString(configLines[i], ";FlipImageSize", "FlipImageSize"); // Enable it } if (section == "[Digits]") { @@ -593,6 +602,7 @@ void migrateConfiguration(void) { } if (section == "[PostProcessing]") { + migrated = migrated | replaceString(configLines[i], "AnalogDigitalTransitionStart", "AnalogToDigitTransitionStart"); // Rename it migrated = migrated | replaceString(configLines[i], ";PreValueUse = true", ";PreValueUse = false"); // Set it to its default value migrated = migrated | replaceString(configLines[i], ";PreValueUse", "PreValueUse"); // Enable it @@ -705,7 +715,6 @@ void migrateConfiguration(void) { } } - std::vector splitString(const std::string& str) { std::vector tokens; @@ -719,8 +728,6 @@ std::vector splitString(const std::string& str) { return tokens; } - - /*bool replace_all(std::string& s, std::string const& toReplace, std::string const& replaceWith) { std::string buf; std::size_t pos = 0; @@ -748,11 +755,10 @@ std::vector splitString(const std::string& str) { return found; }*/ - bool setCpuFrequency(void) { ConfigFile configFile = ConfigFile(CONFIG_FILE); string cpuFrequency = "160"; - esp_pm_config_esp32_t pm_config; + esp_pm_config_t pm_config; if (!configFile.ConfigFileExists()){ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "No ConfigFile defined - exit setCpuFrequency()!"); @@ -764,7 +770,6 @@ bool setCpuFrequency(void) { bool disabledLine = false; bool eof = false; - /* Load config from config file */ while ((!configFile.GetNextParagraph(line, disabledLine, eof) || (line.compare("[System]") != 0)) && !eof) {} diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index b0a9a77eb..5d9d16f70 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -357,7 +357,7 @@ esp_err_t img_tmp_virtual_handler(httpd_req_t *req) if (filetosend == "raw.jpg") return GetRawJPG(req); - // Serve alg.jpg, alg_roi.jpg or digital and analog ROIs + // Serve alg.jpg, alg_roi.jpg or digit and analog ROIs if (ESP_OK == GetJPG(filetosend, req)) return ESP_OK; @@ -451,7 +451,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path) httpd_handle_t start_webserver(void) { httpd_handle_t server = NULL; - httpd_config_t config = { }; + httpd_config_t config = HTTPD_DEFAULT_CONFIG(); config.task_priority = tskIDLE_PRIORITY+3; // previously -> 2022-12-11: tskIDLE_PRIORITY+1; 2021-09-24: tskIDLE_PRIORITY+5 config.stack_size = 12288; // previously -> 2023-01-02: 32768 @@ -459,7 +459,7 @@ httpd_handle_t start_webserver(void) config.server_port = 80; config.ctrl_port = 32768; config.max_open_sockets = 5; //20210921 --> previously 7 - config.max_uri_handlers = 39; // previously 24, 20220511: 35, 20221220: 37, 2023-01-02:38 + config.max_uri_handlers = 40; // Make sure this fits all URI handlers. Memory usage in bytes: 6*max_uri_handlers config.max_resp_headers = 8; config.backlog_conn = 5; config.lru_purge_enable = true; // this cuts old connections if new ones are needed. diff --git a/code/platformio.ini b/code/platformio.ini index 38012347d..51e198625 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -19,7 +19,8 @@ [common:esp32-idf] extends = common:idf - platform = platformio/espressif32 @ 6.5.0 + ; PlatformIO releases, see https://github.com/platformio/platform-espressif32/releases + platform = platformio/espressif32 @ 6.9.0 framework = espidf lib_deps = ${common:idf.lib_deps} @@ -29,7 +30,6 @@ -DUSE_ESP32 -DUSE_ESP32_FRAMEWORK_ESP_IDF - [flags:runtime] build_flags = -Wno-nonnull-compare @@ -46,6 +46,7 @@ ;-Wshadow-compatible-local -fno-exceptions + ; The main env - default [env:esp32cam] extends = common:esp32-idf @@ -56,13 +57,14 @@ build_flags = ${common:esp32-idf.build_flags} ${flags:runtime.build_flags} ; ### Sofware options : (can be set in defines.h) + -D BOARD_ESP32CAM_AITHINKER -D ENABLE_MQTT - -D ENABLE_INFLUXDB + -D ENABLE_INFLUXDB + -D ENABLE_WEBHOOK -D ENABLE_SOFTAP board_build.partitions = partitions.csv monitor_speed = 115200 -monitor_rts = 0 -monitor_dtr = 0 + ; full standalone dev mode ; As sample, the board is nod32s instead of esp32cam (do not change nothing in fact :) @@ -77,8 +79,10 @@ build_flags = ${common:esp32-idf.build_flags} ${flags:clangtidy.build_flags} ; ### Sofware options : (can be set in defines.h) + -D BOARD_ESP32CAM_AITHINKER -D ENABLE_MQTT - -D ENABLE_INFLUXDB + -D ENABLE_INFLUXDB + -D ENABLE_WEBHOOK ;-D ENABLE_SOFTAP ; ### Debug options : ;-D DEBUG_DETAIL_ON @@ -121,8 +125,6 @@ platform_packages = ;;;;espressif/toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5 board_build.partitions = partitions.csv monitor_speed = 115200 -monitor_rts = 0 -monitor_dtr = 0 ; Activate all debug mode @@ -210,5 +212,6 @@ build_flags = ${flags:clangtidy.build_flags} ; ### Sofware options : -D ENABLE_MQTT - -D ENABLE_INFLUXDB + -D ENABLE_INFLUXDB + -D ENABLE_WEBHOOK ;-D ENABLE_SOFTAP ; disabled diff --git a/code/sdkconfig.defaults b/code/sdkconfig.defaults index e41514a16..0fe530363 100644 --- a/code/sdkconfig.defaults +++ b/code/sdkconfig.defaults @@ -135,7 +135,8 @@ CONFIG_OV7670_SUPPORT=n CONFIG_OV7725_SUPPORT=n CONFIG_NT99141_SUPPORT=n CONFIG_OV3660_SUPPORT=n -CONFIG_OV5640_SUPPORT=n +CONFIG_OV2640_SUPPORT=y +CONFIG_OV5640_SUPPORT=y CONFIG_GC2145_SUPPORT=n CONFIG_GC032A_SUPPORT=n CONFIG_GC0308_SUPPORT=n diff --git a/code/test/components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp b/code/test/components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp index 825298ff7..69847981b 100644 --- a/code/test/components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp +++ b/code/test/components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp @@ -20,7 +20,7 @@ class UnderTestCNNGeneral : public ClassFlowCNNGeneral { */ void test_analogToDigit_Standard() { - UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digit100); // 4.8 is a "hanging" 5, i.e. it has not jumped over to 5.0. // A "hanging digit" should still be rounded from Transition. @@ -59,7 +59,7 @@ void test_analogToDigit_Standard() { } void test_analogToDigit_Transition() { - UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digit100); // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175 // Default: dig=3.9, ana=9.7 => erg=3 diff --git a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp index dac99de13..10d4a28d1 100644 --- a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp +++ b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp @@ -16,7 +16,7 @@ class UnderTestCNN : public ClassFlowCNNGeneral { */ void test_ZeigerEval() { - UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100); + UnderTestCNN undertest = UnderTestCNN(nullptr, Digit100); // the 5.2 is already above 5.0 and the previous digit too (3) printf("Test 5.2, 3\n"); @@ -29,11 +29,11 @@ void test_ZeigerEval() TEST_ASSERT_EQUAL(4, undertest.PointerEvalAnalogNew(5.2, 9)); printf("Test 4.4, 9\n"); - // the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3) + // the 4.4 (Digit100) is not above 5 and the previous digit (analog) too (9.3) TEST_ASSERT_EQUAL(4, undertest.PointerEvalAnalogNew(4.4, 9)); printf("Test 4.5, 0\n"); - // the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6) + // the 4.5 (Digit100) is not above 5 and the previous digit (analog) too (9.6) TEST_ASSERT_EQUAL(4, undertest.PointerEvalAnalogNew(4.5, 0)); } @@ -42,7 +42,7 @@ void test_ZeigerEval() * @brief test if all combinations of digit * evaluation are running correctly * - * Desciption on call undertest.PointerEvalHybridNew(float number, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors, float digitalAnalogTransitionStart) + * Desciption on call undertest.PointerEvalHybridNew(float number, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors, float digitAnalogTransitionStart) * @param number: is the current ROI as float value from recognition * @param number_of_predecessors: is the last (lower) ROI as float from recognition * @param eval_predecessors: is the evaluated number. Sometimes a much lower value can change higer values @@ -50,16 +50,16 @@ void test_ZeigerEval() * 0.1 => 0 (eval_predecessors) * The 0 makes a 9.9 to 0 (eval_predecessors) * The 0 makes a 9.8 to 0 - * @param Analog_Predecessors false/true if the last ROI is an analog or digital ROI (default=false) + * @param Analog_Predecessors false/true if the last ROI is an analog or digit ROI (default=false) * runs in special handling because analog is much less precise - * @param digitalAnalogTransitionStart start of the transitionlogic begins on number_of_predecessor (default=9.2) + * @param digitAnalogTransitionStart start of the transitionlogic begins on number_of_predecessor (default=9.2) * * * * */ void test_ZeigerEvalHybrid() { - UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100); + UnderTestCNN undertest = UnderTestCNN(nullptr, Digit100); // the 5.2 and no previous should round down printf("PointerEvalHybridNew(5.2, 0, -1)\n"); @@ -93,17 +93,17 @@ void test_ZeigerEvalHybrid() { // the 5.7 with previous and the previous >=9.5 should trunc to 5 TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.7, 9.6, 9)); - // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6) + // the 4.5 (Digit100) is not above 5 and the previous digit (analog) not over Zero (9.6) TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.5, 9.6, 0)); - // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6) + // the 4.5 (Digit100) is not above 5 and the previous digit (analog) not over Zero (9.6) TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.5, 9.6, 9)); - // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5) + // the 4.5 (Digit100) is not above 5 and the previous digit (analog) not over Zero (9.5) TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.5, 9.5, 9)); // 59.96889 - Pre: 58.94888 // 8.6 : 9.8 : 6.7 - // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5) + // the 4.4 (Digit100) is not above 5 and the previous digit (analog) not over Zero (9.5) TEST_ASSERT_EQUAL(8, undertest.PointerEvalHybridNew(8.6, 9.8, 9)); // pre = 9.9 (0.0 raw) @@ -111,7 +111,7 @@ void test_ZeigerEvalHybrid() { TEST_ASSERT_EQUAL(2, undertest.PointerEvalHybridNew(1.8, 9.0, 9)); // if a digit have an early transition and the pointer is < 9.0 - // prev (pointer) = 6.2, but on digital readout = 6.0 (prev is int parameter) + // prev (pointer) = 6.2, but on digit readout = 6.0 (prev is int parameter) // zahl = 4.6 TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.6, 6.0, 6)); diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index a5676b074..466d4bd63 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -37,9 +37,9 @@ std::string process_doFlow(UnderTestPost* _underTestPost) { * @brief setup flow like it runs after recognition. * * @param analog the analog recognitions as array begins with the highest ROI - * @param digits the digital regocnitions as array begins with the highest ROI - * @param digType type of the model defaults do Digital100 - * @param checkConsistency for Digital type only. Not relvant for newer models + * @param digits the digit regocnitions as array begins with the highest ROI + * @param digType type of the model defaults do Digit100 + * @param checkConsistency for Digit type only. Not relvant for newer models * @param extendedResolution the lowest ROI will directly used (9.7 => 9.7) if false 9.7 => 9 * @param decimal_shift the decimal point offset. -3 corresponds to x.yyy * @return std::string the value result @@ -162,7 +162,7 @@ void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analog std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { ESP_LOGD(TAG, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart); - (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart; + (*NUMBERS)[_n]->AnalogToDigitTransitionStart = _analogdigitTransistionStart; } } } diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h index af74e05da..7ca2d076f 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h @@ -33,13 +33,13 @@ UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType * * @param analog the analog recognitions * @param digits the digit recognitions - * @param digType the digit model type (default Digital100) + * @param digType the digit model type (default Digit100) * @param checkConsistency sets property checkConsistency (default = false) * @param extendedResolution sets property extendedResolution (default = false) * @param decimal_shift set property decimal_shift (Nachkommastellen, default = 0) * @return UnderTestPost* the created testobject */ -UnderTestPost* init_do_flow(std::vector analog, std::vector digits, t_CNNType digType = Digital100, +UnderTestPost* init_do_flow(std::vector analog, std::vector digits, t_CNNType digType = Digit100, bool checkConsistency=false, bool extendedResolution=false, int decimal_shift=0); /** @@ -47,13 +47,13 @@ UnderTestPost* init_do_flow(std::vector analog, std::vector digits * * @param analog the analog recognitions * @param digits the digit recognitions - * @param digType the digit model type (default Digital100) + * @param digType the digit model type (default Digit100) * @param checkConsistency sets property checkConsistency (default = false) * @param extendedResolution sets property extendedResolution (default = false) * @param decimal_shift set property decimal_shift (Nachkommastellen, default = 0) * @return std::string the return value of do_Flow is the Value as string */ -std::string process_doFlow(std::vector analog, std::vector digits, t_CNNType digType = Digital100, +std::string process_doFlow(std::vector analog, std::vector digits, t_CNNType digType = Digit100, bool checkConsistency=false, bool extendedResolution=false, int decimal_shift=0); /** diff --git a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp index e33ffcfa3..ace52e0cf 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp @@ -20,7 +20,7 @@ void testNegative() { // extendResolution=false // da kein negativ, sollte kein Error auftreten - UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0); + UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digit100, false, false, 0); setAllowNegatives(underTestPost, false); setPreValue(underTestPost, preValue); std::string result = process_doFlow(underTestPost); @@ -31,7 +31,7 @@ void testNegative() { // extendResolution=true // da negativ im Rahmen (letzte Stelle -0.2 > ergebnis), kein Error // Aber der PreValue wird gesetzt - underTestPost = init_do_flow(analogs, digits, Digital100, false, true, 0); + underTestPost = init_do_flow(analogs, digits, Digit100, false, true, 0); setAllowNegatives(underTestPost, false); setPreValue(underTestPost, preValue_extended); result = process_doFlow(underTestPost); @@ -42,7 +42,7 @@ void testNegative() { // extendResolution=true // Tolleranz überschritten, Error wird gesetzt, kein ReturnValue preValue_extended = 16.988; // zu groß - underTestPost = init_do_flow(analogs, digits, Digital100, false, true, 0); + underTestPost = init_do_flow(analogs, digits, Digit100, false, true, 0); setAllowNegatives(underTestPost, false); setPreValue(underTestPost, preValue_extended); result = process_doFlow(underTestPost); @@ -53,7 +53,7 @@ void testNegative() { // extendResolution=false // value < (preValue -.01) preValue = 17.00; // zu groß - underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0); + underTestPost = init_do_flow(analogs, digits, Digit100, false, false, 0); setAllowNegatives(underTestPost, false); setPreValue(underTestPost, preValue); result = process_doFlow(underTestPost); @@ -65,7 +65,7 @@ void testNegative() { // value > (preValue -.01) // ist im Rahmen der Ungenauigkeit (-1 auf letzter Stelle) preValue = 16.99; // zu groß - underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0); + underTestPost = init_do_flow(analogs, digits, Digit100, false, false, 0); setAllowNegatives(underTestPost, false); setPreValue(underTestPost, preValue); result = process_doFlow(underTestPost); @@ -77,7 +77,7 @@ void testNegative() { // value < preValue // Aber Prüfung abgeschaltet => kein Fehler preValue = 17.99; // zu groß - underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0); + underTestPost = init_do_flow(analogs, digits, Digit100, false, false, 0); setAllowNegatives(underTestPost, true); setPreValue(underTestPost, preValue_extended); result = process_doFlow(underTestPost); @@ -105,11 +105,11 @@ void testNegative_Issues() { // value < preValue // Prüfung eingeschaltet => Fehler preValue = 22018.09; // zu groß - UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digital100, false, false, -2); + UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digit100, false, false, -2); setAllowNegatives(underTestPost, false); setPreValue(underTestPost, preValue_extended); std::string result = process_doFlow(underTestPost); - TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 22017.98 - Pre: 22018.08 ", underTestPost->getReadoutError().c_str()); + TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 22017.98 - Pre: 22018.09 ", underTestPost->getReadoutError().c_str()); // if negativ no result any more TEST_ASSERT_EQUAL_STRING("", result.c_str()); diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index 64df42a65..6cfbec463 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -178,7 +178,7 @@ void test_doFlowPP2() { std::vector digits = { 1.0, 9.0, 9.0}; // Übergang wurde um 1 erhöht (200, statt 199) std::vector analogs = { 7.1, 4.8, 8.3}; const char* expected = "199.748"; - std::string result = process_doFlow(analogs, digits, Digital); + std::string result = process_doFlow(analogs, digits, Digit); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // Fehler bei Rolling (2002-09-09) @@ -191,15 +191,15 @@ void test_doFlowPP2() { // expected_extended= "32289.4198"; // extendResolution=false, checkConsistency=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // checkConsistency=true und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler Rolling (2022-09-10) @@ -210,20 +210,20 @@ void test_doFlowPP2() { expected_extended= "83.99401"; // checkConsistency=false - result = process_doFlow(analogs, digits, Digital100, false); + result = process_doFlow(analogs, digits, Digit100, false); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=true - result = process_doFlow(analogs, digits, Digital100, true); + result = process_doFlow(analogs, digits, Digit100, true); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true); + result = process_doFlow(analogs, digits, Digit100, false, true); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // checkConsistency=true und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true); + result = process_doFlow(analogs, digits, Digit100, false, true); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler Rolling (2022-09-10) @@ -234,16 +234,16 @@ void test_doFlowPP2() { expected_extended= "123235.6"; // checkConsistency=true - result = process_doFlow(analogs, digits, Digital100, false, false); + result = process_doFlow(analogs, digits, Digit100, false, false); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=true - result = process_doFlow(analogs, digits, Digital100, true, false); + result = process_doFlow(analogs, digits, Digit100, true, false); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true); + result = process_doFlow(analogs, digits, Digit100, false, true); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler bei V11.2.0 @@ -254,11 +254,11 @@ void test_doFlowPP2() { expected_extended= "3249.4692"; // checkConsistency=true - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler bei V11.2.0 @@ -269,11 +269,11 @@ void test_doFlowPP2() { expected_extended= "269.92272"; // extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, false); + result = process_doFlow(analogs, digits, Digit100, false, false); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true); + result = process_doFlow(analogs, digits, Digit100, false, true); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler bei V11.3.1 @@ -284,11 +284,11 @@ void test_doFlowPP2() { expected_extended= "169.35935"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler bei V12.0.1 @@ -299,11 +299,11 @@ void test_doFlowPP2() { expected_extended= "211.03555"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler bei V12.0.1 @@ -314,11 +314,11 @@ void test_doFlowPP2() { expected_extended= "245.9386"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler bei V12.0.1 @@ -329,11 +329,11 @@ void test_doFlowPP2() { expected_extended= "245.9386"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); } @@ -346,11 +346,11 @@ void test_doFlowPP3() { const char* expected_extended= "247.2045"; // extendResolution=false - std::string result = process_doFlow(analogs, digits, Digital100, false, false, 0); + std::string result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); @@ -362,11 +362,11 @@ void test_doFlowPP3() { expected_extended= "142.92690"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); @@ -379,14 +379,14 @@ void test_doFlowPP3() { expected_extended= "170.05287"; // extendResolution=false - UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digit100, false, false, -3); setAnalogdigitTransistionStart(undertestPost, 7.7); result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); delete undertestPost; // checkConsistency=false und extendResolution=true - undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + undertestPost = init_do_flow(analogs, digits, Digit100, false, true, -3); setAnalogdigitTransistionStart(undertestPost, 7.7); result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); @@ -400,11 +400,11 @@ void test_doFlowPP3() { expected_extended= "91.88174"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); @@ -416,11 +416,11 @@ void test_doFlowPP3() { expected_extended= "92.38320"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler V11.3.0 @@ -431,11 +431,11 @@ void test_doFlowPP3() { expected_extended= "7472.7594"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler V12.0.1 @@ -446,11 +446,11 @@ void test_doFlowPP3() { expected_extended= "577.86490"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); @@ -462,11 +462,11 @@ void test_doFlowPP3() { expected_extended= "211.03580"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler V12.0.1 @@ -477,11 +477,11 @@ void test_doFlowPP3() { expected_extended= "126.9231"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digit100, false, false, 0); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digit100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler V12.0.1 @@ -492,11 +492,11 @@ void test_doFlowPP3() { expected_extended= "386.05672"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + result = process_doFlow(analogs, digits, Digit100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + result = process_doFlow(analogs, digits, Digit100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); // Fehler V12.0.1 @@ -508,14 +508,14 @@ void test_doFlowPP3() { expected_extended= "171.24178"; // extendResolution=false - undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + undertestPost = init_do_flow(analogs, digits, Digit100, false, false, -3); setAnalogdigitTransistionStart(undertestPost, 7.7); result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); delete undertestPost; // checkConsistency=false und extendResolution=true - undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + undertestPost = init_do_flow(analogs, digits, Digit100, false, true, -3); setAnalogdigitTransistionStart(undertestPost, 7.7); result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); @@ -533,11 +533,11 @@ void test_doFlowPP4() { const char* expected_extended= "717.01658"; // extendResolution=false - std::string result = process_doFlow(analogs, digits, Digital100, false, false); + std::string result = process_doFlow(analogs, digits, Digit100, false, false); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true); + result = process_doFlow(analogs, digits, Digit100, false, true); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); } diff --git a/code/test/components/jomjol-flowcontroll/test_getReadoutRawString.cpp b/code/test/components/jomjol-flowcontroll/test_getReadoutRawString.cpp index 6ee19aceb..410b2f7a2 100644 --- a/code/test/components/jomjol-flowcontroll/test_getReadoutRawString.cpp +++ b/code/test/components/jomjol-flowcontroll/test_getReadoutRawString.cpp @@ -5,7 +5,7 @@ void test_getReadoutRawString() { // no ROIs setted up - UnderTestPost* _undertestPost = setUpClassFlowPostprocessing(Digital100, Analogue100); + UnderTestPost* _undertestPost = setUpClassFlowPostprocessing(Digit100, Analogue100); string result = _undertestPost->flowAnalog->getReadoutRawString(0); TEST_ASSERT_EQUAL_STRING("", result.c_str()); diff --git a/code/test/components/jomjol_mqtt/test_server_mqtt.cpp b/code/test/components/jomjol_mqtt/test_server_mqtt.cpp new file mode 100644 index 000000000..e59b12254 --- /dev/null +++ b/code/test/components/jomjol_mqtt/test_server_mqtt.cpp @@ -0,0 +1,22 @@ +#include +#include + +void test_createNodeId() +{ + std::string topic = "watermeter"; + TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str()); + + topic = "/watermeter"; + TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str()); + + topic = "home/test/watermeter"; + TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str()); + + topic = "home/test/subtopic/something/test/watermeter"; + TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str()); +} + +void test_mqtt() +{ + test_createNodeId(); +} \ No newline at end of file diff --git a/code/test/components/openmetrics/test_openmetrics.cpp b/code/test/components/openmetrics/test_openmetrics.cpp new file mode 100644 index 000000000..00600cd47 --- /dev/null +++ b/code/test/components/openmetrics/test_openmetrics.cpp @@ -0,0 +1,65 @@ +#include +#include + +void test_createMetric() +{ + // simple happy path + const char *expected = "# HELP metric_name short description\n# TYPE metric_name gauge\nmetric_name 123.456\n"; + std::string result = createMetric("metric_name", "short description", "gauge", "123.456"); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); +} + +/** + * test the replaceString function as it's a dependency to sanitize sequence names + */ +void test_replaceString() +{ + std::string sample = "hello\\world\\"; + replaceAll(sample, "\\", ""); + TEST_ASSERT_EQUAL_STRING("helloworld", sample.c_str()); + + sample = "hello\"world\""; + replaceAll(sample, "\"", ""); + TEST_ASSERT_EQUAL_STRING("helloworld", sample.c_str()); + + sample = "hello\nworld\n"; + replaceAll(sample, "\n", ""); + TEST_ASSERT_EQUAL_STRING("helloworld", sample.c_str()); + + sample = "\\\\\\\\\\\\\\\\\\hello\\world\\\\\\\\\\\\\\\\\\\\"; + replaceAll(sample, "\\", ""); + TEST_ASSERT_EQUAL_STRING("helloworld", sample.c_str()); +} + +void test_createSequenceMetrics() +{ + std::vector NUMBERS; + NumberPost *number_1 = new NumberPost; + number_1->name = "main"; + number_1->ReturnValue = "123.456"; + NUMBERS.push_back(number_1); + + const std::string metricNamePrefix = "ai_on_the_edge_device"; + const std::string metricName = metricNamePrefix + "_flow_value"; + + std::string expected1 = "# HELP " + metricName + " current value of meter readout\n# TYPE " + metricName + " gauge\n" + + metricName + "{sequence=\"" + number_1->name + "\"} " + number_1->ReturnValue + "\n"; + TEST_ASSERT_EQUAL_STRING(expected1.c_str(), createSequenceMetrics(metricNamePrefix, NUMBERS).c_str()); + + NumberPost *number_2 = new NumberPost; + number_2->name = "secondary"; + number_2->ReturnValue = "1.0"; + NUMBERS.push_back(number_2); + + std::string expected2 = "# HELP " + metricName + " current value of meter readout\n# TYPE " + metricName + " gauge\n" + + metricName + "{sequence=\"" + number_1->name + "\"} " + number_1->ReturnValue + "\n" + + metricName + "{sequence=\"" + number_2->name + "\"} " + number_2->ReturnValue + "\n"; + TEST_ASSERT_EQUAL_STRING(expected2.c_str(), createSequenceMetrics(metricNamePrefix, NUMBERS).c_str()); +} + +void test_openmetrics() +{ + test_createMetric(); + test_replaceString(); + test_createSequenceMetrics(); +} diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index f399fb297..d152f1995 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -20,7 +20,8 @@ #include "components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp" #include "components/jomjol-flowcontroll/test_getReadoutRawString.cpp" #include "components/jomjol-flowcontroll/test_cnnflowcontroll.cpp" - +#include "components/openmetrics/test_openmetrics.cpp" +#include "components/jomjol_mqtt/test_server_mqtt.cpp" bool Init_NVS_SDCard() { @@ -151,12 +152,12 @@ extern "C" void app_main() { initGPIO(); Init_NVS_SDCard(); - esp_log_level_set("*", ESP_LOG_DEBUG); // set all components to ERROR level + esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level UNITY_BEGIN(); RUN_TEST(testNegative_Issues); RUN_TEST(testNegative); - /* + RUN_TEST(test_analogToDigit_Standard); RUN_TEST(test_analogToDigit_Transition); RUN_TEST(test_doFlowPP); @@ -167,6 +168,8 @@ extern "C" void app_main() // getReadoutRawString test RUN_TEST(test_getReadoutRawString); - */ + RUN_TEST(test_openmetrics); + RUN_TEST(test_mqtt); + UNITY_END(); } diff --git a/param-docs/expert-params.txt b/param-docs/expert-params.txt index c2fe85c73..056b71288 100644 --- a/param-docs/expert-params.txt +++ b/param-docs/expert-params.txt @@ -1,8 +1,30 @@ -demo WaitBeforeTakingPicture -ImageQuality -ImageSize -FixedExposure +CamFrameSize +CamGainceiling +CamQuality +CamAutoSharpness +CamSharpness +CamSpecialEffect +CamWbMode +CamAwb +CamAwbGain +CamAec +CamAec2 +CamAeLevel +CamAecValue +CamAgc +CamAgcGain +CamBpc +CamWpc +CamRawGma +CamLenc +CamDcw +CamDenoise +CamZoom +CamZoomSize +CamZoomOffsetX +CamZoomOffsetY +demo SearchFieldX SearchFieldY AlignmentAlgo diff --git a/param-docs/parameter-pages/Alignment/FlipImageSize.md b/param-docs/parameter-pages/Alignment/FlipImageSize.md deleted file mode 100644 index 9fdc95bb8..000000000 --- a/param-docs/parameter-pages/Alignment/FlipImageSize.md +++ /dev/null @@ -1,11 +0,0 @@ -# Parameter `FlipImageSize` -Default Value: `false` - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -This parameter can be used to rotate the viewport together with the alignment rotation: -![](img/flipImageSize.png) diff --git a/param-docs/parameter-pages/Alignment/InitialMirror.md b/param-docs/parameter-pages/Alignment/InitialMirror.md deleted file mode 100644 index 072de29c8..000000000 --- a/param-docs/parameter-pages/Alignment/InitialMirror.md +++ /dev/null @@ -1,10 +0,0 @@ -# Parameter `InitialMirror` -Default Value: `false` - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Option for initially mirroring the image on the original x-axis. diff --git a/param-docs/parameter-pages/MQTT/CACert.md b/param-docs/parameter-pages/MQTT/CACert.md index 5ee45b46d..9f2fa8c4e 100644 --- a/param-docs/parameter-pages/MQTT/CACert.md +++ b/param-docs/parameter-pages/MQTT/CACert.md @@ -16,3 +16,6 @@ Usually there is a common RootCA certificate for the MQTT broker !!! Note This also means that you might have to change the protocol and port in [uri](https://jomjol.github.io/AI-on-the-edge-device-docs/Parameters/#parameter-uri) to `mqtts://example.com:8883`! + +!!! Note + Only TLS 1.2 is supported! diff --git a/param-docs/parameter-pages/MQTT/ClientCert.md b/param-docs/parameter-pages/MQTT/ClientCert.md index 9cb49241c..83ca26f94 100644 --- a/param-docs/parameter-pages/MQTT/ClientCert.md +++ b/param-docs/parameter-pages/MQTT/ClientCert.md @@ -17,3 +17,6 @@ Usually there is a one pair of Client Certificate/Key for each client that conne !!! Note If set, `ClientKey` must be set too This also means that you might have to change the protocol and port in [uri](https://jomjol.github.io/AI-on-the-edge-device-docs/Parameters/#parameter-uri) to `mqtts://example.com:8883`! + +!!! Note + Only TLS 1.2 is supported! diff --git a/param-docs/parameter-pages/MQTT/ClientKey.md b/param-docs/parameter-pages/MQTT/ClientKey.md index af862f088..b976ba199 100644 --- a/param-docs/parameter-pages/MQTT/ClientKey.md +++ b/param-docs/parameter-pages/MQTT/ClientKey.md @@ -17,3 +17,6 @@ Usually there is a one pair of Client Certificate/Key for each client that conne !!! Note If set, `ClientCert` must be set too This also means that you might have to change the protocol and port in [uri](https://jomjol.github.io/AI-on-the-edge-device-docs/Parameters/#parameter-uri) to `mqtts://example.com:8883`! + +!!! Note + Only TLS 1.2 is supported! diff --git a/param-docs/parameter-pages/MQTT/MainTopic.md b/param-docs/parameter-pages/MQTT/MainTopic.md index 3cf12ec25..390a3d56f 100644 --- a/param-docs/parameter-pages/MQTT/MainTopic.md +++ b/param-docs/parameter-pages/MQTT/MainTopic.md @@ -8,7 +8,7 @@ The single value will be published with the following key: `MAINTOPIC/NUMBER/RES With: - `NUMBER`: The name of the value (a meter might have more than one value). - The names get defined in the analog and digital ROI configuration (defaults to `main`). + The names get defined in the analog and digit ROI configuration (defaults to `main`). - `RESULT_TOPIC`: Automatically filled with the right name, eg. `value`, `rate`, `timestamp`, `error`, .... The general connection status can be found in `MAINTOPIC/CONNECTION`. @@ -16,3 +16,5 @@ See [MQTT Result Topics](../MQTT-API#result) for a full list of topics. !!! Note The main topic is allowed to contain `/` which can be used to split it into multiple levels, eg. `/basement/meters/watermeter/1/` if you have multiple water meters in your basement. + +The nodeId for the Home Assistant MQTT Service Discovery must follow the schema `//[/]/config`. The node_id is not configurable but derived from the `MainTopic` by stripping any but the last topic level. A `MainTopic` with the value `home/basement/watermeter` is transformed into the node_id `watermeter`, resulting in the discovery topic `homeassistant/sensor/watermeter/value/config` for the current value. diff --git a/param-docs/parameter-pages/PostProcessing/NUMBER.AnalogDigitalTransitionStart.md b/param-docs/parameter-pages/PostProcessing/NUMBER.AnalogDigitTransitionStart.md similarity index 70% rename from param-docs/parameter-pages/PostProcessing/NUMBER.AnalogDigitalTransitionStart.md rename to param-docs/parameter-pages/PostProcessing/NUMBER.AnalogDigitTransitionStart.md index d04831aa0..90bb4f326 100644 --- a/param-docs/parameter-pages/PostProcessing/NUMBER.AnalogDigitalTransitionStart.md +++ b/param-docs/parameter-pages/PostProcessing/NUMBER.AnalogDigitTransitionStart.md @@ -1,9 +1,9 @@ -# Parameter `.AnalogDigitalTransitionStart` +# Parameter `.AnalogDigitTransitionStart` Default Value: `9.2` This can be used if you have wrong values, but the recognition of the individual ROIs are correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. Only used on combination of digits and analog pointers. -See [here](../Watermeter-specific-analog---digital-transition) for details. +See [here](../Watermeter-specific-analog---digit-transition) for details. Range: `6.0` .. `9.9`. diff --git a/param-docs/parameter-pages/PostProcessing/NUMBER.ChangeRateThreshold.md b/param-docs/parameter-pages/PostProcessing/NUMBER.ChangeRateThreshold.md new file mode 100644 index 000000000..9a4d0e14f --- /dev/null +++ b/param-docs/parameter-pages/PostProcessing/NUMBER.ChangeRateThreshold.md @@ -0,0 +1,25 @@ +# Parameter `.ChangeRateThreshold` +Default Value: `2` + +Range: `1` .. `9`. + +Threshold parameter for change rate detection.
+This parameter is intended to compensate for small reading fluctuations that occur when the meter does not change its value for a long time (e.g. at night) or slightly turns backwards. This can eg. happen on watermeters. + +It is only applied to the last digit of the read value (See example below). +If the read value is within PreValue +/- Threshold, no further calculation is carried out and the Value/Prevalue remains at the old value. + +Example: + + Smallest ROI provides value for 0.000x + ChangeRateThreshold = 2 + + Extended Resolution disabled: + PreValue: 123.456'7 >>> Threshold = +/- 0.000'2 + Comparative value >>> max = 123.456'9 and min = 123.456'5 + + Extended Resolution enabled: + PreValue: 123.456'78 >>> Threshold = +/- 0.000'02 + Comparative value >>> max = 123.456'80 and min = 123.456'76 + +![](img/ChangeRateThreshold.png) diff --git a/param-docs/parameter-pages/TakeImage/Aec2.md b/param-docs/parameter-pages/TakeImage/Aec2.md deleted file mode 100644 index d5489ee29..000000000 --- a/param-docs/parameter-pages/TakeImage/Aec2.md +++ /dev/null @@ -1,13 +0,0 @@ -# Parameter `Aec2` -Default Value: `false` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Switch to "Auto-exposure Control 2" algorithm. This may resolve some over-exposure and under-exposure issues. diff --git a/param-docs/parameter-pages/TakeImage/Brightness.md b/param-docs/parameter-pages/TakeImage/Brightness.md deleted file mode 100644 index b5f65aa59..000000000 --- a/param-docs/parameter-pages/TakeImage/Brightness.md +++ /dev/null @@ -1,10 +0,0 @@ -# Parameter `Brightness` -Default Value: `0` - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Image Brightness (`-2` .. `2`) diff --git a/param-docs/parameter-pages/TakeImage/CamAeLevel.md b/param-docs/parameter-pages/TakeImage/CamAeLevel.md new file mode 100644 index 000000000..5a5f3c8fa --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAeLevel.md @@ -0,0 +1,22 @@ +# Parameter `CamAeLevel` + +**Auto-Exposure-Level** + +range on OV2640 (`-2` .. `2`)
+range on OV3660 and OV5640 (`-5` .. `5`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + The exposure offset for automatic exposure, lower values produce darker image. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamAec.md b/param-docs/parameter-pages/TakeImage/CamAec.md new file mode 100644 index 000000000..af30a1df1 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAec.md @@ -0,0 +1,19 @@ +# Parameter `CamAec` + +**Auto-Exposure-Control** + +- When **true**, the camera attempts to automatically control the exposure. +- When **false**, the **CamAecValue** setting is used instead. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamAec2.md b/param-docs/parameter-pages/TakeImage/CamAec2.md new file mode 100644 index 000000000..eb90c5fe0 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAec2.md @@ -0,0 +1,22 @@ +# Parameter `CamAec2` + +**Auto-Exposure-Control2** + +- When **true**, the sensor’s "night mode" is enabled, extending the range of automatic gain control. +- When **false**, the sensor’s "night mode" is disabled. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This may resolve some over-exposure and under-exposure issues. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamAecValue.md b/param-docs/parameter-pages/TakeImage/CamAecValue.md new file mode 100644 index 000000000..e070158e0 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAecValue.md @@ -0,0 +1,21 @@ +# Parameter `CamAecValue` + +**Auto-Exposure-Value** + +Range (`0` .. `1200`) + +Default Value: `160` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + Access the exposure value of the camera, higher values produce brighter images. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamAgc.md b/param-docs/parameter-pages/TakeImage/CamAgc.md new file mode 100644 index 000000000..eaa89b31c --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAgc.md @@ -0,0 +1,16 @@ +# Parameter `CamAgc` + +**Auto-Gain-Control** + +- When **true**, the camera attempts to automatically control the sensor gain, up to the value in the **CamGainceiling** property. +- When **false**, the **CamAgcGain** setting is used instead. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! diff --git a/param-docs/parameter-pages/TakeImage/CamAgcGain.md b/param-docs/parameter-pages/TakeImage/CamAgcGain.md new file mode 100644 index 000000000..d139effa1 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAgcGain.md @@ -0,0 +1,21 @@ +# Parameter `CamAgcGain` + +**Auto-Gain-Control-Value** + +Range (`0` .. `30`) + +Default Value: `15` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This is used when **CamAgc** is off. + +!!! Note + Access the gain level of the sensor, higher values produce brighter images. diff --git a/param-docs/parameter-pages/TakeImage/CamAutoSharpness.md b/param-docs/parameter-pages/TakeImage/CamAutoSharpness.md new file mode 100644 index 000000000..cd3bb27ad --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAutoSharpness.md @@ -0,0 +1,22 @@ +# Parameter `CamAutoSharpness` + +**Auto-Sharpness** + +- When **true**, the camera attempts to automatically adjusts the sharpness. +- When **false**, the **CamSharpness** setting is used instead. + +Default Value: `false` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + The OV2640 does not officially support auto sharpness, this is an experimental parameter! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamAwb.md b/param-docs/parameter-pages/TakeImage/CamAwb.md new file mode 100644 index 000000000..2bb080524 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAwb.md @@ -0,0 +1,16 @@ +# Parameter `CamAwb` + +**Auto-White-Balance** + +- When **true**, the camera attempts to automatically control white balance. +- When **false**, the **CamWbMode** setting is used instead. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! diff --git a/param-docs/parameter-pages/TakeImage/CamAwbGain.md b/param-docs/parameter-pages/TakeImage/CamAwbGain.md new file mode 100644 index 000000000..ca5ca3902 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamAwbGain.md @@ -0,0 +1,15 @@ +# Parameter `CamAwbGain` + +**Auto-White-Balance-Gain** + +- Enable/Disable **CamAwbGain** control. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! diff --git a/param-docs/parameter-pages/TakeImage/CamBpc.md b/param-docs/parameter-pages/TakeImage/CamBpc.md new file mode 100644 index 000000000..975356178 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamBpc.md @@ -0,0 +1,15 @@ +# Parameter `CamBpc` + +**Black-Pixel-Correction** + +- Enable/Disable **black point compensation**, this can make black parts of the image darker. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! diff --git a/param-docs/parameter-pages/TakeImage/CamBrightness.md b/param-docs/parameter-pages/TakeImage/CamBrightness.md new file mode 100644 index 000000000..eebd9e3cc --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamBrightness.md @@ -0,0 +1,16 @@ +# Parameter `CamBrightness` + +**Image-Brightness** + +Range (`-2` .. `2`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamColorbar.md b/param-docs/parameter-pages/TakeImage/CamColorbar.md new file mode 100644 index 000000000..f74f40fd6 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamColorbar.md @@ -0,0 +1,13 @@ +# Parameter `CamColorbar` + +**Colorbar** + +currently not implemented. + +Default Value: `false` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! diff --git a/param-docs/parameter-pages/TakeImage/AutoExposureLevel.md b/param-docs/parameter-pages/TakeImage/CamContrast.md similarity index 52% rename from param-docs/parameter-pages/TakeImage/AutoExposureLevel.md rename to param-docs/parameter-pages/TakeImage/CamContrast.md index b681bf0ff..eca0244ae 100644 --- a/param-docs/parameter-pages/TakeImage/AutoExposureLevel.md +++ b/param-docs/parameter-pages/TakeImage/CamContrast.md @@ -1,15 +1,16 @@ -# Parameter `AutoExposureLevel` +# Parameter `CamContrast` + +**Image-Contrast** + +Range (`-2` .. `2`) + Default Value: `0` +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + !!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! + After changing this parameter you need to update your reference image and alignment markers! !!! Note This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Exposure compensation. Lower values produce darker image. - -Range (`-2` .. `2`) diff --git a/param-docs/parameter-pages/TakeImage/CamDcw.md b/param-docs/parameter-pages/TakeImage/CamDcw.md new file mode 100644 index 000000000..318d71244 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamDcw.md @@ -0,0 +1,21 @@ +# Parameter `CamDcw` + +**Image-Downsize** + +- When **CamDcw** is on, the image that you receive will be the size that you requested (VGA, QQVGA, etc). +- When **CamDcw** is off, the image that you receive will be one of UXGA, SVGA, or CIF. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + + If **CamZoom** is used, this must be activated. + +!!! Note + If **CamDcw** is off, and you pick a different image size, this implicitly turns **CamDcw** back on again. diff --git a/param-docs/parameter-pages/TakeImage/CamDenoise.md b/param-docs/parameter-pages/TakeImage/CamDenoise.md new file mode 100644 index 000000000..978419640 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamDenoise.md @@ -0,0 +1,15 @@ +# Parameter `CamDenoise` + +**Image-Denoise** + +- Denoise Image, is only supported by OV3660 and OV5640 + +range on OV3660 and OV5640 (0 .. 8) + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! diff --git a/param-docs/parameter-pages/TakeImage/CamGainceiling.md b/param-docs/parameter-pages/TakeImage/CamGainceiling.md new file mode 100644 index 000000000..af7a5985a --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamGainceiling.md @@ -0,0 +1,33 @@ +# Parameter `CamGainceiling` + +**Gain-Ceiling** + +Available options: + +- `x2` +- `x4` +- `x8` +- `x16` +- `x32` +- `x64` +- `x128` + +Default Value for ov2640: `x4`
+Default Value for ov5640: `x8` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + A higher gain means that the sensor has a greater response to light, but also makes sensor noise more visible. + + This is used when **CamAgc** is on. + +!!! Note + The **Gain** is an analog multiplier applied to the raw sensor data.
+ The **Ceiling** is the maximum gain value that the sensor will use. diff --git a/param-docs/parameter-pages/TakeImage/CamHmirror.md b/param-docs/parameter-pages/TakeImage/CamHmirror.md new file mode 100644 index 000000000..d6c59127b --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamHmirror.md @@ -0,0 +1,16 @@ +# Parameter `CamHmirror` + +**Mirror-Image** + +- When **true**, the camera image is mirrored left-to-right. + +Default Value: `false` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamLenc.md b/param-docs/parameter-pages/TakeImage/CamLenc.md new file mode 100644 index 000000000..54e6d9ff5 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamLenc.md @@ -0,0 +1,18 @@ +# Parameter `CamLenc` + +**Lens-Correction** + +- Enable/Disable lens correction. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This can help compensate for light fall-off at the edge of the sensor area. diff --git a/param-docs/parameter-pages/TakeImage/CamQuality.md b/param-docs/parameter-pages/TakeImage/CamQuality.md new file mode 100644 index 000000000..db2777674 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamQuality.md @@ -0,0 +1,22 @@ +# Parameter `CamQuality` + +**Image-Quality** + +Range (`8` .. `63`) + +Default Value: `10` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + + Value below 10 could result in system instabilities! + +!!! Note + Quality index for pictures: `8` (highest quality) ... `63` (lowest quality) + + This is similar to the quality setting when exporting a jpeg image from photo editing software. diff --git a/param-docs/parameter-pages/TakeImage/CamRawGma.md b/param-docs/parameter-pages/TakeImage/CamRawGma.md new file mode 100644 index 000000000..cff99f0ca --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamRawGma.md @@ -0,0 +1,21 @@ +# Parameter `CamRawGma` + +**Raw-Gamma** + +- Enable/Disable raw gamma mode. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + The main purpose of the Gamma (GMA) function is to compensate for the non-linear characteristics of the sensor. + GMA converts the pixel values according to the Gamma curve to compensate the sensor output under different light strengths. + The non-linear gamma curve is approximately constructed with different linear functions. Raw gamma compensates the + image in the RAW domain. diff --git a/param-docs/parameter-pages/TakeImage/CamSaturation.md b/param-docs/parameter-pages/TakeImage/CamSaturation.md new file mode 100644 index 000000000..3772acd22 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamSaturation.md @@ -0,0 +1,19 @@ +# Parameter `CamSaturation` + +**Image-Saturation** + +Range (`-2` .. `2`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + Positive values increase saturation (more vibrant colors), negative values lower it (more muted colors). + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamSharpness.md b/param-docs/parameter-pages/TakeImage/CamSharpness.md new file mode 100644 index 000000000..278646f14 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamSharpness.md @@ -0,0 +1,26 @@ +# Parameter `CamSharpness` + +**Image-Sharpness** + +Range (`-2` .. `2`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + The OV2640 does not officially support sharpness, this is an experimental parameter! + +!!! Note + Positive values increase sharpness (more defined edges), negative values lower it (softer edges). + + This is used when **CamAutoSharpness** is off. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamSpecialEffect.md b/param-docs/parameter-pages/TakeImage/CamSpecialEffect.md new file mode 100644 index 000000000..35b341ca8 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamSpecialEffect.md @@ -0,0 +1,26 @@ +# Parameter `CamSpecialEffect` + +**Image-Special-Effect** + +Available options: + +- `no_effect` +- `negative` +- `grayscale` +- `red` +- `green` +- `blue` +- `retro` + +Default Value: `no_effect` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamVflip.md b/param-docs/parameter-pages/TakeImage/CamVflip.md new file mode 100644 index 000000000..4e1dea8ec --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamVflip.md @@ -0,0 +1,19 @@ +# Parameter `CamVflip` + +**Flip-Image** + +- When **true**, the camera image is flipped top-to-bottom. + +Default Value: `false` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + On some OV5640 Cameras, the image becomes reddish when Vflip is used in conjunction with the zoom function! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamWbMode.md b/param-docs/parameter-pages/TakeImage/CamWbMode.md new file mode 100644 index 000000000..458832662 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamWbMode.md @@ -0,0 +1,25 @@ +# Parameter `CamWbMode` + +**White-Balance-Mode** + +Available options: + +- `auto` +- `sunny` +- `cloudy` +- `office` +- `home` + +Default Value: `auto` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This is used when **CamAwb** is off. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamWpc.md b/param-docs/parameter-pages/TakeImage/CamWpc.md new file mode 100644 index 000000000..5349e6e1d --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamWpc.md @@ -0,0 +1,16 @@ +# Parameter `CamWpc` + +**White-Pixel-Correction** + +- Enable/Disable **white point compensation**, his can make white parts of the image whiter. + +Default Value: `true` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamZoom.md b/param-docs/parameter-pages/TakeImage/CamZoom.md new file mode 100644 index 000000000..c1d08440c --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamZoom.md @@ -0,0 +1,21 @@ +# Parameter `CamZoom` + +**Digital-Zoom** + +- Enable/Disable digital zoom. + +Default Value: `false` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + It is always zoomed into the center of the image, if **CamZoomOffsetX** and **CamZoomOffsetY** are zero. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamZoomOffsetX.md b/param-docs/parameter-pages/TakeImage/CamZoomOffsetX.md new file mode 100644 index 000000000..05acde821 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamZoomOffsetX.md @@ -0,0 +1,25 @@ +# Parameter `CamZoomOffsetX` + +**Digital-Zoom-OffsetX** + +range on OV2640 (`-480` .. `480`)
+range on OV3660 (`-704` .. `704`)
+range on OV5640 (`-960` .. `960`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + X displacement of the image from the center.
+ Positive values ​​shift the image to the right, negative values ​​to the left.
+ The maximum possible offset depends on the value of the **CamZoomSize**. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamZoomOffsetY.md b/param-docs/parameter-pages/TakeImage/CamZoomOffsetY.md new file mode 100644 index 000000000..d69f539a9 --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamZoomOffsetY.md @@ -0,0 +1,25 @@ +# Parameter `CamZoomOffsetY` + +**Digital-Zoom-OffsetY** + +range on OV2640 (`-360` .. `360`)
+range on OV3660 (`-528` .. `528`)
+range on OV5640 (`-720` .. `720`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + Y displacement of the image from the center.
+ Positive values ​​move the image up, negative values ​​move the image down.
+ The maximum possible offset depends on the value of the **CamZoomSize**. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/CamZoomSize.md b/param-docs/parameter-pages/TakeImage/CamZoomSize.md new file mode 100644 index 000000000..3a9f540bb --- /dev/null +++ b/param-docs/parameter-pages/TakeImage/CamZoomSize.md @@ -0,0 +1,23 @@ +# Parameter `CamZoomSize` + +**Digital-Zoom-Size** + +range on OV2640 (`0` .. `29`)
+range on OV3660 (`0` .. `43`)
+range on OV5640 (`0` .. `59`) + +Default Value: `0` + +See [here](../datasheets/Camera.ov2640_ds_1.8_.pdf) for the ov2640 camera datasheet.
+See [here](../datasheets/OV5640_datasheet.pdf) for the ov5640 camera datasheet. + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! + + After changing this parameter you need to update your reference image and alignment markers! + +!!! Note + Zoom factor/level of the digital zoom, the larger the value, the more it zooms in. + +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/Contrast.md b/param-docs/parameter-pages/TakeImage/Contrast.md deleted file mode 100644 index 7bc76f2f2..000000000 --- a/param-docs/parameter-pages/TakeImage/Contrast.md +++ /dev/null @@ -1,11 +0,0 @@ -# Parameter `Contrast` -Default Value: `0` - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Image Contrast (`-2` .. `2`) - diff --git a/param-docs/parameter-pages/TakeImage/Demo.md b/param-docs/parameter-pages/TakeImage/Demo.md index 4f66edf76..b34beea98 100644 --- a/param-docs/parameter-pages/TakeImage/Demo.md +++ b/param-docs/parameter-pages/TakeImage/Demo.md @@ -1,9 +1,10 @@ # Parameter `Demo` -Default Value: `false` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! Enable to use demo images instead of the real camera images. Make sure to have a `/demo` folder on your SD-Card and make sure it contains the expected files! -Check [here](../Demo-Mode) for details. +Check [here](../Demo-Mode) for details. + +Default Value: `false` + +!!! Warning + This is an **Expert Parameter**! Only change it if you understand what it does! diff --git a/param-docs/parameter-pages/TakeImage/FixedExposure.md b/param-docs/parameter-pages/TakeImage/FixedExposure.md deleted file mode 100644 index 7db1c4051..000000000 --- a/param-docs/parameter-pages/TakeImage/FixedExposure.md +++ /dev/null @@ -1,13 +0,0 @@ -# Parameter `FixedExposure` -Default Value: `false` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Fixes the illumination setting of camera at the startup and uses this later -> Individual round is faster. diff --git a/param-docs/parameter-pages/TakeImage/Grayscale.md b/param-docs/parameter-pages/TakeImage/Grayscale.md deleted file mode 100644 index 5eca929ae..000000000 --- a/param-docs/parameter-pages/TakeImage/Grayscale.md +++ /dev/null @@ -1,13 +0,0 @@ -# Parameter `Grayscale` -Default Value: `false` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Produces black and white image. diff --git a/param-docs/parameter-pages/TakeImage/ImageQuality.md b/param-docs/parameter-pages/TakeImage/ImageQuality.md deleted file mode 100644 index 7f5c4c09f..000000000 --- a/param-docs/parameter-pages/TakeImage/ImageQuality.md +++ /dev/null @@ -1,10 +0,0 @@ -# Parameter `ImageQuality` -Default Value: `12` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -Quality index for pictures: `8` (highest quality) ... `63` (lowest quality) - -!!! Warning - Value below 12 could result in system instabilities! diff --git a/param-docs/parameter-pages/TakeImage/ImageSize.md b/param-docs/parameter-pages/TakeImage/ImageSize.md deleted file mode 100644 index 73531f3c8..000000000 --- a/param-docs/parameter-pages/TakeImage/ImageSize.md +++ /dev/null @@ -1,12 +0,0 @@ -# Parameter `ImageSize` -Default Value: `VGA` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -Size of the camera picture. - -Available options: - -- `VGA` (640 x 480 pixel) -- `QVGA` (320 x 240 pixel) diff --git a/param-docs/parameter-pages/TakeImage/LEDIntensity.md b/param-docs/parameter-pages/TakeImage/LEDIntensity.md index 56e75827c..29589e857 100644 --- a/param-docs/parameter-pages/TakeImage/LEDIntensity.md +++ b/param-docs/parameter-pages/TakeImage/LEDIntensity.md @@ -1,10 +1,11 @@ # Parameter `LEDIntensity` -Default Value: `50` -!!! Note - This parameter can also be set on the Reference Image configuration page! +Set the Flash LED Intensity: (`0` .. `100`) + +Default Value: `50` !!! Note After changing this parameter you need to update your reference image and alignment markers! -Set the Flash LED Intensity: (`0` .. `100`) +!!! Note + This parameter can also be set on the Reference Image configuration page! diff --git a/param-docs/parameter-pages/TakeImage/Negative.md b/param-docs/parameter-pages/TakeImage/Negative.md deleted file mode 100644 index e0dc675c3..000000000 --- a/param-docs/parameter-pages/TakeImage/Negative.md +++ /dev/null @@ -1,13 +0,0 @@ -# Parameter `Negative` -Default Value: `false` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Inverts the colors. diff --git a/param-docs/parameter-pages/TakeImage/RawImagesLocation.md b/param-docs/parameter-pages/TakeImage/RawImagesLocation.md index 0b53a93c0..6b48a120d 100644 --- a/param-docs/parameter-pages/TakeImage/RawImagesLocation.md +++ b/param-docs/parameter-pages/TakeImage/RawImagesLocation.md @@ -1,7 +1,8 @@ # Parameter `RawImagesLocation` -Default Value: `/log/source` Location on the SD-Card to store the raw images. +Default Value: `/log/source` + !!! Warning A SD-Card has limited write cycles. Since the device does not do [Wear Leveling](https://en.wikipedia.org/wiki/Wear_leveling), this can wear out your SD-Card! diff --git a/param-docs/parameter-pages/TakeImage/RawImagesRetention.md b/param-docs/parameter-pages/TakeImage/RawImagesRetention.md index e14e79bca..d06dbb5ca 100644 --- a/param-docs/parameter-pages/TakeImage/RawImagesRetention.md +++ b/param-docs/parameter-pages/TakeImage/RawImagesRetention.md @@ -1,6 +1,7 @@ # Parameter `RawImagesRetention` -Default Value: `15` + +Number of days to keep the raw images (`0` = forever) Unit: Days -Number of days to keep the raw images (`0` = forever) +Default Value: `15` diff --git a/param-docs/parameter-pages/TakeImage/Saturation.md b/param-docs/parameter-pages/TakeImage/Saturation.md deleted file mode 100644 index 34c165dd5..000000000 --- a/param-docs/parameter-pages/TakeImage/Saturation.md +++ /dev/null @@ -1,11 +0,0 @@ -# Parameter `Saturation` -Default Value: `0` - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Image Saturation (`-2` .. `2`) - diff --git a/param-docs/parameter-pages/TakeImage/Sharpness.md b/param-docs/parameter-pages/TakeImage/Sharpness.md deleted file mode 100644 index 88259fc76..000000000 --- a/param-docs/parameter-pages/TakeImage/Sharpness.md +++ /dev/null @@ -1,15 +0,0 @@ -# Parameter `Sharpness` -Default Value: `0` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Changes the sharpness of the image. Set to `-4` for auto-sharpness. - -Range (`-4` .. `3`) diff --git a/param-docs/parameter-pages/TakeImage/WaitBeforeTakingPicture.md b/param-docs/parameter-pages/TakeImage/WaitBeforeTakingPicture.md index f65775190..d9eeea619 100644 --- a/param-docs/parameter-pages/TakeImage/WaitBeforeTakingPicture.md +++ b/param-docs/parameter-pages/TakeImage/WaitBeforeTakingPicture.md @@ -1,9 +1,10 @@ # Parameter `WaitBeforeTakingPicture` -Default Value: `5` + +Waiting time between switching the flash light (onboard LED) on and taking the picture. Unit: seconds +Default Value: `5` + !!! Warning This is an **Expert Parameter**! Only change it if you understand what it does! - -Waiting time between switching the flash light (onboard LED) on and taking the picture. diff --git a/param-docs/parameter-pages/TakeImage/Zoom.md b/param-docs/parameter-pages/TakeImage/Zoom.md deleted file mode 100644 index 8dc875860..000000000 --- a/param-docs/parameter-pages/TakeImage/Zoom.md +++ /dev/null @@ -1,13 +0,0 @@ -# Parameter `Zoom` -Default Value: `false` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -Crop the camera sensor frame to `ImageSize` resolution instead of scaling it down. diff --git a/param-docs/parameter-pages/TakeImage/ZoomMode.md b/param-docs/parameter-pages/TakeImage/ZoomMode.md deleted file mode 100644 index 05ac0fd48..000000000 --- a/param-docs/parameter-pages/TakeImage/ZoomMode.md +++ /dev/null @@ -1,15 +0,0 @@ -# Parameter `ZoomMode` -Default Value: `0` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -`ZoomMode` only applies when `Zoom` is enabled. -Value 0: Crop the camera sensor frame to `ImageSize` resolution. -Value 1: Scale the camera sensor frame to 800 x 600 pixels then crop it to `ImageSize` resolution. diff --git a/param-docs/parameter-pages/TakeImage/ZoomOffsetX.md b/param-docs/parameter-pages/TakeImage/ZoomOffsetX.md deleted file mode 100644 index 613c2d171..000000000 --- a/param-docs/parameter-pages/TakeImage/ZoomOffsetX.md +++ /dev/null @@ -1,14 +0,0 @@ -# Parameter `ZoomOffsetX` -Default Value: `0` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -`ZoomOffsetX` only applies when `Zoom` is enabled. -X coordinate of the crop location within the camera sensor frame. diff --git a/param-docs/parameter-pages/TakeImage/ZoomOffsetY.md b/param-docs/parameter-pages/TakeImage/ZoomOffsetY.md deleted file mode 100644 index 5880f5665..000000000 --- a/param-docs/parameter-pages/TakeImage/ZoomOffsetY.md +++ /dev/null @@ -1,14 +0,0 @@ -# Parameter `ZoomOffsetY` -Default Value: `0` - -!!! Warning - This is an **Expert Parameter**! Only change it if you understand what it does! - -!!! Note - This parameter can also be set on the Reference Image configuration page! - -!!! Note - After changing this parameter you need to update your reference image and alignment markers! - -`ZoomOffsetY` only applies when `Zoom` is enabled. -Y coordinate of the crop location within the camera sensor frame. diff --git a/param-docs/parameter-pages/Webhook/ApiKey.md b/param-docs/parameter-pages/Webhook/ApiKey.md new file mode 100644 index 000000000..79cf21615 --- /dev/null +++ b/param-docs/parameter-pages/Webhook/ApiKey.md @@ -0,0 +1,4 @@ +# Parameter `ApiKey` +Default Value: `undefined` + +ApiKey sent as Header diff --git a/param-docs/parameter-pages/Webhook/UploadImg.md b/param-docs/parameter-pages/Webhook/UploadImg.md new file mode 100644 index 000000000..fb375642f --- /dev/null +++ b/param-docs/parameter-pages/Webhook/UploadImg.md @@ -0,0 +1,8 @@ +# Parameter `UploadImg` +Default Value: `0` (`NEVER`) + +Available options: + +- `0`: `NEVER` +- `1`: `ALWAYS` +- `2`: `ON_ERROR` \ No newline at end of file diff --git a/param-docs/parameter-pages/Webhook/Uri.md b/param-docs/parameter-pages/Webhook/Uri.md new file mode 100644 index 000000000..7a08cf0bd --- /dev/null +++ b/param-docs/parameter-pages/Webhook/Uri.md @@ -0,0 +1,4 @@ +# Parameter `Uri` +Default Value: `undefined` + +URI of the HTTP Endpoint receiving requests, e.g. `http://192.168.1.1/watermeter/webhook`. diff --git a/param-docs/parameter-pages/img/ChangeRateThreshold.png b/param-docs/parameter-pages/img/ChangeRateThreshold.png new file mode 100644 index 000000000..f05640e9a Binary files /dev/null and b/param-docs/parameter-pages/img/ChangeRateThreshold.png differ diff --git a/sd-card/config/ana-cont_1300_s2.tflite b/sd-card/config/ana-cont_1300_s2.tflite new file mode 100644 index 000000000..b8b72be85 Binary files /dev/null and b/sd-card/config/ana-cont_1300_s2.tflite differ diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index 6e0d1ea62..02f84a9fd 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -1,123 +1,143 @@ -[TakeImage] -;RawImagesLocation = /log/source -WaitBeforeTakingPicture = 5 -;RawImagesRetention = 15 -Brightness = 0 -Contrast = 0 -Saturation = 0 -Sharpness = 0 -LEDIntensity = 50 -ImageQuality = 12 -ImageSize = VGA -Zoom = false -ZoomMode = 0 -ZoomOffsetX = 0 -ZoomOffsetY = 0 -Grayscale = false -Negative = false -Aec2 = false -AutoExposureLevel = 0 -FixedExposure = false -Demo = false - -[Alignment] -InitialRotate = 0.0 -InitialMirror = false -SearchFieldX = 20 -SearchFieldY = 20 -AlignmentAlgo = Default -FlipImageSize = false -/config/ref0.jpg 103 271 -/config/ref1.jpg 442 142 - -[Digits] -Model = /config/dig-cont_0620_s3_q.tflite -CNNGoodThreshold = 0.5 -;ROIImagesLocation = /log/digit -;ROIImagesRetention = 3 -main.dig1 294 126 30 54 false -main.dig2 343 126 30 54 false -main.dig3 391 126 30 54 false - -[Analog] -Model = /config/ana-cont_1208_s2_q.tflite -CNNGoodThreshold = 0.5 -;ROIImagesLocation = /log/analog -;ROIImagesRetention = 3 -main.ana1 432 230 92 92 false -main.ana2 379 332 92 92 false -main.ana3 283 374 92 92 false -main.ana4 155 328 92 92 false - -[PostProcessing] -main.DecimalShift = 0 -main.AnalogDigitalTransitionStart = 9.2 -PreValueUse = true -PreValueAgeStartup = 720 -main.AllowNegativeRates = false -main.MaxRateValue = 0.05 -;main.MaxRateType = AbsoluteChange -main.ExtendedResolution = false -main.IgnoreLeadingNaN = false -ErrorMessage = true -CheckDigitIncreaseConsistency = false - -;[MQTT] -;Uri = mqtt://IP-ADRESS:1883 -;MainTopic = watermeter -;ClientID = watermeter -;user = USERNAME -;password = PASSWORD -RetainMessages = false -HomeassistantDiscovery = false -;MeterType = other -;CACert = /config/certs/RootCA.pem -;ClientCert = /config/certs/client.pem.crt -;ClientKey = /config/certs/client.pem.key - -;[InfluxDB] -;Uri = undefined -;Database = undefined -;Measurement = undefined -;user = undefined -;password = undefined - -;[InfluxDBv2] -;Uri = undefined -;Bucket = undefined -;Measurement = undefined -;Org = undefined -;Token = undefined -;main.Fieldname = undefined - -;[GPIO] -;MainTopicMQTT = wasserzaehler/GPIO -;IO0 = input disabled 10 false false -;IO1 = input disabled 10 false false -;IO3 = input disabled 10 false false -;IO4 = built-in-led disabled 10 false false -;IO12 = input-pullup disabled 10 false false -;IO13 = input-pullup disabled 10 false false -LEDType = WS2812 -LEDNumbers = 2 -LEDColor = 150 150 150 - -[AutoTimer] -AutoStart = true -Interval = 5 - -[DataLogging] -DataLogActive = true -DataFilesRetention = 3 - -[Debug] -LogLevel = 1 -LogfilesRetention = 3 - -[System] -TimeZone = CET-1CEST,M3.5.0,M10.5.0/3 -;TimeServer = pool.ntp.org -;Hostname = undefined -RSSIThreshold = -75 -CPUFrequency = 160 -SetupMode = true +[TakeImage] +;RawImagesLocation = /log/source +;RawImagesRetention = 15 +WaitBeforeTakingPicture = 2 +CamGainceiling = x8 +CamQuality = 10 +CamBrightness = 0 +CamContrast = 0 +CamSaturation = 0 +CamSharpness = 0 +CamAutoSharpness = false +CamSpecialEffect = no_effect +CamWbMode = auto +CamAwb = true +CamAwbGain = true +CamAec = true +CamAec2 = true +CamAeLevel = 2 +CamAecValue = 600 +CamAgc = true +CamAgcGain = 8 +CamBpc = true +CamWpc = true +CamRawGma = true +CamLenc = true +CamHmirror = false +CamVflip = false +CamDcw = true +CamDenoise = 0 +CamZoom = false +CamZoomOffsetX = 0 +CamZoomOffsetY = 0 +CamZoomSize = 0 +LEDIntensity = 50 +Demo = false + +[Alignment] +InitialRotate = 0.0 +InitialMirror = false +SearchFieldX = 20 +SearchFieldY = 20 +AlignmentAlgo = Default +FlipImageSize = false +/config/ref0.jpg 103 271 +/config/ref1.jpg 442 142 + +[Digits] +Model = /config/dig-cont_0710_s3_q.tflite +CNNGoodThreshold = 0.5 +;ROIImagesLocation = /log/digit +;ROIImagesRetention = 3 +main.dig1 294 126 30 54 false +main.dig2 343 126 30 54 false +main.dig3 391 126 30 54 false + +[Analog] +Model = /config/ana-cont_1300_s2.tflite +CNNGoodThreshold = 0.5 +;ROIImagesLocation = /log/analog +;ROIImagesRetention = 3 +main.ana1 432 230 92 92 false +main.ana2 379 332 92 92 false +main.ana3 283 374 92 92 false +main.ana4 155 328 92 92 false + +[PostProcessing] +main.DecimalShift = 0 +main.AnalogDigitTransitionStart = 9.2 +main.ChangeRateThreshold = 2 +PreValueUse = true +PreValueAgeStartup = 720 +main.AllowNegativeRates = false +main.MaxRateValue = 0.05 +;main.MaxRateType = AbsoluteChange +main.ExtendedResolution = false +main.IgnoreLeadingNaN = false +ErrorMessage = true +CheckDigitIncreaseConsistency = false + +;[MQTT] +;Uri = mqtt://IP-ADRESS:1883 +;MainTopic = watermeter +;ClientID = watermeter +;user = USERNAME +;password = PASSWORD +RetainMessages = false +HomeassistantDiscovery = false +;MeterType = other +;CACert = /config/certs/RootCA.pem +;ClientCert = /config/certs/client.pem.crt +;ClientKey = /config/certs/client.pem.key + +;[InfluxDB] +;Uri = undefined +;Database = undefined +;Measurement = undefined +;user = undefined +;password = undefined + +;[InfluxDBv2] +;Uri = undefined +;Bucket = undefined +;Measurement = undefined +;Org = undefined +;Token = undefined +;main.Fieldname = undefined + +;[Webhook] +;Uri = undefined +;ApiKey = undefined +;UploadImg = 0 + +;[GPIO] +;MainTopicMQTT = wasserzaehler/GPIO +;IO0 = input disabled 10 false false +;IO1 = input disabled 10 false false +;IO3 = input disabled 10 false false +;IO4 = built-in-led disabled 10 false false +;IO12 = input-pullup disabled 10 false false +;IO13 = input-pullup disabled 10 false false +LEDType = WS2812 +LEDNumbers = 2 +LEDColor = 150 150 150 + +[AutoTimer] +AutoStart = true +Interval = 5 + +[DataLogging] +DataLogActive = true +DataFilesRetention = 3 + +[Debug] +LogLevel = 1 +LogfilesRetention = 3 + +[System] +TimeZone = CET-1CEST,M3.5.0,M10.5.0/3 +;TimeServer = pool.ntp.org +;Hostname = undefined +RSSIThreshold = -75 +CPUFrequency = 160 +SetupMode = true diff --git a/sd-card/config/dig-class100-0168_s2_q.tflite b/sd-card/config/dig-class100-0168_s2_q.tflite deleted file mode 100644 index 8dd82963e..000000000 Binary files a/sd-card/config/dig-class100-0168_s2_q.tflite and /dev/null differ diff --git a/sd-card/config/dig-class100-0173-s2-q.tflite b/sd-card/config/dig-class100-0173-s2-q.tflite new file mode 100644 index 000000000..100e2d279 Binary files /dev/null and b/sd-card/config/dig-class100-0173-s2-q.tflite differ diff --git a/sd-card/config/dig-class11_1701_s2.tflite b/sd-card/config/dig-class11_1701_s2.tflite new file mode 100644 index 000000000..7dd74d445 Binary files /dev/null and b/sd-card/config/dig-class11_1701_s2.tflite differ diff --git a/sd-card/config/dig-cont_0640_s3_q.tflite b/sd-card/config/dig-cont_0640_s3_q.tflite new file mode 100644 index 000000000..41536f523 Binary files /dev/null and b/sd-card/config/dig-cont_0640_s3_q.tflite differ diff --git a/sd-card/config/dig-cont_0700_s3_q.tflite b/sd-card/config/dig-cont_0700_s3_q.tflite new file mode 100644 index 000000000..bdd9f57be Binary files /dev/null and b/sd-card/config/dig-cont_0700_s3_q.tflite differ diff --git a/sd-card/config/dig-cont_0710_s3_q.tflite b/sd-card/config/dig-cont_0710_s3_q.tflite new file mode 100644 index 000000000..e4e76b7ab Binary files /dev/null and b/sd-card/config/dig-cont_0710_s3_q.tflite differ diff --git a/sd-card/html/edit_alignment.html b/sd-card/html/edit_alignment.html index 944803c7e..0ba6b3876 100644 --- a/sd-card/html/edit_alignment.html +++ b/sd-card/html/edit_alignment.html @@ -1,9 +1,10 @@ - + + - Alignment markers - + Alignment markers + + + - + + + + @@ -89,7 +94,7 @@
-

Alignment Markers

+

Alignment Markers

CLICK HERE for usage description. More infos in documentation: Alignment @@ -112,480 +117,544 @@

Alignment Markers


- - - - - - - - - - - - - - - - - - - - - - - - - - - - +
Marker: - - Filename:
x: dx:
y: dy:
Selected Image Area:Resulting Marker:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + +
Marker: + + Filename:
x: dx:
y: dy:
Selected Image Area:Resulting Marker:
Reference Image: + +
- - - - - - + + + diff --git a/sd-card/html/edit_analog.html b/sd-card/html/edit_analog.html index 8f7dfcfe3..8b713dbb5 100644 --- a/sd-card/html/edit_analog.html +++ b/sd-card/html/edit_analog.html @@ -1,82 +1,15 @@ - + + Analog ROI - - + - + + + @@ -125,7 +58,6 @@

Analog ROI

- @@ -133,9 +65,11 @@

Analog ROI

+ + + + + + + @@ -199,10 +139,9 @@

Analog ROI


The following settings are only used for easier setup, they are not persisted on the device:
-
+


-
Number Sequence:
ROI:
Multiplier:
(only based on order) @@ -183,14 +120,17 @@

Analog ROI

x: Δx:
y: Δy:
@@ -212,22 +151,24 @@

Analog ROI

+ - - + +
Reference Image: + +
- - - - - + + + + + + @@ -43,9 +47,10 @@

Configuration - "Config.ini" Editor

- - - + + + + + + + + +
+
+
+

Configuration

@@ -252,227 +283,409 @@

Configuration

$TOOLTIP_TakeImage_RawImagesRetention - + - + Wait Before Taking Picture - Seconds + + $TOOLTIP_TakeImage_WaitBeforeTakingPicture + + + + + CamGainceiling + + + - $TOOLTIP_TakeImage_Demo + $TOOLTIP_TakeImage_CamGainceiling + + + + + Image Quality + + + + + $TOOLTIP_TakeImage_CamQuality - + - Wait Before Taking Picture + Brightness - Seconds + - $TOOLTIP_TakeImage_WaitBeforeTakingPicture + $TOOLTIP_TakeImage_CamBrightness - + - Brightness + Contrast - + - $TOOLTIP_TakeImage_Brightness + $TOOLTIP_TakeImage_CamContrast - + - Contrast + Saturation - + - $TOOLTIP_TakeImage_Contrast + $TOOLTIP_TakeImage_CamSaturation - + - Saturation + AutoSharpness - + - $TOOLTIP_TakeImage_Saturation + $TOOLTIP_TakeImage_CamAutoSharpness - + - Sharpness + Sharpness - + - $TOOLTIP_TakeImage_Sharpness + $TOOLTIP_TakeImage_CamSharpness - + - LED Intensity + SpecialEffect - + - $TOOLTIP_TakeImage_LEDIntensity + $TOOLTIP_TakeImage_CamSpecialEffect + + + + + White Balance Mode + + + + + $TOOLTIP_TakeImage_CamWbMode - + - Image Quality + White Balance - + - $TOOLTIP_TakeImage_ImageQuality + $TOOLTIP_TakeImage_CamAwb - + - Image Size + Auto White Balance - + + - $TOOLTIP_TakeImage_ImageSize + $TOOLTIP_TakeImage_CamAwbGain - + - Zoom + Auto-Exposure Control - + + - $TOOLTIP_TakeImage_Zoom + $TOOLTIP_TakeImage_CamAec - + - Zoom Mode + Auto-Exposure Control 2 - + + - $TOOLTIP_TakeImage_ZoomMode + $TOOLTIP_TakeImage_CamAec2 + + + + + Auto Exposure Level + + + + + $TOOLTIP_TakeImage_CamAeLevel + + + + + Auto Exposure Value + + + + + $TOOLTIP_TakeImage_CamAecValue - + + + Auto Gain + + + + + $TOOLTIP_TakeImage_CamAgc + + - Zoom Offset X + Gain Manuall Value - Pixel + - $TOOLTIP_TakeImage_ZoomOffsetX + $TOOLTIP_TakeImage_CamAgcGain - + + + Black Pixel Correction + + + + + $TOOLTIP_TakeImage_CamBpc + + + + + White Pixel Correction + + + + + $TOOLTIP_TakeImage_CamWpc + + - Zoom Offset Y + CamRawGma - Pixel + - $TOOLTIP_TakeImage_ZoomOffsetY + $TOOLTIP_TakeImage_CamRawGma - + + + Lens Correction + + + + + $TOOLTIP_TakeImage_CamLenc + + + + + Mirror Image + + + + + $TOOLTIP_TakeImage_CamHmirror + + + - Grayscale + Flip Image - + + - $TOOLTIP_TakeImage_Grayscale + $TOOLTIP_TakeImage_CamVflip - + - Negative + Downsize - + + - $TOOLTIP_TakeImage_Negative + $TOOLTIP_TakeImage_CamDcw + + + + + Denoise + + + + + $TOOLTIP_TakeImage_CamDenoise - + - Auto-exposure Control 2 + Zoom - + + - $TOOLTIP_TakeImage_Aec2 + $TOOLTIP_TakeImage_CamZoom - + - Auto Exposure Level + Zoom Size - + + + $TOOLTIP_TakeImage_CamZoomSize + + + + + Zoom Offset X + + + Pixel + + $TOOLTIP_TakeImage_CamZoomOffsetX + + + + + Zoom Offset Y - $TOOLTIP_TakeImage_AutoExposureLevel + + Pixel + + $TOOLTIP_TakeImage_CamZoomOffsetY - + + + LED Intensity + + + + + $TOOLTIP_TakeImage_LEDIntensity + + + - Fixed Exposure + - + + - $TOOLTIP_TakeImage_FixedExposure + $TOOLTIP_TakeImage_Demo @@ -480,7 +693,7 @@

Configuration

Alignment

- + Search Field X @@ -491,7 +704,7 @@

Configuration

$TOOLTIP_Alignment_SearchFieldX - + Search Field Y @@ -502,7 +715,7 @@

Configuration

$TOOLTIP_Alignment_SearchFieldY - + @@ -518,39 +731,13 @@

Configuration

$TOOLTIP_Alignment_AlignmentAlgo - - - Flip Image Size - - - - - $TOOLTIP_Alignment_FlipImageSize - - - - - Initial Mirror - - - - - $TOOLTIP_Alignment_InitialMirror - - - + Rotation angle - degree + degree $TOOLTIP_Alignment_InitialRotate @@ -663,13 +850,13 @@

@@ -688,8 +875,8 @@

$TOOLTIP_PostProcessing_CheckDigitIncreaseConsistency @@ -719,12 +906,12 @@

- - + + - - $TOOLTIP_PostProcessing_NUMBER.AnalogDigitalTransitionStart + $TOOLTIP_PostProcessing_NUMBER.AnalogToDigitTransitionStart @@ -782,32 +969,58 @@

+ + + + + + $TOOLTIP_PostProcessing_NUMBER.ChangeRateThreshold + + $TOOLTIP_PostProcessing_NUMBER.ExtendedResolution - + $TOOLTIP_PostProcessing_NUMBER.IgnoreLeadingNaN - - + + @@ -913,8 +1126,8 @@

$TOOLTIP_MQTT_RetainMessages @@ -935,8 +1148,8 @@

$TOOLTIP_MQTT_HomeassistantDiscovery @@ -1135,6 +1348,52 @@

$TOOLTIP_InfluxDBv2_NUMBER.Field + + + +

+ + +

+ + + + + + + + + + + + $TOOLTIP_Webhook_Uri + + + + + + + + + + + $TOOLTIP_Webhook_ApiKey + + + + + + + + + + + $TOOLTIP_Webhook_UploadImg + @@ -1445,6 +1704,8 @@

LED Color - - R - G + + + G - B + + + B - $TOOLTIP_GPIO_LEDColor @@ -1570,15 +1841,15 @@

$TOOLTIP_AutoTimer_AutoStart @@ -1659,8 +1930,8 @@

$TOOLTIP_System_CPUFrequency + + + Tooltip + + + + + + @@ -1788,9 +2071,9 @@

-1) { - if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined)) { - return; - } + document.getElementById("Category_MQTT_enabled").checked = category["MQTT"]["enabled"]; + setVisible("MQTTItem", category["MQTT"]["enabled"]); - if (_optional) { - document.getElementById(_cat+"_"+_name+"_enabled").checked = NUMBERS[_number][_cat][_name]["enabled"]; - for (var j = 1; j <= anzpara; ++j) { - document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !NUMBERS[_number][_cat][_name]["enabled"]; - } - } - - document.getElementById(_cat+"_"+_name+"_text").style.color = "black" - setEnabled(_cat+"_"+_name, true); + document.getElementById("Category_GPIO_enabled").checked = category["GPIO"]["enabled"]; + setVisible("GPIO_item", category["GPIO"]["enabled"]); - for (var j = 1; j <= anzpara; ++j) { - let element = document.getElementById(_cat+"_"+_name+"_value"+j); - if (element.tagName.toLowerCase() == "select") { - var textToFind = NUMBERS[_number][_cat][_name]["value"+j]; - if (textToFind == undefined) { - continue; - } + document.getElementById("Category_InfluxDB_enabled").checked = category["InfluxDB"]["enabled"]; + setVisible("InfluxDBv1Item", category["InfluxDB"]["enabled"]); - _isFound = false; - element.selectedIndex = -1; - for (var i = 0; i < element.options.length; i++) { - if (element.options[i].value.toLowerCase() === textToFind.toLowerCase()) { - element.selectedIndex = i; - _isFound = true; - break; - } - } - if (!_isFound) { - _zw_txt = "In the selected field the value '" + textToFind + "' in the parameter '"; - _zw_txt = _zw_txt + _cat + "' in the field '" + _name + "' is invalid. PLEASE CHECK BEFORE SAVING!"; - firework.launch(_zw_txt, 'warning', 10000); - } - } - else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { - element.checked = NUMBERS[_number][_cat][_name]["value"+j] == "true"; - } - else { - element.value = NUMBERS[_number][_cat][_name]["value"+j]; - } - } - } - else { - if (_optional) { - document.getElementById(_cat+"_"+_name+"_enabled").checked = _param[_cat][_name]["enabled"]; - for (var j = 1; j <= anzpara; ++j) { - document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_param[_cat][_name]["enabled"]; - } - } - document.getElementById(_cat+"_"+_name+"_text").style.color = "black" - setEnabled(_cat+"_"+_name, true); + document.getElementById("Category_InfluxDBv2_enabled").checked = category["InfluxDBv2"]["enabled"]; + setVisible("InfluxDBv2Item", category["InfluxDBv2"]["enabled"]); - for (var j = 1; j <= anzpara; ++j) { - let element = document.getElementById(_cat+"_"+_name+"_value"+j); - if (element.tagName.toLowerCase() == "select") { - var textToFind = _param[_cat][_name]["value"+j]; - if (textToFind == undefined) { - continue; - } - - _isFound = false; - element.selectedIndex = -1; - for (var i = 0; i < element.options.length; i++) { - if (element.options[i].value.toLowerCase() === textToFind.toLowerCase()) { - element.selectedIndex = i; - _isFound = true; - break; - } - } - if (!_isFound) { - _zw_txt = "In the selected field the value '" + textToFind + "' in the section '"; - _zw_txt = _zw_txt + _cat + "' in the field '" + _name + "' is invalid. PLEASE CHECK BEFORE SAVING!"; - firework.launch(_zw_txt, 'warning', 10000); - } + document.getElementById("Category_Webhook_enabled").checked = category["Webhook"]["enabled"]; + setVisible("WebhookItem", category["Webhook"]["enabled"]); - } - else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { - element.checked = _param[_cat][_name]["value"+j] == "true"; - } - else { - element.value = _param[_cat][_name]["value"+j]; - } - } - } + WriteParameter(param, category, "TakeImage", "RawImagesLocation", true); + WriteParameter(param, category, "TakeImage", "RawImagesRetention", true); - ///////////////// am Ende, falls Kategorie als gesamtes nicht ausgewählt --> deaktivieren - if (_category[_cat]["enabled"] == false) { - if (_optional) { - document.getElementById(_cat+"_"+_name+"_enabled").disabled = true; - for (var j = 1; j <= anzpara; ++j) { - document.getElementById(_cat+"_"+_name+"_value"+j).disabled = true; - } - } - document.getElementById(_cat+"_"+_name+"_text").style="color: gray;" - setEnabled(_cat+"_"+_name, false); - } + WriteParameter(param, category, "TakeImage", "WaitBeforeTakingPicture", false); + WriteParameter(param, category, "TakeImage", "CamGainceiling", false); + WriteParameter(param, category, "TakeImage", "CamQuality", false); + WriteParameter(param, category, "TakeImage", "CamBrightness", false); + WriteParameter(param, category, "TakeImage", "CamContrast", false); + WriteParameter(param, category, "TakeImage", "CamSaturation", false); + WriteParameter(param, category, "TakeImage", "CamSharpness", false); + WriteParameter(param, category, "TakeImage", "CamAutoSharpness", false); + WriteParameter(param, category, "TakeImage", "CamSpecialEffect", false); + WriteParameter(param, category, "TakeImage", "CamWbMode", false); + WriteParameter(param, category, "TakeImage", "CamAwb", false); + WriteParameter(param, category, "TakeImage", "CamAwbGain", false); + WriteParameter(param, category, "TakeImage", "CamAec", false); + WriteParameter(param, category, "TakeImage", "CamAec2", false); + WriteParameter(param, category, "TakeImage", "CamAeLevel", false); + WriteParameter(param, category, "TakeImage", "CamAecValue", false); + WriteParameter(param, category, "TakeImage", "CamAgc", false); + WriteParameter(param, category, "TakeImage", "CamAgcGain", false); + WriteParameter(param, category, "TakeImage", "CamBpc", false); + WriteParameter(param, category, "TakeImage", "CamWpc", false); + WriteParameter(param, category, "TakeImage", "CamRawGma", false); + WriteParameter(param, category, "TakeImage", "CamLenc", false); + WriteParameter(param, category, "TakeImage", "CamHmirror", false); + WriteParameter(param, category, "TakeImage", "CamVflip", false); + WriteParameter(param, category, "TakeImage", "CamDcw", false); + WriteParameter(param, category, "TakeImage", "CamDenoise", false); + WriteParameter(param, category, "TakeImage", "CamZoom", false); + WriteParameter(param, category, "TakeImage", "CamZoomOffsetX", false); + WriteParameter(param, category, "TakeImage", "CamZoomOffsetY", false); + WriteParameter(param, category, "TakeImage", "CamZoomSize", false); + WriteParameter(param, category, "TakeImage", "LEDIntensity", false); + WriteParameter(param, category, "TakeImage", "Demo", false); + + WriteParameter(param, category, "Alignment", "SearchFieldX", false); + WriteParameter(param, category, "Alignment", "SearchFieldY", false); + WriteParameter(param, category, "Alignment", "AlignmentAlgo", true); + WriteParameter(param, category, "Alignment", "InitialRotate", false); - EnDisableItem(_category[_cat]["enabled"], _param, _category, _cat, _name, _optional, _number); -} + WriteParameter(param, category, "Digits", "CNNGoodThreshold", true); + WriteParameter(param, category, "Digits", "ROIImagesLocation", true); + WriteParameter(param, category, "Digits", "ROIImagesRetention", true); + + WriteParameter(param, category, "Analog", "ROIImagesLocation", true); + WriteParameter(param, category, "Analog", "ROIImagesRetention", true); + + WriteParameter(param, category, "PostProcessing", "PreValueUse", false); + WriteParameter(param, category, "PostProcessing", "PreValueAgeStartup", true); + WriteParameter(param, category, "PostProcessing", "ErrorMessage", false); + WriteParameter(param, category, "PostProcessing", "CheckDigitIncreaseConsistency", false); + WriteParameter(param, category, "MQTT", "Uri", true); + WriteParameter(param, category, "MQTT", "MainTopic", true); + WriteParameter(param, category, "MQTT", "ClientID", true); + WriteParameter(param, category, "MQTT", "user", true); + WriteParameter(param, category, "MQTT", "password", true); + WriteParameter(param, category, "MQTT", "RetainMessages", false); + WriteParameter(param, category, "MQTT", "HomeassistantDiscovery", false); + WriteParameter(param, category, "MQTT", "MeterType", true); + WriteParameter(param, category, "MQTT", "CACert", true); + WriteParameter(param, category, "MQTT", "ClientCert", true); + WriteParameter(param, category, "MQTT", "ClientKey", true); + + WriteParameter(param, category, "InfluxDB", "Uri", true); + WriteParameter(param, category, "InfluxDB", "Database", true); + // WriteParameter(param, category, "InfluxDB", "Measurement", true); + WriteParameter(param, category, "InfluxDB", "user", true); + WriteParameter(param, category, "InfluxDB", "password", true); + // WriteParameter(param, category, "InfluxDB", "Field", true); -function InvertEnableItem(_cat, _param) { - _zw = _cat + "_" + _param + "_enabled"; - _isOn = document.getElementById(_zw).checked; + WriteParameter(param, category, "InfluxDBv2", "Uri", true); + WriteParameter(param, category, "InfluxDBv2", "Bucket", true); + // WriteParameter(param, category, "InfluxDBv2", "Measurement", true); + WriteParameter(param, category, "InfluxDBv2", "Org", true); + WriteParameter(param, category, "InfluxDBv2", "Token", true); + // WriteParameter(param, category, "InfluxDBv2", "Field", true); - _color = "rgb(122, 122, 122)"; - - if (_isOn) { - _color = "black"; - } + WriteParameter(param, category, "Webhook", "Uri", true); + WriteParameter(param, category, "Webhook", "ApiKey", true); + WriteParameter(param, category, "Webhook", "UploadImg", true); - _zw = _cat + "_" + _param + "_text"; - document.getElementById(_zw).disabled = !_isOn; - document.getElementById(_zw).style.color = _color; + WriteParameter(param, category, "GPIO", "IO0", true); + WriteParameter(param, category, "GPIO", "IO1", true); + WriteParameter(param, category, "GPIO", "IO3", true); + WriteParameter(param, category, "GPIO", "IO4", true); + WriteParameter(param, category, "GPIO", "IO12", true); + WriteParameter(param, category, "GPIO", "IO13", true); + WriteParameter(param, category, "GPIO", "LEDType", false); + WriteParameter(param, category, "GPIO", "LEDNumbers", false); + WriteParameter(param, category, "GPIO", "LEDColor", false); - setEnabled(_cat + "_" + _param, _isOn); + WriteParameter(param, category, "AutoTimer", "AutoStart", false); + WriteParameter(param, category, "AutoTimer", "Interval", false); - for (var j = 1; j <= param[_cat][_param]["anzParam"]; ++j) { - document.getElementById(_cat+"_"+_param+"_value"+j).disabled = !_isOn; - document.getElementById(_cat+"_"+_param+"_value"+j).style.color = _color; - } + WriteParameter(param, category, "DataLogging", "DataLogActive", false); + WriteParameter(param, category, "DataLogging", "DataFilesRetention", false); + + WriteParameter(param, category, "Debug", "LogLevel", false); + WriteParameter(param, category, "Debug", "LogfilesRetention", false); + + WriteParameter(param, category, "System", "Tooltip", false); + WriteParameter(param, category, "System", "TimeZone", true); + WriteParameter(param, category, "System", "Hostname", true); + WriteParameter(param, category, "System", "TimeServer", true); + WriteParameter(param, category, "System", "RSSIThreshold", true); + WriteParameter(param, category, "System", "CPUFrequency", true); + + WriteModelFiles(); } +function WriteModelFiles() { + list_tflite = getTFLITEList(); -function setEnabled(className, enabled) { - _color = "rgb(122, 122, 122)"; - if (enabled) { - _color = "black"; + var _indexDig = document.getElementById("Digits_Model_value1"); + var _indexAna = document.getElementById("Analog_Model_value1"); + + while (_indexDig.length) { + _indexDig.remove(0); + } + + while (_indexAna.length) { + _indexAna.remove(0); } - let elements = document.getElementsByClassName(className); - for (i = 0; i < elements.length; i++) { - if (enabled) { - elements[i].classList.remove("disabled"); - } - else { - elements[i].classList.add("disabled"); + for (var i = 0; i < list_tflite.length; ++i) { + var optionDig = document.createElement("option"); + var optionAna = document.createElement("option"); + + var text = list_tflite[i].replace("/config/", ""); + + if (list_tflite[i].includes("/dig")) { // Its a digital file, only show in the digital list box + optionDig.text = text; + optionDig.value = list_tflite[i]; + _indexDig.add(optionDig); } - - let inputs = elements[i].getElementsByTagName("input"); - for (j = 0; j < inputs.length; j++) { - if (inputs[j].id.endsWith("_enabled")) { - continue; - } - - inputs[j].style.color = _color; - if (enabled) { - inputs[j].removeAttribute("disabled"); - } - else { - inputs[j].setAttribute("disabled", "disabled"); - } + else if (list_tflite[i].includes("/ana")) { // Its a digital file, only show in the analog list box + optionAna.text = text; + optionAna.value = list_tflite[i]; + _indexAna.add(optionAna); + } + else { // all other files, show in both list boxes + optionDig.text = text; + optionDig.value = list_tflite[i]; + _indexDig.add(optionDig); + + optionAna.text = text; + optionAna.value = list_tflite[i]; + _indexAna.add(optionAna); } } + + WriteParameter(param, category, "Analog", "Model", false); + WriteParameter(param, category, "Digits", "Model", false); } +function ReadParameterAll() { + category["Analog"]["enabled"] = document.getElementById("Category_Analog_enabled").checked; + category["Digits"]["enabled"] = document.getElementById("Category_Digits_enabled").checked; + category["MQTT"]["enabled"] = document.getElementById("Category_MQTT_enabled").checked; + category["InfluxDB"]["enabled"] = document.getElementById("Category_InfluxDB_enabled").checked; + category["InfluxDBv2"]["enabled"] = document.getElementById("Category_InfluxDBv2_enabled").checked; + category["Webhook"]["enabled"] = document.getElementById("Category_Webhook_enabled").checked; + category["GPIO"]["enabled"] = document.getElementById("Category_GPIO_enabled").checked; -function setVisible(className, visible) { - let elements = document.getElementsByClassName(className); - for (i = 0; i < elements.length; i++) { - if (visible) { - elements[i].classList.remove("hidden"); - } - else { - elements[i].classList.add("hidden"); - } - } -} + ReadParameter(param, "TakeImage", "RawImagesLocation", true); + ReadParameter(param, "TakeImage", "RawImagesRetention", true); + ReadParameter(param, "TakeImage", "WaitBeforeTakingPicture", false); + ReadParameter(param, "TakeImage", "CamGainceiling", false); + ReadParameter(param, "TakeImage", "CamQuality", false); + ReadParameter(param, "TakeImage", "CamBrightness", false); + ReadParameter(param, "TakeImage", "CamContrast", false); + ReadParameter(param, "TakeImage", "CamSaturation", false); + ReadParameter(param, "TakeImage", "CamSharpness", false); + ReadParameter(param, "TakeImage", "CamAutoSharpness", false); + ReadParameter(param, "TakeImage", "CamSpecialEffect", false); + ReadParameter(param, "TakeImage", "CamWbMode", false); + ReadParameter(param, "TakeImage", "CamAwb", false); + ReadParameter(param, "TakeImage", "CamAwbGain", false); + ReadParameter(param, "TakeImage", "CamAec", false); + ReadParameter(param, "TakeImage", "CamAec2", false); + ReadParameter(param, "TakeImage", "CamAeLevel", false); + ReadParameter(param, "TakeImage", "CamAecValue", false); + ReadParameter(param, "TakeImage", "CamAgc", false); + ReadParameter(param, "TakeImage", "CamAgcGain", false); + ReadParameter(param, "TakeImage", "CamBpc", false); + ReadParameter(param, "TakeImage", "CamWpc", false); + ReadParameter(param, "TakeImage", "CamRawGma", false); + ReadParameter(param, "TakeImage", "CamLenc", false); + ReadParameter(param, "TakeImage", "CamHmirror", false); + ReadParameter(param, "TakeImage", "CamVflip", false); + ReadParameter(param, "TakeImage", "CamDcw", false); + ReadParameter(param, "TakeImage", "CamDenoise", false); + ReadParameter(param, "TakeImage", "CamZoom", false); + ReadParameter(param, "TakeImage", "CamZoomOffsetX", false); + ReadParameter(param, "TakeImage", "CamZoomOffsetY", false); + ReadParameter(param, "TakeImage", "CamZoomSize", false); + ReadParameter(param, "TakeImage", "LEDIntensity", false); + ReadParameter(param, "TakeImage", "Demo", false); + ReadParameter(param, "Alignment", "SearchFieldX", false); + ReadParameter(param, "Alignment", "SearchFieldY", false); + ReadParameter(param, "Alignment", "AlignmentAlgo", true); + ReadParameter(param, "Alignment", "InitialRotate", false); -function EnDisableItem(_status, _param, _category, _cat, _name, _optional, _number = -1) { - _status = _category[_cat]["enabled"]; + ReadParameter(param, "Digits", "Model", false); + ReadParameter(param, "Digits", "CNNGoodThreshold", true); + ReadParameter(param, "Digits", "ROIImagesLocation", true); + ReadParameter(param, "Digits", "ROIImagesRetention", true); - _color = "rgb(122, 122, 122)"; - if (_status) { - _color = "black"; - } + ReadParameter(param, "Analog", "Model", false); + ReadParameter(param, "Analog", "ROIImagesLocation", true); + ReadParameter(param, "Analog", "ROIImagesRetention", true); - if (_optional) { - document.getElementById(_cat+"_"+_name+"_enabled").disabled = !_status; - document.getElementById(_cat+"_"+_name+"_enabled").style.color = _color; - } + ReadParameter(param, "PostProcessing", "PreValueUse", false); + ReadParameter(param, "PostProcessing", "PreValueAgeStartup", true); + ReadParameter(param, "PostProcessing", "ErrorMessage", false); + ReadParameter(param, "PostProcessing", "CheckDigitIncreaseConsistency", false); - if (_number == -1) { - if (!_param[_cat][_name]["enabled"]) { - _status = false; - _color = "rgb(122, 122, 122)"; - } - } - else { - if (!NUMBERS[_number][_cat][_name]["enabled"]) { - _status = false; - _color = "rgb(122, 122, 122)"; - } - } + ReadParameter(param, "MQTT", "Uri", true); + ReadParameter(param, "MQTT", "MainTopic", true); + ReadParameter(param, "MQTT", "ClientID", true); + ReadParameter(param, "MQTT", "user", true); + ReadParameter(param, "MQTT", "password", true); + ReadParameter(param, "MQTT", "RetainMessages", false); + ReadParameter(param, "MQTT", "HomeassistantDiscovery", false); + ReadParameter(param, "MQTT", "MeterType", true); + ReadParameter(param, "MQTT", "CACert", true); + ReadParameter(param, "MQTT", "ClientCert", true); + ReadParameter(param, "MQTT", "ClientKey", true); - document.getElementById(_cat+"_"+_name+"_text").disabled = !_status; - document.getElementById(_cat+"_"+_name+"_text").style.color = _color; + ReadParameter(param, "InfluxDB", "Uri", true); + ReadParameter(param, "InfluxDB", "Database", true); + ReadParameter(param, "InfluxDB", "Measurement", true); + ReadParameter(param, "InfluxDB", "user", true); + ReadParameter(param, "InfluxDB", "password", true); - setEnabled(_cat+"_"+_name, _status); + ReadParameter(param, "InfluxDBv2", "Uri", true); + ReadParameter(param, "InfluxDBv2", "Bucket", true); + ReadParameter(param, "InfluxDBv2", "Measurement", true); + ReadParameter(param, "InfluxDBv2", "Org", true); + ReadParameter(param, "InfluxDBv2", "Token", true); + // ReadParameter(param, "InfluxDB", "Field", true); - for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { - document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_status; - document.getElementById(_cat+"_"+_name+"_value"+j).style.color = _color; - } + ReadParameter(param, "Webhook", "Uri", true); + ReadParameter(param, "Webhook", "ApiKey", true); + ReadParameter(param, "Webhook", "UploadImg", true); + + ReadParameter(param, "GPIO", "IO0", true); + ReadParameter(param, "GPIO", "IO1", true); + ReadParameter(param, "GPIO", "IO3", true); + ReadParameter(param, "GPIO", "IO4", true); + ReadParameter(param, "GPIO", "IO12", true); + ReadParameter(param, "GPIO", "IO13", true); + ReadParameter(param, "GPIO", "LEDType", false); + ReadParameter(param, "GPIO", "LEDNumbers", false); + ReadParameter(param, "GPIO", "LEDColor", false); + + // Folgende Zeilen sind für Abwärtskompatibität < v9.0.0 notwendig (manchmal parameter auskommentiert) + param["GPIO"]["LEDType"]["enabled"] = true; + param["GPIO"]["LEDNumbers"]["enabled"] = true; + param["GPIO"]["LEDColor"]["enabled"] = true; + param["GPIO"]["LEDType"]["found"] = true; + param["GPIO"]["LEDNumbers"]["found"] = true; + param["GPIO"]["LEDColor"]["found"] = true; + + ReadParameter(param, "AutoTimer", "AutoStart", false); + ReadParameter(param, "AutoTimer", "Interval", false); + + ReadParameter(param, "DataLogging", "DataLogActive", false); + ReadParameter(param, "DataLogging", "DataFilesRetention", false); + + ReadParameter(param, "Debug", "LogLevel", false); + ReadParameter(param, "Debug", "LogfilesRetention", false); + + ReadParameter(param, "System", "Tooltip", false); + ReadParameter(param, "System", "TimeZone", true); + ReadParameter(param, "System", "Hostname", true); + ReadParameter(param, "System", "TimeServer", true); + ReadParameter(param, "System", "RSSIThreshold", true); + ReadParameter(param, "System", "CPUFrequency", true); + + var sel = document.getElementById("Numbers_value1"); + UpdateInputIndividual(sel); + + // FormatDecimalValue(param, "PostProcessing", "MaxRateValue"); } +function UpdateAfterCategoryCheck() { + ReadParameterAll(); + category["Analog"]["enabled"] = document.getElementById("Category_Analog_enabled").checked; + category["Digits"]["enabled"] = document.getElementById("Category_Digits_enabled").checked; + category["MQTT"]["enabled"] = document.getElementById("Category_MQTT_enabled").checked; + category["InfluxDB"]["enabled"] = document.getElementById("Category_InfluxDB_enabled").checked; + category["InfluxDBv2"]["enabled"] = document.getElementById("Category_InfluxDBv2_enabled").checked; + category["GPIO"]["enabled"] = document.getElementById("Category_GPIO_enabled").checked; + category["Webhook"]["enabled"] = document.getElementById("Category_Webhook_enabled").checked; -function ReadParameter(_param, _cat, _name, _optional, _number = -1) { - if (_number > -1) { - if (_cat == "Digits") { - _cat = "digit"; - } - - if (_cat == "Analog") { - _cat = "analog"; - } + UpdateInput(); + var sel = document.getElementById("Numbers_value1"); + UpdateInputIndividual(sel); +} - if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined)) { - return; - } +function UpdateExpertModus() { + // var _style = 'display:none;'; + var _style_pur = 'none'; + var _hidden = true; + if (document.getElementById("ExpertModus_enabled").checked) { + // _style = ''; + _style_pur = ''; + _hidden = false; + document.getElementById("Button_Edit_Config_Raw").style.display = ""; + firework.launch("Expert view activated. Please use carefully", 'warning', 5000); + } + else { + document.getElementById("Button_Edit_Config_Raw").style.display = "none"; + } - if (_optional) { - NUMBERS[_number][_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked; - } + const expert = document.querySelectorAll(".expert"); + for (var i = 0; i < expert.length; i++) { + expert[i].style.display = _style_pur; + // document.getElementById(expert[i].id).style = _style; + } - for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { - let element = document.getElementById(_cat+"_"+_name+"_value"+j); - if (element.tagName.toLowerCase() == "select") { - NUMBERS[_number][_cat][_name]["value"+j] = element.selectedIndex > -1 ? element.options[element.selectedIndex].value : ""; - } - else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { - NUMBERS[_number][_cat][_name]["value"+j] = element.checked; - } - else { - if ((NUMBERS[_number][_cat][_name].checkRegExList != null) && (NUMBERS[_number][_cat][_name].checkRegExList[j-1] != null)) { - if (!element.value.match(NUMBERS[_cat][_name].checkRegExList[j-1])) { - element.classList.add("invalid-input"); - } - else { - element.classList.remove("invalid-input"); - } - } - NUMBERS[_number][_cat][_name]["value"+j] = element.value; - } + // Enable / Disable die Optionen in den Menues für die Auswahl. Falls kein Expertenmodus soll nur ein Wert (built-in-led oder externan-flash-ws281x) möglich sein + Array.from(document.querySelector("#GPIO_IO4_value1").options).forEach(function(option_element) { + if (option_element.value != "built-in-led") { + option_element.hidden = _hidden; } - } - else - { - if (_optional) { - _param[_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked; + }); + + Array.from(document.querySelector("#GPIO_IO12_value1").options).forEach(function(option_element) { + if (option_element.value != "external-flash-ws281x") { + option_element.hidden = _hidden; } + }); +} - for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { - let element = document.getElementById(_cat+"_"+_name+"_value"+j); - if (element.tagName.toLowerCase() == "select") { - _param[_cat][_name]["value"+j] = element.selectedIndex > -1 ? element.options[element.selectedIndex].value : ""; - } - else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { - _param[_cat][_name]["value"+j] = element.checked; - } - else { - if ((_param[_cat][_name].checkRegExList != null) && (_param[_cat][_name].checkRegExList[j-1] != null)) { - if (!element.value.match(_param[_cat][_name].checkRegExList[j-1])) { - element.classList.add("invalid-input"); - } - else { - element.classList.remove("invalid-input"); - } - } - _param[_cat][_name]["value"+j] = element.value; - } - } +function UpdateTooltipModus() { + var _style_pur = 'none'; + var _hidden = true; + + if (!document.getElementById("System_Tooltip_value1").selectedIndex) { + _style_pur = ''; + _hidden = false; + //firework.launch("Tooltip view activated.", 'warning', 5000); } -} + const tooltip = document.querySelectorAll(".tooltip"); + + for (var i = 0; i < tooltip.length; i++) { + tooltip[i].style.display = _style_pur; + } +} -function UpdateInputIndividual(sel) { - if (NUNBERSAkt != -1) { - ReadParameter(param, "PostProcessing", "DecimalShift", true, NUNBERSAkt); - ReadParameter(param, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt); - ReadParameter(param, "PostProcessing", "MaxRateValue", true, NUNBERSAkt); - ReadParameter(param, "PostProcessing", "MaxRateType", true, NUNBERSAkt); - ReadParameter(param, "PostProcessing", "ExtendedResolution", false, NUNBERSAkt); - ReadParameter(param, "PostProcessing", "IgnoreLeadingNaN", false, NUNBERSAkt); - ReadParameter(param, "PostProcessing", "AllowNegativeRates", false, NUNBERSAkt); - ReadParameter(param, "InfluxDB", "Field", true, NUNBERSAkt); - ReadParameter(param, "InfluxDBv2", "Field", true, NUNBERSAkt); - ReadParameter(param, "InfluxDB", "Measurement", true, NUNBERSAkt); - ReadParameter(param, "InfluxDBv2", "Measurement", true, NUNBERSAkt); +function saveTextAsFile() { + ReadParameterAll(); + if (document.getElementsByClassName("invalid-input").length > 0) { + firework.launch("Settings cannot be saved. Please check your entries!", 'danger', 30000); + return; } - // var sel = document.getElementById("Numbers_value1"); - NUNBERSAkt = sel.selectedIndex; - WriteParameter(param, category, "PostProcessing", "DecimalShift", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "MaxRateType", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "ExtendedResolution", false, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "IgnoreLeadingNaN", false, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", false, NUNBERSAkt); - WriteParameter(param, category, "InfluxDB", "Field", true, NUNBERSAkt); - WriteParameter(param, category, "InfluxDBv2", "Field", true, NUNBERSAkt); - WriteParameter(param, category, "InfluxDB", "Measurement", true, NUNBERSAkt); - WriteParameter(param, category, "InfluxDBv2", "Measurement", true, NUNBERSAkt); -} + if (confirm("Are you sure you want to save the configuration?")) { + ReadParameterAll(); + WriteConfigININew(); + SaveConfigToServer(domainname); + firework.launch('Configuration saved. It will get applied after the next reboot!', 'success', 5000); -function UpdateInput() { - document.getElementById("Category_Digits_enabled").checked = category["Digits"]["enabled"]; - setVisible("DigitItem", category["Digits"]["enabled"]); + if (changeCamValue == 1) { + camSettingsSet(); + firework.launch('You have changed the camera settings, so creating a new reference image and updating the alignment marks is mandatory!', 'success', 10000); + } + } +} - document.getElementById("Category_Analog_enabled").checked = category["Analog"]["enabled"]; - setVisible("AnalogItem", category["Analog"]["enabled"]); +function camSettingsSet(){ + document.getElementById("overlay").style.display = "block"; + document.getElementById("overlaytext").innerHTML = "Save Cam Settings..."; + + var _waitb_temp = document.getElementById("TakeImage_WaitBeforeTakingPicture_value1").value; - document.getElementById("Category_MQTT_enabled").checked = category["MQTT"]["enabled"]; - setVisible("MQTTItem", category["MQTT"]["enabled"]); + var _aecgc_temp = document.getElementById("TakeImage_CamGainceiling_value1").selectedIndex; + var _qual_temp = document.getElementById("TakeImage_CamQuality_value1").value; + + var _bri_temp = document.getElementById("TakeImage_CamBrightness_value1").value; + var _con_temp = document.getElementById("TakeImage_CamContrast_value1").value; + var _sat_temp = document.getElementById("TakeImage_CamSaturation_value1").value; + var _shp_temp = document.getElementById("TakeImage_CamSharpness_value1").value; + + var _ashp_temp = document.getElementById("TakeImage_CamAutoSharpness_value1").value; + if (_ashp_temp == '0') { + _ashp_temp = '1'; + } + else { + _ashp_temp = '0'; + } - document.getElementById("Category_GPIO_enabled").checked = category["GPIO"]["enabled"]; - setVisible("GPIO_item", category["GPIO"]["enabled"]); + var _spe_temp = document.getElementById("TakeImage_CamSpecialEffect_value1").selectedIndex; + var _wbm_temp = document.getElementById("TakeImage_CamWbMode_value1").selectedIndex; + + var _awb_temp = document.getElementById("TakeImage_CamAwb_value1").selectedIndex; + if (_awb_temp == '0') { + _awb_temp = '1'; + } + else { + _awb_temp = '0'; + } - document.getElementById("Category_InfluxDB_enabled").checked = category["InfluxDB"]["enabled"]; - setVisible("InfluxDBv1Item", category["InfluxDB"]["enabled"]); + var _awbg_temp = document.getElementById("TakeImage_CamAwbGain_value1").selectedIndex; + if (_awbg_temp == '0') { + _awbg_temp = '1'; + } + else { + _awbg_temp = '0'; + } - document.getElementById("Category_InfluxDBv2_enabled").checked = category["InfluxDBv2"]["enabled"]; - setVisible("InfluxDBv2Item", category["InfluxDBv2"]["enabled"]); + var _aec_temp = document.getElementById("TakeImage_CamAec_value1").selectedIndex; + if (_aec_temp == '0') { + _aec_temp = '1'; + } + else { + _aec_temp = '0'; + } + + var _aec2_temp = document.getElementById("TakeImage_CamAec2_value1").selectedIndex; + if (_aec2_temp == '0') { + _aec2_temp = '1'; + } + else { + _aec2_temp = '0'; + } + + var _ael_temp = document.getElementById("TakeImage_CamAeLevel_value1").value; + var _aecv_temp = document.getElementById("TakeImage_CamAecValue_value1").value; - WriteParameter(param, category, "TakeImage", "RawImagesLocation", true); - WriteParameter(param, category, "TakeImage", "RawImagesRetention", true); - WriteParameter(param, category, "TakeImage", "Demo", false); - WriteParameter(param, category, "TakeImage", "WaitBeforeTakingPicture", false); - WriteParameter(param, category, "TakeImage", "ImageQuality", false); - WriteParameter(param, category, "TakeImage", "Brightness", false); - WriteParameter(param, category, "TakeImage", "Contrast", false); - WriteParameter(param, category, "TakeImage", "Saturation", false); - WriteParameter(param, category, "TakeImage", "Sharpness", false); - WriteParameter(param, category, "TakeImage", "LEDIntensity", false); - WriteParameter(param, category, "TakeImage", "ImageSize", false); - WriteParameter(param, category, "TakeImage", "Zoom", false); - WriteParameter(param, category, "TakeImage", "ZoomMode", false); - WriteParameter(param, category, "TakeImage", "ZoomOffsetX", false); - WriteParameter(param, category, "TakeImage", "ZoomOffsetY", false); - WriteParameter(param, category, "TakeImage", "Grayscale", false); - WriteParameter(param, category, "TakeImage", "Negative", false); - WriteParameter(param, category, "TakeImage", "Aec2", false); - WriteParameter(param, category, "TakeImage", "AutoExposureLevel", false); - WriteParameter(param, category, "TakeImage", "FixedExposure", false); + var _agc_temp = document.getElementById("TakeImage_CamAgc_value1").selectedIndex; + if (_agc_temp == '0') { + _agc_temp = '1'; + } + else { + _agc_temp = '0'; + } + + var _agcg_temp = document.getElementById("TakeImage_CamAgcGain_value1").value; + + var _bpc_temp = document.getElementById("TakeImage_CamBpc_value1").selectedIndex; + if (_bpc_temp == '0') { + _bpc_temp = '1'; + } + else { + _bpc_temp = '0'; + } + + var _wpc_temp = document.getElementById("TakeImage_CamWpc_value1").selectedIndex; + if (_wpc_temp == '0') { + _wpc_temp = '1'; + } + else { + _wpc_temp = '0'; + } + + var _rgma_temp = document.getElementById("TakeImage_CamRawGma_value1").selectedIndex; + if (_rgma_temp == '0') { + _rgma_temp = '1'; + } + else { + _rgma_temp = '0'; + } + + var _lenc_temp = document.getElementById("TakeImage_CamLenc_value1").selectedIndex; + if (_lenc_temp == '0') { + _lenc_temp = '1'; + } + else { + _lenc_temp = '0'; + } - WriteParameter(param, category, "Alignment", "SearchFieldX", false); - WriteParameter(param, category, "Alignment", "SearchFieldY", false); - WriteParameter(param, category, "Alignment", "AlignmentAlgo", true); - WriteParameter(param, category, "Alignment", "FlipImageSize", false); - WriteParameter(param, category, "Alignment", "InitialMirror", false); - WriteParameter(param, category, "Alignment", "InitialRotate", false); + var _mirror_temp = document.getElementById("TakeImage_CamHmirror_value1").selectedIndex; + if (_mirror_temp == '0') { + _mirror_temp = '1'; + } + else { + _mirror_temp = '0'; + } + + var _flip_temp = document.getElementById("TakeImage_CamVflip_value1").selectedIndex; + if (_flip_temp == '0') { + _flip_temp = '1'; + } + else { + _flip_temp = '0'; + } + + var _dcw_temp = document.getElementById("TakeImage_CamDcw_value1").selectedIndex; + if (_dcw_temp == '0') { + _dcw_temp = '1'; + } + else { + _dcw_temp = '0'; + } - WriteParameter(param, category, "Digits", "CNNGoodThreshold", true); - WriteParameter(param, category, "Digits", "ROIImagesLocation", true); - WriteParameter(param, category, "Digits", "ROIImagesRetention", true); - - WriteParameter(param, category, "Analog", "ROIImagesLocation", true); - WriteParameter(param, category, "Analog", "ROIImagesRetention", true); - - WriteParameter(param, category, "PostProcessing", "PreValueUse", false); - WriteParameter(param, category, "PostProcessing", "PreValueAgeStartup", true); - // WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", true); - WriteParameter(param, category, "PostProcessing", "ErrorMessage", false); - WriteParameter(param, category, "PostProcessing", "CheckDigitIncreaseConsistency", false); + var _denoise_temp = document.getElementById("TakeImage_CamDenoise_value1").value; - WriteParameter(param, category, "MQTT", "Uri", true); - WriteParameter(param, category, "MQTT", "MainTopic", true); - WriteParameter(param, category, "MQTT", "ClientID", true); - WriteParameter(param, category, "MQTT", "user", true); - WriteParameter(param, category, "MQTT", "password", true); - WriteParameter(param, category, "MQTT", "RetainMessages", false); - WriteParameter(param, category, "MQTT", "HomeassistantDiscovery", false); - WriteParameter(param, category, "MQTT", "MeterType", true); - WriteParameter(param, category, "MQTT", "CACert", true); - WriteParameter(param, category, "MQTT", "ClientCert", true); - WriteParameter(param, category, "MQTT", "ClientKey", true); - - WriteParameter(param, category, "InfluxDB", "Uri", true); - WriteParameter(param, category, "InfluxDB", "Database", true); - // WriteParameter(param, category, "InfluxDB", "Measurement", true); - WriteParameter(param, category, "InfluxDB", "user", true); - WriteParameter(param, category, "InfluxDB", "password", true); - // WriteParameter(param, category, "InfluxDB", "Field", true); + var _ledi_temp = document.getElementById("TakeImage_LEDIntensity_value1").value; - WriteParameter(param, category, "InfluxDBv2", "Uri", true); - WriteParameter(param, category, "InfluxDBv2", "Bucket", true); - // WriteParameter(param, category, "InfluxDBv2", "Measurement", true); - WriteParameter(param, category, "InfluxDBv2", "Org", true); - WriteParameter(param, category, "InfluxDBv2", "Token", true); - // WriteParameter(param, category, "InfluxDBv2", "Field", true); + var _zoom_temp = document.getElementById("TakeImage_CamZoom_value1").selectedIndex; + if (_zoom_temp == '0') { + _zoom_temp = '1'; + } + else { + _zoom_temp = '0'; + } - WriteParameter(param, category, "GPIO", "IO0", true); - WriteParameter(param, category, "GPIO", "IO1", true); - WriteParameter(param, category, "GPIO", "IO3", true); - WriteParameter(param, category, "GPIO", "IO4", true); - WriteParameter(param, category, "GPIO", "IO12", true); - WriteParameter(param, category, "GPIO", "IO13", true); - WriteParameter(param, category, "GPIO", "LEDType", false); - WriteParameter(param, category, "GPIO", "LEDNumbers", false); - WriteParameter(param, category, "GPIO", "LEDColor", false); + var _zoomx_temp = document.getElementById("TakeImage_CamZoomOffsetX_value1").value; + var _zoomy_temp = document.getElementById("TakeImage_CamZoomOffsetY_value1").value; + var _zooms_temp = document.getElementById("TakeImage_CamZoomSize_value1").value; + + var url = domainname + "/editflow?task=cam_settings"; + + if (domainname.length > 0){ + url = url + "&host=" + domainname; + } + + url = url + "&waitb=" + _waitb_temp + "&aecgc=" + _aecgc_temp + "&qual=" + _qual_temp; + url = url + "&bri=" + _bri_temp + "&con=" + _con_temp + "&sat=" + _sat_temp + "&shp=" + _shp_temp + "&ashp=" + _ashp_temp; + url = url + "&spe=" + _spe_temp + "&wbm=" + _wbm_temp + "&awb=" + _awb_temp + "&awbg=" + _awbg_temp; + url = url + "&aec=" + _aec_temp + "&aec2=" + _aec2_temp + "&ael=" + _ael_temp + "&aecv=" + _aecv_temp; + + url = url + "&agc=" + _agc_temp + "&agcg=" + _agcg_temp + "&bpc=" + _bpc_temp + "&wpc=" + _wpc_temp; + url = url + "&rgma=" + _rgma_temp + "&lenc=" + _lenc_temp + "&mirror=" + _mirror_temp + "&flip=" + _flip_temp; + url = url + "&dcw=" + _dcw_temp + "&den=" + _denoise_temp + "&ledi=" + _ledi_temp; + + if (_zoom_temp != '0') { + url = url + "&zoom=" + _zoom_temp + "&zooms=" + _zooms_temp; + url = url + "&zoomx=" + _zoomx_temp + "&zoomy=" + _zoomy_temp; + } + else { + url = url + "&zoom=0" + "&zooms=0" + "&zoomx=0" + "&zoomy=0"; + } - WriteParameter(param, category, "AutoTimer", "AutoStart", false); - WriteParameter(param, category, "AutoTimer", "Interval", false); + var durchlaufe = 0; - WriteParameter(param, category, "DataLogging", "DataLogActive", false); - WriteParameter(param, category, "DataLogging", "DataFilesRetention", false); + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + async function task() { + while (true) { + var xhttp = new XMLHttpRequest(); + + if (durchlaufe > 10) { + document.getElementById("overlay").style.display = "none"; + firework.launch('Save Cam Settings aborted, timeout!', 'danger', 5000); + return; + } + + try { + xhttp.open("GET", url, false); + xhttp.send(); + } catch (error){} + + if (xhttp.responseText == "CamSettingsSet") { + document.getElementById("overlay").style.display = "none"; + firework.launch('Cam Settings saved', 'success', 2000); + return; + } + else { + // Get status + var _xhttp = new XMLHttpRequest(); + durchlaufe = durchlaufe + 1; + + try { + _xhttp.open("GET", domainname + "/statusflow", false); + _xhttp.send(); + } + catch (error){} - WriteParameter(param, category, "Debug", "LogLevel", false); - WriteParameter(param, category, "Debug", "LogfilesRetention", false); + document.getElementById("overlaytext").innerHTML = "Device is busy, plase waiting...

Current step: " + _xhttp.responseText; + console.log("Device is busy, waiting 2s then checking again..."); + await sleep(2000); + } + } + } - WriteParameter(param, category, "System", "TimeZone", true); - WriteParameter(param, category, "System", "Hostname", true); - WriteParameter(param, category, "System", "TimeServer", true); - WriteParameter(param, category, "System", "RSSIThreshold", true); - WriteParameter(param, category, "System", "CPUFrequency", true); + setTimeout(function() { + // Delay so the overlay gets shown + task(); + }, 1); +} + +function doReboot() { + if (confirm("Are you sure you want to reboot?")) { + var stringota = domainname + "/reboot"; + window.location = stringota; + window.location.href = stringota; + window.location.assign(stringota); + window.location.replace(stringota); + } +} - WriteModelFiles(); +function FormatDecimalValue(_param, _cat, _name) { + for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { + var _val = _param[_cat][_name]["value"+j]; + _val = _val.replace(",", "."); + _param[_cat][_name]["value"+j] = _val; + } } +function editConfigRaw() { + if (confirm("Proceed to switch to raw edit mode? Unsaved changes will get lost")) { + var stringota = domainname + "/edit_config_raw.html?v=$COMMIT_HASH"; + window.location = stringota; + window.location.href = stringota; + window.location.assign(stringota); + window.location.replace(stringota); + } +} -function WriteModelFiles() { - list_tflite = getTFLITEList(); +function numberChanged() { + var sel = document.getElementById("Numbers_value1"); + _neu = sel.selectedIndex; + UpdateInputIndividual(sel); - var _indexDig = document.getElementById("Digits_Model_value1"); - var _indexAna = document.getElementById("Analog_Model_value1"); - - while (_indexDig.length) { - _indexDig.remove(0); - } - - while (_indexAna.length) { - _indexAna.remove(0); + var _selInflux = document.getElementById("NumbersInfluxDBv2_value1"); + if (_selInflux.selectedIndex != _neu) { + _selInflux.selectedIndex = _neu } +} + +function numberInfluxDBv2Changed() { + var sel = document.getElementById("NumbersInfluxDBv2_value1"); + _neu = sel.selectedIndex; + UpdateInputIndividual(sel); - for (var i = 0; i < list_tflite.length; ++i) { - var optionDig = document.createElement("option"); - var optionAna = document.createElement("option"); - - var text = list_tflite[i].replace("/config/", ""); - - if (list_tflite[i].includes("/dig")) { // Its a digital file, only show in the digital list box - optionDig.text = text; - optionDig.value = list_tflite[i]; - _indexDig.add(optionDig); - } - else if (list_tflite[i].includes("/ana")) { // Its a digital file, only show in the analog list box - optionAna.text = text; - optionAna.value = list_tflite[i]; - _indexAna.add(optionAna); - } - else { // all other files, show in both list boxes - optionDig.text = text; - optionDig.value = list_tflite[i]; - _indexDig.add(optionDig); - - optionAna.text = text; - optionAna.value = list_tflite[i]; - _indexAna.add(optionAna); - } + var _sel2 = document.getElementById("Numbers_value1"); + if (_sel2.selectedIndex != _neu) { + _sel2.selectedIndex = _neu } - WriteParameter(param, category, "Analog", "Model", false); - WriteParameter(param, category, "Digits", "Model", false); + var _sel3 = document.getElementById("NumbersInfluxDB_value1"); + if (_sel3.selectedIndex != _neu) { + _sel3.selectedIndex = _neu + } } - -function ReadParameterAll() { - category["Analog"]["enabled"] = document.getElementById("Category_Analog_enabled").checked; - category["Digits"]["enabled"] = document.getElementById("Category_Digits_enabled").checked; - category["MQTT"]["enabled"] = document.getElementById("Category_MQTT_enabled").checked; - category["InfluxDB"]["enabled"] = document.getElementById("Category_InfluxDB_enabled").checked; - category["InfluxDBv2"]["enabled"] = document.getElementById("Category_InfluxDBv2_enabled").checked; - category["GPIO"]["enabled"] = document.getElementById("Category_GPIO_enabled").checked; +function numberInfluxDBChanged() { + var sel = document.getElementById("NumbersInfluxDB_value1"); + _neu = sel.selectedIndex; + UpdateInputIndividual(sel); - ReadParameter(param, "TakeImage", "RawImagesLocation", true); - ReadParameter(param, "TakeImage", "RawImagesRetention", true); - ReadParameter(param, "TakeImage", "Demo", false); - ReadParameter(param, "TakeImage", "WaitBeforeTakingPicture", false); - ReadParameter(param, "TakeImage", "ImageQuality", false); - ReadParameter(param, "TakeImage", "Brightness", false); - ReadParameter(param, "TakeImage", "Contrast", false); - ReadParameter(param, "TakeImage", "Saturation", false); - ReadParameter(param, "TakeImage", "Sharpness", false); - ReadParameter(param, "TakeImage", "LEDIntensity", false); - ReadParameter(param, "TakeImage", "ImageSize", false); - ReadParameter(param, "TakeImage", "Zoom", false); - ReadParameter(param, "TakeImage", "ZoomMode", false); - ReadParameter(param, "TakeImage", "ZoomOffsetX", false); - ReadParameter(param, "TakeImage", "ZoomOffsetY", false); - ReadParameter(param, "TakeImage", "Grayscale", false); - ReadParameter(param, "TakeImage", "Negative", false); - ReadParameter(param, "TakeImage", "Aec2", false); - ReadParameter(param, "TakeImage", "AutoExposureLevel", false); - ReadParameter(param, "TakeImage", "FixedExposure", false); + var _sel2 = document.getElementById("Numbers_value1"); + if (_sel2.selectedIndex != _neu) { + _sel2.selectedIndex = _neu + } - ReadParameter(param, "Alignment", "SearchFieldX", false); - ReadParameter(param, "Alignment", "SearchFieldY", false); - ReadParameter(param, "Alignment", "AlignmentAlgo", true); - ReadParameter(param, "Alignment", "FlipImageSize", false); - ReadParameter(param, "Alignment", "InitialMirror", false); - ReadParameter(param, "Alignment", "InitialRotate", false); + var _sel3 = document.getElementById("NumbersInfluxDBv2_value1"); + if (_sel3.selectedIndex != _neu) { + _sel3.selectedIndex = _neu + } +} - ReadParameter(param, "Digits", "Model", false); - ReadParameter(param, "Digits", "CNNGoodThreshold", true); - ReadParameter(param, "Digits", "ROIImagesLocation", true); - ReadParameter(param, "Digits", "ROIImagesRetention", true); +function getParameterByName(name, url = window.location.href) { + name = name.replace(/[\[\]]/g, '\\$&'); + var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), + results = regex.exec(url); - ReadParameter(param, "Analog", "Model", false); - ReadParameter(param, "Analog", "ROIImagesLocation", true); - ReadParameter(param, "Analog", "ROIImagesRetention", true); + if (!results) {return null;} + if (!results[2]) {return '';} + + return decodeURIComponent(results[2].replace(/\+/g, ' ')); +} - ReadParameter(param, "PostProcessing", "PreValueUse", false); - ReadParameter(param, "PostProcessing", "PreValueAgeStartup", true); - ReadParameter(param, "PostProcessing", "ErrorMessage", false); - ReadParameter(param, "PostProcessing", "CheckDigitIncreaseConsistency", false); +function InvertEnableItem(_cat, _param) { + _zw = _cat + "_" + _param + "_enabled"; + _isOn = document.getElementById(_zw).checked; - ReadParameter(param, "MQTT", "Uri", true); - ReadParameter(param, "MQTT", "MainTopic", true); - ReadParameter(param, "MQTT", "ClientID", true); - ReadParameter(param, "MQTT", "user", true); - ReadParameter(param, "MQTT", "password", true); - ReadParameter(param, "MQTT", "RetainMessages", false); - ReadParameter(param, "MQTT", "HomeassistantDiscovery", false); - ReadParameter(param, "MQTT", "MeterType", true); - ReadParameter(param, "MQTT", "CACert", true); - ReadParameter(param, "MQTT", "ClientCert", true); - ReadParameter(param, "MQTT", "ClientKey", true); + _color = "rgb(122, 122, 122)"; + + if (_isOn) { + _color = "black"; + } - ReadParameter(param, "InfluxDB", "Uri", true); - ReadParameter(param, "InfluxDB", "Database", true); - ReadParameter(param, "InfluxDB", "Measurement", true); - ReadParameter(param, "InfluxDB", "user", true); - ReadParameter(param, "InfluxDB", "password", true); + _zw = _cat + "_" + _param + "_text"; + document.getElementById(_zw).disabled = !_isOn; + document.getElementById(_zw).style.color = _color; - ReadParameter(param, "InfluxDBv2", "Uri", true); - ReadParameter(param, "InfluxDBv2", "Bucket", true); - ReadParameter(param, "InfluxDBv2", "Measurement", true); - ReadParameter(param, "InfluxDBv2", "Org", true); - ReadParameter(param, "InfluxDBv2", "Token", true); - // ReadParameter(param, "InfluxDB", "Field", true); + setEnabled(_cat + "_" + _param, _isOn); - ReadParameter(param, "GPIO", "IO0", true); - ReadParameter(param, "GPIO", "IO1", true); - ReadParameter(param, "GPIO", "IO3", true); - ReadParameter(param, "GPIO", "IO4", true); - ReadParameter(param, "GPIO", "IO12", true); - ReadParameter(param, "GPIO", "IO13", true); - ReadParameter(param, "GPIO", "LEDType", false); - ReadParameter(param, "GPIO", "LEDNumbers", false); - ReadParameter(param, "GPIO", "LEDColor", false); - // Folgende Zeilen sind für Abwärtskompatibität < v9.0.0 notwendig (manchmal parameter auskommentiert) - param["GPIO"]["LEDType"]["enabled"] = true; - param["GPIO"]["LEDNumbers"]["enabled"] = true; - param["GPIO"]["LEDColor"]["enabled"] = true; - param["GPIO"]["LEDType"]["found"] = true; - param["GPIO"]["LEDNumbers"]["found"] = true; - param["GPIO"]["LEDColor"]["found"] = true; + for (var j = 1; j <= param[_cat][_param]["anzParam"]; ++j) { + document.getElementById(_cat+"_"+_param+"_value"+j).disabled = !_isOn; + document.getElementById(_cat+"_"+_param+"_value"+j).style.color = _color; + } +} - ReadParameter(param, "AutoTimer", "AutoStart", false); - ReadParameter(param, "AutoTimer", "Interval", false); - - ReadParameter(param, "DataLogging", "DataLogActive", false); - ReadParameter(param, "DataLogging", "DataFilesRetention", false); +function setEnabled(className, enabled) { + _color = "rgb(122, 122, 122)"; + + if (enabled) { + _color = "black"; + } - ReadParameter(param, "Debug", "LogLevel", false); - ReadParameter(param, "Debug", "LogfilesRetention", false); + let elements = document.getElementsByClassName(className); + for (i = 0; i < elements.length; i++) { + if (enabled) { + elements[i].classList.remove("disabled"); + } + else { + elements[i].classList.add("disabled"); + } - ReadParameter(param, "System", "TimeZone", true); - ReadParameter(param, "System", "Hostname", true); - ReadParameter(param, "System", "TimeServer", true); - ReadParameter(param, "System", "RSSIThreshold", true); - ReadParameter(param, "System", "CPUFrequency", true); + let inputs = elements[i].getElementsByTagName("input"); + for (j = 0; j < inputs.length; j++) { + if (inputs[j].id.endsWith("_enabled")) { + continue; + } - var sel = document.getElementById("Numbers_value1"); - UpdateInputIndividual(sel); - - // FormatDecimalValue(param, "PostProcessing", "MaxRateValue"); + inputs[j].style.color = _color; + if (enabled) { + inputs[j].removeAttribute("disabled"); + } + else { + inputs[j].setAttribute("disabled", "disabled"); + } + } + } } - -function FormatDecimalValue(_param, _cat, _name) { - for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { - var _val = _param[_cat][_name]["value"+j]; - _val = _val.replace(",", "."); - _param[_cat][_name]["value"+j] = _val; +function setVisible(className, visible) { + let elements = document.getElementsByClassName(className); + + for (i = 0; i < elements.length; i++) { + if (visible) { + elements[i].classList.remove("hidden"); + } + else { + elements[i].classList.add("hidden"); + } } } +function EnDisableItem(_status, _param, _category, _cat, _name, _optional, _number = -1) { + // _status = _category[_cat]["enabled"]; -function UpdateAfterCategoryCheck() { - ReadParameterAll(); - category["Analog"]["enabled"] = document.getElementById("Category_Analog_enabled").checked; - category["Digits"]["enabled"] = document.getElementById("Category_Digits_enabled").checked; - category["MQTT"]["enabled"] = document.getElementById("Category_MQTT_enabled").checked; - category["InfluxDB"]["enabled"] = document.getElementById("Category_InfluxDB_enabled").checked; - category["InfluxDBv2"]["enabled"] = document.getElementById("Category_InfluxDBv2_enabled").checked; - category["GPIO"]["enabled"] = document.getElementById("Category_GPIO_enabled").checked; - - UpdateInput(); - var sel = document.getElementById("Numbers_value1"); - UpdateInputIndividual(sel); -} + _color = "rgb(122, 122, 122)"; + + if (_status) { + _color = "black"; + } + if (_optional) { + document.getElementById(_cat+"_"+_name+"_enabled").disabled = !_status; + document.getElementById(_cat+"_"+_name+"_enabled").style.color = _color; + } -function UpdateExpertModus() { - // var _style = 'display:none;'; - var _style_pur = 'none'; - var _hidden = true; - if (document.getElementById("ExpertModus_enabled").checked) { - // _style = ''; - _style_pur = ''; - _hidden = false; - document.getElementById("Button_Edit_Config_Raw").style.display = ""; - firework.launch("Expert view activated. Please use carefully", 'warning', 5000); + if (_number == -1) { + if (!_param[_cat][_name]["enabled"]) { + _status = false; + _color = "rgb(122, 122, 122)"; + } } else { - document.getElementById("Button_Edit_Config_Raw").style.display = "none"; + if (!NUMBERS[_number][_cat][_name]["enabled"]) { + _status = false; + _color = "rgb(122, 122, 122)"; + } } - const expert = document.querySelectorAll(".expert"); - for (var i = 0; i < expert.length; i++) { - expert[i].style.display = _style_pur; - // document.getElementById(expert[i].id).style = _style; + document.getElementById(_cat+"_"+_name+"_text").disabled = !_status; + document.getElementById(_cat+"_"+_name+"_text").style.color = _color; + + setEnabled(_cat+"_"+_name, _status); + + for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { + document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_status; + document.getElementById(_cat+"_"+_name+"_value"+j).style.color = _color; } +} - // Enable / Disable die Optionen in den Menues für die Auswahl. Falls kein Expertenmodus soll nur ein Wert (built-in-led oder externan-flash-ws281x) möglich sein - Array.from(document.querySelector("#GPIO_IO4_value1").options).forEach(function(option_element) { - if (option_element.value != "built-in-led") { - option_element.hidden = _hidden; +function ReadParameter(_param, _cat, _name, _optional, _number = -1) { + if (_number > -1) { + if (_cat == "Digits") { + _cat = "digit"; + } + + if (_cat == "Analog") { + _cat = "analog"; } - }); - Array.from(document.querySelector("#GPIO_IO12_value1").options).forEach(function(option_element) { - if (option_element.value != "external-flash-ws281x") { - option_element.hidden = _hidden; + if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined)) { + return; } - }); -} + if (_optional) { + NUMBERS[_number][_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked; + } -function saveTextAsFile() { - ReadParameterAll(); - if (document.getElementsByClassName("invalid-input").length > 0) { - firework.launch("Settings cannot be saved. Please check your entries!", 'danger', 30000); - return; + for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { + let element = document.getElementById(_cat+"_"+_name+"_value"+j); + + if (element.tagName.toLowerCase() == "select") { + NUMBERS[_number][_cat][_name]["value"+j] = element.selectedIndex > -1 ? element.options[element.selectedIndex].value : ""; + } + else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { + NUMBERS[_number][_cat][_name]["value"+j] = element.checked; + } + else { + if ((NUMBERS[_number][_cat][_name].checkRegExList != null) && (NUMBERS[_number][_cat][_name].checkRegExList[j-1] != null)) { + if (!element.value.match(NUMBERS[_cat][_name].checkRegExList[j-1])) { + element.classList.add("invalid-input"); + } + else { + element.classList.remove("invalid-input"); + } + } + + NUMBERS[_number][_cat][_name]["value"+j] = element.value; + } + } } + else + { + if (_optional) { + _param[_cat][_name]["enabled"] = document.getElementById(_cat+"_"+_name+"_enabled").checked; + } - if (confirm("Are you sure you want to save the configuration?")) { - ReadParameterAll(); - WriteConfigININew(); - SaveConfigToServer(domainname); - - firework.launch('Configuration saved. It will get applied after the next reboot!', 'success', 5000); - - if (changeCamValue == 1) { - firework.launch('You have changed the camera settings, so creating a new reference image and updating the alignment marks is mandatory!', 'success', 10000); - } + for (var j = 1; j <= _param[_cat][_name]["anzParam"]; ++j) { + let element = document.getElementById(_cat+"_"+_name+"_value"+j); + + if (element.tagName.toLowerCase() == "select") { + _param[_cat][_name]["value"+j] = element.selectedIndex > -1 ? element.options[element.selectedIndex].value : ""; + } + else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { + _param[_cat][_name]["value"+j] = element.checked; + } + else { + if ((_param[_cat][_name].checkRegExList != null) && (_param[_cat][_name].checkRegExList[j-1] != null)) { + if (!element.value.match(_param[_cat][_name].checkRegExList[j-1])) { + element.classList.add("invalid-input"); + } + else { + element.classList.remove("invalid-input"); + } + } + + _param[_cat][_name]["value"+j] = element.value; + } + } } } - -function doReboot() { - if (confirm("Are you sure you want to reboot?")) { - var stringota = getDomainname() + "/reboot"; - window.location = stringota; - window.location.href = stringota; - window.location.assign(stringota); - window.location.replace(stringota); +function WriteParameter(_param, _category, _cat, _name, _optional, _number = -1) { + let anzpara; + try { + anzpara = _param[_cat][_name].anzParam; + } + catch (error) { + firework.launch("Parameter '" + _name + "' in category '" + _cat + "' is unknown!", 'danger', 30000); + return; } -} - -function editConfigRaw() { - if (confirm("Proceed to switch to raw edit mode? Unsaved changes will get lost")) { - var stringota = getDomainname() + "/edit_config_raw.html?v=$COMMIT_HASH"; - window.location = stringota; - window.location.href = stringota; - window.location.assign(stringota); - window.location.replace(stringota); - } -} + if (_number > -1) { + if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined)) { + return; + } + if (_optional) { + document.getElementById(_cat+"_"+_name+"_enabled").checked = NUMBERS[_number][_cat][_name]["enabled"]; + + for (var j = 1; j <= anzpara; ++j) { + document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !NUMBERS[_number][_cat][_name]["enabled"]; + } + } + + document.getElementById(_cat+"_"+_name+"_text").style.color = "black" + setEnabled(_cat+"_"+_name, true); -function numberChanged() { - var sel = document.getElementById("Numbers_value1"); - _neu = sel.selectedIndex; - UpdateInputIndividual(sel); + for (var j = 1; j <= anzpara; ++j) { + let element = document.getElementById(_cat+"_"+_name+"_value"+j); + + if (element.tagName.toLowerCase() == "select") { + var textToFind = NUMBERS[_number][_cat][_name]["value"+j]; + + if (textToFind == undefined) { + continue; + } - var _selInflux = document.getElementById("NumbersInfluxDBv2_value1"); - if (_selInflux.selectedIndex != _neu) { - _selInflux.selectedIndex = _neu + _isFound = false; + element.selectedIndex = -1; + + for (var i = 0; i < element.options.length; i++) { + if (element.options[i].value.toLowerCase() === textToFind.toLowerCase()) { + element.selectedIndex = i; + _isFound = true; + break; + } + } + + if (!_isFound) { + _zw_txt = "In the selected field the value '" + textToFind + "' in the parameter '"; + _zw_txt = _zw_txt + _cat + "' in the field '" + _name + "' is invalid. PLEASE CHECK BEFORE SAVING!"; + firework.launch(_zw_txt, 'warning', 10000); + } + } + else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { + element.checked = NUMBERS[_number][_cat][_name]["value"+j] == "true"; + } + else { + element.value = NUMBERS[_number][_cat][_name]["value"+j]; + } + } } -} - - -function numberInfluxDBv2Changed() { - var sel = document.getElementById("NumbersInfluxDBv2_value1"); - _neu = sel.selectedIndex; - UpdateInputIndividual(sel); + else { + if (_optional) { + document.getElementById(_cat+"_"+_name+"_enabled").checked = _param[_cat][_name]["enabled"]; + + for (var j = 1; j <= anzpara; ++j) { + document.getElementById(_cat+"_"+_name+"_value"+j).disabled = !_param[_cat][_name]["enabled"]; + } + } + + document.getElementById(_cat+"_"+_name+"_text").style.color = "black" + setEnabled(_cat+"_"+_name, true); - var _sel2 = document.getElementById("Numbers_value1"); - if (_sel2.selectedIndex != _neu) { - _sel2.selectedIndex = _neu - } + for (var j = 1; j <= anzpara; ++j) { + let element = document.getElementById(_cat+"_"+_name+"_value"+j); + + if (element.tagName.toLowerCase() == "select") { + var textToFind = _param[_cat][_name]["value"+j]; + + if (textToFind == undefined) { + continue; + } + + _isFound = false; + element.selectedIndex = -1; + + for (var i = 0; i < element.options.length; i++) { + if (element.options[i].value.toLowerCase() === textToFind.toLowerCase()) { + element.selectedIndex = i; + _isFound = true; + break; + } + } + + if (!_isFound) { + _zw_txt = "In the selected field the value '" + textToFind + "' in the section '"; + _zw_txt = _zw_txt + _cat + "' in the field '" + _name + "' is invalid. PLEASE CHECK BEFORE SAVING!"; + firework.launch(_zw_txt, 'warning', 10000); + } - var _sel3 = document.getElementById("NumbersInfluxDB_value1"); - if (_sel3.selectedIndex != _neu) { - _sel3.selectedIndex = _neu + } + else if ((element.getAttribute("type") != null) && (element.getAttribute("type").toLowerCase() == "checkbox")) { + element.checked = _param[_cat][_name]["value"+j] == "true"; + } + else { + element.value = _param[_cat][_name]["value"+j]; + } + } } -} - -function numberInfluxDBChanged() { - var sel = document.getElementById("NumbersInfluxDB_value1"); - _neu = sel.selectedIndex; - UpdateInputIndividual(sel); - - var _sel2 = document.getElementById("Numbers_value1"); - if (_sel2.selectedIndex != _neu) { - _sel2.selectedIndex = _neu + ///////////////// am Ende, falls Kategorie als gesamtes nicht ausgewählt --> deaktivieren + if (_category[_cat]["enabled"] == false) { + if (_optional) { + document.getElementById(_cat+"_"+_name+"_enabled").disabled = true; + + for (var j = 1; j <= anzpara; ++j) { + document.getElementById(_cat+"_"+_name+"_value"+j).disabled = true; + } + } + + document.getElementById(_cat+"_"+_name+"_text").style="color: gray;" + setEnabled(_cat+"_"+_name, false); } - var _sel3 = document.getElementById("NumbersInfluxDBv2_value1"); - if (_sel3.selectedIndex != _neu) { - _sel3.selectedIndex = _neu - } + EnDisableItem(_category[_cat]["enabled"], _param, _category, _cat, _name, _optional, _number); } - /* hash #description open the details part of the page */ function openDescription() { if(window.location.hash) { var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character + if(hash == 'description') { document.getElementById("desc_details").open = true; document.getElementById("reboot").style.display = "none"; @@ -2641,6 +3238,5 @@

Digit ROI

} var _index = document.getElementById("index"); + while (_index.length){ _index.remove(0); } @@ -582,7 +553,7 @@

Digit ROI

if(window.location.hash) { var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character if(hash == 'description') { - document.getElementById("desc_details").open = true; + document.getElementById("desc_details").open = false; } } } @@ -590,14 +561,21 @@

Digit ROI

function init() { openDescription(); domainname = getDomainname(); - canvas.addEventListener('mousedown', mouseDown, false); - canvas.addEventListener('mouseup', mouseUp, false); - canvas.addEventListener('mousemove', mouseMove, false); - loadCanvas(domainname + "/fileserver/config/reference.jpg"); - loadConfig(domainname); + + if (!loadConfig(domainname)) { + firework.launch('Configuration could not be loaded! Please reload the page!', 'danger', 30000); + return; + } + ParseConfig(); param = getConfigParameters(); cofcat = getConfigCategory(); + + canvas.addEventListener('mousedown', mouseDown, false); + canvas.addEventListener('mouseup', mouseUp, false); + canvas.addEventListener('mousemove', mouseMove, false); + loadCanvas(domainname + "/fileserver/config/reference.jpg"); + UpdateNUMBERS(); /* Check if the ROIs are equidistant. Only if not, untick the checkbox */ @@ -717,6 +695,7 @@

Digit ROI

} erg = CreateNUMBER(_numbernew); + if (erg != "") { firework.launch(erg, 'danger', 30000); } @@ -844,14 +823,17 @@

Digit ROI

function mouseUp() { drag = false; + if (rect.w < 0) { rect.w = -rect.w rect.startX-=rect.w } + if (rect.h < 0) { rect.h = -rect.h rect.startY-=rect.h } + document.getElementById("refdx").value = rect.w; document.getElementById("refdy").value = rect.h; document.getElementById("refx").value = rect.startX; @@ -876,10 +858,12 @@

Digit ROI

} document.getElementById("refdx").value = rect.w; document.getElementById("refdy").value = rect.h; + draw(); } else { draw(); + var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); @@ -915,10 +899,10 @@

Digit ROI

rect.startX = document.getElementById("refx").value; rect.startY = document.getElementById("refy").value; - draw(); if (lockSpaceEquidistant) { makeX_SpaceEquidistant(); - } + } + draw(); } document.getElementById("saveroi").disabled = false; @@ -990,11 +974,13 @@

Digit ROI

_roialt= sel.options[sel.selectedIndex].text; var _roinew = prompt("Please enter a new name for the selected ROI", _roialt); + if (_roinew === null) { return; //break out of the function early because prompt was aborted } erg = RenameROI(_number, "digit", _roialt, _roinew); + if (erg != "") { firework.launch(erg, 'danger', 30000); } diff --git a/sd-card/html/edit_reference.html b/sd-card/html/edit_reference.html index 84efe305b..7716f40be 100644 --- a/sd-card/html/edit_reference.html +++ b/sd-card/html/edit_reference.html @@ -1,8 +1,9 @@ - + + - Reference Image and Camera Settings + Reference Image and Camera Settings diff --git a/sd-card/html/file_server.html b/sd-card/html/file_server.html index 591892667..564140868 100644 --- a/sd-card/html/file_server.html +++ b/sd-card/html/file_server.html @@ -1,9 +1,11 @@ - + + - + + @@ -78,221 +129,209 @@
- + + diff --git a/sd-card/html/readconfigcommon.js b/sd-card/html/readconfigcommon.js index 9be51c5c0..c417f1eec 100644 --- a/sd-card/html/readconfigcommon.js +++ b/sd-card/html/readconfigcommon.js @@ -1,11 +1,13 @@ function SaveConfigToServer(_domainname){ // leere Zeilen am Ende löschen var zw = config_split.length - 1; + while (config_split[zw] == "") { config_split.pop(); } var config_gesamt = ""; + for (var i = 0; i < config_split.length; ++i) { config_gesamt = config_gesamt + config_split[i] + "\n"; @@ -26,231 +28,232 @@ function UpdateConfig(zw, _index, _enhance, _domainname){ function createReader(file) { var image = new Image(); + reader.onload = function(evt) { var image = new Image(); + image.onload = function(evt) { var width = this.width; var height = this.height; - //alert (width); // will produce something like 198 }; + image.src = evt.target.result; }; + reader.readAsDataURL(file); } -function ZerlegeZeile(input, delimiter = " =\t\r") - { - var Output = Array(0); +function ZerlegeZeile(input, delimiter = " =\t\r") { + var Output = Array(0); // delimiter = " =,\t"; - /* The input can have multiple formats: - * - key = value - * - key = value1 value2 value3 ... - * - key value1 value2 value3 ... - * - * Examples: - * - ImageSize = VGA - * - IO0 = input disabled 10 false false - * - main.dig1 28 144 55 100 false - * - * This causes issues eg. if a password key has a whitespace or equal sign in its value. - * As a workaround and to not break any legacy usage, we enforce to only use the - * equal sign, if the key is "password" - */ - if (input.includes("password") || input.includes("Token")) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence - var pos = input.indexOf("="); - delimiter = " \t\r" - Output.push(trim(input.substr(0, pos), delimiter)); - Output.push(trim(input.substr(pos +1, input.length), delimiter)); - } - else { // Legacy Mode - input = trim(input, delimiter); - var pos = findDelimiterPos(input, delimiter); - var token; - while (pos > -1) { - token = input.substr(0, pos); - token = trim(token, delimiter); - Output.push(token); - input = input.substr(pos+1, input.length); - input = trim(input, delimiter); - pos = findDelimiterPos(input, delimiter); - } - Output.push(input); - } + /* The input can have multiple formats: + * - key = value + * - key = value1 value2 value3 ... + * - key value1 value2 value3 ... + * + * Examples: + * - ImageSize = VGA + * - IO0 = input disabled 10 false false + * - main.dig1 28 144 55 100 false + * + * This causes issues eg. if a password key has a whitespace or equal sign in its value. + * As a workaround and to not break any legacy usage, we enforce to only use the + * equal sign, if the key is "password" + */ + if (input.includes("password") || input.includes("Token")) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence + var pos = input.indexOf("="); + delimiter = " \t\r" + Output.push(trim(input.substr(0, pos), delimiter)); + Output.push(trim(input.substr(pos +1, input.length), delimiter)); + } + else { // Legacy Mode + input = trim(input, delimiter); + var pos = findDelimiterPos(input, delimiter); + var token; + + while (pos > -1) { + token = input.substr(0, pos); + token = trim(token, delimiter); + Output.push(token); + input = input.substr(pos+1, input.length); + input = trim(input, delimiter); + pos = findDelimiterPos(input, delimiter); + } + + Output.push(input); + } - return Output; - } + return Output; +} -function findDelimiterPos(input, delimiter) - { - var pos = -1; - var zw; - var akt_del; +function findDelimiterPos(input, delimiter) { + var pos = -1; + var zw; + var akt_del; - for (var anz = 0; anz < delimiter.length; ++anz) - { - akt_del = delimiter[anz]; - zw = input.indexOf(akt_del); - if (zw > -1) - { - if (pos > -1) - { - if (zw < pos) - pos = zw; - } - else - pos = zw; - } - } - return pos; - } + for (var anz = 0; anz < delimiter.length; ++anz) { + akt_del = delimiter[anz]; + zw = input.indexOf(akt_del); + + if (zw > -1) { + if (pos > -1) { + if (zw < pos) { + pos = zw; + } + } + else { + pos = zw; + } + } + } + + return pos; +} -function trim(istring, adddelimiter) - { - while ((istring.length > 0) && (adddelimiter.indexOf(istring[0]) >= 0)){ - istring = istring.substr(1, istring.length-1); - } +function trim(istring, adddelimiter) { + while ((istring.length > 0) && (adddelimiter.indexOf(istring[0]) >= 0)) { + istring = istring.substr(1, istring.length-1); + } - while ((istring.length > 0) && (adddelimiter.indexOf(istring[istring.length-1]) >= 0)){ - istring = istring.substr(0, istring.length-1); - } + while ((istring.length > 0) && (adddelimiter.indexOf(istring[istring.length-1]) >= 0)) { + istring = istring.substr(0, istring.length-1); + } - return istring; - } + return istring; +} -function getConfig() -{ - return config_gesamt; +function getConfig() { + return config_gesamt; } -function loadConfig(_domainname) -{ - var xhttp = new XMLHttpRequest(); - try { - url = _domainname + '/fileserver/config/config.ini'; - xhttp.open("GET", url, false); - xhttp.send(); - config_gesamt = xhttp.responseText; - config_gesamt = config_gesamt.replace("InitalRotate", "InitialRotate"); // Korrigiere Schreibfehler in config.ini !!!!! - } - catch (error) - { -// firework.launch('Deleting Config.ini failed!', 'danger', 30000); - } - return true; +function loadConfig(_domainname) { + var xhttp = new XMLHttpRequest(); + + try { + url = _domainname + '/fileserver/config/config.ini'; + xhttp.open("GET", url, false); + xhttp.send(); + config_gesamt = xhttp.responseText; + config_gesamt = config_gesamt.replace("InitalRotate", "InitialRotate"); // Korrigiere Schreibfehler in config.ini !!!!! + } catch (error) {} + + return true; } -function dataURLtoBlob(dataurl) -{ - var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], +function dataURLtoBlob(dataurl) { + var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); - while(n--){ - u8arr[n] = bstr.charCodeAt(n); - } - return new Blob([u8arr], {type:mime}); + + while(n--){ + u8arr[n] = bstr.charCodeAt(n); + } + + return new Blob([u8arr], {type:mime}); } -function FileCopyOnServer(_source, _target, _domainname = ""){ - url = _domainname + "/editflow?task=copy&in=" + _source + "&out=" + _target; - var xhttp = new XMLHttpRequest(); - try { - xhttp.open("GET", url, false); - xhttp.send(); } - catch (error) - { -// firework.launch('Deleting Config.ini failed!', 'danger', 30000); - } +function FileCopyOnServer(_source, _target, _domainname = "") { + url = _domainname + "/editflow?task=copy&in=" + _source + "&out=" + _target; + var xhttp = new XMLHttpRequest(); + + try { + xhttp.open("GET", url, false); + xhttp.send(); + } catch (error) {} } -function FileDeleteOnServer(_filename, _domainname = ""){ - var xhttp = new XMLHttpRequest(); - var okay = false; +function FileDeleteOnServer(_filename, _domainname = "") { + var xhttp = new XMLHttpRequest(); + var okay = false; - xhttp.onreadystatechange = function() { - if (xhttp.readyState == 4) { - if (xhttp.status == 200) { - okay = true; - } else if (xhttp.status == 0) { -// firework.launch('Server closed the connection abruptly!', 'danger', 30000); -// location.reload() - } else { -// firework.launch('An error occured: ' + xhttp.responseText, 'danger', 30000); -// location.reload() - } - } - }; - try { - var url = _domainname + "/delete" + _filename; - xhttp.open("POST", url, false); - xhttp.send(); - } - catch (error) - { -// firework.launch('Deleting Config.ini failed!', 'danger', 30000); - } + xhttp.onreadystatechange = function() { + if (xhttp.readyState == 4) { + if (xhttp.status == 200) { + okay = true; + } + else if (xhttp.status == 0) { + // firework.launch('Server closed the connection abruptly!', 'danger', 30000); + // location.reload() + } + else { + // firework.launch('An error occured: ' + xhttp.responseText, 'danger', 30000); + // location.reload() + } + } + }; + + try { + var url = _domainname + "/delete" + _filename; + xhttp.open("POST", url, false); + xhttp.send(); + } catch (error) {} - return okay; + return okay; } -function FileSendContent(_content, _filename, _domainname = ""){ - var xhttp = new XMLHttpRequest(); - var okay = false; +function FileSendContent(_content, _filename, _domainname = "") { + var xhttp = new XMLHttpRequest(); + var okay = false; - xhttp.onreadystatechange = function() { - if (xhttp.readyState == 4) { - if (xhttp.status == 200) { - okay = true; - } else if (xhttp.status == 0) { + xhttp.onreadystatechange = function() { + if (xhttp.readyState == 4) { + if (xhttp.status == 200) { + okay = true; + } + else if (xhttp.status == 0) { firework.launch('Server closed the connection abruptly!', 'danger', 30000); - } else { + } + else { firework.launch('An error occured: ' + xhttp.responseText, 'danger', 30000); - } - } - }; + } + } + }; - try { - upload_path = _domainname + "/upload" + _filename; - xhttp.open("POST", upload_path, false); - xhttp.send(_content); - } - catch (error) - { -// firework.launch('Deleting Config.ini failed!', 'danger', 30000); - } + try { + upload_path = _domainname + "/upload" + _filename; + xhttp.open("POST", upload_path, false); + xhttp.send(_content); + } catch (error) {} + return okay; } function MakeRefImageZW(zw, _enhance, _domainname){ - var _filename = zw["name"].replace("/config/", "/img_tmp/"); + var _filename = zw["name"].replace("/config/", "/img_tmp/"); - var url = _domainname + "/editflow?task=cutref&in=/config/reference.jpg&out=" + _filename + "&x=" + zw["x"] + "&y=" + zw["y"] + "&dx=" + zw["dx"] + "&dy=" + zw["dy"]; + var url = _domainname + "/editflow?task=cutref&in=/config/reference.jpg&out=" + _filename + "&x=" + zw["x"] + "&y=" + zw["y"] + "&dx=" + zw["dx"] + "&dy=" + zw["dy"]; - if (_enhance == true){ - url = url + "&enhance=true"; - } + if (_enhance == true){ + url = url + "&enhance=true"; + } - var xhttp = new XMLHttpRequest(); + var xhttp = new XMLHttpRequest(); - try { - xhttp.open("GET", url, false); - xhttp.send(); - } catch (error){} + try { + xhttp.open("GET", url, false); + xhttp.send(); + } catch (error){} - if (xhttp.responseText == "CutImage Done") { - firework.launch('Image Contrast got enhanced', 'success', 5000); - return true; - } - else { - return false; - } + if (xhttp.responseText == "CutImage Done") { + if (_enhance == true) { + firework.launch('Image Contrast got enhanced', 'success', 5000); + } + else { + firework.launch('Alignment Marker have been updated', 'success', 5000); + } + return true; + } + else { + return false; + } } diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index 641b94ec0..91bd1d7f4 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -8,706 +8,907 @@ var REFERENCES = new Array(0); function getNUMBERSList() { - _domainname = getDomainname(); - var namenumberslist = ""; - - var xhttp = new XMLHttpRequest(); - xhttp.addEventListener('load', function(event) { - if (xhttp.status >= 200 && xhttp.status < 300) { - namenumberslist = xhttp.responseText; - } else { - console.warn(request.statusText, request.responseText); - } - }); - - try { - url = _domainname + '/editflow?task=namenumbers'; - xhttp.open("GET", url, false); - xhttp.send(); - } - catch (error) - { -// alert("Loading Hostname failed"); - } - - namenumberslist = namenumberslist.split("\t"); -// namenumberslist.pop(); - - return namenumberslist; + _domainname = getDomainname(); + var namenumberslist = ""; + + var xhttp = new XMLHttpRequest(); + + xhttp.addEventListener('load', function(event) { + if (xhttp.status >= 200 && xhttp.status < 300) { + namenumberslist = xhttp.responseText; + } + else { + console.warn(request.statusText, request.responseText); + } + }); + + try { + url = _domainname + '/editflow?task=namenumbers'; + xhttp.open("GET", url, false); + xhttp.send(); + } catch (error) {} + + namenumberslist = namenumberslist.split("\t"); + + return namenumberslist; } function getDATAList() { - _domainname = getDomainname(); - datalist = ""; - - var xhttp = new XMLHttpRequest(); - xhttp.addEventListener('load', function(event) { - if (xhttp.status >= 200 && xhttp.status < 300) { - datalist = xhttp.responseText; - } else { - console.warn(request.statusText, request.responseText); - } - }); - - try { - url = _domainname + '/editflow?task=data'; - xhttp.open("GET", url, false); - xhttp.send(); - } - catch (error) - { -// alert("Loading Hostname failed"); - } - - datalist = datalist.split("\t"); - datalist.pop(); - datalist.sort(); - - return datalist; + _domainname = getDomainname(); + datalist = ""; + + var xhttp = new XMLHttpRequest(); + + xhttp.addEventListener('load', function(event) { + if (xhttp.status >= 200 && xhttp.status < 300) { + datalist = xhttp.responseText; + } + else { + console.warn(request.statusText, request.responseText); + } + }); + + try { + url = _domainname + '/editflow?task=data'; + xhttp.open("GET", url, false); + xhttp.send(); + } catch (error) {} + + datalist = datalist.split("\t"); + datalist.pop(); + datalist.sort(); + + return datalist; } function getTFLITEList() { - _domainname = getDomainname(); - tflitelist = ""; - - var xhttp = new XMLHttpRequest(); - xhttp.addEventListener('load', function(event) { - if (xhttp.status >= 200 && xhttp.status < 300) { - tflitelist = xhttp.responseText; - } else { - console.warn(request.statusText, request.responseText); - } - }); - - try { - url = _domainname + '/editflow?task=tflite'; - xhttp.open("GET", url, false); - xhttp.send(); - } - catch (error) - { -// alert("Loading Hostname failed"); - } - - tflitelist = tflitelist.split("\t"); - tflitelist.sort(); - - return tflitelist; + _domainname = getDomainname(); + tflitelist = ""; + + var xhttp = new XMLHttpRequest(); + + xhttp.addEventListener('load', function(event) { + if (xhttp.status >= 200 && xhttp.status < 300) { + tflitelist = xhttp.responseText; + } + else { + console.warn(request.statusText, request.responseText); + } + }); + + try { + url = _domainname + '/editflow?task=tflite'; + xhttp.open("GET", url, false); + xhttp.send(); + } catch (error) {} + + tflitelist = tflitelist.split("\t"); + tflitelist.sort(); + + return tflitelist; } function ParseConfig() { - config_split = config_gesamt.split("\n"); - var aktline = 0; - - param = new Object(); - category = new Object(); - - var catname = "TakeImage"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "RawImagesLocation"); - ParamAddValue(param, catname, "WaitBeforeTakingPicture"); - ParamAddValue(param, catname, "RawImagesRetention"); - ParamAddValue(param, catname, "Demo"); - ParamAddValue(param, catname, "Brightness"); - ParamAddValue(param, catname, "Contrast"); - ParamAddValue(param, catname, "Saturation"); - ParamAddValue(param, catname, "Sharpness"); - ParamAddValue(param, catname, "LEDIntensity"); - ParamAddValue(param, catname, "ImageQuality"); - ParamAddValue(param, catname, "ImageSize"); - ParamAddValue(param, catname, "Zoom"); - ParamAddValue(param, catname, "ZoomMode"); - ParamAddValue(param, catname, "ZoomOffsetX"); - ParamAddValue(param, catname, "ZoomOffsetY"); - ParamAddValue(param, catname, "Grayscale"); - ParamAddValue(param, catname, "Negative"); - ParamAddValue(param, catname, "Aec2"); - ParamAddValue(param, catname, "AutoExposureLevel"); - ParamAddValue(param, catname, "FixedExposure"); - - var catname = "Alignment"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "InitialRotate"); - ParamAddValue(param, catname, "InitialMirror"); - ParamAddValue(param, catname, "SearchFieldX"); - ParamAddValue(param, catname, "SearchFieldY"); - ParamAddValue(param, catname, "AlignmentAlgo"); - ParamAddValue(param, catname, "FlipImageSize"); - - var catname = "Digits"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "Model"); - ParamAddValue(param, catname, "CNNGoodThreshold", 1); - ParamAddValue(param, catname, "ROIImagesLocation"); - ParamAddValue(param, catname, "ROIImagesRetention"); - - var catname = "Analog"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "Model"); - ParamAddValue(param, catname, "ROIImagesLocation"); - ParamAddValue(param, catname, "ROIImagesRetention"); - - var catname = "PostProcessing"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "DecimalShift", 1, true); - ParamAddValue(param, catname, "AnalogDigitalTransitionStart", 1, true); - ParamAddValue(param, catname, "PreValueUse"); - ParamAddValue(param, catname, "PreValueAgeStartup"); - ParamAddValue(param, catname, "AllowNegativeRates", 1, true, "true"); - ParamAddValue(param, catname, "MaxRateValue", 1, true); - ParamAddValue(param, catname, "MaxRateType", 1, true); - ParamAddValue(param, catname, "ExtendedResolution", 1, true, "false"); - ParamAddValue(param, catname, "IgnoreLeadingNaN", 1, true, "false"); - ParamAddValue(param, catname, "ErrorMessage"); - ParamAddValue(param, catname, "CheckDigitIncreaseConsistency"); - - var catname = "MQTT"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "Uri"); - ParamAddValue(param, catname, "MainTopic", 1, false); - ParamAddValue(param, catname, "ClientID"); - ParamAddValue(param, catname, "user"); - ParamAddValue(param, catname, "password"); - ParamAddValue(param, catname, "RetainMessages"); - ParamAddValue(param, catname, "HomeassistantDiscovery"); - ParamAddValue(param, catname, "MeterType"); - ParamAddValue(param, catname, "CACert"); - ParamAddValue(param, catname, "ClientCert"); - ParamAddValue(param, catname, "ClientKey"); - - var catname = "InfluxDB"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "Uri"); - ParamAddValue(param, catname, "Database"); + config_split = config_gesamt.split("\n"); + var aktline = 0; + + param = new Object(); + category = new Object(); + + var catname = "TakeImage"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "RawImagesLocation"); + ParamAddValue(param, catname, "RawImagesRetention"); + ParamAddValue(param, catname, "WaitBeforeTakingPicture"); + ParamAddValue(param, catname, "CamGainceiling"); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) + ParamAddValue(param, catname, "CamQuality"); // 0 - 63 + ParamAddValue(param, catname, "CamBrightness"); // (-2 to 2) - set brightness + ParamAddValue(param, catname, "CamContrast"); //-2 - 2 + ParamAddValue(param, catname, "CamSaturation"); //-2 - 2 + ParamAddValue(param, catname, "CamSharpness"); //-2 - 2 + ParamAddValue(param, catname, "CamAutoSharpness"); // (1 or 0) + ParamAddValue(param, catname, "CamSpecialEffect"); // 0 - 6 + ParamAddValue(param, catname, "CamWbMode"); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) + ParamAddValue(param, catname, "CamAwb"); // white balance enable (0 or 1) + ParamAddValue(param, catname, "CamAwbGain"); // Auto White Balance enable (0 or 1) + ParamAddValue(param, catname, "CamAec"); // auto exposure off (1 or 0) + ParamAddValue(param, catname, "CamAec2"); // automatic exposure sensor (0 or 1) + ParamAddValue(param, catname, "CamAeLevel"); // auto exposure levels (-2 to 2) + ParamAddValue(param, catname, "CamAecValue"); // set exposure manually (0-1200) + ParamAddValue(param, catname, "CamAgc"); // auto gain off (1 or 0) + ParamAddValue(param, catname, "CamAgcGain"); // set gain manually (0 - 30) + ParamAddValue(param, catname, "CamBpc"); // black pixel correction + ParamAddValue(param, catname, "CamWpc"); // white pixel correction + ParamAddValue(param, catname, "CamRawGma"); // (1 or 0) + ParamAddValue(param, catname, "CamLenc"); // lens correction (1 or 0) + ParamAddValue(param, catname, "CamHmirror"); // (0 or 1) flip horizontally + ParamAddValue(param, catname, "CamVflip"); // Invert image (0 or 1) + ParamAddValue(param, catname, "CamDcw"); // downsize enable (1 or 0) + ParamAddValue(param, catname, "CamDenoise"); // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) + ParamAddValue(param, catname, "CamZoom"); + ParamAddValue(param, catname, "CamZoomOffsetX"); + ParamAddValue(param, catname, "CamZoomOffsetY"); + ParamAddValue(param, catname, "CamZoomSize"); + ParamAddValue(param, catname, "LEDIntensity"); + ParamAddValue(param, catname, "Demo"); + + var catname = "Alignment"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "InitialRotate"); + ParamAddValue(param, catname, "SearchFieldX"); + ParamAddValue(param, catname, "SearchFieldY"); + ParamAddValue(param, catname, "AlignmentAlgo"); + + var catname = "Digits"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Model"); + ParamAddValue(param, catname, "CNNGoodThreshold", 1); + ParamAddValue(param, catname, "ROIImagesLocation"); + ParamAddValue(param, catname, "ROIImagesRetention"); + + var catname = "Analog"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Model"); + ParamAddValue(param, catname, "ROIImagesLocation"); + ParamAddValue(param, catname, "ROIImagesRetention"); + + var catname = "PostProcessing"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "DecimalShift", 1, true); + ParamAddValue(param, catname, "AnalogToDigitTransitionStart", 1, true, "9.2"); + ParamAddValue(param, catname, "ChangeRateThreshold", 1, true, "2"); + // ParamAddValue(param, catname, "PreValueUse", 1, true, "true"); + ParamAddValue(param, catname, "PreValueUse"); + ParamAddValue(param, catname, "PreValueAgeStartup"); + ParamAddValue(param, catname, "AllowNegativeRates", 1, true, "false"); + ParamAddValue(param, catname, "MaxRateValue", 1, true, "0.05"); + ParamAddValue(param, catname, "MaxRateType", 1, true); + ParamAddValue(param, catname, "ExtendedResolution", 1, true, "false"); + ParamAddValue(param, catname, "IgnoreLeadingNaN", 1, true, "false"); + // ParamAddValue(param, catname, "IgnoreAllNaN", 1, true, "false"); + ParamAddValue(param, catname, "ErrorMessage"); + ParamAddValue(param, catname, "CheckDigitIncreaseConsistency"); + + var catname = "MQTT"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Uri"); + ParamAddValue(param, catname, "MainTopic", 1, false); + ParamAddValue(param, catname, "ClientID"); + ParamAddValue(param, catname, "user"); + ParamAddValue(param, catname, "password"); + ParamAddValue(param, catname, "RetainMessages"); + ParamAddValue(param, catname, "HomeassistantDiscovery"); + ParamAddValue(param, catname, "MeterType"); + ParamAddValue(param, catname, "CACert"); + ParamAddValue(param, catname, "ClientCert"); + ParamAddValue(param, catname, "ClientKey"); + + var catname = "InfluxDB"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Uri"); + ParamAddValue(param, catname, "Database"); // ParamAddValue(param, catname, "Measurement"); - ParamAddValue(param, catname, "user"); - ParamAddValue(param, catname, "password"); - ParamAddValue(param, catname, "Measurement", 1, true); - ParamAddValue(param, catname, "Field", 1, true); - - var catname = "InfluxDBv2"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "Uri"); - ParamAddValue(param, catname, "Bucket"); + ParamAddValue(param, catname, "user"); + ParamAddValue(param, catname, "password"); + ParamAddValue(param, catname, "Measurement", 1, true); + ParamAddValue(param, catname, "Field", 1, true); + + var catname = "InfluxDBv2"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Uri"); + ParamAddValue(param, catname, "Bucket"); // ParamAddValue(param, catname, "Measurement"); - ParamAddValue(param, catname, "Org"); - ParamAddValue(param, catname, "Token"); - ParamAddValue(param, catname, "Measurement", 1, true); - ParamAddValue(param, catname, "Field", 1, true); - - var catname = "GPIO"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "IO0", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); - ParamAddValue(param, catname, "IO1", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); - ParamAddValue(param, catname, "IO3", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); - ParamAddValue(param, catname, "IO4", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); - ParamAddValue(param, catname, "IO12", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); - ParamAddValue(param, catname, "IO13", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); - ParamAddValue(param, catname, "LEDType"); - ParamAddValue(param, catname, "LEDNumbers"); - ParamAddValue(param, catname, "LEDColor", 3); + ParamAddValue(param, catname, "Org"); + ParamAddValue(param, catname, "Token"); + ParamAddValue(param, catname, "Measurement", 1, true); + ParamAddValue(param, catname, "Field", 1, true); + + var catname = "Webhook"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Uri"); + ParamAddValue(param, catname, "ApiKey"); + ParamAddValue(param, catname, "UploadImg"); + + var catname = "GPIO"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "IO0", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); + ParamAddValue(param, catname, "IO1", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); + ParamAddValue(param, catname, "IO3", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); + ParamAddValue(param, catname, "IO4", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); + ParamAddValue(param, catname, "IO12", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); + ParamAddValue(param, catname, "IO13", 6, false, "", [null, null, /^[0-9]*$/, null, null, /^[a-zA-Z0-9_-]*$/]); + ParamAddValue(param, catname, "LEDType"); + ParamAddValue(param, catname, "LEDNumbers"); + ParamAddValue(param, catname, "LEDColor", 3); // Default Values, um abwärtskompatiblität zu gewährleisten - param[catname]["LEDType"]["value1"] = "WS2812"; - param[catname]["LEDNumbers"]["value1"] = "2"; - param[catname]["LEDColor"]["value1"] = "50"; - param[catname]["LEDColor"]["value2"] = "50"; - param[catname]["LEDColor"]["value3"] = "50"; - - - var catname = "AutoTimer"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "AutoStart"); - ParamAddValue(param, catname, "Interval"); - - var catname = "DataLogging"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "DataLogActive"); - ParamAddValue(param, catname, "DataFilesRetention"); - - var catname = "Debug"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "LogLevel"); - ParamAddValue(param, catname, "LogfilesRetention"); - - var catname = "System"; - category[catname] = new Object(); - category[catname]["enabled"] = false; - category[catname]["found"] = false; - param[catname] = new Object(); - ParamAddValue(param, catname, "TimeZone"); - ParamAddValue(param, catname, "TimeServer"); - ParamAddValue(param, catname, "Hostname"); - ParamAddValue(param, catname, "RSSIThreshold"); - ParamAddValue(param, catname, "CPUFrequency"); - ParamAddValue(param, catname, "SetupMode"); + param[catname]["LEDType"]["value1"] = "WS2812"; + param[catname]["LEDNumbers"]["value1"] = "2"; + param[catname]["LEDColor"]["value1"] = "50"; + param[catname]["LEDColor"]["value2"] = "50"; + param[catname]["LEDColor"]["value3"] = "50"; + + var catname = "AutoTimer"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "AutoStart"); + ParamAddValue(param, catname, "Interval"); + + var catname = "DataLogging"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "DataLogActive"); + ParamAddValue(param, catname, "DataFilesRetention"); + + var catname = "Debug"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "LogLevel"); + ParamAddValue(param, catname, "LogfilesRetention"); + + var catname = "System"; + category[catname] = new Object(); + category[catname]["enabled"] = false; + category[catname]["found"] = false; + param[catname] = new Object(); + ParamAddValue(param, catname, "Tooltip"); + ParamAddValue(param, catname, "TimeZone"); + ParamAddValue(param, catname, "TimeServer"); + ParamAddValue(param, catname, "Hostname"); + ParamAddValue(param, catname, "RSSIThreshold"); + ParamAddValue(param, catname, "CPUFrequency"); + ParamAddValue(param, catname, "SetupMode"); - - while (aktline < config_split.length){ - for (var cat in category) { - zw = cat.toUpperCase(); - zw1 = "[" + zw + "]"; - zw2 = ";[" + zw + "]"; - if ((config_split[aktline].trim().toUpperCase() == zw1) || (config_split[aktline].trim().toUpperCase() == zw2)) { - if (config_split[aktline].trim().toUpperCase() == zw1) { - category[cat]["enabled"] = true; - } - category[cat]["found"] = true; - category[cat]["line"] = aktline; - aktline = ParseConfigParamAll(aktline, cat); - continue; - } - } - aktline++; - } - - // Make the downward compatiblity with DataLogging - if (category["DataLogging"]["found"] == false) - { - category["DataLogging"]["found"] = true; - category["DataLogging"]["enabled"] = true; - - param["DataLogging"]["DataLogActive"]["found"] = true; - param["DataLogging"]["DataLogActive"]["enabled"] = true; - param["DataLogging"]["DataLogActive"]["value1"] = "true"; + while (aktline < config_split.length){ + for (var cat in category) { + zw = cat.toUpperCase(); + zw1 = "[" + zw + "]"; + zw2 = ";[" + zw + "]"; + + if ((config_split[aktline].trim().toUpperCase() == zw1) || (config_split[aktline].trim().toUpperCase() == zw2)) { + if (config_split[aktline].trim().toUpperCase() == zw1) { + category[cat]["enabled"] = true; + } + + category[cat]["found"] = true; + category[cat]["line"] = aktline; + aktline = ParseConfigParamAll(aktline, cat); + continue; + } + } + + aktline++; + } + + // Make the downward compatiblity with DataLogging + if (category["DataLogging"]["found"] == false) { + category["DataLogging"]["found"] = true; + category["DataLogging"]["enabled"] = true; + + param["DataLogging"]["DataLogActive"]["found"] = true; + param["DataLogging"]["DataLogActive"]["enabled"] = true; + param["DataLogging"]["DataLogActive"]["value1"] = "true"; - param["DataLogging"]["DataFilesRetention"]["found"] = true; - param["DataLogging"]["DataFilesRetention"]["enabled"] = true; - param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; - } - - if (category["DataLogging"]["enabled"] == false) - category["DataLogging"]["enabled"] = true - - if (param["DataLogging"]["DataLogActive"]["enabled"] == false && param["DataLogging"]["DataLogActive"]["value1"] == "") - { - param["DataLogging"]["DataLogActive"]["found"] = true; - param["DataLogging"]["DataLogActive"]["enabled"] = true; - param["DataLogging"]["DataLogActive"]["value1"] = "true"; - } - - if (param["DataLogging"]["DataFilesRetention"]["enabled"] == false && param["DataLogging"]["DataFilesRetention"]["value1"] == "") - { - param["DataLogging"]["DataFilesRetention"]["found"] = true; - param["DataLogging"]["DataFilesRetention"]["enabled"] = true; - param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; - } - - // Downward compatibility: Create RSSIThreshold if not available - if (param["System"]["RSSIThreshold"]["found"] == false) - { - param["System"]["RSSIThreshold"]["found"] = true; - param["System"]["RSSIThreshold"]["enabled"] = false; - param["System"]["RSSIThreshold"]["value1"] = "0"; - } + param["DataLogging"]["DataFilesRetention"]["found"] = true; + param["DataLogging"]["DataFilesRetention"]["enabled"] = true; + param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; + } + + if (category["DataLogging"]["enabled"] == false) { + category["DataLogging"]["enabled"] = true + } + + if (param["DataLogging"]["DataLogActive"]["enabled"] == false && param["DataLogging"]["DataLogActive"]["value1"] == "") { + param["DataLogging"]["DataLogActive"]["found"] = true; + param["DataLogging"]["DataLogActive"]["enabled"] = true; + param["DataLogging"]["DataLogActive"]["value1"] = "true"; + } + + if (param["DataLogging"]["DataFilesRetention"]["enabled"] == false && param["DataLogging"]["DataFilesRetention"]["value1"] == "") { + param["DataLogging"]["DataFilesRetention"]["found"] = true; + param["DataLogging"]["DataFilesRetention"]["enabled"] = true; + param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; + } + + // Downward compatibility: Create RSSIThreshold if not available + if (param["System"]["RSSIThreshold"]["found"] == false) { + param["System"]["RSSIThreshold"]["found"] = true; + param["System"]["RSSIThreshold"]["enabled"] = false; + param["System"]["RSSIThreshold"]["value1"] = "0"; + } } -function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _defaultValue = "", _checkRegExList = null){ - param[_cat][_param] = new Object(); - param[_cat][_param]["found"] = false; - param[_cat][_param]["enabled"] = false; - param[_cat][_param]["line"] = -1; - param[_cat][_param]["anzParam"] = _anzParam; - param[_cat][_param]["defaultValue"] = _defaultValue; - param[_cat][_param]["Numbers"] = _isNUMBER; - param[_cat][_param].checkRegExList = _checkRegExList; +function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _defaultValue = "", _checkRegExList = null) { + param[_cat][_param] = new Object(); + param[_cat][_param]["found"] = false; + param[_cat][_param]["enabled"] = false; + param[_cat][_param]["line"] = -1; + param[_cat][_param]["anzParam"] = _anzParam; + param[_cat][_param]["defaultValue"] = _defaultValue; + param[_cat][_param]["Numbers"] = _isNUMBER; + param[_cat][_param].checkRegExList = _checkRegExList; }; -function ParseConfigParamAll(_aktline, _catname){ - ++_aktline; - - while ((_aktline < config_split.length) - && !(config_split[_aktline][0] == "[") - && !((config_split[_aktline][0] == ";") && (config_split[_aktline][1] == "["))) { - var _input = config_split[_aktline]; - let [isCom, input] = isCommented(_input); - var linesplit = ZerlegeZeile(input); - ParamExtractValueAll(param, linesplit, _catname, _aktline, isCom); - if (!isCom && (linesplit.length >= 5) && (_catname == 'Digits')) - ExtractROIs(input, "digit"); - if (!isCom && (linesplit.length >= 5) && (_catname == 'Analog')) - ExtractROIs(input, "analog"); - if (!isCom && (linesplit.length == 3) && (_catname == 'Alignment')) - { - _newref = new Object(); - _newref["name"] = linesplit[0]; - _newref["x"] = linesplit[1]; - _newref["y"] = linesplit[2]; - REFERENCES.push(_newref); - } - - ++_aktline; - } - return _aktline; + +function ParseConfigParamAll(_aktline, _catname) { + ++_aktline; + + while ((_aktline < config_split.length) && !(config_split[_aktline][0] == "[") && !((config_split[_aktline][0] == ";") && (config_split[_aktline][1] == "["))) { + var _input = config_split[_aktline]; + let [isCom, input] = isCommented(_input); + var linesplit = ZerlegeZeile(input); + ParamExtractValueAll(param, linesplit, _catname, _aktline, isCom); + + if (!isCom && (linesplit.length >= 5) && (_catname == 'Digits')) { + ExtractROIs(input, "digit"); + } + + if (!isCom && (linesplit.length >= 5) && (_catname == 'Analog')) { + ExtractROIs(input, "analog"); + } + + if (!isCom && (linesplit.length == 3) && (_catname == 'Alignment')) { + _newref = new Object(); + _newref["name"] = linesplit[0]; + _newref["x"] = linesplit[1]; + _newref["y"] = linesplit[2]; + REFERENCES.push(_newref); + } + + ++_aktline; + } + + return _aktline; } -function ParamExtractValue(_param, _linesplit, _catname, _paramname, _aktline, _iscom, _anzvalue = 1){ - if ((_linesplit[0].toUpperCase() == _paramname.toUpperCase()) && (_linesplit.length > _anzvalue)) - { - _param[_catname][_paramname]["found"] = true; - _param[_catname][_paramname]["enabled"] = !_iscom; - _param[_catname][_paramname]["line"] = _aktline; - _param[_catname][_paramname]["anzpara"] = _anzvalue; - for (var j = 1; j <= _anzvalue; ++j) { - _param[_catname][_paramname]["value"+j] = _linesplit[j]; - } - } + +function ParamExtractValue(_param, _linesplit, _catname, _paramname, _aktline, _iscom, _anzvalue = 1) { + if ((_linesplit[0].toUpperCase() == _paramname.toUpperCase()) && (_linesplit.length > _anzvalue)) { + _param[_catname][_paramname]["found"] = true; + _param[_catname][_paramname]["enabled"] = !_iscom; + _param[_catname][_paramname]["line"] = _aktline; + _param[_catname][_paramname]["anzpara"] = _anzvalue; + + for (var j = 1; j <= _anzvalue; ++j) { + _param[_catname][_paramname]["value"+j] = _linesplit[j]; + } + } } -function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom){ - for (var paramname in _param[_catname]) { - _AktROI = "default"; - _AktPara = _linesplit[0]; - _pospunkt = _AktPara.indexOf ("."); - if (_pospunkt > -1) - { - _AktROI = _AktPara.substring(0, _pospunkt); - _AktPara = _AktPara.substring(_pospunkt+1); - } - if (_AktPara.toUpperCase() == paramname.toUpperCase()) - { - while (_linesplit.length <= _param[_catname][paramname]["anzParam"]) { - _linesplit.push(""); - } - - _param[_catname][paramname]["found"] = true; - _param[_catname][paramname]["enabled"] = !_iscom; - _param[_catname][paramname]["line"] = _aktline; - if (_param[_catname][paramname]["Numbers"] == true) // möglicher Multiusage - { - abc = getNUMBERS(_linesplit[0]); - abc[_catname][paramname] = new Object; - abc[_catname][paramname]["found"] = true; - abc[_catname][paramname]["enabled"] = !_iscom; + +function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) { + for (var paramname in _param[_catname]) { + _AktROI = "default"; + _AktPara = _linesplit[0]; + _pospunkt = _AktPara.indexOf ("."); + + if (_pospunkt > -1) { + _AktROI = _AktPara.substring(0, _pospunkt); + _AktPara = _AktPara.substring(_pospunkt+1); + } + + if (_AktPara.toUpperCase() == paramname.toUpperCase()) { + while (_linesplit.length <= _param[_catname][paramname]["anzParam"]) { + _linesplit.push(""); + } + + _param[_catname][paramname]["found"] = true; + _param[_catname][paramname]["enabled"] = !_iscom; + _param[_catname][paramname]["line"] = _aktline; + + if (_param[_catname][paramname]["Numbers"] == true) { // möglicher Multiusage + abc = getNUMBERS(_linesplit[0]); + abc[_catname][paramname] = new Object; + abc[_catname][paramname]["found"] = true; + abc[_catname][paramname]["enabled"] = !_iscom; - for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { - abc[_catname][paramname]["value"+j] = _linesplit[j]; - } - if (abc["name"] == "default") - { - for (_num in NUMBERS) // wert mit Default belegen - { - if (NUMBERS[_num][_catname][paramname]["found"] == false) - { - NUMBERS[_num][_catname][paramname]["found"] = true; - NUMBERS[_num][_catname][paramname]["enabled"] = !_iscom; - NUMBERS[_num][_catname][paramname]["line"] = _aktline; - for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { - NUMBERS[_num][_catname][paramname]["value"+j] = _linesplit[j]; - } - - } - } + for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { + abc[_catname][paramname]["value"+j] = _linesplit[j]; + } + + if (abc["name"] == "default") { + for (_num in NUMBERS) { // wert mit Default belegen + if (NUMBERS[_num][_catname][paramname]["found"] == false) { + NUMBERS[_num][_catname][paramname]["found"] = true; + NUMBERS[_num][_catname][paramname]["enabled"] = !_iscom; + NUMBERS[_num][_catname][paramname]["line"] = _aktline; + + for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { + NUMBERS[_num][_catname][paramname]["value"+j] = _linesplit[j]; + } + } } - } - else - { - _param[_catname][paramname]["found"] = true; - _param[_catname][paramname]["enabled"] = !_iscom; - _param[_catname][paramname]["line"] = _aktline; - for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { - _param[_catname][paramname]["value"+j] = _linesplit[j]; - } - } - } - } + } + } + else { + _param[_catname][paramname]["found"] = true; + _param[_catname][paramname]["enabled"] = !_iscom; + _param[_catname][paramname]["line"] = _aktline; + + for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { + _param[_catname][paramname]["value"+j] = _linesplit[j]; + } + } + } + } } + +function getCamConfig() { + ParseConfig(); + + param["System"]["Tooltip"]["enabled"] = true; + param["Alignment"]["InitialRotate"]["enabled"] = true; + + param["TakeImage"]["WaitBeforeTakingPicture"]["enabled"] = true; + param["TakeImage"]["CamGainceiling"]["enabled"] = true; // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) + param["TakeImage"]["CamQuality"]["enabled"] = true; // 0 - 63 + param["TakeImage"]["CamBrightness"]["enabled"] = true; // (-2 to 2) - set brightness + param["TakeImage"]["CamContrast"]["enabled"] = true; //-2 - 2 + param["TakeImage"]["CamSaturation"]["enabled"] = true; //-2 - 2 + param["TakeImage"]["CamSharpness"]["enabled"] = true; //-2 - 2 + param["TakeImage"]["CamAutoSharpness"]["enabled"] = true; //(1 or 0) + param["TakeImage"]["CamSpecialEffect"]["enabled"] = true; // 0 - 6 + param["TakeImage"]["CamWbMode"]["enabled"] = true; // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) + param["TakeImage"]["CamAwb"]["enabled"] = true; // white balance enable (0 or 1) + param["TakeImage"]["CamAwbGain"]["enabled"] = true; // Auto White Balance enable (0 or 1) + param["TakeImage"]["CamAec"]["enabled"] = true; // auto exposure off (1 or 0) + param["TakeImage"]["CamAec2"]["enabled"] = true; // automatic exposure sensor (0 or 1) + param["TakeImage"]["CamAeLevel"]["enabled"] = true; // auto exposure levels (-2 to 2) + param["TakeImage"]["CamAecValue"]["enabled"] = true; // set exposure manually (0-1200) + param["TakeImage"]["CamAgc"]["enabled"] = true; // auto gain off (1 or 0) + param["TakeImage"]["CamAgcGain"]["enabled"] = true; // set gain manually (0 - 30) + param["TakeImage"]["CamBpc"]["enabled"] = true; // black pixel correction + param["TakeImage"]["CamWpc"]["enabled"] = true; // white pixel correction + param["TakeImage"]["CamRawGma"]["enabled"] = true; // (1 or 0) + param["TakeImage"]["CamLenc"]["enabled"] = true; // lens correction (1 or 0) + param["TakeImage"]["CamHmirror"]["enabled"] = true; // (0 or 1) flip horizontally + param["TakeImage"]["CamVflip"]["enabled"] = true; // Invert image (0 or 1) + param["TakeImage"]["CamDcw"]["enabled"] = true; // downsize enable (1 or 0) + param["TakeImage"]["CamDenoise"]["enabled"] = true; // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) + param["TakeImage"]["CamZoom"]["enabled"] = true; + param["TakeImage"]["CamZoomOffsetX"]["enabled"] = true; + param["TakeImage"]["CamZoomOffsetY"]["enabled"] = true; + param["TakeImage"]["CamZoomSize"]["enabled"] = true; + param["TakeImage"]["LEDIntensity"]["enabled"] = true; + + if (!param["System"]["Tooltip"]["found"]) { + param["System"]["Tooltip"]["found"] = true; + param["System"]["Tooltip"].value1 = 'true'; + } + + if (!param["Alignment"]["InitialRotate"]["found"]) { + param["Alignment"]["InitialRotate"]["found"] = true; + param["Alignment"]["InitialRotate"].value1 = 'false'; + } + + if (!param["TakeImage"]["WaitBeforeTakingPicture"]["found"]) { + param["TakeImage"]["WaitBeforeTakingPicture"]["found"] = true; + param["TakeImage"]["WaitBeforeTakingPicture"].value1 = '5'; + } + if (!param["TakeImage"]["CamGainceiling"]["found"]) { + param["TakeImage"]["CamGainceiling"]["found"] = true; + // param["TakeImage"]["CamGainceiling"].value1 = '2'; + param["TakeImage"]["CamGainceiling"].value1 = 'x8'; + } + if (!param["TakeImage"]["CamQuality"]["found"]) { + param["TakeImage"]["CamQuality"]["found"] = true; + param["TakeImage"]["CamQuality"].value1 = '10'; + } + if (!param["TakeImage"]["CamBrightness"]["found"]) { + param["TakeImage"]["CamBrightness"]["found"] = true; + param["TakeImage"]["CamBrightness"].value1 = '0'; + } + if (!param["TakeImage"]["CamContrast"]["found"]) { + param["TakeImage"]["CamContrast"]["found"] = true; + param["TakeImage"]["CamContrast"].value1 = '0'; + } + if (!param["TakeImage"]["CamSaturation"]["found"]) { + param["TakeImage"]["CamSaturation"]["found"] = true; + param["TakeImage"]["CamSaturation"].value1 = '0'; + } + if (!param["TakeImage"]["CamSharpness"]["found"]) { + param["TakeImage"]["CamSharpness"]["found"] = true; + param["TakeImage"]["CamSharpness"].value1 = '0'; + } + if (!param["TakeImage"]["CamAutoSharpness"]["found"]) { + param["TakeImage"]["CamAutoSharpness"]["found"] = true; + param["TakeImage"]["CamAutoSharpness"].value1 = 'false'; + } + if (!param["TakeImage"]["CamSpecialEffect"]["found"]) { + param["TakeImage"]["CamSpecialEffect"]["found"] = true; + param["TakeImage"]["CamSpecialEffect"].value1 = 'no_effect'; + } + if (!param["TakeImage"]["CamWbMode"]["found"]) { + param["TakeImage"]["CamWbMode"]["found"] = true; + param["TakeImage"]["CamWbMode"].value1 = 'auto'; + } + if (!param["TakeImage"]["CamAwb"]["found"]) { + param["TakeImage"]["CamAwb"]["found"] = true; + param["TakeImage"]["CamAwb"].value1 = 'true'; + } + if (!param["TakeImage"]["CamAwbGain"]["found"]) { + param["TakeImage"]["CamAwbGain"]["found"] = true; + param["TakeImage"]["CamAwbGain"].value1 = 'true'; + } + if (!param["TakeImage"]["CamAec"]["found"]) { + param["TakeImage"]["CamAec"]["found"] = true; + param["TakeImage"]["CamAec"].value1 = 'true'; + } + if (!param["TakeImage"]["CamAec2"]["found"]) { + param["TakeImage"]["CamAec2"]["found"] = true; + param["TakeImage"]["CamAec2"].value1 = 'true'; + } + if (!param["TakeImage"]["CamAeLevel"]["found"]) { + param["TakeImage"]["CamAeLevel"]["found"] = true; + param["TakeImage"]["CamAeLevel"].value1 = '2'; + } + if (!param["TakeImage"]["CamAecValue"]["found"]) { + param["TakeImage"]["CamAecValue"]["found"] = true; + param["TakeImage"]["CamAecValue"].value1 = '600'; + } + if (!param["TakeImage"]["CamAgc"]["found"]) { + param["TakeImage"]["CamAgc"]["found"] = true; + param["TakeImage"]["CamAgc"].value1 = 'true'; + } + if (!param["TakeImage"]["CamAgcGain"]["found"]) { + param["TakeImage"]["CamAgcGain"]["found"] = true; + param["TakeImage"]["CamAgcGain"].value1 = '8'; + } + if (!param["TakeImage"]["CamBpc"]["found"]) { + param["TakeImage"]["CamBpc"]["found"] = true; + param["TakeImage"]["CamBpc"].value1 = 'true'; + } + if (!param["TakeImage"]["CamWpc"]["found"]) { + param["TakeImage"]["CamWpc"]["found"] = true; + param["TakeImage"]["CamWpc"].value1 = 'true'; + } + if (!param["TakeImage"]["CamRawGma"]["found"]) { + param["TakeImage"]["CamRawGma"]["found"] = true; + param["TakeImage"]["CamRawGma"].value1 = 'true'; + } + if (!param["TakeImage"]["CamLenc"]["found"]) { + param["TakeImage"]["CamLenc"]["found"] = true; + param["TakeImage"]["CamLenc"].value1 = 'true'; + } + if (!param["TakeImage"]["CamHmirror"]["found"]) { + param["TakeImage"]["CamHmirror"]["found"] = true; + param["TakeImage"]["CamHmirror"].value1 = 'false'; + } + if (!param["TakeImage"]["CamVflip"]["found"]) { + param["TakeImage"]["CamVflip"]["found"] = true; + param["TakeImage"]["CamVflip"].value1 = 'false'; + } + if (!param["TakeImage"]["CamDcw"]["found"]) { + param["TakeImage"]["CamDcw"]["found"] = true; + param["TakeImage"]["CamDcw"].value1 = 'true'; + } + if (!param["TakeImage"]["CamDenoise"]["found"]) { + param["TakeImage"]["CamDenoise"]["found"] = true; + param["TakeImage"]["CamDenoise"].value1 = '0'; + } + if (!param["TakeImage"]["CamZoom"]["found"]) { + param["TakeImage"]["CamZoom"]["found"] = true; + param["TakeImage"]["CamZoom"].value1 = 'false'; + } + if (!param["TakeImage"]["CamZoomOffsetX"]["found"]) { + param["TakeImage"]["CamZoomOffsetX"]["found"] = true; + param["TakeImage"]["CamZoomOffsetX"].value1 = '0'; + } + if (!param["TakeImage"]["CamZoomOffsetY"]["found"]) { + param["TakeImage"]["CamZoomOffsetY"]["found"] = true; + param["TakeImage"]["CamZoomOffsetY"].value1 = '0'; + } + if (!param["TakeImage"]["CamZoomSize"]["found"]) { + param["TakeImage"]["CamZoomSize"]["found"] = true; + param["TakeImage"]["CamZoomSize"].value1 = '0'; + } + if (!param["TakeImage"]["LEDIntensity"]["found"]) { + param["TakeImage"]["LEDIntensity"]["found"] = true; + param["TakeImage"]["LEDIntensity"].value1 = '50'; + } + + return param; +} + + function getConfigParameters() { - return param; + return param; } -function WriteConfigININew() -{ - // Cleanup empty NUMBERS - for (var j = 0; j < NUMBERS.length; ++j) - { - if ((NUMBERS[j]["digit"].length + NUMBERS[j]["analog"].length) == 0) - { - NUMBERS.splice(j, 1); - } - } - - config_split = new Array(0); - - for (var cat in param) { - text = "[" + cat + "]"; - if (!category[cat]["enabled"]) { - text = ";" + text; - } - config_split.push(text); - - for (var name in param[cat]) { - if (param[cat][name]["Numbers"]) - { - for (_num in NUMBERS) - { - text = NUMBERS[_num]["name"] + "." + name; - - var text = text + " =" + +function WriteConfigININew() { + // Cleanup empty NUMBERS + for (var j = 0; j < NUMBERS.length; ++j) { + if ((NUMBERS[j]["digit"].length + NUMBERS[j]["analog"].length) == 0) { + NUMBERS.splice(j, 1); + } + } + + config_split = new Array(0); + + for (var cat in param) { + text = "[" + cat + "]"; + + if (!category[cat]["enabled"]) { + text = ";" + text; + } + + config_split.push(text); + + for (var name in param[cat]) { + if (param[cat][name]["Numbers"]) { + for (_num in NUMBERS) { + text = NUMBERS[_num]["name"] + "." + name; + + var text = text + " =" - for (var j = 1; j <= param[cat][name]["anzParam"]; ++j) { - if (!(typeof NUMBERS[_num][cat][name]["value"+j] == 'undefined')) - text = text + " " + NUMBERS[_num][cat][name]["value"+j]; - } - if (!NUMBERS[_num][cat][name]["enabled"]) { - text = ";" + text; - } - config_split.push(text); - } - } - else - { - var text = name + " =" - for (var j = 1; j <= param[cat][name]["anzParam"]; ++j) { - if (!(typeof param[cat][name]["value"+j] == 'undefined')) - text = text + " " + param[cat][name]["value"+j]; - } - if (!param[cat][name]["enabled"]) { - text = ";" + text; + if (!(typeof NUMBERS[_num][cat][name]["value"+j] == 'undefined')) { + text = text + " " + NUMBERS[_num][cat][name]["value"+j]; + } + } + + if (!NUMBERS[_num][cat][name]["enabled"]) { + text = ";" + text; } + config_split.push(text); - } - } - if (cat == "Digits") - { - for (var _roi in NUMBERS) - { - if (NUMBERS[_roi]["digit"].length > 0) - { - for (var _roiddet in NUMBERS[_roi]["digit"]) - { - text = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["digit"][_roiddet]["name"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["x"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["y"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["dx"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["dy"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["CCW"]; - config_split.push(text); - } + } + } + else { + var text = name + " =" + + for (var j = 1; j <= param[cat][name]["anzParam"]; ++j) { + if (!(typeof param[cat][name]["value"+j] == 'undefined')) { + text = text + " " + param[cat][name]["value"+j]; } - } - } - if (cat == "Analog") - { - for (var _roi in NUMBERS) - { - if (NUMBERS[_roi]["analog"].length > 0) - { - for (var _roiddet in NUMBERS[_roi]["analog"]) - { - text = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["analog"][_roiddet]["name"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["x"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["y"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["dx"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["dy"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["CCW"]; - config_split.push(text); - } + } + + if (!param[cat][name]["enabled"]) { + text = ";" + text; + } + + config_split.push(text); + } + } + + if (cat == "Digits") { + for (var _roi in NUMBERS) { + if (NUMBERS[_roi]["digit"].length > 0) { + for (var _roiddet in NUMBERS[_roi]["digit"]) { + text = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["digit"][_roiddet]["name"]; + text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["x"]; + text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["y"]; + text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["dx"]; + text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["dy"]; + text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["CCW"]; + config_split.push(text); } - } - } - if (cat == "Alignment") - { - for (var _roi in REFERENCES) - { - text = REFERENCES[_roi]["name"]; - text = text + " " + REFERENCES[_roi]["x"]; - text = text + " " + REFERENCES[_roi]["y"]; - config_split.push(text); - } - } - - config_split.push(""); - } + } + } + } + + if (cat == "Analog") { + for (var _roi in NUMBERS) { + if (NUMBERS[_roi]["analog"].length > 0) { + for (var _roiddet in NUMBERS[_roi]["analog"]) { + text = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["analog"][_roiddet]["name"]; + text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["x"]; + text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["y"]; + text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["dx"]; + text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["dy"]; + text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["CCW"]; + config_split.push(text); + } + } + } + } + + if (cat == "Alignment") { + for (var _roi in REFERENCES) { + text = REFERENCES[_roi]["name"]; + text = text + " " + REFERENCES[_roi]["x"]; + text = text + " " + REFERENCES[_roi]["y"]; + config_split.push(text); + } + } + + config_split.push(""); + } } -function isCommented(input) - { - let isComment = false; - if (input.charAt(0) == ';') { - isComment = true; - input = input.substr(1, input.length-1); - }; - return [isComment, input]; - } +function isCommented(input) { + let isComment = false; + + if (input.charAt(0) == ';') { + isComment = true; + input = input.substr(1, input.length-1); + } + + return [isComment, input]; +} + function SaveConfigToServer(_domainname){ - // leere Zeilen am Ende löschen - var zw = config_split.length - 1; - while (config_split[zw] == "") { - config_split.pop(); - } - - var config_gesamt = ""; - for (var i = 0; i < config_split.length; ++i) - { - config_gesamt = config_gesamt + config_split[i] + "\n"; - } - - FileDeleteOnServer("/config/config.ini", _domainname); - FileSendContent(config_gesamt, "/config/config.ini", _domainname); + // leere Zeilen am Ende löschen + var zw = config_split.length - 1; + + while (config_split[zw] == "") { + config_split.pop(); + } + + var config_gesamt = ""; + + for (var i = 0; i < config_split.length; ++i) + { + config_gesamt = config_gesamt + config_split[i] + "\n"; + } + + FileDeleteOnServer("/config/config.ini", _domainname); + FileSendContent(config_gesamt, "/config/config.ini", _domainname); } + function getConfig() { - return config_gesamt; - } + return config_gesamt; +} + function getConfigCategory() { - return category; + return category; } function ExtractROIs(_aktline, _type){ - var linesplit = ZerlegeZeile(_aktline); - abc = getNUMBERS(linesplit[0], _type); - abc["pos_ref"] = _aktline; - abc["x"] = linesplit[1]; - abc["y"] = linesplit[2]; - abc["dx"] = linesplit[3]; - abc["dy"] = linesplit[4]; - abc["ar"] = parseFloat(linesplit[3]) / parseFloat(linesplit[4]); - abc["CCW"] = "false"; - if (linesplit.length >= 6) - abc["CCW"] = linesplit[5]; + var linesplit = ZerlegeZeile(_aktline); + abc = getNUMBERS(linesplit[0], _type); + abc["pos_ref"] = _aktline; + abc["x"] = linesplit[1]; + abc["y"] = linesplit[2]; + abc["dx"] = linesplit[3]; + abc["dy"] = linesplit[4]; + abc["ar"] = parseFloat(linesplit[3]) / parseFloat(linesplit[4]); + abc["CCW"] = "false"; + + if (linesplit.length >= 6) { + abc["CCW"] = linesplit[5]; + } } -function getNUMBERS(_name, _type, _create = true) -{ - _pospunkt = _name.indexOf ("."); - if (_pospunkt > -1) - { - _digit = _name.substring(0, _pospunkt); - _roi = _name.substring(_pospunkt+1); - } - else - { - _digit = "default"; - _roi = _name; - } - - _ret = -1; - - for (i = 0; i < NUMBERS.length; ++i) - { - if (NUMBERS[i]["name"] == _digit) - _ret = NUMBERS[i]; - } - - if (!_create) // nicht gefunden und soll auch nicht erzeugt werden, ggf. geht eine NULL zurück - return _ret; - - if (_ret == -1) - { - _ret = new Object(); - _ret["name"] = _digit; - _ret['digit'] = new Array(); - _ret['analog'] = new Array(); - - for (_cat in param) - for (_param in param[_cat]) - if (param[_cat][_param]["Numbers"] == true){ - if (typeof _ret[_cat] == 'undefined') - _ret[_cat] = new Object(); - _ret[_cat][_param] = new Object(); - _ret[_cat][_param]["found"] = false; - _ret[_cat][_param]["enabled"] = false; - _ret[_cat][_param]["anzParam"] = param[_cat][_param]["anzParam"]; +function getNUMBERS(_name, _type, _create = true) { + _pospunkt = _name.indexOf ("."); + + if (_pospunkt > -1) { + _digit = _name.substring(0, _pospunkt); + _roi = _name.substring(_pospunkt+1); + } + else { + _digit = "default"; + _roi = _name; + } - } + _ret = -1; - NUMBERS.push(_ret); - } + for (i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _digit) { + _ret = NUMBERS[i]; + } + } - if (typeof _type == 'undefined') // muss schon existieren !!! - also erst nach Digits / Analog aufrufen + if (!_create) { // nicht gefunden und soll auch nicht erzeugt werden, ggf. geht eine NULL zurück return _ret; + } - neuroi = new Object(); - neuroi["name"] = _roi; - _ret[_type].push(neuroi); + if (_ret == -1) { + _ret = new Object(); + _ret["name"] = _digit; + _ret['digit'] = new Array(); + _ret['analog'] = new Array(); + + for (_cat in param) { + for (_param in param[_cat]) { + if (param[_cat][_param]["Numbers"] == true){ + if (typeof _ret[_cat] == 'undefined') { + _ret[_cat] = new Object(); + } + + _ret[_cat][_param] = new Object(); + _ret[_cat][_param]["found"] = false; + _ret[_cat][_param]["enabled"] = false; + _ret[_cat][_param]["anzParam"] = param[_cat][_param]["anzParam"]; + } + } + } + + NUMBERS.push(_ret); + } + if (typeof _type == 'undefined') { // muss schon existieren !!! - also erst nach Digits / Analog aufrufen + return _ret; + } - return neuroi; + neuroi = new Object(); + neuroi["name"] = _roi; + _ret[_type].push(neuroi); + return neuroi; } -function CopyReferenceToImgTmp(_domainname) -{ - for (index = 0; index < 2; ++index) - { - _filenamevon = REFERENCES[index]["name"]; - _filenamenach = _filenamevon.replace("/config/", "/img_tmp/"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); +function CopyReferenceToImgTmp(_domainname) { + for (index = 0; index < 2; ++index) { + _filenamevon = REFERENCES[index]["name"]; + _filenamenach = _filenamevon.replace("/config/", "/img_tmp/"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); - _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - } + _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); + _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + } } + function GetReferencesInfo(){ - return REFERENCES; + return REFERENCES; } function UpdateConfigReferences(_domainname){ - for (var index = 0; index < 2; ++index) - { - _filenamenach = REFERENCES[index]["name"]; - _filenamevon = _filenamenach.replace("/config/", "/img_tmp/"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + for (var index = 0; index < 2; ++index) { + _filenamenach = REFERENCES[index]["name"]; + _filenamevon = _filenamenach.replace("/config/", "/img_tmp/"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); - _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - } + _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); + _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + } } @@ -740,186 +941,217 @@ function getNUMBERInfo(){ return NUMBERS; } + function RenameNUMBER(_alt, _neu){ - if ((_neu.indexOf(".") >= 0) || (_neu.indexOf(",") >= 0) || - (_neu.indexOf(" ") >= 0) || (_neu.indexOf("\"") >= 0)) - { - return "Number sequence name must not contain , . \" or a space"; - } - - index = -1; - found = false; - for (i = 0; i < NUMBERS.length; ++i) { - if (NUMBERS[i]["name"] == _alt) - index = i; - if (NUMBERS[i]["name"] == _neu) - found = true; - } - - if (found) - return "Number sequence name is already existing, please choose another name"; - - NUMBERS[index]["name"] = _neu; + if ((_neu.indexOf(".") >= 0) || (_neu.indexOf(",") >= 0) || (_neu.indexOf(" ") >= 0) || (_neu.indexOf("\"") >= 0)) { + return "Number sequence name must not contain , . \" or a space"; + } + + index = -1; + found = false; + + for (i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _alt) { + index = i; + } + + if (NUMBERS[i]["name"] == _neu) { + found = true; + } + } + + if (found) { + return "Number sequence name is already existing, please choose another name"; + } + + NUMBERS[index]["name"] = _neu; - return ""; + return ""; } + function DeleteNUMBER(_delete){ - if (NUMBERS.length == 1) - return "One number sequence is mandatory. Therefore this cannot be deleted" + if (NUMBERS.length == 1) { + return "One number sequence is mandatory. Therefore this cannot be deleted" + } + index = -1; + + for (i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _delete) { + index = i; + } + } - index = -1; - for (i = 0; i < NUMBERS.length; ++i) { - if (NUMBERS[i]["name"] == _delete) - index = i; - } - - if (index > -1) { - NUMBERS.splice(index, 1); - } + if (index > -1) { + NUMBERS.splice(index, 1); + } - return ""; + return ""; } + function CreateNUMBER(_numbernew){ - found = false; - for (i = 0; i < NUMBERS.length; ++i) { - if (NUMBERS[i]["name"] == _numbernew) - found = true; - } - - if (found) - return "Number sequence name is already existing, please choose another name"; - - _ret = new Object(); - _ret["name"] = _numbernew; - _ret['digit'] = new Array(); - _ret['analog'] = new Array(); - - for (_cat in param) - for (_param in param[_cat]) - if (param[_cat][_param]["Numbers"] == true) - { - if (typeof (_ret[_cat]) === "undefined") - { - _ret[_cat] = new Object(); - } - _ret[_cat][_param] = new Object(); - if (param[_cat][_param]["defaultValue"] === "") - { - _ret[_cat][_param]["found"] = false; - _ret[_cat][_param]["enabled"] = false; - } - else - { - _ret[_cat][_param]["found"] = true; - _ret[_cat][_param]["enabled"] = true; - _ret[_cat][_param]["value1"] = param[_cat][_param]["defaultValue"]; + found = false; + + for (i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _numbernew) { + found = true; + } + } - } - _ret[_cat][_param]["anzParam"] = param[_cat][_param]["anzParam"]; + if (found) { + return "Number sequence name is already existing, please choose another name"; + } - } + _ret = new Object(); + _ret["name"] = _numbernew; + _ret['digit'] = new Array(); + _ret['analog'] = new Array(); + + for (_cat in param) { + for (_param in param[_cat]) { + if (param[_cat][_param]["Numbers"] == true) { + if (typeof (_ret[_cat]) === "undefined") { + _ret[_cat] = new Object(); + } + + _ret[_cat][_param] = new Object(); + + if (param[_cat][_param]["defaultValue"] === "") { + _ret[_cat][_param]["found"] = false; + _ret[_cat][_param]["enabled"] = false; + } + else { + _ret[_cat][_param]["found"] = true; + _ret[_cat][_param]["enabled"] = true; + _ret[_cat][_param]["value1"] = param[_cat][_param]["defaultValue"]; + + } + + _ret[_cat][_param]["anzParam"] = param[_cat][_param]["anzParam"]; + } + } + } - NUMBERS.push(_ret); - return ""; + NUMBERS.push(_ret); + return ""; } function getROIInfo(_typeROI, _number){ - index = -1; - for (var i = 0; i < NUMBERS.length; ++i) - if (NUMBERS[i]["name"] == _number) - index = i; - - if (index != -1) - return NUMBERS[index][_typeROI]; - else - return ""; + index = -1; + + for (var i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _number) { + index = i; + } + } + + if (index != -1) { + return NUMBERS[index][_typeROI]; + } + else { + return ""; + } } function RenameROI(_number, _type, _alt, _neu){ - if ((_neu.includes("=")) || (_neu.includes(".")) || (_neu.includes(":")) || - (_neu.includes(",")) || (_neu.includes(";")) || (_neu.includes(" ")) || - (_neu.includes("\""))) - { - return "ROI name must not contain . : , ; = \" or space"; - } - - index = -1; - found = false; - _indexnumber = -1; - for (j = 0; j < NUMBERS.length; ++j) - if (NUMBERS[j]["name"] == _number) - _indexnumber = j; - - if (_indexnumber == -1) - return "Number sequence not existing. ROI cannot be renamed" - - for (i = 0; i < NUMBERS[_indexnumber][_type].length; ++i) { - if (NUMBERS[_indexnumber][_type][i]["name"] == _alt) - index = i; - if (NUMBERS[_indexnumber][_type][i]["name"] == _neu) - found = true; - } - - if (found) - return "ROI name is already existing, please choose another name"; - - NUMBERS[_indexnumber][_type][index]["name"] = _neu; + if ((_neu.includes("=")) || (_neu.includes(".")) || (_neu.includes(":")) || (_neu.includes(",")) || (_neu.includes(";")) || (_neu.includes(" ")) || (_neu.includes("\""))) { + return "ROI name must not contain . : , ; = \" or space"; + } + + index = -1; + found = false; + _indexnumber = -1; + + for (j = 0; j < NUMBERS.length; ++j) { + if (NUMBERS[j]["name"] == _number) { + _indexnumber = j; + } + } + + if (_indexnumber == -1) { + return "Number sequence not existing. ROI cannot be renamed" + } + + for (i = 0; i < NUMBERS[_indexnumber][_type].length; ++i) { + if (NUMBERS[_indexnumber][_type][i]["name"] == _alt) { + index = i; + } + + if (NUMBERS[_indexnumber][_type][i]["name"] == _neu) { + found = true; + } + } + + if (found) { + return "ROI name is already existing, please choose another name"; + } + + NUMBERS[_indexnumber][_type][index]["name"] = _neu; - return ""; + return ""; } -function DeleteNUMBER(_delte){ - if (NUMBERS.length == 1) - return "The last number cannot be deleted" - - index = -1; - for (i = 0; i < NUMBERS.length; ++i) { - if (NUMBERS[i]["name"] == _delte) - index = i; - } +function DeleteNUMBER(_delte) { + if (NUMBERS.length == 1) { + return "The last number cannot be deleted" + } + + index = -1; + + for (i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _delte) { + index = i; + } + } - if (index > -1) { - NUMBERS.splice(index, 1); - } + if (index > -1) { + NUMBERS.splice(index, 1); + } - return ""; + return ""; } function CreateROI(_number, _type, _pos, _roinew, _x, _y, _dx, _dy, _CCW){ - _indexnumber = -1; - for (j = 0; j < NUMBERS.length; ++j) - if (NUMBERS[j]["name"] == _number) - _indexnumber = j; - - if (_indexnumber == -1) - return "Number sequence not existing. ROI cannot be created" - - found = false; - for (i = 0; i < NUMBERS[_indexnumber][_type].length; ++i) { - if (NUMBERS[_indexnumber][_type][i]["name"] == _roinew) - found = true; - } - - if (found) - return "ROI name is already existing, please choose another name"; - - _ret = new Object(); - _ret["name"] = _roinew; - _ret["x"] = _x; - _ret["y"] = _y; - _ret["dx"] = _dx; - _ret["dy"] = _dy; - _ret["ar"] = _dx / _dy; - _ret["CCW"] = _CCW; - - NUMBERS[_indexnumber][_type].splice(_pos+1, 0, _ret); - - return ""; + _indexnumber = -1; + + for (j = 0; j < NUMBERS.length; ++j) { + if (NUMBERS[j]["name"] == _number) { + _indexnumber = j; + } + } + + if (_indexnumber == -1) { + return "Number sequence not existing. ROI cannot be created" + } + + found = false; + + for (i = 0; i < NUMBERS[_indexnumber][_type].length; ++i) { + if (NUMBERS[_indexnumber][_type][i]["name"] == _roinew) { + found = true; + } + } + + if (found) { + return "ROI name is already existing, please choose another name"; + } + + _ret = new Object(); + _ret["name"] = _roinew; + _ret["x"] = _x; + _ret["y"] = _y; + _ret["dx"] = _dx; + _ret["dy"] = _dy; + _ret["ar"] = _dx / _dy; + _ret["CCW"] = _CCW; + + NUMBERS[_indexnumber][_type].splice(_pos+1, 0, _ret); + + return ""; } diff --git a/sd-card/html/setup.html b/sd-card/html/setup.html index 3c94bf9ba..a51c6ffa8 100644 --- a/sd-card/html/setup.html +++ b/sd-card/html/setup.html @@ -71,7 +71,7 @@

Digitizer - AI on the edge - Initial setup

-

An ESP32 all inclusive neural network recognition system for meter digitalization

+

An ESP32 all inclusive neural network recognition system for meter Digitization