I don’t think you need to make any modifications to the Bridge library. The SerialBridgeClass constructor (of which the Bridge object is a instance) accepts a HardwareSerial object as a parameter. You can forget about the default 'Bridge" instance and create your own:
This works, but is a bit sub-optimal as it’s not a drop in replacement (outside of the initial setup)
Note that FileSystem.open() ignores its BridgeClass when calling FileSystem.open(), so even changing the code
File f = FileSystem.open(file_name, FILE_APPEND):
File f = fileSystem2.open(file_name, FILE_APPEND);
the File is using the default Bridge class. However, since FileSystem.open is just a wrapper for File.open, I was able to get it to work by changing that to:
File f(file_name, FILE_APPEND, Bridge2);
I’m going to use this method for now since it doesn’t require hacking on IDE code. However, I’d like to figure out a way to make it more seamless.
If you really wanted to modify the bridge, I would consider using a defined symbol that you set before including any Bridge library header files. For example:
#define CUSTOM_BRIDGE_PORT Serial2
Then, down at the bottom of Bridge.cpp:
// Bridge instance
// Leonardo variants (where HardwareSerial is Serial1)
This way, the code works as it did before if CUSTOM_BRIDGE_PORT is not defined, but will use the defined port if it is.
Unfortunately, this doesn’t work as the FileIO.cpp file is compiled separately from the sketch, and we’d need a compiler define ("-DCUSTOM_BRIDGE_PORT") or something similar to get the FileIO.cpp file to see the define.