Skip to content

Progress towards getting LED flash working#85

Open
acutetech wants to merge 1 commit intorecheck_camera_combinationsfrom
led_flash_work
Open

Progress towards getting LED flash working#85
acutetech wants to merge 1 commit intorecheck_camera_combinationsfrom
led_flash_work

Conversation

@acutetech
Copy link

I am experimenting to find out what is necessary to get the LED flash turning on at the right times so that the motion detection frames are illuminated every 1s (or so) and also the frames which grab the actual images once awake.

This is work in progress and I am not there yet.

However I have detected a problem where the LED turns on and stays on - I have a hypothesis on this and in the spirit of having branches that add just one feature I am going to pause this branch and make a new one "semaphore_for_I2C" to investigate that.

BTW, this branch fixes a couple of points that came up in an earlier review.

@gemini-code-assist
Copy link

Summary of Changes

Hello @acutetech, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on advancing the integration of LED flash with motion detection, aiming to ensure proper illumination during both motion detection and subsequent image capture. Key changes involve a significant refactoring of the HM0360 image sensor's preparation and strobe control logic, alongside the introduction of a new utility for precise timing measurements within the image processing and neural network pipeline. The PR also includes general code cleanup, improved variable initialization, and updates to the build system and documentation, addressing feedback from previous reviews.

Highlights

  • LED Flash and HM0360 Configuration: Refactored the HM0360 image sensor's preparation for motion detection and its STROBE output configuration for LED flash, including the removal of the hm0360_md_enableMD function and integration of its logic into an enhanced hm0360_md_prepare function.
  • Timing and Debugging Improvements: Introduced a new utility function, app_getElapsedMs, to accurately measure elapsed time, and integrated it into the image processing task to monitor the duration of image capture and neural network execution.
  • Code Cleanup and Initialization: Addressed several minor code quality issues, such as initializing variables (cameraSystemEnabled, cameraInitialised), clarifying comments, and replacing sprintf with cli_append for CLI output.
  • Build System Update: Modified the makefile to ensure the main C file is consistently rebuilt, guaranteeing that build timestamps reflect the latest compilation.
  • Documentation and Strobe Experimentation: Updated the HM0360 summary documentation with a new date and external resources, and added several new configuration files in the _Tools directory to support ongoing experiments with HM0360 strobe settings.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/CLI-commands.c
    • Replaced sprintf with cli_append for CLI output.
    • Converted a multi-line comment to a single-line comment.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/cvapp.cpp
    • Added a comment clarifying the TFLM library definition.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/fatfs_task.c
    • Commented out calls to f_chdir in load_configuration and save_configuration.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/hm0360_md.c
    • Removed the hm0360_md_enableMD function.
    • Modified hm0360_md_prepare to accept mdFrameInterval and incorporate logic previously in hm0360_md_enableMD.
    • Added a call to ledFlashDisable() at the start of image_sleepNow.
    • Consolidated conditional compilation blocks for HM0360.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/hm0360_md.h
    • Updated the signature of hm0360_md_prepare to include mdFrameInterval.
    • Commented out the declaration of hm0360_md_enableMD.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/if_task.c
    • Added a descriptive comment for xI2CTxSemaphore.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/image_task.c
    • Added a detailed file header comment.
    • Initialized cameraSystemEnabled to 0 and cameraInitialised to false.
    • Removed local timing variables and replaced their usage with the new app_getElapsedMs function.
    • Removed CAMERA_CONFIG_MD case from configure_image_sensor.
    • Added startTime initialization before NN initialization and printed NN initialization time.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/image_task.h
    • Removed CAMERA_CONFIG_MD from the CAMERA_CONFIG_E enum.
    • Changed FLASHDURATION define from 100 to 50.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/ww500_md.c
    • Implemented app_getElapsedMs function to calculate elapsed time in milliseconds.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/ww500_md.h
    • Declared the new app_getElapsedMs function.
  • EPII_CM55M_APP_S/app/ww_projects/ww500_md/ww500_md.mk
    • Introduced OBJECT_DESTINATION variable and updated the force_rebuild_main target to use it, ensuring consistent rebuilds.
  • _Documentation/HM0360_on WW500_Summary.md
    • Updated the date in the document header.
    • Added a new section "Other sources of Information" with links to HM0360 examples.
  • _Tools/hm0360_strobe_dynamic1.txt
    • Added a new file for dynamic strobe configuration experiments.
  • _Tools/hm0360_strobe_dynamic1B.txt
    • Added a new file for dynamic strobe configuration experiments, setting STROBE_FRAME_L to 0.
  • _Tools/hm0360_strobe_dynamic1C.txt
    • Added a new file for dynamic strobe configuration experiments, setting STROBE_FRAME_L to 1.
  • _Tools/hm0360_strobe_dynamic1D.txt
    • Added a new file for dynamic strobe configuration experiments, setting STROBE_FRAME_L to 2.
  • _Tools/hm0360_strobe_dynamic1E.txt
    • Added a new file for dynamic strobe configuration experiments, setting STROBE_FRAME_L to 3.
  • _Tools/hm0360_strobe_dynamic1F.txt
    • Added a new file for dynamic strobe configuration experiments, restoring STROBE_FRAME_L to 4.
  • _Tools/hm0360_strobe_static.txt
    • Renamed to _Tools/hm0360_strobe_align_end.txt.
    • Modified STROBE_CFG and STROBE_SEL register values for strobe configuration.
  • _Tools/hm0360_strobe_static_off.txt
    • Renamed to _Tools/hm0360_strobe_dynamic1A.txt.
    • Modified STROBE_CFG register value for strobe configuration.
  • _Tools/hm0360_strobe_static_on.txt
    • Renamed to _Tools/hm0360_strobe_line200.txt.
    • Modified STROBE_CFG and STROBE_LINE_L register values for strobe configuration.
Activity
  • The author is actively experimenting with LED flash timing for motion detection and image capture.
  • A potential issue with the LED staying on has been identified, leading to a planned new branch ('semaphore_for_I2C') for further investigation.
  • Several minor issues identified in a previous review have been addressed in this branch.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request focuses on refining the LED flash functionality and motion detection settings for the HM0360 camera. Key changes include refactoring time measurement logic into a utility function, consolidating HM0360 configuration, and updating flash duration. Several configuration files for the HM0360 strobe settings have also been added or modified, reflecting ongoing experimentation. The changes also address minor code cleanliness improvements such as explicit variable initialization and removal of unused variables.

Comment on lines +749 to +750
// CGP - no need to?
//f_chdir(dirManager->base_dir);

Choose a reason for hiding this comment

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

medium

The f_chdir(dirManager->base_dir); call is commented out with a note "CGP - no need to?". If this line is truly no longer needed, it should be removed entirely to avoid dead code and potential confusion. If it's a temporary disablement for testing, please add a more descriptive comment explaining the reason and the plan for its eventual removal or re-enablement.

Comment on lines +843 to +844
// CGP - no need to?
//f_chdir(dirManager->base_dir);

Choose a reason for hiding this comment

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

medium

Similar to the previous comment, this f_chdir(dirManager->base_dir); call is commented out. Please clarify if it's permanently removed or temporarily disabled, and update the code or comment accordingly.

uint8_t brightnessPercent;
uint8_t mdInterval;

uint16_t mdInterval;

Choose a reason for hiding this comment

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

medium

The type of mdInterval has been changed from uint8_t to uint16_t. Please add a comment explaining the reason for this type promotion. Is it to support larger motion detection intervals, or for another purpose?

    uint16_t mdInterval; // Changed from uint8_t to support larger intervals

Comment on lines +2649 to +2679
// Now merged (above)
//#ifdef USE_HM0360_MD
// // HM0360 for motion detection only.
// // If the camera system is disabled then ensure MD is off and flash LED is off
// if (hm0360_md_isHM0360Present()) {
// hm0360_md_prepare(enabled, mdInterval); // select CONTEXT_B registers (if enabled)
//
// // Consider turning on the LED flashes, controlled by the HM0360 STROBE output
// if (!enabled) {
// // No STROBE pulses
// xprintf("Camera disabled - no LED flashes\n");
// hm0360_md_configureStrobe(0);
// }
// else if ((brightnessPercent == 0) || (ledInUse == 0)) {
// // No STROBE pulses
// xprintf("Preparing HM0360 for MD - no LED flashes\n");
// hm0360_md_configureStrobe(0);
// }
// else {
// // Configure STROBE pulses - NOTE: normal mode is 0x0b = 'dynamic 2'
// xprintf("Preparing HM0360 for MD - with LED flashes 0x%02x\n", fatfs_getOperationalParameter(OP_PARAMETER_STROBE_MODE));
// //hm0360_md_configureStrobe(0x0B);
// hm0360_md_configureStrobe(fatfs_getOperationalParameter(OP_PARAMETER_STROBE_MODE));
// }
// }
// else {
// // HM0360 is missing
// xprintf("HM0360 missing...\n");
// }
//
//#endif // USE_HM0360_MD

Choose a reason for hiding this comment

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

medium

The previous #ifdef USE_HM0360_MD block has been commented out after merging its logic into the combined #if defined(USE_HM0360) || defined(USE_HM0360_MD) block. Once the new consolidated logic is confirmed stable, this large commented-out section should be removed to reduce code clutter and improve readability.


// Default Duration (ms) that LED Flash is on
#define FLASHDURATION 100
#define FLASHDURATION 50

Choose a reason for hiding this comment

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

medium

The FLASHDURATION has been reduced from 100 to 50 milliseconds. Please add a comment explaining the functional reason for this change. For example, is it for power saving, to prevent overexposure, or based on new hardware characteristics?

#define FLASHDURATION 50 // Reduced to 50ms to prevent overexposure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant