From c1ab24170f798a81e4f238448f2bf453d8400ab8 Mon Sep 17 00:00:00 2001 From: Exploit34 Date: Fri, 8 Aug 2025 00:22:07 +0000 Subject: [PATCH] Unit tests were performed on the different methods of the I2C class to verify that they are functioning at 100%. The pyproject was improved and uses were added to the example folder. --- .github/workflows/ci.yml | 19 ++ .github/workflows/publish.yml | 1 + README.md | 77 +++++++- README.rst | 0 example/I2c_Rasp.py | 20 ++ poetry.lock | 276 +++++++++++++++++++++++++++- pyproject.toml | 32 ++-- setup.cfg | 9 +- setup.py | 11 +- src/RPiLCD/I2CRasp.py | 119 ++++++++++++ src/RPiLCD/LDCRasp.py | 0 src/RPiLCD/__init__.py | 5 + tests/unit/__init__.py | 11 ++ tests/unit/test_I2C.py | 16 ++ tests/unit/test_display.py | 21 +++ tests/unit/test_toggle_backlight.py | 18 ++ tests/unit/test_write.py | 18 ++ 17 files changed, 629 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml create mode 100644 README.rst create mode 100644 example/I2c_Rasp.py create mode 100644 src/RPiLCD/I2CRasp.py create mode 100644 src/RPiLCD/LDCRasp.py create mode 100644 tests/unit/test_I2C.py create mode 100644 tests/unit/test_display.py create mode 100644 tests/unit/test_toggle_backlight.py create mode 100644 tests/unit/test_write.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c8024bc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.10 + + - name: Instala dependencias + run: | + poetry install + - name: Ejecuta pruebas + run: | + poetry run pytest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..3a75250 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1 @@ +## Publish \ No newline at end of file diff --git a/README.md b/README.md index afb0ae5..39afd73 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,77 @@ # RPiLCD -🐍📟 RPiLCD: Librería en Python para controlar pantallas LCD en Raspberry Pi (compatible con I2C y control directo). Fácil, flexible y lista para tus proyectos. +[![Ask DeepWiki](https://devin.ai/assets/askdeepwiki.png)](https://deepwiki.com/Exploit34/RPiLCD) + +🐍📟 RPiLCD is a Python library for controlling LCD character displays on the Raspberry Pi. It's designed to be easy, flexible, and compatible with I2C interfaces, making it perfect for your hardware projects. + +## Features + +* **Simple Interface:** Provides an easy-to-use API for writing text, clearing the screen, and controlling the cursor. +* **I2C Support:** Works seamlessly with common I2C LCD backpack modules, saving you GPIO pins. +* **Lightweight:** Minimal dependencies, ensuring it's light on resources. +* **Flexible:** Easily integrate LCD display functionality into your Python scripts and applications running on a Raspberry Pi. + +## Installation + +You can install the library using pip: + +```bash +pip install rpilcd +``` + +The library depends on `smbus` for I2C communication and `RPi.GPIO` for pin control. These will be installed automatically. + +## Usage + +Here is a basic example of how to initialize an I2C LCD and write text to it. + +```python +import time +from RPiLCD import LCD + +# Assuming a 16x2 LCD with I2C address 0x27 +# lcd = LCD(address=0x27, port=1, cols=16, rows=2) + +# The library needs to be implemented. This is a placeholder for usage. +# A typical implementation would look like this: + +class MockLCD: + def __init__(self, address, port, cols, rows): + print(f"Initializing LCD at address {address} on port {port} ({cols}x{rows})") + + def text(self, message, line): + print(f"Writing to line {line}: {message}") + + def clear(self): + print("Clearing the display.") + +# Initialize the display +lcd = MockLCD(address=0x27, port=1, cols=16, rows=2) + +try: + # Clear the display + lcd.clear() + + # Write a message to the first line + lcd.text("Hello, World!", 1) + + # Write a message to the second line + lcd.text("RPiLCD in action", 2) + + time.sleep(5) # Wait for 5 seconds + + lcd.clear() + +except KeyboardInterrupt: + print("Program stopped.") + lcd.clear() + +``` + +## Dependencies + +* [smbus](https://pypi.org/project/smbus-cffi/) or [smbus2](https://pypi.org/project/smbus2/) +* [RPi.GPIO](https://pypi.org/project/RPi.GPIO/) + +## License + +This project is licensed under the GNU Lesser General Public License v2.1. See the [LICENSE](LICENSE) file for more details. \ No newline at end of file diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/example/I2c_Rasp.py b/example/I2c_Rasp.py new file mode 100644 index 0000000..b6c2a2e --- /dev/null +++ b/example/I2c_Rasp.py @@ -0,0 +1,20 @@ +from RPiLCD import I2C +from time import sleep + +lcd = I2C(address=0x27, width=16, rows=2) + +lcd.clear() + +lcd.display_text("Hello everyone", line=1, align="left") + +sleep(2) + +lcd.display_text("Welcome people!", line=2, align="center") + +lcd.toggle_backlight(False) +sleep(1) + +lcd.toggle_backlight(True) + +lcd.clear() + diff --git a/poetry.lock b/poetry.lock index 07edcd2..c1f5e7d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,223 @@ # This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["dev"] +markers = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "coverage" +version = "7.10.2" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.9" +groups = ["dev"] +files = [ + {file = "coverage-7.10.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:79f0283ab5e6499fd5fe382ca3d62afa40fb50ff227676a3125d18af70eabf65"}, + {file = "coverage-7.10.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e4545e906f595ee8ab8e03e21be20d899bfc06647925bc5b224ad7e8c40e08b8"}, + {file = "coverage-7.10.2-cp310-cp310-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:ae385e1d58fbc6a9b1c315e5510ac52281e271478b45f92ca9b5ad42cf39643f"}, + {file = "coverage-7.10.2-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:6f0cbe5f7dd19f3a32bac2251b95d51c3b89621ac88a2648096ce40f9a5aa1e7"}, + {file = "coverage-7.10.2-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:fd17f427f041f6b116dc90b4049c6f3e1230524407d00daa2d8c7915037b5947"}, + {file = "coverage-7.10.2-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:7f10ca4cde7b466405cce0a0e9971a13eb22e57a5ecc8b5f93a81090cc9c7eb9"}, + {file = "coverage-7.10.2-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:3b990df23dd51dccce26d18fb09fd85a77ebe46368f387b0ffba7a74e470b31b"}, + {file = "coverage-7.10.2-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:cc3902584d25c7eef57fb38f440aa849a26a3a9f761a029a72b69acfca4e31f8"}, + {file = "coverage-7.10.2-cp310-cp310-win32.whl", hash = "sha256:9dd37e9ac00d5eb72f38ed93e3cdf2280b1dbda3bb9b48c6941805f265ad8d87"}, + {file = "coverage-7.10.2-cp310-cp310-win_amd64.whl", hash = "sha256:99d16f15cb5baf0729354c5bd3080ae53847a4072b9ba1e10957522fb290417f"}, + {file = "coverage-7.10.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:2c3b210d79925a476dfc8d74c7d53224888421edebf3a611f3adae923e212b27"}, + {file = "coverage-7.10.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bf67d1787cd317c3f8b2e4c6ed1ae93497be7e30605a0d32237ac37a37a8a322"}, + {file = "coverage-7.10.2-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:069b779d03d458602bc0e27189876e7d8bdf6b24ac0f12900de22dd2154e6ad7"}, + {file = "coverage-7.10.2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:4c2de4cb80b9990e71c62c2d3e9f3ec71b804b1f9ca4784ec7e74127e0f42468"}, + {file = "coverage-7.10.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:75bf7ab2374a7eb107602f1e07310cda164016cd60968abf817b7a0b5703e288"}, + {file = "coverage-7.10.2-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:3f37516458ec1550815134937f73d6d15b434059cd10f64678a2068f65c62406"}, + {file = "coverage-7.10.2-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:de3c6271c482c250d3303fb5c6bdb8ca025fff20a67245e1425df04dc990ece9"}, + {file = "coverage-7.10.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:98a838101321ac3089c9bb1d4bfa967e8afed58021fda72d7880dc1997f20ae1"}, + {file = "coverage-7.10.2-cp311-cp311-win32.whl", hash = "sha256:f2a79145a531a0e42df32d37be5af069b4a914845b6f686590739b786f2f7bce"}, + {file = "coverage-7.10.2-cp311-cp311-win_amd64.whl", hash = "sha256:e4f5f1320f8ee0d7cfa421ceb257bef9d39fd614dd3ddcfcacd284d4824ed2c2"}, + {file = "coverage-7.10.2-cp311-cp311-win_arm64.whl", hash = "sha256:d8f2d83118f25328552c728b8e91babf93217db259ca5c2cd4dd4220b8926293"}, + {file = "coverage-7.10.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:890ad3a26da9ec7bf69255b9371800e2a8da9bc223ae5d86daeb940b42247c83"}, + {file = "coverage-7.10.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:38fd1ccfca7838c031d7a7874d4353e2f1b98eb5d2a80a2fe5732d542ae25e9c"}, + {file = "coverage-7.10.2-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:76c1ffaaf4f6f0f6e8e9ca06f24bb6454a7a5d4ced97a1bc466f0d6baf4bd518"}, + {file = "coverage-7.10.2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:86da8a3a84b79ead5c7d0e960c34f580bc3b231bb546627773a3f53c532c2f21"}, + {file = "coverage-7.10.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:99cef9731c8a39801830a604cc53c93c9e57ea8b44953d26589499eded9576e0"}, + {file = "coverage-7.10.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:ea58b112f2966a8b91eb13f5d3b1f8bb43c180d624cd3283fb33b1cedcc2dd75"}, + {file = "coverage-7.10.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:20f405188d28da9522b7232e51154e1b884fc18d0b3a10f382d54784715bbe01"}, + {file = "coverage-7.10.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:64586ce42bbe0da4d9f76f97235c545d1abb9b25985a8791857690f96e23dc3b"}, + {file = "coverage-7.10.2-cp312-cp312-win32.whl", hash = "sha256:bc2e69b795d97ee6d126e7e22e78a509438b46be6ff44f4dccbb5230f550d340"}, + {file = "coverage-7.10.2-cp312-cp312-win_amd64.whl", hash = "sha256:adda2268b8cf0d11f160fad3743b4dfe9813cd6ecf02c1d6397eceaa5b45b388"}, + {file = "coverage-7.10.2-cp312-cp312-win_arm64.whl", hash = "sha256:164429decd0d6b39a0582eaa30c67bf482612c0330572343042d0ed9e7f15c20"}, + {file = "coverage-7.10.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:aca7b5645afa688de6d4f8e89d30c577f62956fefb1bad021490d63173874186"}, + {file = "coverage-7.10.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:96e5921342574a14303dfdb73de0019e1ac041c863743c8fe1aa6c2b4a257226"}, + {file = "coverage-7.10.2-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:11333094c1bff621aa811b67ed794865cbcaa99984dedea4bd9cf780ad64ecba"}, + {file = "coverage-7.10.2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:6eb586fa7d2aee8d65d5ae1dd71414020b2f447435c57ee8de8abea0a77d5074"}, + {file = "coverage-7.10.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:2d358f259d8019d4ef25d8c5b78aca4c7af25e28bd4231312911c22a0e824a57"}, + {file = "coverage-7.10.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:5250bda76e30382e0a2dcd68d961afcab92c3a7613606e6269855c6979a1b0bb"}, + {file = "coverage-7.10.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:a91e027d66eff214d88d9afbe528e21c9ef1ecdf4956c46e366c50f3094696d0"}, + {file = "coverage-7.10.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:228946da741558904e2c03ce870ba5efd9cd6e48cbc004d9a27abee08100a15a"}, + {file = "coverage-7.10.2-cp313-cp313-win32.whl", hash = "sha256:95e23987b52d02e7c413bf2d6dc6288bd5721beb518052109a13bfdc62c8033b"}, + {file = "coverage-7.10.2-cp313-cp313-win_amd64.whl", hash = "sha256:f35481d42c6d146d48ec92d4e239c23f97b53a3f1fbd2302e7c64336f28641fe"}, + {file = "coverage-7.10.2-cp313-cp313-win_arm64.whl", hash = "sha256:65b451949cb789c346f9f9002441fc934d8ccedcc9ec09daabc2139ad13853f7"}, + {file = "coverage-7.10.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:e8415918856a3e7d57a4e0ad94651b761317de459eb74d34cc1bb51aad80f07e"}, + {file = "coverage-7.10.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:f287a25a8ca53901c613498e4a40885b19361a2fe8fbfdbb7f8ef2cad2a23f03"}, + {file = "coverage-7.10.2-cp313-cp313t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:75cc1a3f8c88c69bf16a871dab1fe5a7303fdb1e9f285f204b60f1ee539b8fc0"}, + {file = "coverage-7.10.2-cp313-cp313t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:ca07fa78cc9d26bc8c4740de1abd3489cf9c47cc06d9a8ab3d552ff5101af4c0"}, + {file = "coverage-7.10.2-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c2e117e64c26300032755d4520cd769f2623cde1a1d1c3515b05a3b8add0ade1"}, + {file = "coverage-7.10.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:daaf98009977f577b71f8800208f4d40d4dcf5c2db53d4d822787cdc198d76e1"}, + {file = "coverage-7.10.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:ea8d8fe546c528535c761ba424410bbeb36ba8a0f24be653e94b70c93fd8a8ca"}, + {file = "coverage-7.10.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:fe024d40ac31eb8d5aae70215b41dafa264676caa4404ae155f77d2fa95c37bb"}, + {file = "coverage-7.10.2-cp313-cp313t-win32.whl", hash = "sha256:8f34b09f68bdadec122ffad312154eda965ade433559cc1eadd96cca3de5c824"}, + {file = "coverage-7.10.2-cp313-cp313t-win_amd64.whl", hash = "sha256:71d40b3ac0f26fa9ffa6ee16219a714fed5c6ec197cdcd2018904ab5e75bcfa3"}, + {file = "coverage-7.10.2-cp313-cp313t-win_arm64.whl", hash = "sha256:abb57fdd38bf6f7dcc66b38dafb7af7c5fdc31ac6029ce373a6f7f5331d6f60f"}, + {file = "coverage-7.10.2-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:a3e853cc04987c85ec410905667eed4bf08b1d84d80dfab2684bb250ac8da4f6"}, + {file = "coverage-7.10.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:0100b19f230df72c90fdb36db59d3f39232391e8d89616a7de30f677da4f532b"}, + {file = "coverage-7.10.2-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:9c1cd71483ea78331bdfadb8dcec4f4edfb73c7002c1206d8e0af6797853f5be"}, + {file = "coverage-7.10.2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:9f75dbf4899e29a37d74f48342f29279391668ef625fdac6d2f67363518056a1"}, + {file = "coverage-7.10.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a7df481e7508de1c38b9b8043da48d94931aefa3e32b47dd20277e4978ed5b95"}, + {file = "coverage-7.10.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:835f39e618099325e7612b3406f57af30ab0a0af350490eff6421e2e5f608e46"}, + {file = "coverage-7.10.2-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:12e52b5aa00aa720097d6947d2eb9e404e7c1101ad775f9661ba165ed0a28303"}, + {file = "coverage-7.10.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:718044729bf1fe3e9eb9f31b52e44ddae07e434ec050c8c628bf5adc56fe4bdd"}, + {file = "coverage-7.10.2-cp314-cp314-win32.whl", hash = "sha256:f256173b48cc68486299d510a3e729a96e62c889703807482dbf56946befb5c8"}, + {file = "coverage-7.10.2-cp314-cp314-win_amd64.whl", hash = "sha256:2e980e4179f33d9b65ac4acb86c9c0dde904098853f27f289766657ed16e07b3"}, + {file = "coverage-7.10.2-cp314-cp314-win_arm64.whl", hash = "sha256:14fb5b6641ab5b3c4161572579f0f2ea8834f9d3af2f7dd8fbaecd58ef9175cc"}, + {file = "coverage-7.10.2-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:e96649ac34a3d0e6491e82a2af71098e43be2874b619547c3282fc11d3840a4b"}, + {file = "coverage-7.10.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1a2e934e9da26341d342d30bfe91422bbfdb3f1f069ec87f19b2909d10d8dcc4"}, + {file = "coverage-7.10.2-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:651015dcd5fd9b5a51ca79ece60d353cacc5beaf304db750407b29c89f72fe2b"}, + {file = "coverage-7.10.2-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:81bf6a32212f9f66da03d63ecb9cd9bd48e662050a937db7199dbf47d19831de"}, + {file = "coverage-7.10.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d800705f6951f75a905ea6feb03fff8f3ea3468b81e7563373ddc29aa3e5d1ca"}, + {file = "coverage-7.10.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:248b5394718e10d067354448dc406d651709c6765669679311170da18e0e9af8"}, + {file = "coverage-7.10.2-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:5c61675a922b569137cf943770d7ad3edd0202d992ce53ac328c5ff68213ccf4"}, + {file = "coverage-7.10.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:52d708b5fd65589461381fa442d9905f5903d76c086c6a4108e8e9efdca7a7ed"}, + {file = "coverage-7.10.2-cp314-cp314t-win32.whl", hash = "sha256:916369b3b914186b2c5e5ad2f7264b02cff5df96cdd7cdad65dccd39aa5fd9f0"}, + {file = "coverage-7.10.2-cp314-cp314t-win_amd64.whl", hash = "sha256:5b9d538e8e04916a5df63052d698b30c74eb0174f2ca9cd942c981f274a18eaf"}, + {file = "coverage-7.10.2-cp314-cp314t-win_arm64.whl", hash = "sha256:04c74f9ef1f925456a9fd23a7eef1103126186d0500ef9a0acb0bd2514bdc7cc"}, + {file = "coverage-7.10.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:765b13b164685a2f8b2abef867ad07aebedc0e090c757958a186f64e39d63dbd"}, + {file = "coverage-7.10.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a219b70100500d0c7fd3ebb824a3302efb6b1a122baa9d4eb3f43df8f0b3d899"}, + {file = "coverage-7.10.2-cp39-cp39-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:e33e79a219105aa315439ee051bd50b6caa705dc4164a5aba6932c8ac3ce2d98"}, + {file = "coverage-7.10.2-cp39-cp39-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:bc3945b7bad33957a9eca16e9e5eae4b17cb03173ef594fdaad228f4fc7da53b"}, + {file = "coverage-7.10.2-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9bdff88e858ee608a924acfad32a180d2bf6e13e059d6a7174abbae075f30436"}, + {file = "coverage-7.10.2-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:44329cbed24966c0b49acb386352c9722219af1f0c80db7f218af7793d251902"}, + {file = "coverage-7.10.2-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:be127f292496d0fbe20d8025f73221b36117b3587f890346e80a13b310712982"}, + {file = "coverage-7.10.2-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:6c031da749a05f7a01447dd7f47beedb498edd293e31e1878c0d52db18787df0"}, + {file = "coverage-7.10.2-cp39-cp39-win32.whl", hash = "sha256:22aca3e691c7709c5999ccf48b7a8ff5cf5a8bd6fe9b36efbd4993f5a36b2fcf"}, + {file = "coverage-7.10.2-cp39-cp39-win_amd64.whl", hash = "sha256:c7195444b932356055a8e287fa910bf9753a84a1bc33aeb3770e8fca521e032e"}, + {file = "coverage-7.10.2-py3-none-any.whl", hash = "sha256:95db3750dd2e6e93d99fa2498f3a1580581e49c494bddccc6f85c5c21604921f"}, + {file = "coverage-7.10.2.tar.gz", hash = "sha256:5d6e6d84e6dd31a8ded64759626627247d676a23c1b892e1326f7c55c8d61055"}, +] + +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + +[package.extras] +toml = ["tomli ; python_full_version <= \"3.11.0a6\""] + +[[package]] +name = "exceptiongroup" +version = "1.3.0" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +markers = "python_version == \"3.10\"" +files = [ + {file = "exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10"}, + {file = "exceptiongroup-1.3.0.tar.gz", hash = "sha256:b241f5885f560bc56a59ee63ca4c6a8bfa46ae4ad651af316d4e81817bb9fd88"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.6.0", markers = "python_version < \"3.13\""} + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "iniconfig" +version = "2.1.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760"}, + {file = "iniconfig-2.1.0.tar.gz", hash = "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7"}, +] + +[[package]] +name = "packaging" +version = "25.0" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484"}, + {file = "packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f"}, +] + +[[package]] +name = "pluggy" +version = "1.6.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.9" +groups = ["dev"] +files = [ + {file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"}, + {file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["coverage", "pytest", "pytest-benchmark"] + +[[package]] +name = "pytest" +version = "7.4.4" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, + {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "pytest-cov" +version = "4.1.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "pytest-cov-4.1.0.tar.gz", hash = "sha256:3904b13dfbfec47f003b8e77fd5b589cd11904a21ddf1ab38a64f204d6a10ef6"}, + {file = "pytest_cov-4.1.0-py3-none-any.whl", hash = "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a"}, +] + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] + [[package]] name = "rpi-gpio" version = "0.7.1" @@ -30,7 +248,63 @@ files = [ {file = "smbus-1.1.post2.tar.gz", hash = "sha256:f96d345e0aa10053a8a4917634f1dc37ba1f656fa5cace7629b71777e90855c6"}, ] +[[package]] +name = "tomli" +version = "2.2.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +markers = "python_full_version <= \"3.11.0a6\"" +files = [ + {file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"}, + {file = "tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8"}, + {file = "tomli-2.2.1-cp311-cp311-win32.whl", hash = "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff"}, + {file = "tomli-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b"}, + {file = "tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea"}, + {file = "tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e"}, + {file = "tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98"}, + {file = "tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4"}, + {file = "tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7"}, + {file = "tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744"}, + {file = "tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec"}, + {file = "tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69"}, + {file = "tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc"}, + {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, +] + +[[package]] +name = "typing-extensions" +version = "4.14.1" +description = "Backported and Experimental Type Hints for Python 3.9+" +optional = false +python-versions = ">=3.9" +groups = ["dev"] +markers = "python_version == \"3.10\"" +files = [ + {file = "typing_extensions-4.14.1-py3-none-any.whl", hash = "sha256:d1e1e3b58374dc93031d6eda2420a48ea44a36c2b4766a4fdeb3710755731d76"}, + {file = "typing_extensions-4.14.1.tar.gz", hash = "sha256:38b39f4aeeab64884ce9f74c94263ef78f3c22467c8724005483154c26648d36"}, +] + [metadata] lock-version = "2.1" python-versions = ">=3.10" -content-hash = "cf481d9ccc0a192950e1e2ba8f108ca9858bc3d37cc61c9b60fabacf8ffbbb65" +content-hash = "5df736efd47e82c51f4cc9462163491122826bf6ea26ad018ec5140a6424ca11" diff --git a/pyproject.toml b/pyproject.toml index 62ed846..23fab6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,29 +1,27 @@ -[project] +[tool.poetry] name = "rpilcd" version = "0.1.0" -description = "este libreria es para el manejo de las lcd display en las raspberry pi" -authors = [ - {name = "Esteban",email = "herrerazanecheverry@gmail.com"} -] -license = {text = "LGPL"} +description = "Esta librería es para el manejo de pantallas LCD en la Raspberry Pi" +authors = ["Esteban, herrerazanecheverry@gmail.com"] +license = "LGPL" readme = "README.md" -requires-python = ">=3.10" -packages = [{ include = "src", from = "." }] -dependencies = [ - "smbus (>=1.1.post2,<2.0)", - "rpi-gpio (>=0.7.1,<0.8.0)" +packages = [ + { include = "RPiLCD", from = "src" } ] +keywords = ["raspberrypi", "lcd", "i2c", "display"] -[tool.poetry.scripts] -test = "pytest:main" +[tool.poetry.dependencies] +python = ">=3.10" +smbus = ">=1.1.post2,<2.0" +rpi-gpio = ">=0.7.1,<0.8.0" [tool.poetry.group.dev.dependencies] pytest = "^7.0" pytest-cov = "^4.0" -[tool.setuptools.packages.find] -where = ["src"] +[tool.poetry.scripts] +test = "pytest:main" [build-system] -requires = ["poetry-core>=2.0.0,<3.0.0", "setuptools", "wheel"] -build-backend = ["poetry.core.masonry.api", "setuptools.build_meta"] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/setup.cfg b/setup.cfg index 72b4170..ec79337 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,11 +2,12 @@ name = RPiLCD version = 0.1.0 description = Librería para controlar LCD en Raspberry Pi -long_description = file: README.md -long_description_content_type = text/markdown +long_description = file: README.rst +long_description_content_type = text/x-rst author = Esteban author_email = herrerazanecheverry@gmail.com -license = MIT +license = LGPLv3 +keywords = raspberry, raspberry pi, lcd, liquid crystal, rpi, i2c, displayScreen url = https://github.com/Exploit34/RPiLCD [options] @@ -14,4 +15,4 @@ packages = find: python_requires = >=3.10 install_requires = smbus2 - RPi.GPIO + RPi.GPIO \ No newline at end of file diff --git a/setup.py b/setup.py index d6e162e..7b3dd89 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,17 @@ from setuptools import setup -setup( +readme = open("README.rst").read() + +setup ( name="RPiLCD", version="0.1.0", description="Librería para controlar LCD en Raspberry Pi", + long_description=readme, + long_description_content_type="text/x-rst", + author="Esteban", + author_email="herrerazanecheverry@gmail.com", + license="LGPLv3", + url = "https://github.com/Exploit34/RPiLCD", + keywords='raspberry, raspberry pi, lcd, liquid crystal, rpi, i2c, displayScreen', packages=["RPiLCD"] ) diff --git a/src/RPiLCD/I2CRasp.py b/src/RPiLCD/I2CRasp.py new file mode 100644 index 0000000..b2271ad --- /dev/null +++ b/src/RPiLCD/I2CRasp.py @@ -0,0 +1,119 @@ +from smbus import SMBus +from time import sleep +import logging + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +ALIGN_OPTIONS = { + 'left': 'ljust', + 'right': 'rjust', + 'center': 'center' +} + +CLEAR_DISPLAY = 0x01 +ENABLE_BIT = 0b00000100 +LINES = { + 1: 0x80, + 2: 0xC0, + 3: 0x94, + 4: 0xD4 +} + +LCD_BACKLIGHT = 0x08 +LCD_NOBACKLIGHT = 0x00 + +class I2C: + def __init__(self, address, width, rows, bus=1, backlight=True): + """Inicializa el LCD con la dirección I2C, dimensiones y retroiluminación.""" + self.address = address + self.bus = SMBus(bus) + self.width = width + self.rows = rows + self.backlight_status = backlight + self.delay = 0.0005 + + self.initialize_display() + + def update_config(self, address=None, bus=None, width=None, rows=None, backlight=None): + """Permite cambiar las variables de configuración del LCD.""" + if address is not None: + self.address = address + if bus is not None: + self.bus = SMBus(bus) + if width is not None: + self.width = width + if rows is not None: + self.rows = rows + if backlight is not None: + self.backlight_status = backlight + + self.initialize_display() + + def initialize_display(self): + """Envía comandos de inicialización al LCD.""" + init_commands = [0x33, 0x32, 0x06, 0x0C, 0x28, CLEAR_DISPLAY] + for cmd in init_commands: + self.write(cmd) + sleep(self.delay) + + def _write_byte(self, byte): + """Escribe un byte en el bus con el modo de habilitación activado.""" + try: + self.bus.write_byte(self.address, byte) + self.bus.write_byte(self.address, (byte | ENABLE_BIT)) + sleep(self.delay) + self.bus.write_byte(self.address, (byte & ~ENABLE_BIT)) + sleep(self.delay) + except Exception as e: + logger.error(f"Error al escribir byte: {e}") + + def write(self, byte, mode=0): + """Escribe un comando o dato al LCD, considerando el estado de retroiluminación.""" + backlight_mode = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT + self._write_byte(mode | (byte & 0xF0) | backlight_mode) + self._write_byte(mode | ((byte << 4) & 0xF0) | backlight_mode) + + def display_text(self, text, line=1, align='left'): + """Muestra texto en una línea específica con el alineamiento indicado.""" + if line not in LINES: + raise ValueError("Número de línea no válido. Debe ser 1, 2, 3 o 4.") + + if not isinstance(self.width, int) or self.width <= 0: + raise ValueError("Ancho inválido para la pantalla LCD.") + + if not isinstance(self.rows, int) or self.rows <= 0: + raise ValueError("Número de filas inválido para la pantalla LCD.") + + self.write(LINES[line]) + aligned_text = getattr(text[:self.width], ALIGN_OPTIONS.get(align, 'ljust'))(self.width) + + for char in aligned_text: + self.write(ord(char), mode=1) + + def toggle_backlight(self, turn_on=True): + """Activa o desactiva la retroiluminación del LCD.""" + self.backlight_status = turn_on + self.write(0x00) + + def _split_text(self, text): + """Divide el texto para que quepa en líneas, intentando romper en espacios.""" + words = text.split(' ') + lines = [] + current_line = '' + + for word in words: + if len(current_line) + len(word) + 1 <= self.width: + current_line += ' ' + word if current_line else word + else: + lines.append(current_line) + current_line = word + + if current_line: + lines.append(current_line) + return lines + + def clear(self): + """Limpia la pantalla del LCD.""" + self.write(CLEAR_DISPLAY) + sleep(self.delay) \ No newline at end of file diff --git a/src/RPiLCD/LDCRasp.py b/src/RPiLCD/LDCRasp.py new file mode 100644 index 0000000..e69de29 diff --git a/src/RPiLCD/__init__.py b/src/RPiLCD/__init__.py index e69de29..42f7286 100644 --- a/src/RPiLCD/__init__.py +++ b/src/RPiLCD/__init__.py @@ -0,0 +1,5 @@ +from .I2CRasp import I2C + +__all__ = [ + 'I2C' +] \ No newline at end of file diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index e69de29..8c2fc19 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -0,0 +1,11 @@ +from .test_I2C import testI2C +from .test_display import testDisplay +from .test_write import testWrite +from .test_toggle_backlight import testBacklight + +__all__ = [ + 'testI2C', + 'testDisplay', + 'testWrite', + 'testBacklight' +] \ No newline at end of file diff --git a/tests/unit/test_I2C.py b/tests/unit/test_I2C.py new file mode 100644 index 0000000..3407f14 --- /dev/null +++ b/tests/unit/test_I2C.py @@ -0,0 +1,16 @@ +import unittest +from unittest.mock import patch, MagicMock +from src.RPiLCD import I2C + +class testI2C(unittest.TestCase): + @patch('src.RPiLCD.I2CRasp.SMBus') + def test_init(self, mock_smbus): + mock_bus_instance = MagicMock() + mock_smbus.return_value = mock_bus_instance + + i2c = I2C(address=0x27, width=16, rows=2) + self.assertIsNotNone(i2c) + mock_smbus.assert_called_once_with(1) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/test_display.py b/tests/unit/test_display.py new file mode 100644 index 0000000..3600844 --- /dev/null +++ b/tests/unit/test_display.py @@ -0,0 +1,21 @@ +import unittest +from unittest.mock import patch, MagicMock +from src.RPiLCD import I2C + +class testDisplay(unittest.TestCase): + @patch('src.RPiLCD.I2CRasp.SMBus') + def test_write_text(self, mock_smbus): + mock_bus_instance = MagicMock() + mock_smbus.return_value = mock_bus_instance + + lcd = I2C(address=0x27, width=16, rows=2) + self.assertIsNotNone(lcd) + mock_smbus.assert_called_once_with(1) + + lcd.display_text("Hello Juan", line=1, align="left") + lcd.display_text("LCD", line=2, align="center") + lcd.display_text("LCD Display", line=3, align="right") + lcd.display_text("4 buses", line=4, align="center") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/test_toggle_backlight.py b/tests/unit/test_toggle_backlight.py new file mode 100644 index 0000000..641eebd --- /dev/null +++ b/tests/unit/test_toggle_backlight.py @@ -0,0 +1,18 @@ +import unittest +from unittest.mock import patch, MagicMock +from src.RPiLCD import I2C + +class testBacklight(unittest.TestCase): + @patch('src.RPiLCD.I2CRasp.SMBus') + def test_write_text(self, mock_smbus): + mock_bus_instance = MagicMock() + mock_smbus.return_value = mock_bus_instance + + lcd = I2C(address=0x27, width=16, rows=2) + self.assertIsNotNone(lcd) + mock_smbus.assert_called_once_with(1) + + lcd.toggle_backlight(turn_on=False) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/unit/test_write.py b/tests/unit/test_write.py new file mode 100644 index 0000000..472d6de --- /dev/null +++ b/tests/unit/test_write.py @@ -0,0 +1,18 @@ +import unittest +from unittest.mock import patch, MagicMock +from src.RPiLCD import I2C + +class testWrite(unittest.TestCase): + @patch('src.RPiLCD.I2CRasp.SMBus') + def test_write_text(self, mock_smbus): + mock_bus_instance = MagicMock() + mock_smbus.return_value = mock_bus_instance + + lcd = I2C(address=0x27, width=16, rows=2) + self.assertIsNotNone(lcd) + mock_smbus.assert_called_once_with(1) + + lcd.write(0x27) + +if __name__ == "__main__": + unittest.main()