Skip to content

Update camera example for support LED Intensity #6791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

DmytroKorniienko
Copy link

Closes #6790

@CLAassistant
Copy link

CLAassistant commented May 23, 2022

CLA assistant check
All committers have signed the CLA.

@me-no-dev
Copy link
Member

My 2 cents:

  • BrownOut should not be disabled here at all. Especially since you are using WiFi. BrownOut issues should be resolved in hardware. It is after all a hardware issue.
  • You have modified way more than just disabling BO and adding ledc init. Revert all other modifications in order to continue the discussion. Changing the example structure it outside of the scope of the issue.
  • It is hard to grasp what is the actual problem by reading all comments. Is it that the LED powers on full brightness and that causes the BO? If that is the case, then digitalWrite(LED, level_to_turn_off) in the beginning of setup() should be sufficient to turn off the LED

@DmytroKorniienko
Copy link
Author

My 2 cents:

  • BrownOut should not be disabled here at all. Especially since you are using WiFi. BrownOut issues should be resolved in hardware. It is after all a hardware issue.
  • You have modified way more than just disabling BO and adding ledc init. Revert all other modifications in order to continue the discussion. Changing the example structure it outside of the scope of the issue.
  • It is hard to grasp what is the actual problem by reading all comments. Is it that the LED powers on full brightness and that causes the BO? If that is the case, then digitalWrite(LED, level_to_turn_off) in the beginning of setup() should be sufficient to turn off the LED
  1. Changes reverted and new commit prepared
  2. BO not related with a LED but anyway I deleted this code part

@DmytroKorniienko DmytroKorniienko requested a review from SuGlider May 25, 2022 14:21
//#define CONFIG_LED_ILLUMINATOR_ENABLED 1
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
#define FLASH_LED_GPIO GPIO_NUM_4
#define CONFIG_LED_MAX_INTENSITY 255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_LED_MAX_INTENSITY - defined but not used anywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_LED_MAX_INTENSITY - defined but not used anywhere.

It used for UI led intensity limit

#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
void enable_led(bool en)
{ // Turn LED On or Off
    int duty = en ? led_duty : 0;
    if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY))
    {
        duty = CONFIG_LED_MAX_INTENSITY;
    }
    ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty);
    ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL);
    ESP_LOGI(TAG, "Set LED intensity to %d", duty);
}
#endif

#else
ESP_LOGI(TAG, "Flash led illumination is not configured");
#endif
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all this code should go to CameraWebServer.ino instead of here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all this code should go to CameraWebServer.ino instead of here.

Please take a look - CONFIG_LED_ILLUMINATOR_ENABLED is defined in a app_httpd.cpp file and MAY be undifined on compile time for CameraWebServer.ino since compile order may be various. So we have an issue in this case. This can be resolved by moving defines in the header file (as I suggest in the fist commit) but:

Changing the example structure it outside of the scope of the issue.

So what is your desision for this case? Move all defines in the one CameraWebServer.ino or separate header or something else?

cc: @me-no-dev

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually ... CONFIG_LED_ILLUMINATOR_ENABLED is defined nowhere.
I also searched it in sdkconfig and there is nothing there as well.

This is a sort of loose example, maybe coming from IDF.

I changed my mind... just leave it there. I see other code lines in app_httpd.cpp that test CONFIG_LED_ILLUMINATOR_ENABLED.

ledcSetup(LEDC_CHANNEL_0, 4000, LEDC_TIMER_8_BIT);
ledcAttachPin(FLASH_LED_GPIO, LEDC_CHANNEL_0);
#else
ESP_LOGI(TAG, "Flash led illumination is not configured");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Arduino function log_i(...) instead of IDF ESP_LOGI()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Arduino function log_i(...) instead of IDF ESP_LOGI()

There are more then one line with ESP_LOGI (I think example was ported from IDF), so all must be changed or only this one or maybe leave as is? :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... it is used all over in app_httpd.cpp.
If possible, it should be changed everywhere.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple for now. Keep it using ESP_LOGI()

@@ -1304,3 +1315,14 @@ void startCameraServer()
httpd_register_uri_handler(stream_httpd, &stream_uri);
}
}

void ledc_setup()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ledc_setup() could have as parameters all the information declared in the #define, making it more generic and clear.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ledc_setup() could have as parameters all the information declared in the #define, making it more generic and clear.

This is possible of course, but requre a lot of changes and still requre a defines since some boards can have different GPIO pins for led or not have a led at all. I can prepare such changes if you ready to review it, but first of all please look to the comment above where discussing about example structure. Can I append new header file for defines or not? I will move forvard depending of answer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ... maybe this example should be refactored for good.
Let's keep it simple for now. Keep it as you proposed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is a copy of another example we have for ESP-IDF and turned into Arduino sketch. Structure allows changes if they make sense :)

Copy link
Collaborator

@SuGlider SuGlider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are my suggestions for this PR.

@SuGlider
Copy link
Collaborator

SuGlider commented May 27, 2022

This example seems to come from an IDF example/structure.
It has a bad structure for an Arduino example and uses CONFIG_XXX with ESP_LOGX() etc.

I found some other Arduino and IDF implementations that are based on this same example:
https://github.com/easytarget/esp32-cam-webserver
https://github.com/bkeevil/esp32-cam (also with the webrowser and an Iluminator component)

I think the whole code may need a refactoring and a review.
Not sure if @DmytroKorniienko wants to do that.

Given it only modifies a tiny piece in the example, I'm also not sure what is best to do with it as well...
@me-no-dev - I would like your opinion again! It seems that the very first code was a good Arduino code, but it got changed along the time and now it seems it need a deep review.

@DmytroKorniienko
Copy link
Author

I think the whole code may need a refactoring and a review.
Not sure if @DmytroKorniienko wants to do that.

Unfortunately I'm not ready to spend a lot of time with this example. Reason is quite simple - this is not so interesting for me and I better continue work with my own project: https://github.com/DmytroKorniienko/esp32cam_EmbUI which has intesity support too and based on Asyncwebser. Feel free to close this PR and start new work with code refactoring if you want. No offense on my part :). I'm willing to make partial corrections, but not a complete rewrite of the example, because I don't think byte array-packed resources (index.html) are a good idea and prefer using a filesystem.

@rodyeo
Copy link

rodyeo commented Jul 27, 2022

The ESP32-CAM Flight Light LED Illuminator solution which everyone is awaiting is now resolved by the blog author and programmer Bye Renzo

https://www.mischianti.org/forums/topic/esp32-cam-upgrade-camerawebserver-with-flash-on-esp32-framework-2-0-4/

Thank you ;)

@VojtechBartoska VojtechBartoska added Type: Example Issue is related to specific example. Status: Needs investigation We need to do some research before taking next steps on this issue labels Aug 10, 2022
@VojtechBartoska
Copy link
Contributor

@PilnyTomas Please research shared resources and evaluate if the refactoring is needed and how. We can discuss later what are the options.

Related HW is available.

@PilnyTomas
Copy link
Contributor

PilnyTomas commented Aug 24, 2022

Have you tried compiling it for all the possible boards? Changes in PR should not break stuff for other users.
For example, S3 results in an error:
app_httpd.cpp:92:40: error: 'LEDC_HIGH_SPEED_MODE' was not declared in this scope

@VojtechBartoska VojtechBartoska added this to the 2.1.0 milestone Aug 24, 2022
@VojtechBartoska
Copy link
Contributor

any updates on this @DmytroKorniienko? Thanks

@VojtechBartoska
Copy link
Contributor

Due to no answer, @PilnyTomas will take over and finish this PR.

@DmytroKorniienko
Copy link
Author

Due to no answer, @PilnyTomas will take over and finish this PR.

Hi, I have some other tasks not related with opensource, so can't monitor PR with a so long lifecycle))). But I can take a look if this still necessary. I have ESP32-CAM and ESP32,ESP32-C3,ESP32-S2,ESP32-S3 without attached camera - so can only test ability to compile/link without errors. Let me know if this what you need, otherwise - feel free to do all needed work by yourself.

  • BTW Why CI hardware tests is skipped? I thought this easy can point to an errors and exclude routine checking...

@DmytroKorniienko
Copy link
Author

@PilnyTomas

Have you tried compiling it for all the possible boards? Changes in PR should not break stuff for other users. For example, S3 results in an error: app_httpd.cpp:92:40: error: 'LEDC_HIGH_SPEED_MODE' was not declared in this scope

You can use LOW SPEED mode, then code compiled without errors at S3:
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
#define CONFIG_LED_LEDC_LOW_SPEED_MODE

Moreover CONFIG_LED_ILLUMINATOR_ENABLED is DISABLED by default, so changes can't break something in an exising code. If you have any suggestions - please explain.

CC: @VojtechBartoska

@PilnyTomas
Copy link
Contributor

Hi @DmytroKorniienko, the code should detect which board is used with #if CONFIG_IDF_TARGET_ESP32S3 and decide whether to enable some functionality or not. The aim is that the user will be able to compile for any SoC or board without any change in code.

@DmytroKorniienko
Copy link
Author

Hi @DmytroKorniienko, the code should detect which board is used with #if CONFIG_IDF_TARGET_ESP32S3 and decide whether to enable some functionality or not. The aim is that the user will be able to compile for any SoC or board without any change in code.

Hi @PilnyTomas, as I said - CONFIG_LED_ILLUMINATOR_ENABLED is disabled by default. Are you think there is a good idea to enable it??? Some boards can be without leds at all, some have led on a other pin then ESP32_CAM module and at my opinion - impossible make universal variant for all cases. But if you want and going to do improvements - go ahead.

BTW: Instead of analyzing CONFIG_IDF_TARGET_ESP32S3 better check SOC_LEDC_SUPPORT_HS_MODE, look at hal/ledc_types.h:

typedef enum {
#if SOC_LEDC_SUPPORT_HS_MODE
    LEDC_HIGH_SPEED_MODE = 0, /*!< LEDC high speed speed_mode */
#endif
    LEDC_LOW_SPEED_MODE,      /*!< LEDC low speed speed_mode */
    LEDC_SPEED_MODE_MAX,      /*!< LEDC speed limit */
} ledc_mode_t;

@P-R-O-C-H-Y
Copy link
Member

@DmytroKorniienko Thanks for your time, but closing this PR as I have created new PR #7533 with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs investigation We need to do some research before taking next steps on this issue Type: Example Issue is related to specific example.
Projects
Development

Successfully merging this pull request may close these issues.

LED Intensity support is missed in the example CameraWebServer
8 participants