Coder Social home page Coder Social logo

Broken CPython support about python_lcd HOT 4 CLOSED

dhylands avatar dhylands commented on September 9, 2024
Broken CPython support

from python_lcd.

Comments (4)

clach04 avatar clach04 commented on September 9, 2024

Error details:

Traceback (most recent call last):
  File "my_demo.py", line 40, in <module>
    lcd.custom_char(0, happy_face)
  File "/home/pi/py/python_lcd_clach04/lcd/lcd_api.py", line 170, in custom_char
    self.hal_sleep_us(40)
  File "/home/pi/py/python_lcd_clach04/lcd/lcd_api.py", line 208, in hal_sleep_us
    time.sleep_us(usecs)
AttributeError: module 'time' has no attribute 'sleep_us'

from python_lcd.

dhylands avatar dhylands commented on September 9, 2024

The intent is that lcd_api.py should be independent of the platform. So it shouldn't have a sleep or a sleep_us in it. sleep_us is used so that you don't need to have floating point enabled (not all micropython port provide support for floating point operations).

Unfortunately, the sleep stuff came in fairly late in the development, so I added a "default" implementation in lcd_api.py so as not to break the existing implementations.

Specific hal layers can override this if desired. circuitpython, for example, also doesn't support sleep_us so it provides a hal_sleep_us function like this:

def hal_sleep_us(self, usecs):
"""Sleep for some time (given in microseconds)."""
sleep(float(usecs)/1e6)

It looks like i2c_lcd.py (which is intended for CPython use) should provide a similar hal_sleep_us function.

from python_lcd.

dhylands avatar dhylands commented on September 9, 2024

I think that adding some comments to the hal_sleep_us function implemented in lcd_api.py would also help.

from python_lcd.

clach04 avatar clach04 commented on September 9, 2024

Thanks for taking the time to explain this, really helpful. I posted a PR that resolves the issue and should help with other platforms. It may benefit from further comments/hints.

from python_lcd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.