hosaka / micropython-st7735

MicroPython driver and HAL example for Sitronix ST7735 TFT displays.
MIT License
26 stars 20 forks source link

strange python code or is it me?? #2

Closed PeterKenyon closed 8 years ago

PeterKenyon commented 8 years ago

how does the power method work, shurely this isn't what was intended. line 100 says self.power = state BUT self.power is the name of the method bizarre??

hosaka commented 8 years ago

You are correct! This is my mistake. This will execute, but will reassign the function to the state value. Well spotted, I'll fix it asap.

hosaka commented 8 years ago

Just to demonstrate the error:

>>> class Node():
...     power = 0
...     def power(self):
...             self.power = 5
...             return self.power
... 
>>> n = Node()
>>> n.power()
5
>>> n.power()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
PeterKenyon commented 8 years ago

I saw you have changed this to use a backing variable power_on but doesn't that require it to be initialised somewhere, (also for backlight),

hosaka commented 8 years ago

They're both initialised in the st7735.py#L64. So when you inherit your class from TFT, your class will inherit those too.

PeterKenyon commented 8 years ago

oh OK, just keeping you on your toes ;-)