Skip to content
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

Generic application multi-sensor #98

Closed
SERIDJ opened this issue Jul 20, 2020 · 4 comments
Closed

Generic application multi-sensor #98

SERIDJ opened this issue Jul 20, 2020 · 4 comments
Labels
question Further information is requested

Comments

@SERIDJ
Copy link

SERIDJ commented Jul 20, 2020

hi,

i am working on application multi-sensor using esp-idf-lib so i connect all my sensor with mux TCA9548A and i want to now if i need to create instance i2c_dev_t dev for each sensor or i can use one for all same sensor ?

@SERIDJ SERIDJ changed the title multi-sensor geniric application multi-sensor Jul 20, 2020
@UncleRus UncleRus added the question Further information is requested label Jul 23, 2020
@UncleRus
Copy link
Owner

Hi! You need separate descriptors for each i2c device.

@UncleRus UncleRus changed the title geniric application multi-sensor Generic application multi-sensor Jul 23, 2020
@SERIDJ
Copy link
Author

SERIDJ commented Jul 23, 2020

@UncleRus oky so i work with detected device so i can create instance with malloc bcs number of device is detected with i2ccannser

now i create max :

//
static float pressure, temperature, humidity;
static bmp280_t dev_bme280 [8] = {0};
static bmp280_params_t params_bme280 [8] = {0};
/
/
uint16_t lux;
i2c_dev_t dev_bh1750[8]= {0};
/
***************************************************/
i2c_dev_t dev_pcf8574[8];
uint16_t read_port_pcf8574;

/****************************************************/

@UncleRus
Copy link
Owner

Yes you can create device descriptors dynamically, e.g.

i2c_dev_t *bh1750; // pointer to device descriptor

...

bh1750 = malloc(sizeof(i2c_dev_t)); // allocate memory for descriptor
memset(bh1750, 0, sizeof(i2c_dev_t))); // fill it with zeroes

... // init descriptor, init device, use it

free(bh1750); // free allocated memory

@SERIDJ
Copy link
Author

SERIDJ commented Jul 23, 2020

Ah yes yes but for sensor i don't think I free memory bcs I use all time read_bh1750 and I don't initialize device for each read

So it's don't give problem if I don't use free(p) ?

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

No branches or pull requests

2 participants