lewisxhe / SensorLib

Commonly used I2C , SPI device multi-platform libraries
MIT License
70 stars 15 forks source link

Do not call Wire.begin inside the sensor.begin #10

Closed dizcza closed 6 months ago

dizcza commented 6 months ago

Calling Wire.begin inside a sensor initialization is a bad practice and developers should avoid it by all means.

QMI8658.

lyusupov commented 6 months ago

@dizcza would you mind to try teaching Adafruit to write their libraries first ?

https://github.com/adafruit/Adafruit_BME680/blob/master/Adafruit_BME680.cpp#L100-L110

dizcza commented 6 months ago

I would if I used their lib. Is it a dependency?

lewisxhe commented 6 months ago

This library was originally designed to be used by ESP32. ESP32 originally has the ability to prevent repeated initialization processing. If the user initializes the Wire externally, the Wire first used by the first user will be used.

dizcza commented 6 months ago

As a matter of fact, I did open an issue on Adafruit.

This library was originally designed to be used by ESP32.

So I cannot use it for non-esp32 boards? It looks like I can... except that I don't know how, for instance, SMT32 handles the issue of repeated Wire initialization.

ESP32 originally has the ability to prevent repeated initialization processing. If the user initializes the Wire externally, the Wire first used by the first user will be used.

You rely on the implementation-specific behavior of underlying firmware functionality. I know that others do exactly what you've described. Well, as long as it works.

dizcza commented 6 months ago

A short question. Does QMI8658 output accelerometer values in m/s^2 and gyroscope in degrees per second?

lewisxhe commented 6 months ago

yes