-
Notifications
You must be signed in to change notification settings - Fork 647
Magnetic sensor ma730 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Nice job owen! But I am not sure this static constructor is the best idea. I agree it is very simple to use though. MagneticSensorSPI sensor1 = MagneticSensorSPI::AS5147(PIN_MAG1);
MagneticSensorSPI sensor2 = MagneticSensorSPI::AS5147(PIN_MAG2);How I was imagining it was more like this: MagneticSensorSPI sensor = MagneticSensorSPI(AS5147, CS_PIN);And to have: struct SensoConfig_s{
.... // all that we need
};
SensoConfig_s AS5147 = {...};
SensoConfig_s AS5600 = {...};I am not sure that it is a better idea any more. The only thing that is maybe interesting is that the user can define their own sensor config in the arduino sketch and then provide it to the constructor. With dedicated constructors it is a bit more complicated. And if we want to support more sensors (AS5047 and AS5048B - the same settings) we need a constructor for each one. |
|
I've checked the following for you: It works. I suspect it would behave as you feared if the static function did not use the I also tried the above with different SPI speeds. e.g. sensor1 at 1K clock_speed and sensor2 at 1M clock_speed. This worked but going lower than 1k made the faster sensor stop working. I think most people would stick to a single clock speed but I don't think the spec requires it. So given that the above works then it's really down to which code style we prefer. |
|
I've tried with an i2C as well: Works too. |
|
I agree that your config approach looks tidy too - Propbably need a static class prefix on the well known configs e.g: I'd be happy with that too. And as you say - it would allow developers to create their own. I'm leaning slightly to your approach - I like how the config struct defines what can be changed. |
|
I am just not sure that either Honestly I would prefer for these classes to as configurable as possible (generic is a better word maybe) and then to have a configuration instance that they receive over the constructor for each new sensor. As well as I would prefer to create a class for the SImplefocShield that incorporates BLDMotor instance. But I agree that having these configuration already done would help people spend less time reading the docs. |
|
How about the sensor has the struct definition in it and then a new SensorLibrary.h has some struct instances? |
|
@askuric - I've pushed commit with struct based approach. The 3 struct instances listed above are defined in a new |
|
Hey Owen, great work! |
|
I thought of a few other names such as Catalog.h or HardwareConfigs.h. I don't mind what it is really. Feel free to make changes. |
Added support for MA730.
Added clock_speed configurability to spi and i2c
Allow i2c sda/scl pins to be reconfigured
Allow spi mode to be changed
Provide helper static constructors that hides things like needing to know registers, resolutions chip_address e.g:
@askuric - I'm happy to discuss static constructors as you may have a better way or see other problems with this approach.