-
Notifications
You must be signed in to change notification settings - Fork 791
Larsio_Paint_Music: refactor for use with adafruit_usb_host_mouse lib… #3122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a small fix to resolve crash about missing cursor image.
Also one other request about a fix for the audio driver fallback logic which is unrelated to the main change of this PR but was uncovered while testing.
|
||
return True | ||
|
||
self.mouse = find_and_init_boot_mouse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This raises an exception when the app is run without Fruit Jam OS files present
Error with I2S audio: [Errno 2] No such file/directory: /launcher_assets/mouse_cursor.bmp
Initializing sound manager...
Fatal error: D10 in use
There is fallback code here: https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Fruit_Jam/Larsio_Paint_Music/code.py#L101-L116 attempting to try again due to catching generic exceptions. But the second try also fails because on of the DAC pins is in use.
I think we could make use of the new deinit()
function added here: https://github.com/adafruit/Adafruit_CircuitPython_FruitJam/pull/23/files in order to resolve the trying again issue.
As for the cursor bmp I lean towards just working around it by passing a placeholder image i.e.
self.mouse = find_and_init_boot_mouse(cursor_image="sprites/lars_note.bmp")
This app is also managing the visual cursor itself rather than using the one from the usb_host_mouse library. But in this case I think it makes more sense to have the app handle it since it's also using custom changing cursor images based on the notes selected doing so under usb_host_mouse object with the current API would be very tricky I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a generic note: We all made our initial programs before the USB and FruitJam libraries were fleshed out. Breakout will need some extensive rework when I get to it.
Maybe a short guide on best practices to write programs that use best practices on the Fruit Jam and FJOS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is fallback code here: https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Fruit_Jam/Larsio_Paint_Music/code.py#L101-L116 attempting to try again due to catching generic exceptions. But the second try also fails because on of the DAC pins is in use.
The fallback has been a bit troubling to me, it's actually attempting to give up on the DAC and use PWM audio connected to board.D10. Of course most of the times I've encountered the fallback the issue wasn't actually that the I2S DAC wasn't available but as you encountered some other error was caught instead. In those cases falling back to PWM is never going to work. However if a speaker was connected to board.D10 and there was no DAC, I think the fallback would actually work as intended without having to add the deinit. That being said I don't see any problem adding a deinit and it's certainly cleaner. If it were my program I would probably handle the fall back differently but my goal in updating a learning guide program has been to change as little as possible to address the specific issue I'm trying to solve. If I were to be completely thorough, I probably should go back and compare the learn guide with the changes I'm making to see if any of the guide details need to be updated. but I've opted to trying to minimize the changes instead 😁
There is a second PWM fallback in code.py but I didn't see an easy way to run the deinit there. I'll think about it but I'm not sure it's necessary. |
We don't want to merge this until adafruit/Adafruit_CircuitPython_USB_Host_Mouse#6 has been merged.... |
This PR removes some of the low level mouse initialization and processing from the Larsio_Paint_Music application and replaces it with the API from the Adafruit_USB_Host_Mouse library.
adafruit/Adafruit_CircuitPython_USB_Host_Mouse#5 should probably be merged before this one.