Skip to content

add set_gas_heater(); Was available on arduino but not CircuitPython #61

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 5 commits into from
Jun 5, 2023

Conversation

garberw
Copy link
Contributor

@garberw garberw commented Mar 16, 2023

translated Bosch code from .cpp to python. Not sure about license.
Having trouble with code checks in pull request and how to fix them and resubmit.

@garberw
Copy link
Contributor Author

garberw commented Mar 16, 2023

all checks passed. took three attempts.

@jposada202020 jposada202020 requested a review from a team March 16, 2023 11:37
@@ -45,10 +97,34 @@
except ImportError:
pass

__version__ = "0.0.0+auto.0"
__version__ = "3.4.12"
Copy link
Contributor

Choose a reason for hiding this comment

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

This version should stay the way it was. All of our libraries have this placeholder value that gets filled in by the actions when releases are made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes by all means; was not sure how to do this !!

@FoamyGuy
Copy link
Contributor

Thanks for adding this additional functionality. Can you link to the code or project that you worked from where you got the license that was added?

I think the format for it needs to be a bit different, but I'm not positive, will bring it up to some others for input.

@garberw
Copy link
Contributor Author

garberw commented Mar 20, 2023

github adafruit bme680 arduino code including Bosch library
github adafruit bme680 arduino code bme68x.c file from Bosch library

Bosch code includes Bosch license.

My code is just a translation of the relevant parts of the Bosch library (the open source part) from C to Python.
We still need to check some of the bit manipulation. The C code expects uint8_t is different from uint32_t for
example whereas python uses "unlimited precision integers".

USE AT YOUR OWN RISK. I tried it and it runs. Since it is a heater I am not sure how to test if it works !!!!
I don't think it would really be likely to burn out your heater though.

NOTE the adafruit python defaults were the same as the C arduino defaults but until now we had no easy way to change them.

@tekktrik
Copy link
Member

tekktrik commented Mar 20, 2023

BSD should be REUSE compliant, for what it's worth. You can add multiple licenses to files by adding the license to LICENSES/ and adding it as an SPDX header: https://github.com/tekktrik/CircuitPython_CSV/blob/main/circuitpython_csv.py I think BSD 3 Clause is roughly equivalent to MIT but may be worth considering if we want to use code requiring multiple licenses.

I can also take a look at some of the typing here, and I think the syntax and exact implementation can be made to conform more to the other those of the other libraries due to implementation differences. For example, I see casts to float where I don't believe they're necessary because CircuitPython division of int and float always results in float so there's no need to cast.

@garberw
Copy link
Contributor Author

garberw commented Mar 20, 2023

Yes the casts to float were more of a form of documentation.

@FoamyGuy
Copy link
Contributor

We discussed this in the weeds during 4/24 meeting. Conclusion was that it is okay to bring in BSD-3 licensed code.

I'll work on getting the attribution lines setup and revert the version back to 0s.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

The latest commit moves the BSD license over to it's own file and is now re-use compliant and passing actions.

The changes look good to me, but I don't have the right hardware for testing the functionality.

@FoamyGuy FoamyGuy merged commit d7909fe into adafruit:main Jun 5, 2023
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.

Took a quick look, but I also don't have hardware I think. I think I'd like to take a second look at this once some of these points have been resolved just to see if there's anything I missed. I appreciate everyone's work!

Comment on lines +34 to +36
@file bme68x_defs.h
@date 2021-05-24
@version v4.4.6
Copy link
Member

Choose a reason for hiding this comment

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

I think these should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

@@ -14,6 +16,10 @@

* Author(s): Limor Fried


original Adafruit_BME680 with addition of set_gas_heater(). Other new members are private.
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed, I think we can just use the GitHub release to announce things similar to a changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

Comment on lines +488 to +493
* @brief Enable and configure gas reading + heater
* @param heater_temp
* Desired temperature in degrees Centigrade
* @param heater_time
* Time to keep heater on in milliseconds
* @return True on success, False on failure
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the Arduino-style docstrings, so instances of these will need to be converted to the typical style for sphinx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct

Comment on lines +156 to +161
INT32 = int
INT16 = int
INT8 = int
UINT32 = int
UINT16 = int
UINT8 = int
Copy link
Member

Choose a reason for hiding this comment

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

I think using int in all applicable places is fine since there isn't really a distinct "typewise" within Python. If needed, docstrings should explain limits (e.g., 0 - 255). That will save us using type aliases where not strictly needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

@@ -116,6 +152,43 @@
)


# garberw added begin ===========================
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed since it's a contextual comment.

Copy link
Member

Choose a reason for hiding this comment

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

There's a few comments like these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they were just meant to highlight changes. remove them for sure.

return (reg_data & ~bitname_msk) | (data & bitname_msk)


class GasHeaterException(Exception):
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a hyperspecific exception that could just be replaced with something like OSError, most likely.

Comment on lines +495 to +496
if (heater_temp == 0) or (heater_time == 0):
return False
Copy link
Member

Choose a reason for hiding this comment

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

This could be:

Suggested change
if (heater_temp == 0) or (heater_time == 0):
return False
if not heater_temp or not heater_time:
return False

Comment on lines +506 to +515
op_mode: UINT8 = _BME68X_FORCED_MODE
# restrict to enable = True
enable: bool = True
nb_conv: UINT8 = 0
hctrl: UINT8 = _BME68X_ENABLE_HEATER
run_gas: UINT8 = 0
ctrl_gas_data_0: UINT8 = 0
ctrl_gas_data_1: UINT8 = 0
ctrl_gas_addr_0: UINT8 = _BME68X_REG_CTRL_GAS_0
ctrl_gas_addr_1: UINT8 = _BME68X_REG_CTRL_GAS_1
Copy link
Member

Choose a reason for hiding this comment

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

I think this is using a lot of local variables where using what they equate to might be more efficient. This comment holds for the other methods as well.

Comment on lines +1 to +11
# SPDX-FileCopyrightText: 2017 ladyada for Adafruit Industries
#
# SPDX-License-Identifier: MIT

Contributors to Adafruit_CircuitPython_BME680_modified
=============================================================

Limor (Ladyada) Fried

William Garber
many others
Copy link
Member

Choose a reason for hiding this comment

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

It might be worth just adding contributors' names to the SPDX headers as opposed to using a contribuitors file (for consistency reason).

Comment on lines +573 to +574
except GasHeaterException as exc:
raise exc
Copy link
Member

Choose a reason for hiding this comment

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

Since the exception is just being passed through, I don't think there's a need to try the above block. There's another instance of this below as well.

@garberw
Copy link
Contributor Author

garberw commented Jun 5, 2023 via email

@garberw
Copy link
Contributor Author

garberw commented Jun 5, 2023 via email

@tekktrik
Copy link
Member

tekktrik commented Jun 6, 2023

Ah, I apologize, I did not realize at the time that this wasn't a request for review, but the merging. No worriies, if you'd like to address it, I would open a new PR. Otherwise, it can be a TODO for later :)

@garberw
Copy link
Contributor Author

garberw commented Jun 6, 2023 via email

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 6, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_BME680 to 3.5.0 from 3.4.13:
  > Merge pull request adafruit/Adafruit_CircuitPython_BME680#61 from garberw/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_Crickit to 2.3.15 from 2.3.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_Crickit#37 from OptionalLion411/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_MatrixKeypad to 1.2.14 from 1.2.13:
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixKeypad#16 from gtbcoding/isssue/13-type-annotation

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
@FoamyGuy
Copy link
Contributor

Sorry for the confusion on this one, I can make a follow up PR with those suggested changes

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.

3 participants