Closed yatli closed 2 years ago
See my PR last few commits for a different approach to fixing this issue.
I do like this approach, though. I guess if the port is open then the M8 is just unresponsive, and m8c won't disconnect.
It won't compile in windows though due to
I don't think that's the right way. If the USB port becomes disconnected, the serial port will become invalid and regular serial read/write calls fail. I'm not sure why anything special is needed to detect that.
@smootalicious yeah. Even if we have a drop-in replacement for unistd, there will not be /dev/ttyACM0. COMs in windows are handled another way, and it's better to use a generic detection routine.
@bloopclick I don't know. Guess the 0-byte detection is a way to work around some M8 quirks? Also, if I power off Teensy, it does spmetimes fall into that 0byte codepath instead of throwing an error.
Yes, it appears that the purpose of the zero-byte path is to automatically shut down m8c when the teensy is disconnected. The slight problem is that the M8 sends zero bytes on the help screens and it tricks the zero byte path into shutting down m8c. My crude solution was to reset the zero-byte counter if the user has a button pressed, since the help screens require holding down a button.
@smootalicious yes, that's exactly why I used the zero-byte path - just didn't test it enough it seems :) I wonder if it would be possible to check for the device somehow via libserialport. It would be easy to call the M8 detection routine every now and then, but that probably doesn't play well with multiple devices.
Fixed using packet write tests in #82
✅ Linux: Tested ❓ macOS: Should work 🚧 win32: Does it have
<unistd.h>
at all? Should work for mingw64.