From 0dfdcbeed9d24596fd9516b00a5203f197764912 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 16 Jul 2020 14:23:59 -0700 Subject: [PATCH 1/5] added the lsm6dso32 --- README.rst.license | 3 ++ adafruit_lsm6ds.py | 50 ++++++++++++++++++++----- examples/lsm6ds_lsm6dso32_simpletest.py | 12 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 README.rst.license create mode 100644 examples/lsm6ds_lsm6dso32_simpletest.py diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds.py index c54bfcc..8b267e7 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds.py @@ -123,16 +123,6 @@ class AccelRange(CV): """Options for ``accelerometer_range``""" -AccelRange.add_values( - ( - ("RANGE_2G", 0, 2, 0.061), - ("RANGE_16G", 1, 16, 0.488), - ("RANGE_4G", 2, 4, 0.122), - ("RANGE_8G", 3, 8, 0.244), - ) -) - - class GyroRange(CV): """Options for ``gyro_data_range``""" @@ -236,6 +226,7 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS): self._bdu = True + self._add_accel_ranges() self.accelerometer_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member self.gyro_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member @@ -248,10 +239,22 @@ def reset(self): while self._sw_reset: sleep(0.001) + @staticmethod + def _add_accel_ranges(): + AccelRange.add_values( + ( + ("RANGE_2G", 0, 2, 0.061), + ("RANGE_16G", 1, 16, 0.488), + ("RANGE_4G", 2, 4, 0.122), + ("RANGE_8G", 3, 8, 0.244), + ) + ) + @property def acceleration(self): """The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2.""" raw_accel_data = self._raw_accel_data + x = self._scale_xl_data(raw_accel_data[0]) y = self._scale_xl_data(raw_accel_data[1]) z = self._scale_xl_data(raw_accel_data[2]) @@ -386,6 +389,33 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS): self._i3c_disable = True +class LSM6DSO32(LSM6DS): # pylint: disable=too-many-instance-attributes + + """Driver for the LSM6DSO32 6-axis accelerometer and gyroscope. + + :param ~busio.I2C i2c_bus: The I2C bus the LSM6DSO32 is connected to. + :param address: The I2C slave address of the sensor + + """ + + CHIP_ID = _LSM6DS_CHIP_ID + + def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS): + super().__init__(i2c_bus, address) + self._i3c_disable = True + self.accelerometer_range = AccelRange.RANGE_8G # pylint:disable=no-member + + def _add_accel_ranges(self): + AccelRange.add_values( + ( + ("RANGE_4G", 0, 4, 0.122), + ("RANGE_32G", 1, 32, 0.976), + ("RANGE_8G", 2, 8, 0.244), + ("RANGE_16G", 3, 16, 0.488), + ) + ) + + class LSM6DS33(LSM6DS): # pylint: disable=too-many-instance-attributes """Driver for the LSM6DS33 6-axis accelerometer and gyroscope. diff --git a/examples/lsm6ds_lsm6dso32_simpletest.py b/examples/lsm6ds_lsm6dso32_simpletest.py new file mode 100644 index 0000000..6fcd137 --- /dev/null +++ b/examples/lsm6ds_lsm6dso32_simpletest.py @@ -0,0 +1,12 @@ +import time +import board +import busio +from adafruit_lsm6ds import LSM6DSO32 + +i2c = busio.I2C(board.SCL, board.SDA) +sensor = LSM6DSO32(i2c) +while True: + print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration)) + print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro)) + print("") + time.sleep(0.5) From a3938a09fb95b49005da51ecbdffee8ccfc6b27b Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 16 Jul 2020 18:37:51 -0700 Subject: [PATCH 2/5] adding the lsm6dso32 --- .github/workflows/build.yml | 18 +- .github/workflows/release.yml | 4 + .gitignore | 6 + .pre-commit-config.yaml | 19 ++ .pylintrc | 4 + .readthedocs.yml | 4 + CODE_OF_CONDUCT.md | 16 +- LICENSES/CC-BY-4.0.txt | 324 +++++++++++++++++++++++ LICENSES/MIT.txt | 19 ++ LICENSES/Unlicense.txt | 20 ++ README.rst | 10 +- adafruit_lsm6ds.py | 20 +- docs/_static/favicon.ico.license | 3 + docs/api.rst.license | 3 + docs/conf.py | 24 +- docs/examples.rst.license | 3 + docs/index.rst | 25 +- docs/index.rst.license | 3 + examples/lsm6ds_full_test.py | 3 + examples/lsm6ds_ism330dhct_simpletest.py | 3 + examples/lsm6ds_lsm6ds33_simpletest.py | 3 + examples/lsm6ds_lsm6dso32_simpletest.py | 3 + examples/lsm6ds_lsm6dsox_simpletest.py | 3 + examples/lsm6ds_pedometer.py | 3 + examples/lsm6ds_rate_test.py | 3 + pyproject.toml | 6 + requirements.txt | 5 + setup.py | 10 +- 28 files changed, 539 insertions(+), 28 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst.license create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst.license create mode 100644 pyproject.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6977a9..07a71f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,14 +42,14 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting + - name: Pre-commit hooks run: | - black --check --target-version=py35 . + pre-commit run --all-files - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) @@ -55,3 +59,9 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Build Python package + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: diff --git a/.gitignore b/.gitignore index e7e0f2d..2c6ddfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,15 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + *.mpy .idea __pycache__ _build *.pyc .env +.python-version +build*/ bundles *.DS_Store .eggs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6cd77e3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: 19.10b0 + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: latest + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace diff --git a/.pylintrc b/.pylintrc index d8f0ee8..54a9d35 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/.readthedocs.yml b/.readthedocs.yml index f4243ad..a1e2575 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 7ca3a1d..be1966c 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + # Adafruit Community Code of Conduct ## Our Pledge @@ -34,6 +40,8 @@ Examples of unacceptable behavior by participants include: * Excessive or unwelcome helping; answering outside the scope of the question asked * Trolling, insulting/derogatory comments, and personal or political attacks +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission @@ -72,10 +80,10 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community moderators. You may also send an -open message from any channel, or a direct message to @kattni#1507, -@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or -@Andon#8175. +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @danh#1614, @cater#2442, +@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst b/README.rst index 49322d2..9acc2d1 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg - :target: https://adafru.it/discord + :target: https://discord.gg/nBQh6qu :alt: Discord @@ -14,7 +14,11 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS/actions :alt: Build Status -CircuitPython library for the ST LSM6DSOX, LSM6DS33, and ISM330DHCX 6-dof Accelerometer and Gyros +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + +CircuitPython helper library for the LSM6DS family of motion sensors from ST Dependencies @@ -27,7 +31,7 @@ This driver depends on: Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading -`the Adafruit library and driver bundle `_. +`the Adafruit library and driver bundle `_. Installing from PyPI ===================== diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds.py index 8b267e7..ac9138b 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT # The MIT License (MIT) # # Copyright (c) 2019 Bryan Siepert for Adafruit Industries @@ -23,7 +26,7 @@ `adafruit_lsm6ds` ================================================================================ -CircuitPython library for the ST LSM6DSOX 6-axis Accelerometer and Gyro +CircuitPython helper library for the LSM6DS family of motion sensors from ST * Author(s): Bryan Siepert @@ -35,6 +38,19 @@ * Adafruit LSM6DSOX Breakout +* Adafruit ISM330DHCX Breakout + +* Adafruit LSM6DSO32 Breakout + +* Adafruit LSM6DS33 Breakout + +* Adafruit ISM330DHCX + LIS3MDL FEATHERWING + +* Adafruit LSM6DSOX + LIS3MDL - 9 DOF IMU Breakout + +* Adafruit LSM6DS33 + LIS3MDL - 9 DOF IMU Breakout + +* Adafruit LSM6DSOX + LIS3MDL 9 DOF IMU FeatherWing **Software and Dependencies:** @@ -57,7 +73,7 @@ from adafruit_register.i2c_bit import RWBit __version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS.git" _LSM6DS_DEFAULT_ADDRESS = const(0x6A) diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index d3dfe22..db5f737 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys @@ -46,7 +50,7 @@ master_doc = "index" # General information about the project. -project = "Adafruit LSM6DSOX Library" +project = "Adafruit LSM6DS Library" copyright = "2019 Bryan Siepert" author = "Bryan Siepert" @@ -122,7 +126,7 @@ html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = "AdafruitLsm6dsoxLibrarydoc" +htmlhelp_basename = "AdafruitLsm6dsLibrarydoc" # -- Options for LaTeX output --------------------------------------------- @@ -147,8 +151,8 @@ latex_documents = [ ( master_doc, - "AdafruitLSM6DSOXLibrary.tex", - "AdafruitLSM6DSOX Library Documentation", + "AdafruitLSM6DSLibrary.tex", + "AdafruitLSM6DS Library Documentation", author, "manual", ), @@ -161,11 +165,11 @@ man_pages = [ ( master_doc, - "AdafruitLSM6DSOXlibrary", - "Adafruit LSM6DSOX Library Documentation", + "AdafruitLSM6DSlibrary", + "Adafruit LSM6DS Library Documentation", [author], 1, - ) + ), ] # -- Options for Texinfo output ------------------------------------------- @@ -176,10 +180,10 @@ texinfo_documents = [ ( master_doc, - "AdafruitLSM6DSOXLibrary", - "Adafruit LSM6DSOX Library Documentation", + "AdafruitLSM6DSLibrary", + "Adafruit LSM6DS Library Documentation", author, - "AdafruitLSM6DSOXLibrary", + "AdafruitLSM6DSLibrary", "One line description of project.", "Miscellaneous", ), diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/docs/index.rst b/docs/index.rst index 709c5c0..9759d9a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -20,16 +20,37 @@ Table of Contents api +.. toctree:: + :caption: Tutorials + + LSM6DSOX and ISM330DHC 6 DoF IMU Guide + Adafruit LSM6DS33 6-DoF IMU Breakout Guide + ST 9-DoF Combo Breakouts and Wings Guide + .. toctree:: :caption: Related Products - Adafruit LSM6DSOX Breakout + * Adafruit LSM6DSOX Breakout + + * Adafruit ISM330DHCX Breakout + + * Adafruit LSM6DSO32 Breakout + + * Adafruit LSM6DS33 Breakout + + * Adafruit ISM330DHCX + LIS3MDL FEATHERWING + + * Adafruit LSM6DSOX + LIS3MDL - 9 DOF IMU Breakout + + * Adafruit LSM6DS33 + LIS3MDL - 9 DOF IMU Breakout + + * Adafruit LSM6DSOX + LIS3MDL 9 DOF IMU FeatherWing .. toctree:: :caption: Other Links - Download + Download CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/examples/lsm6ds_full_test.py b/examples/lsm6ds_full_test.py index 4272d60..a55318f 100644 --- a/examples/lsm6ds_full_test.py +++ b/examples/lsm6ds_full_test.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT import time import board import busio diff --git a/examples/lsm6ds_ism330dhct_simpletest.py b/examples/lsm6ds_ism330dhct_simpletest.py index 03fa3d4..0e8254f 100644 --- a/examples/lsm6ds_ism330dhct_simpletest.py +++ b/examples/lsm6ds_ism330dhct_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT import time import board import busio diff --git a/examples/lsm6ds_lsm6ds33_simpletest.py b/examples/lsm6ds_lsm6ds33_simpletest.py index c4b4fed..e598dc8 100644 --- a/examples/lsm6ds_lsm6ds33_simpletest.py +++ b/examples/lsm6ds_lsm6ds33_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT import time import board import busio diff --git a/examples/lsm6ds_lsm6dso32_simpletest.py b/examples/lsm6ds_lsm6dso32_simpletest.py index 6fcd137..1f48d59 100644 --- a/examples/lsm6ds_lsm6dso32_simpletest.py +++ b/examples/lsm6ds_lsm6dso32_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT import time import board import busio diff --git a/examples/lsm6ds_lsm6dsox_simpletest.py b/examples/lsm6ds_lsm6dsox_simpletest.py index 961a679..126a5ca 100644 --- a/examples/lsm6ds_lsm6dsox_simpletest.py +++ b/examples/lsm6ds_lsm6dsox_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT import time import board import busio diff --git a/examples/lsm6ds_pedometer.py b/examples/lsm6ds_pedometer.py index 967201d..0af1b01 100644 --- a/examples/lsm6ds_pedometer.py +++ b/examples/lsm6ds_pedometer.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT """ This example shows off how to use the step counter built into the ST LSM6DS series IMUs. The steps are calculated in the chip so you don't have to do any calculations!""" diff --git a/examples/lsm6ds_rate_test.py b/examples/lsm6ds_rate_test.py index 642edbd..921e9bf 100644 --- a/examples/lsm6ds_rate_test.py +++ b/examples/lsm6ds_rate_test.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT import board import busio diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f3c35ae --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +[tool.black] +target-version = ['py35'] diff --git a/requirements.txt b/requirements.txt index d5d88a1..cc92861 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,8 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT + Adafruit-Blinka adafruit-circuitpython-busdevice adafruit-circuitpython-register diff --git a/setup.py b/setup.py index 88c1432..b26bb4a 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,8 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: @@ -21,7 +26,7 @@ name="adafruit-circuitpython-lsm6ds", use_scm_version=True, setup_requires=["setuptools_scm"], - description="CircuitPython library for the ST LSM6DSOX, LSM6DS33, and ISM330DHCX 6-DOF Accelerometer and Gyros", + description="CircuitPython helper library for the LSM6DS family of motion sensors from ST", long_description=long_description, long_description_content_type="text/x-rst", # The project's main homepage. @@ -48,8 +53,7 @@ "Programming Language :: Python :: 3.5", ], # What does your project relate to? - keywords="adafruit blinka circuitpython micropython lsm6ds lsm6dsox lsm6ds33 icm330dhcx imu gyro gyroscope inemo" - "accelerometer", + keywords="adafruit blinka circuitpython micropython lsm6ds lsm6dsox lsmds33 lsm6dso32 st imu gyro accelerometer ism330dhcx imu gyro gyroscope inemo", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, From b28544c15b6d954d5e06d058e99deae8096e5d6d Mon Sep 17 00:00:00 2001 From: siddacious Date: Tue, 21 Jul 2020 09:15:12 -0700 Subject: [PATCH 3/5] restructing --- README.rst | 6 +- .../__init__.py | 175 +++++------------- adafruit_lsm6ds/ism330dhcx.py | 36 ++++ adafruit_lsm6ds/lsm6ds33.py | 19 ++ adafruit_lsm6ds/lsm6dso32.py | 34 ++++ adafruit_lsm6ds/lsm6dsox.py | 23 +++ examples/lsm6ds_full_test.py | 14 +- examples/lsm6ds_ism330dhct_simpletest.py | 2 +- examples/lsm6ds_lsm6ds33_simpletest.py | 2 +- examples/lsm6ds_lsm6dso32_simpletest.py | 2 +- examples/lsm6ds_lsm6dsox_simpletest.py | 2 +- examples/lsm6ds_pedometer.py | 3 +- examples/lsm6ds_rate_test.py | 12 +- 13 files changed, 180 insertions(+), 150 deletions(-) rename adafruit_lsm6ds.py => adafruit_lsm6ds/__init__.py (77%) create mode 100644 adafruit_lsm6ds/ism330dhcx.py create mode 100644 adafruit_lsm6ds/lsm6ds33.py create mode 100644 adafruit_lsm6ds/lsm6dso32.py create mode 100644 adafruit_lsm6ds/lsm6dsox.py diff --git a/README.rst b/README.rst index 9acc2d1..0caa2d5 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg - :target: https://discord.gg/nBQh6qu + :target: https://adafru.it/discord :alt: Discord @@ -65,11 +65,11 @@ Usage Example import time import board import busio - import adafruit_lsm6ds + from adafruit_lsm6ds.lsm6dsox import LSM6DSOX i2c = busio.I2C(board.SCL, board.SDA) - sox = adafruit_lsm6ds.LSM6DSOX(i2c) + sox = LSM6DSOX(i2c) while True: print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2"%(sox.acceleration)) diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds/__init__.py similarity index 77% rename from adafruit_lsm6ds.py rename to adafruit_lsm6ds/__init__.py index ac9138b..b73693d 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds/__init__.py @@ -64,55 +64,19 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS.git" + from time import sleep from math import radians from micropython import const import adafruit_bus_device.i2c_device as i2c_device + from adafruit_register.i2c_struct import ROUnaryStruct, Struct from adafruit_register.i2c_bits import RWBits from adafruit_register.i2c_bit import RWBit -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS.git" - - -_LSM6DS_DEFAULT_ADDRESS = const(0x6A) - -_LSM6DS_CHIP_ID = const(0x6C) -_ISM330DHCX_CHIP_ID = const(0x6B) -_LSM6DS33_CHIP_ID = const(0x69) - -_LSM6DS_FUNC_CFG_ACCESS = const(0x1) -_LSM6DS_PIN_CTRL = const(0x2) -_LSM6DS_UI_INT_OIS = const(0x6F) -_LSM6DS_WHOAMI = const(0xF) -_LSM6DS_CTRL1_XL = const(0x10) -_LSM6DS_CTRL2_G = const(0x11) -_LSM6DS_CTRL3_C = const(0x12) -_LSM6DS_CTRL_5_C = const(0x14) -_LSM6DS_MASTER_CONFIG = const(0x14) -_LSM6DS_CTRL8_XL = const(0x17) -_LSM6DS_CTRL9_XL = const(0x18) -_LSM6DS_CTRL10_C = const(0x19) -_LSM6DS_OUT_TEMP_L = const(0x20) -_LSM6DS_OUT_TEMP_H = const(0x21) -_LSM6DS_OUTX_L_G = const(0x22) -_LSM6DS_OUTX_H_G = const(0x23) -_LSM6DS_OUTY_L_G = const(0x24) -_LSM6DS_OUTY_H_G = const(0x25) -_LSM6DS_OUTZ_L_G = const(0x26) -_LSM6DS_OUTZ_H_G = const(0x27) -_LSM6DS_OUTX_L_A = const(0x28) -_LSM6DS_OUTX_H_A = const(0x29) -_LSM6DS_OUTY_L_A = const(0x2A) -_LSM6DS_OUTY_H_A = const(0x2B) -_LSM6DS_OUTZ_L_A = const(0x2C) -_LSM6DS_OUTZ_H_A = const(0x2D) -_LSM6DS_STEP_COUNTER = const(0x4B) -_LSM6DS_TAP_CFG = const(0x58) - -_MILLI_G_TO_ACCEL = 0.00980665 - class CV: """struct helper""" @@ -143,18 +107,6 @@ class GyroRange(CV): """Options for ``gyro_data_range``""" -GyroRange.add_values( - ( - ("RANGE_125_DPS", 125, 125, 4.375), - ("RANGE_250_DPS", 0, 250, 8.75), - ("RANGE_500_DPS", 1, 500, 17.50), - ("RANGE_1000_DPS", 2, 1000, 35.0), - ("RANGE_2000_DPS", 3, 2000, 70.0), - ("RANGE_4000_DPS", 4000, 4000, 140.0), - ) -) - - class Rate(CV): """Options for ``accelerometer_data_rate`` and ``gyro_data_rate``""" @@ -190,6 +142,25 @@ class AccelHPF(CV): ) ) +LSM6DS_DEFAULT_ADDRESS = const(0x6A) + +LSM6DS_CHIP_ID = const(0x6C) + +_LSM6DS_WHOAMI = const(0xF) +_LSM6DS_CTRL1_XL = const(0x10) +_LSM6DS_CTRL2_G = const(0x11) +_LSM6DS_CTRL3_C = const(0x12) +_LSM6DS_CTRL8_XL = const(0x17) +_LSM6DS_CTRL9_XL = const(0x18) +_LSM6DS_CTRL10_C = const(0x19) +_LSM6DS_OUT_TEMP_L = const(0x20) +_LSM6DS_OUTX_L_G = const(0x22) +_LSM6DS_OUTX_L_A = const(0x28) +_LSM6DS_STEP_COUNTER = const(0x4B) +_LSM6DS_TAP_CFG = const(0x58) + +_MILLI_G_TO_ACCEL = 0.00980665 + class LSM6DS: # pylint: disable=too-many-instance-attributes @@ -224,10 +195,12 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes _pedometer_reset = RWBit(_LSM6DS_CTRL10_C, 1) _func_enable = RWBit(_LSM6DS_CTRL10_C, 2) _ped_enable = RWBit(_LSM6DS_TAP_CFG, 6) - + pedometer_steps = ROUnaryStruct(_LSM6DS_STEP_COUNTER, " Date: Fri, 7 Aug 2020 20:31:39 -0700 Subject: [PATCH 4/5] removed duplicate __version__, adjusted `gyro_range` --- adafruit_lsm6ds/__init__.py | 35 +++++++++---------- adafruit_lsm6ds/ism330dhcx.py | 28 ++++++++++++--- ...est.py => lsm6ds_ism330dhcx_simpletest.py} | 0 3 files changed, 39 insertions(+), 24 deletions(-) rename examples/{lsm6ds_ism330dhct_simpletest.py => lsm6ds_ism330dhcx_simpletest.py} (100%) diff --git a/adafruit_lsm6ds/__init__.py b/adafruit_lsm6ds/__init__.py index b73693d..d0ca01f 100644 --- a/adafruit_lsm6ds/__init__.py +++ b/adafruit_lsm6ds/__init__.py @@ -62,9 +62,6 @@ * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register """ -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git" - __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS.git" @@ -212,7 +209,8 @@ def __init__(self, i2c_bus, address=LSM6DS_DEFAULT_ADDRESS): "Failed to find %s - check your wiring!" % self.__class__.__name__ ) self.reset() - self._add_gyro_ranges() + if not hasattr(GyroRange, "string"): + self._add_gyro_ranges() self._bdu = True self._add_accel_ranges() @@ -296,30 +294,29 @@ def accelerometer_range(self, value): @property def gyro_range(self): - """Adjusts the range of values that the sensor can measure, from 125 Degrees/second to 4000 - degrees/s. Note that larger ranges will be less accurate. Must be a `GyroRange`. 4000 DPS - is only available for the ISM330DHCX""" + """Adjusts the range of values that the sensor can measure, from 125 Degrees/s to 2000 + degrees/s. Note that larger ranges will be less accurate. Must be a `GyroRange`.""" return self._cached_gyro_range @gyro_range.setter def gyro_range(self, value): + self._set_gyro_range(value) + sleep(0.2) + + def _set_gyro_range(self, value): if not GyroRange.is_valid(value): raise AttributeError("range must be a `GyroRange`") - if value is GyroRange.RANGE_125_DPS: - self._gyro_range_125dps = True - self._gyro_range_4000dps = False - elif value == 4000: - self._gyro_range_125dps = False - self._gyro_range_4000dps = True - else: + self._gyro_range_4000dps = False + + # range uses `FS_G` enum + if value <= GyroRange.RANGE_2000_DPS: # pylint: disable=no-member self._gyro_range_125dps = False - self._gyro_range_4000dps = False self._gyro_range = value + # range uses the `FS_125` bit + if value is GyroRange.RANGE_125_DPS: # pylint: disable=no-member + self._gyro_range_125dps = True - self._cached_gyro_range = value - sleep(0.2) # needed to let new range settle - - # pylint: enable=no-member + self._cached_gyro_range = value # needed to let new range settle @property def accelerometer_data_rate(self): diff --git a/adafruit_lsm6ds/ism330dhcx.py b/adafruit_lsm6ds/ism330dhcx.py index 8ff5e2e..d3fffa4 100644 --- a/adafruit_lsm6ds/ism330dhcx.py +++ b/adafruit_lsm6ds/ism330dhcx.py @@ -4,6 +4,7 @@ """ This module provides the ISM330DHCX subclass of LSM6DS for using ISM330DHCX sensors. """ +from time import sleep from . import LSM6DS, LSM6DS_DEFAULT_ADDRESS, GyroRange @@ -19,11 +20,6 @@ class ISM330DHCX(LSM6DS): # pylint: disable=too-many-instance-attributes CHIP_ID = 0x6B def __init__(self, i2c_bus, address=LSM6DS_DEFAULT_ADDRESS): - super().__init__(i2c_bus, address) - - # Called DEVICE_CONF in the datasheet, but it recommends setting it - self._i3c_disable = True - GyroRange.add_values( ( ("RANGE_125_DPS", 125, 125, 4.375), @@ -34,3 +30,25 @@ def __init__(self, i2c_bus, address=LSM6DS_DEFAULT_ADDRESS): ("RANGE_4000_DPS", 4000, 4000, 140.0), ) ) + super().__init__(i2c_bus, address) + + # Called DEVICE_CONF in the datasheet, but it recommends setting it + self._i3c_disable = True + + @property + def gyro_range(self): + """Adjusts the range of values that the sensor can measure, from 125 Degrees/s to 4000 + degrees/s. Note that larger ranges will be less accurate. Must be a `GyroRange`. 4000 DPS + is only available for the ISM330DHCX""" + return self._cached_gyro_range + + @gyro_range.setter + def gyro_range(self, value): + super()._set_gyro_range(value) + + # range uses the `FS_4000` bit + if value is GyroRange.RANGE_4000_DPS: # pylint: disable=no-member + self._gyro_range_125dps = False + self._gyro_range_4000dps = True + + sleep(0.2) # needed to let new range settle diff --git a/examples/lsm6ds_ism330dhct_simpletest.py b/examples/lsm6ds_ism330dhcx_simpletest.py similarity index 100% rename from examples/lsm6ds_ism330dhct_simpletest.py rename to examples/lsm6ds_ism330dhcx_simpletest.py From 7178527b7a2cbaf1bcff1a58bb8c931c65fe82e8 Mon Sep 17 00:00:00 2001 From: siddacious Date: Fri, 7 Aug 2020 21:02:50 -0700 Subject: [PATCH 5/5] moving 4k dps into the only place that cares about it --- adafruit_lsm6ds/__init__.py | 2 -- adafruit_lsm6ds/ism330dhcx.py | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/adafruit_lsm6ds/__init__.py b/adafruit_lsm6ds/__init__.py index d0ca01f..c475021 100644 --- a/adafruit_lsm6ds/__init__.py +++ b/adafruit_lsm6ds/__init__.py @@ -182,7 +182,6 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes _gyro_data_rate = RWBits(4, _LSM6DS_CTRL2_G, 4) _gyro_range = RWBits(2, _LSM6DS_CTRL2_G, 2) _gyro_range_125dps = RWBit(_LSM6DS_CTRL2_G, 1) - _gyro_range_4000dps = RWBit(_LSM6DS_CTRL2_G, 0) _sw_reset = RWBit(_LSM6DS_CTRL3_C, 0) _bdu = RWBit(_LSM6DS_CTRL3_C, 6) @@ -306,7 +305,6 @@ def gyro_range(self, value): def _set_gyro_range(self, value): if not GyroRange.is_valid(value): raise AttributeError("range must be a `GyroRange`") - self._gyro_range_4000dps = False # range uses `FS_G` enum if value <= GyroRange.RANGE_2000_DPS: # pylint: disable=no-member diff --git a/adafruit_lsm6ds/ism330dhcx.py b/adafruit_lsm6ds/ism330dhcx.py index d3fffa4..fb971ee 100644 --- a/adafruit_lsm6ds/ism330dhcx.py +++ b/adafruit_lsm6ds/ism330dhcx.py @@ -5,7 +5,9 @@ This module provides the ISM330DHCX subclass of LSM6DS for using ISM330DHCX sensors. """ from time import sleep -from . import LSM6DS, LSM6DS_DEFAULT_ADDRESS, GyroRange +from . import LSM6DS, LSM6DS_DEFAULT_ADDRESS, GyroRange, RWBit, const + +_LSM6DS_CTRL2_G = const(0x11) class ISM330DHCX(LSM6DS): # pylint: disable=too-many-instance-attributes @@ -18,6 +20,7 @@ class ISM330DHCX(LSM6DS): # pylint: disable=too-many-instance-attributes """ CHIP_ID = 0x6B + _gyro_range_4000dps = RWBit(_LSM6DS_CTRL2_G, 0) def __init__(self, i2c_bus, address=LSM6DS_DEFAULT_ADDRESS): GyroRange.add_values( @@ -50,5 +53,7 @@ def gyro_range(self, value): if value is GyroRange.RANGE_4000_DPS: # pylint: disable=no-member self._gyro_range_125dps = False self._gyro_range_4000dps = True + else: + self._gyro_range_4000dps = False sleep(0.2) # needed to let new range settle