Skip to content
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

memory_optimization #15

Closed
wants to merge 10 commits into from
Closed

memory_optimization #15

wants to merge 10 commits into from

Conversation

jposada202020
Copy link
Contributor

@jposada202020 jposada202020 commented Mar 17, 2023

For a QT PY M0, you must use the mpy file. closes #11

These are breaking changes. Learning Guide probably need updating.

Tested with examples.
Initial test code:

# SPDX-FileCopyrightText: 2023 Jose D. Montoya
#
# SPDX-License-Identifier: Unlicense

"""
TMP117 Properties Test
"""
import time
import board
import adafruit_tmp117

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
tmp117 = adafruit_tmp117.TMP117(i2c)
alert_status = tmp117.alert_status
while True:
    print("My ID:", tmp117._part_id)
    print("My Serial Numer: ", tmp117.serial_number)
    print("Temperature Offset: ", tmp117.temperature_offset)
    print("High Limit: ", tmp117.high_limit)
    print("Low Limit: ", tmp117.low_limit)
    print("Alert status: ", tmp117.alert_status)
    print("High alert:", alert_status.high_alert)
    print("Low alert:", alert_status.low_alert)
    print("Averaged Measurements: ", tmp117.averaged_measurements)
    print("Measurement Mode: ", tmp117.measurement_mode)
    print("Measurement Delay: ", tmp117.measurement_delay)
    print("Alert Mode: ", tmp117.alert_mode)
    print("Temperature: %.2f degrees C" % tmp117.temperature)
    time.sleep(1)

Results

Adafruit CircuitPython 8.0.4 on 2023-03-15; Adafruit QT Py M0 with samd21e18
>>> import tb
My ID: 279
My Serial Numer:  bytearray(b'\x0co\x0fpG\xa4')
Temperature Offset:  0.0
High Limit:  192.0
Low Limit:  -256.0
Alert status:  AlertStatus(high_alert=False, low_alert=False)
High alert: False
Low alert: False
Averaged Measurements:  1
Measurement Mode:  0
Measurement Delay:  4
Alert Mode:  False
Temperature: 19.52 degrees C

@jposada202020 jposada202020 requested a review from a team March 17, 2023 10:11
Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Is this optimization needed for a specific use case? I don't think it's bad or anything, but I do know that other libraries use the CV method to emulate enum-like behavior.

I think it's worth bringing up how to bets optimize this. Another solution would be to create a library that provides this functionality, as currently if you use multiple libraries that have it then it's just duplicated. This Arduino-like "definition" solution would also work though, but has the drawback of being slightly un-Pythonic since the enum-like behavior of Category.SELECTION is appealing and very user-friendly. Definitely would want to hear what others have to say.

@jposada202020
Copy link
Contributor Author

Hiya, optimization is needed for M0 boards where the library currently does not fit.
In order to do this, as previously discussed with @dhalbert in issue #11, I removed CV in this PR.
I saw this as a solution to solve the memory optimization issue. For sure there are tradeoffs, and maybe there are better solutions, but this one that I found to work. :)

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Gotchyha, thanks for clarifying! I added some feedback below.

examples/tmp117_rate_and_averaging_test.py Outdated Show resolved Hide resolved
examples/tmp117_rate_and_averaging_test.py Outdated Show resolved Hide resolved
examples/tmp117_single_measurement_test.py Outdated Show resolved Hide resolved
docs/conf.py Outdated Show resolved Hide resolved
adafruit_tmp117.py Outdated Show resolved Hide resolved
adafruit_tmp117.py Outdated Show resolved Hide resolved
adafruit_tmp117.py Show resolved Hide resolved
adafruit_tmp117.py Outdated Show resolved Hide resolved
adafruit_tmp117.py Show resolved Hide resolved
@jposada202020
Copy link
Contributor Author

Last commit dd7a0ab is a proposal to get the properties values more clean. I have tested and works with all the examples. However, we could also use the proposed change in 719aebd .

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Let's revert this back to 719aebd since I think it's better to have getters return the same thing (e.g., if obj.x = 4, then x = obj.x should also be 4) That makes comparisons much easier as well. I also added a comment or two above!

@jposada202020
Copy link
Contributor Author

Reverted to desired state after having some quality time with GIT 😮‍💨

@jposada202020 jposada202020 closed this by deleting the head repository May 13, 2023
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.

QTPy Memory Error
2 participants