51 lines
1.7 KiB
C
51 lines
1.7 KiB
C
#include "sensor.h"
|
|
#include <stdio.h>
|
|
#include "driver/i2c.h"
|
|
|
|
#define SDA_PIN GPIO_NUM_2
|
|
#define CLK_PIN GPIO_NUM_14
|
|
#define SENSOR_ADDR 0x45 //default address is 0x44 (pin 2 logic low). We chose 0x45 with logic high in v0.9 and 0x44 with newer versions where second sensor is removed.
|
|
|
|
|
|
// Dummy implementations for the purpose of this example
|
|
// Replace these with actual sensor initialization and data retrieval logic
|
|
|
|
static const i2c_config_t config = {
|
|
.mode = I2C_MODE_MASTER,
|
|
.sda_io_num = GPIO_NUM_2,
|
|
.scl_io_num = GPIO_NUM_14,
|
|
.sda_pullup_en = GPIO_PULLUP_DISABLE,
|
|
.scl_pullup_en = GPIO_PULLUP_DISABLE,
|
|
.clk_stretch_tick = 5
|
|
};
|
|
|
|
// Function to initialize the sensor
|
|
void initSensor(void) {
|
|
esp_err_t err = i2c_driver_install(I2C_NUM_0, config.mode);
|
|
esp_err_t err2 = i2c_param_config(I2C_NUM_0, &config);
|
|
// Initialize the sensor hardware
|
|
// For example, set up I2C communication, configure registers, etc.
|
|
printf("Sensor initialized.\n");
|
|
}
|
|
|
|
// Function to get the current humidity level
|
|
// Returns the humidity as a percentage (0-100)
|
|
float getHumidity(void) {
|
|
// Read humidity data from the sensor
|
|
// This is a dummy value for the purpose of this example
|
|
float humidity = 50.0; // Replace with actual sensor reading
|
|
printf("Humidity read: %.2f%%\n", humidity);
|
|
return humidity;
|
|
}
|
|
|
|
// Function to get the current temperature
|
|
// Returns the temperature in degrees Celsius
|
|
float getTemperature(void) {
|
|
// Read temperature data from the sensor
|
|
// This is a dummy value for the purpose of this example
|
|
float temperature = 22.0; // Replace with actual sensor reading
|
|
printf("Temperature read: %.2f°C\n", temperature);
|
|
return temperature;
|
|
}
|
|
|