Skip to content

fix: fix data acquisition from TSL2561 luminosity sensor #2790

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

Merged
merged 3 commits into from
Jul 18, 2025

Conversation

marcnause
Copy link
Contributor

@marcnause marcnause commented Jul 17, 2025

Fixes #2783

Changes

  • Try to find sensor by checking all possible sensor IDs (0x29, 0x39, 0x49)
  • Fix data acquisition
  • Display sensor IDs in hex format in Sensors screen

I think there are still a few things to fix in the screen, but data acquisition works, which was the scope of the issue.

Screenshots / Recordings

Screen_recording_20250717_191534.mp4

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Add support for detecting TSL2561 sensors at multiple I2C addresses and correct raw luminosity reads, while updating the sensor screen to display addresses in hex

New Features:

  • Detect TSL2561 devices by probing all potential I2C addresses (0x29, 0x39, 0x49)
  • Display sensor addresses in hexadecimal format in the Sensor screen

Bug Fixes:

  • Fix raw data acquisition for full spectrum, infrared, and visible channels using correct read commands and bit operations

Enhancements:

  • Refactor TSL2561 class to centralize constants, use byte types, and streamline enable/read logic
  • Update SensorActivity to use integer lists for addresses and rebuild scan output accordingly

@marcnause marcnause added Bug Unexpected problem or unintended behavior in app Fix Solution to an existing issue in app java Pull requests that update Java code labels Jul 17, 2025
Copy link

sourcery-ai bot commented Jul 17, 2025

Reviewer's Guide

Refactor the TSL2561 sensor driver to scan multiple I2C addresses, clean up constants, and correct data reads, and update the sensor list UI to use integer addresses and show IDs in hex.

File-Level Changes

Change Details Files
Refactor TSL2561 implementation for robust address scanning and accurate data acquisition
  • Converted magic values into grouped static final constants
  • Introduced ADDRESSES array and loop to detect sensor at 0x29,0x39,0x49
  • Unified I2C read/write calls to use dynamic address and WORD_BIT/COMMAND_BIT flags
  • Corrected raw reading logic (byte masking, combining) and replaced sleeps with switch-case
app/src/main/java/io/pslab/communication/sensors/TSL2561.java
Update sensor activity to use integer addresses and display IDs in hex
  • Changed dataAddress type from String to Integer and updated bundle save/restore
  • Reordered and expanded sensorAddr map to include multiple TSL2561 addresses
  • Built scan result string to prefix addresses with 0x and use hex format
  • Updated list population to append integer addresses and sensor names accordingly
app/src/main/java/io/pslab/activity/SensorActivity.java

Assessment against linked issues

Issue Objective Addressed Explanation
#2783 Ensure that data from the TSL2561 sensor is correctly acquired and displayed in the corresponding screen.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

github-actions bot commented Jul 17, 2025

@marcnause marcnause added Status: Review Required Requested reviews from peers and maintainers and removed Bug Unexpected problem or unintended behavior in app labels Jul 17, 2025
Copy link
Collaborator

@AsCress AsCress left a comment

Choose a reason for hiding this comment

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

@marcnause Thank you very much for this !

When the sensor was probed a second time after being active, the expected value was not returned and the app did not recognize the sensor.
@AsCress AsCress merged commit 04bafa8 into fossasia:development Jul 18, 2025
4 checks passed
@marcnause marcnause deleted the fixTSL2561 branch July 20, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Solution to an existing issue in app java Pull requests that update Java code Status: Review Required Requested reviews from peers and maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants