adafruit / Adafruit_CircuitPython_RTTTL

Play RTTTL tunes in CircuitPython
MIT License
4 stars 12 forks source link

not compatible with CP 3.0 audioio API #8

Closed jerryneedell closed 6 years ago

jerryneedell commented 6 years ago

this line causes an error under CP3.0 because of an API change. https://github.com/adafruit/Adafruit_CircuitPython_RTTTL/blob/master/adafruit_rtttl.py#L170

Adafruit CircuitPython 3.0.0-alpha.6-143-g990da6d on 2018-05-19; Adafruit CircuitPlayground Express with samd21g18
>>> 
>>> import rttl_example
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rttl_example.py", line 33, in <module>
  File "adafruit_rtttl.py", line 173, in play
  File "adafruit_rtttl.py", line 170, in play
TypeError: extra positional arguments given
>>> 

test code


import adafruit_rtttl
import digitalio
import board

enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
enable.switch_to_output(value=True)

adafruit_rtttl.play(board.SPEAKER, "itchy:d=8,o=6,b=160:c,a5,4p,c,a,4p,c,a5,c,a5," + \
    "c,a,4p,p,c,d,e,p,e,f,g,4p,d,c,4d,f,4a#,4a,2c7")
adafruit_rtttl.play(board.SPEAKER, "Phantom:d=4,o=5,b=140:c,f,c,d#.,8c#,2c#,a#4," + \
    "d#,8a#4,2c,c,f,c,d#.,8c#,2c#,a#4,d#.,8a#4,2c,p,c,f,g#,c.6,8a#,2a#,a#,d#.6,8a#," + \
    "2c6,p,c6,2f.6,8d#6,8c#6,8c6,8a#,8g#,8g,8f,2e,c#,c#.,8c,2c")
idcrook commented 6 years ago

Is there an existing workaround for this CPX CP 3.0 incompatibility?

ladyada commented 6 years ago

woops we missed this one - no workaround right now! we have to fix :)

ladyada commented 6 years ago

@jerryneedell wanna try submitting a PR fix?

idcrook commented 6 years ago

I am going to try to get up a CP build/test env and take a stab at a fix for this issue

jerryneedell commented 6 years ago

oops -- looks like I dropped the ball on this one -- sorry @ladyada . @idcrook please go ahead - let me me know if you run into problems and I can take a look at it.

idcrook commented 6 years ago

OK, I am creating a CircuitPython build and have successfully built a CP .uf2 on macOS and deployed to a CPX.

Are there some example python code snippets for idiomatically addressing 2.0 / 3.0 / 4.0 version compatibility handling that you can point me to, @jerryneedell ? I was thinking I would put version checks inline in the code and then use the appropriate function signatures.

  1. I am not familiar with how to check running CircuitPython version
  2. Is the favored method to do inline checks within the library such as RTTTL, or is there some other method?
jerryneedell commented 6 years ago

There is precedent for doing an inline check.

@idcrook you can check the version via sys.implementation.version[0] - here is an example: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/blob/master/adafruit_circuitplayground/express.py#L624

I'd do something similar and see if any of the reviewers have alternative suggestions. Good luck!

idcrook commented 6 years ago

Thank you for the code pointer, @jerryneedell -- was exactly what I was looking for. I've submitted a PR

idcrook commented 6 years ago

The PR was accepted and merged. It has been observed working on both CP/libs 2.x, and CP/libs 3.x on a CircuitPlayground Express. I think this issue can be closed, and perhaps the RTTTL library released with the fix?

ladyada commented 6 years ago

heya @kattni yay wanna re-release & close?

kattni commented 6 years ago

Done!