jfjlaros / simpleRPC

Simple RPC implementation for Arduino.
MIT License
50 stars 17 forks source link

usb_serial_class plugin support #7

Closed drbeefsupreme closed 3 years ago

drbeefsupreme commented 3 years ago

Is your feature request related to a problem? Please describe. I want to use simpleRPC with a Teensy 3.6. I tried to run HardwareSerialIO::begin with the Serial object but the compiler tells me error: no matching function for call to 'HardwareSerialIO::begin(usb_serial_class&)

Describe the solution you'd like I think a new plugin that works with usb_serial_class, or possibly overloading HardwareSerialIO::begin to work with it.

Alternative solution They both inherit from Stream so maybe just have HardwareSerialIO::begin take in a Stream? This might cause other issues if used improperly though, I don't know what else a Stream might be.

Additional context I figured out that this is because the Teensy treats the USB serial port separately from the I/O pin serial ports, unlike most ordinary Arduinos which link the USB TX and RX with the serial TX and RX via a resistor and thus HardwareSerial covers both. So with the Teensy they are treated with a separate class, but are still hardware serial ports (at least for the Teensy 3.6, I haven't looked at other ones yet).

I am pretty new to the Teensy/Arduino world, not to mention C++, but this seems like an easy problem that only needs a few lines of code to fix. I will give it the old college try tomorrow.

jfjlaros commented 3 years ago

I see you have already implemented something. If your solution works, could you submit a pull request?

drbeefsupreme commented 3 years ago

I forked the repo and tried my first dumb idea, but it didn't work. Didn't get a chance to work on it yesterday. I ought to have time some night this week though. I don't really follow GitHub etiquette for my personal forks, so the fact that I merged a PR on my fork just means I was being lazy with the device I was pushing the repo to - I didn't want to modify my platformio file to work with a branch other than master.

jfjlaros commented 3 years ago

I didn't see any obvious mistakes, except perhaps for a missing prototype in io.h. You might want to add the following line.

void begin(usb_serial_class&);
jfjlaros commented 3 years ago

Could you try the last version on the master branch?

chrisflesher commented 3 years ago

We just merged some code that introduces a Stream class for issue #8, can you try pulling from master and see if it works? The syntax would be HardwareSerialIO::begin(&usb_serial_class)

drbeefsupreme commented 3 years ago

Thanks, I will try this out tonight with my Teensy 3.6 and report back.

drbeefsupreme commented 3 years ago

It works! I used SerialIO::begin though (which I think is what you meant?). Thank you very much.

jfjlaros commented 3 years ago

Nice.