wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.08k stars 611 forks source link

Implement SPI and I2C simulation #649

Closed pjreiniger closed 6 years ago

pjreiniger commented 7 years ago

In order to simulate things like the ADX* family of sensors, NavX, Pixy, etc, it would be nice to have have a method do simulate the read/write/transaction calls the library does. I see two options

Use existing callback scheme

Create new callback types

@ThadHouse - you seem to be the simulator person. I was wondering if you had any plans to do this simulation, or thoughts on my ideas before I start doing PRs

virtuald commented 7 years ago

Using the existing callback scheme isn't that bad for most hardware types -- it's worth noting how RobotPy deals with this -- it's basically a mini-hal for each operation. It would be more difficult to implement well in Java/C++. I don't have time to write anything, but see the implementation at:

The NavX stuff is a bit more complex, but still it's not so bad:

pjreiniger commented 7 years ago

In python you have the luxury of basically doing source overriding. That is what my team did last year, but I'm trying to move 100% to the callback scheme, which is in this case is messy.

As I said, I have prototyped an implementation, but it is grosser than I think it should be for an open source solution

Simulators: I2C and SPI Accelerometers SPI Gyro I2C and SPI NavX

Callback Scheme

Attached

pjreiniger commented 6 years ago

Fixed int #688