#include <stdio.h>
#include <string.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c.h"
#include "esp_log.h"
#include "esp_timer.h"
//#include "ssd1306.h"
#include "mpu6050.h"
static const char *TAG_MAIN = "SSD1306_TEST";
// [Incluir aqui todas as definições e funções do componente SSD1306 do código anterior]
// ... (código do componente SSD1306 vai aqui)
// Função principal de teste
void app_main(void) {
ESP_LOGI(TAG_MAIN, "Iniciando MPU6050 com ESP-IDF");
// Inicializar I2C
esp_err_t ret = i2c_master_init();
if (ret != ESP_OK) {
ESP_LOGE(TAG_MAIN, "Falha ao inicializar I2C: %s", esp_err_to_name(ret));
return;
}
ESP_LOGI(TAG_MAIN, "I2C inicializado");
// Aguardar um pouco para estabilização
vTaskDelay(1000 / portTICK_PERIOD_MS);
// Inicializar MPU6050
ret = mpu6050_init();
if (ret != ESP_OK) {
ESP_LOGE(TAG_MAIN, "Falha ao inicializar MPU6050");
return;
}
// Criar task para leitura contínua
// xTaskCreate(mpu6050_task, "mpu6050_task", 4096, NULL, 5, NULL);
// printf("=== INICIANDO TESTE COMPLETO SSD1306 ===");
// // Inicializar I2C e display
// i2c_init();
// vTaskDelay(100 / portTICK_PERIOD_MS);
// ssd1306_init();
// // Tela de boas-vindas
// ssd1306_clear_buffer();
// ssd1306_draw_string(15, 20, "SSD1306 TEST");
// ssd1306_draw_string(25, 35, "Iniciando...");
// ssd1306_update_display();
// vTaskDelay(2000 / portTICK_PERIOD_MS);
mpu6050_data_t sensor_data;
float accel_g[3], gyro_dps[3], temp_c;
while (1) {
esp_err_t ret = mpu6050_read_all(&sensor_data);
if (ret == ESP_OK) {
// Converter dados brutos para valores físicos
mpu6050_convert_data(&sensor_data, accel_g, gyro_dps, &temp_c);
// Imprimir os dados
printf("Accel: X=%.2fg Y=%.2fg Z=%.2fg\n",
accel_g[0], accel_g[1], accel_g[2]);
printf("Gyro: X=%.2f°/s Y=%.2f°/s Z=%.2f°/s\n",
gyro_dps[0], gyro_dps[1], gyro_dps[2]);
printf("Temp: %.2f°C\n", temp_c);
printf("---");
} else {
ESP_LOGE(TAG, "Erro ao ler dados do sensor: %s\n", esp_err_to_name(ret));
}
vTaskDelay(500 / portTICK_PERIOD_MS); // Ler a cada 500ms
}
// Executar todos os testes
while (1) {
// test_pixels();
// test_text();
// test_lines();
// test_rectangles();
// test_progress_bar();
// test_circles();
// test_wave_animation();
// test_system_info();
// test_scrolling_text();
// test_contrast();
// Tela final
// ssd1306_clear_buffer();
// ssd1306_draw_string(10, 20, "Todos os testes");
// ssd1306_draw_string(25, 35, "concluidos!");
// ssd1306_update_display();
// vTaskDelay(3000 / portTICK_PERIOD_MS);
// printf("=== REINICIANDO TESTES ===");
}
}