I was workign on some other USBHost extensions and found I needed debug information that was
being generated by a Teensy plugged into the USB host port that was output using Serial Emulation
to be available. Likewise I wanted the ability to feed data back to that other Teensy.
So I decided to create USBHost_t36 implemention to handle the USB types that include Serial Emulation
USBSerialEmu class.
The USBSerialEmu code was based on the USBSerial code as well as RAWHID. I found that there was a bug
in the Receiving of data that was sent by the remote SEREMU output, I would miss the first character
Fixed.
USBSerial fixed same bug in reading first character
This delta originated to do the work similar to what was done
for the MIDI code base and support two versions of the object.
All of the code was renamed to a new base class USBSerialBase
which has everything, except the main buffer.
Two sub-classes were made that the only difference is the size of the
buffer to hold all of the USB RX and TX information.
This started off to try to support an FT2232H device which transers
512 bytes at a time instead of what most of our devices were transfering
which is 64 bytes.
While doing this, I found that we have a similar issue with the T4.x
boards which now transfer 512 bytes as well and our Serial object would
not handle it.
So there are two sublasses:
```
USBSerial - for those up to 64 byte transfers
USBSerial_BigBuffer - for up to 512 bytes
```
Note: by default the biguffer version will only handle those
devices > 64 bytes, but you can pass in an optional parameter of the
minimum size, so doing something like:
```
USBSerial_BigBuffer userial(myusb, 1);
```
Will handle all up to 512.
Also the FTDI2232H supports two USB to Serial objects, and our code
was setup that in most cases including when we put in VID:PID pair in
our table, the code would claim would claim
the object at device level so only one USB Serial adapter.
So changed table to support saying for this VID:PID claim at
interface level. It now works, but not sure for the device I have as
it is a USB to Serial and JTAG and not sure how to test 2nd one.
But while doing this created a test sketch for Multiple Host USB Serial
objects and the two are claimed by this.
I also created a new version of the Teensy USBToSerial example sketch
that if you configure USB type to Dual Serial or Triple Serial will output
SerialUSB1 to Serial2 and SerialUSB2 to Serial3, which works, and then
tried T4 configured for Dual plugged
into T4.1 with above sketch and could talk to both USB Serial adapters.
The Claim code was rearranged a lot, so hopefully did not break
anything.
But tested with
T4 as mentioned, both Single and Dual Serial
T3.2 with Single Serial, plus: Serial, Joystick, Keyboard...
FTDI - USB to Serial adapter (Sparkfun)
CP2104 - Adafruit
PL2303 - some clones ...
So hopefully most things are still working
Turns out they are a lot different than other PS3 controllers.
When plugged into USB, it appears like these units do not send
any reports. They do allow us to do pairing (which is differnt)
than other PS3, as well as set the Bulb LED color, which I now
have it alternating colors every few seconds and also it tries
to pair it with a BT dongle
When connected to Bluetooth, it now is setup to generate reports,
as well as again set the bulb color and rumble.
So far it maps the 3 button bytes into the buttons field and then
simply copies most all of the data down into Axis, starting where
the Trigger button is.
JoystickBT.ino was updated, to know about this controller and as
mentioned above in the USB case it tries to pair and plays with the
color of bulb.
In the BT case it tries to display data. I did a quick and dirty
change of the Accel/Gyro like stuff which is probably totally wrong.
Pressing some of the buttons will set bulb color and pressing trigger
will set rumble.
PS3 Motion controller - very little mapping of axis
The first gigabyte fix, was to always force the keyboard into boot protocol mode, which appeared to work well for all of the keyboards I tried.
Unforationally it caused issues with some wireless keyboard/mouse combo packages, including some logitech and some microsoft keyboards.
This version instead, I created a list (currently only one vendor id), of vendor id:product id, that need to be forced into boot mode. Knowing that if there is one keyboard vendor with this N key rollover feature, there are probably others. So while this list can be expanded, this requires users to update library. So added a method forceBootProtocol method to keyboard class that allows the user to try it out without needing to update the library sources.
The mouse test program has example of either setting it before the keyboard is initiated, as well as another way that when a connection is found it asks for the vendor id, and if it is the one of my gigabyte keyboard, it calls the function then.
While doing this I found some of the query functions like idVendor on the keyboard class would not compile as the keyboard object has multiple inheritence and both base classes have this. So like the joystick objects I added these to the top level function and these functions will direct the calls to the approrpriate places.
Support for using the Microsoft XBox 360 wireless receiver for windows
to be able to communicate with XBox 360 wireless controllers.
In theory this should support up to 4 controllers. So far I have only
tested with one as I only have one.
Added a joystick only test that should support up to 4 joystick objects.
WIP - So far i am getting the basic values for 1 XBox 360 controller. The device should handle up to 4 devices, but so far hard coded to only handle 1...
Added support for Joysticks, that on some of them we can not receive more of the Joysticks axis. So far mainly on PS3 and PS4. So you can now get the Gyro/accel stuff. You get feedback on the DS4 touch area, PS3 you can get the pressure values on several of the buttons. LIke the RT/LT ones.
In addition added some support for Rumble. So far it appears to be working somewhat on the PS3 and PS4 controllers. On the PS4 you can also set the RGB LED light values and on the PS3 you can set the 4 LEDS on the front., which are normally used to say which controller it is.
While the other Joystick objects currently supported by the USB Host
code are driven by HID data, the Xbox does not contain HID data and
instead works at the top level.
To handle this I made the Joystick object use multiple InHeritence like:
class JoystickController : public USBDriver, public USBHIDInput
This allowed me to have the object work either way. This did add some
complexity in that some of the methods like is the object connected
(The bool operator) had to be overwritten as both of the bases classes
had it. In addition needed to update the other query functions to be
able to grab the data from mydevice or device depending on which type of
controller was connected.
Since this looked like a valid way, I then merged the Keyboard Extras
code that Keyboard and made it also do a similar multiple inheritance.
In this case however I restricted the HID top level report handle code
to only accept it if on the same object that claimed the keyboard.
The mouse test app was updated as well
Needed HID Parser to support Bidirectional Transfers
The HidParser code was setup such that the claim for a report, the caller could say I want to claim the whole thinig and allowed callback functions for processing of in buffer and out buffer.
Allow RawHID to contribute Transfer_t
Since RawHID may need more resources than most, maybe it should contribute the additional structures
The constructor for a RAWHID object allows you to specify the top usage
that it wishes to connect to. I used this for example to be able to
connect to a Teensy with the RAWHID associated with emulating the
Serial object.
If a HID Input class says that it wants to claim the whole interface, I
reuse the buffer associated with holding the HID descriptor and use it
for output buffers.
I did a quick test using the Serial test app, where I can type in lines like:
#38400,7E1
And it reopens the serial port at the specified baud and format. Note the formats the test app looks for is 7E1, 7O1, 8N1, 8N2.
Tested on an FTDI, PL2303 and CH341. I also tested going to Teensy 3.2 CDCACM. But as far as I know the teensy could not care less about Baud/Format.
Unless of course there is a way to query the value and use it to set a Hardware Serial port to it.