Skip to content

As5600 #798

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

As5600 #798

wants to merge 6 commits into from

Conversation

tyeth
Copy link
Member

@tyeth tyeth commented Aug 21, 2025

Adds the magnetic angle sensor.
Worth noting the device zeros on reset/init.

Not sure my angular calculation from the "scaled" value correctly gives 0-359 which I think is what's expected.
Also didn't have a great magnet for testing, but did see rotation, and returning to approximate expected angle

@brief Destructor for an AS5600 sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_AS5600() { delete _as5600; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never called, check reinit of same sensor without reboot!
Otherwise if issues then check object in begin and delete if necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before deleting like this, check that the object does not refer to a nullptr otherwise it'll crash.

Something like this would check if the ptr == nullptr

if (_as5600)
 delete _as5600;

@tyeth tyeth requested a review from brentru August 22, 2025 18:08
@tyeth
Copy link
Member Author

tyeth commented Aug 22, 2025

Note to self - Do not merge without testing reinitialising the as5600

Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyeth Requesting two changes

@brief Destructor for an AS5600 sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_AS5600() { delete _as5600; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before deleting like this, check that the object does not refer to a nullptr otherwise it'll crash.

Something like this would check if the ptr == nullptr

if (_as5600)
 delete _as5600;

*/
/*******************************************************************************/
bool getEventRaw(sensors_event_t *rawEvent) {
ulong start = millis();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable, start

@tyeth
Copy link
Member Author

tyeth commented Aug 22, 2025

As mentioned in the MLX pull request, I believe (not verified 100%) the destructors are not being called, due to the delete *iter line being disabled:
https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/blob/main/src/components/i2c/WipperSnapper_I2C.cpp#L1038
I only say that due to having the delete in there with an if check first plus set to nullptr, but it still crashed - now in actual fact that may have been due to testing reinitialisation too where the main adafruit_mlx driver didn't yet have the i2c_dev=nullptr fix applied that I later locally applied in testing.
I should verify if the destructors are being called, presumably by the erase_ later in the same code block of wipper_i2c.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants