|
1 /** |
|
2 * @file iotbalkon.c |
|
3 * @brief iotbalkon project. |
|
4 */ |
1 |
5 |
2 |
6 #include "config.h" |
3 #include <stdio.h> |
|
4 #include "freertos/FreeRTOS.h" |
|
5 #include "freertos/task.h" |
|
6 #include "driver/gpio.h" |
|
7 #include "esp_log.h" |
|
8 |
|
9 |
|
10 |
7 |
11 static const char *TAG = "iotbalkon"; |
8 static const char *TAG = "iotbalkon"; |
12 |
9 |
|
10 |
|
11 static TaskHandle_t xTaskBMP280 = NULL; |
|
12 |
|
13 extern BMP280_State *bmp280_state; ///< I2C state |
|
14 extern SemaphoreHandle_t xSemaphoreBMP280; ///< I2C lock semaphore |
|
15 extern bmp280_params_t bmp280_params; |
|
16 extern bmp280_t bmp280_dev; |
|
17 |
|
18 |
13 void app_main(void) |
19 void app_main(void) |
14 { |
20 { |
15 ESP_LOGI(TAG, "Starting"); |
21 #ifdef CONFIG_CODE_PRODUCTION |
|
22 ESP_LOGI(TAG, "Starting production"); |
|
23 #endif |
|
24 #ifdef CONFIG_CODE_TESTING |
|
25 ESP_LOGI(TAG, "Starting testing"); |
|
26 #endif |
|
27 |
|
28 ESP_ERROR_CHECK(i2cdev_init()); |
|
29 |
|
30 bmp280_init_default_params(&bmp280_params); |
|
31 memset(&bmp280_dev, 0, sizeof(bmp280_t)); |
|
32 |
|
33 i2c_dev_t dev = { 0 }; |
|
34 dev.cfg.sda_io_num = CONFIG_I2C_MASTER_SDA; |
|
35 dev.cfg.scl_io_num = CONFIG_I2C_MASTER_SCL; |
|
36 dev.cfg.master.clk_speed = 1000000; |
|
37 |
|
38 dev.addr = 0x39; |
|
39 if (i2c_dev_probe(&dev, I2C_DEV_WRITE) == 0) { |
|
40 ESP_LOGI(TAG, "Found ADPS-9930"); |
|
41 } |
|
42 dev.addr = 0x40; |
|
43 if (i2c_dev_probe(&dev, I2C_DEV_WRITE) == 0) { |
|
44 ESP_LOGI(TAG, "Found INA219 Battery"); |
|
45 } |
|
46 dev.addr = 0x41; |
|
47 if (i2c_dev_probe(&dev, I2C_DEV_WRITE) == 0) { |
|
48 ESP_LOGI(TAG, "Found INA219 Solar"); |
|
49 } |
|
50 dev.addr = 0x76; |
|
51 if (i2c_dev_probe(&dev, I2C_DEV_WRITE) == 0) { |
|
52 ESP_ERROR_CHECK(bmp280_init_desc(&bmp280_dev, BMP280_I2C_ADDRESS_0, 0, CONFIG_I2C_MASTER_SDA, CONFIG_I2C_MASTER_SCL)); |
|
53 ESP_ERROR_CHECK(bmp280_init(&bmp280_dev, &bmp280_params)); |
|
54 ESP_LOGI(TAG, "Found BMP280 @ 0x76 id: 0x%02x", bmp280_dev.id); |
|
55 } |
|
56 dev.addr = 0x77; |
|
57 if (i2c_dev_probe(&dev, I2C_DEV_WRITE) == 0) { |
|
58 ESP_LOGI(TAG, "Found BMP280 @ 0x77"); |
|
59 } |
|
60 |
|
61 /* |
|
62 * Create FreeRTOS tasks |
|
63 */ |
|
64 xSemaphoreBMP280 = xSemaphoreCreateMutex(); |
|
65 |
|
66 xTaskCreate(&task_bmp280, "task_bmp280", 2560, NULL, 8, &xTaskBMP280); |
|
67 |
|
68 /* |
|
69 * Main application loop. |
|
70 */ |
|
71 while (1) { |
|
72 request_bmp280(); |
|
73 vTaskDelay(2000 / portTICK_PERIOD_MS); |
|
74 } |
|
75 // Not reached. |
16 } |
76 } |