-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
make wire accessing functions virtual #66
Labels
enhancement
New feature or request
Comments
Q: how does one knows the _channel? Does the derived class provides a channel parameter in constructor or setter/getter function for the channel? Not tested, however I think the setting of the I2C channel should also be under the mutex control. Otherwise one can change channel in another thread before the actual read is done. I use it like this in my derived ENCODER class:
uint8_t ENCODER::readReg(uint8_t reg) {
xSemaphoreTake(i2cMutex, portMAX_DELAY);
if(!_mux->setMuxChannel(_channel)) {
xSemaphoreGive(i2cMutex);
_error = AS5600_ERROR_MUX;
return 0;
}
uint8_t ret = AS5600::readReg(reg);
xSemaphoreGive(i2cMutex);
_mux->freeMux();
return ret;
} |
#ifndef AS5600_ENCODER_H
#define AS5600_ENCODER_H
#include "AS5600.h"
#include "i2c_mux.h"
class ENCODER : public AS5600 {
public:
const int AS5600_ERROR_MUX = -300;
ENCODER(I2CMUX* mux, uint8_t channel);
//bool init();
bool isConnected() override;
float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES);
int32_t getCumulativePosition();
void update();
protected:
uint8_t readReg(uint8_t reg) override;
uint16_t readReg2(uint8_t reg) override;
uint8_t writeReg(uint8_t reg, uint8_t value) override;
uint8_t writeReg2(uint8_t reg, uint16_t value) override;
private:
I2CMUX* _mux;
uint8_t _channel;
float _angular_speed;
};
#endif |
it is only about to be allowed to overide... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will be great to been able to overwrite the methods accessing the wire virtual.
So it will be possible in a derived class to easy access the sensor behind a mux.
virtual bool isConnected();
(updated for syntac highlighting)
The text was updated successfully, but these errors were encountered: