Added temperature handling and temperature wordmap. Also removed to old versions. Integrated and functional

This commit is contained in:
Matthias Mitscherlich
2024-03-25 15:34:16 +01:00
parent e7dd0ea1f6
commit 39dcb7cf80
7 changed files with 154 additions and 4052 deletions
+59 -55
View File
@@ -45,6 +45,8 @@
#include "clockwordmap.h"
#include "daywordmap.h"
#include "ota.h"
#include "temperature.h"
#include "temperaturewordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
@@ -107,9 +109,6 @@ extern "C" void app_main(void)
ret = nvs_flash_init();
}
ESP_LOGE("Test", "System start");
vTaskDelay(100);
// -----------------------------------------------------------------------------------------------------------------
// UART
//
@@ -128,15 +127,10 @@ extern "C" void app_main(void)
ESP_ERROR_CHECK(uart_set_pin(debugUart, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(debugUart, 1024, 1024, 0, NULL, 0));
ESP_LOGE("Test", "Uart installed");
vTaskDelay(100);
// uart uartDebug = uart(&debugUart);
// uartDebug.open();
// uartDebug.write(255, 255, (uint8_t*)"START", 5);
ESP_LOGE("Test", "Uart interface open");
vTaskDelay(100);
esplog esplogger = esplog();
esplogger.open();
@@ -150,9 +144,6 @@ extern "C" void app_main(void)
// Call the logger executable within a dedicated task and forget about it afterwards
xTaskCreate(loggerTask, (const char*)"loggerTask", 3000, &debugLogger, 3, &loggerTaskHandle);
ESP_LOGE("Test", "Logger Task started");
vTaskDelay(100);
LOGGER_PRINT("\n\r-----------------------------------------------------------------------\n\r");
LOGGER_PRINT("System Start\n\r");
LOGGER_PRINT("\n\r");
@@ -160,30 +151,27 @@ extern "C" void app_main(void)
LOGGER_PRINT("Release: %d.%d \n\r", MAJORRELEASE, MINORRELEASE);
LOGGER_PRINT("Compiled on %s at %s\n\r\n\r\n\r", __DATE__, __TIME__);
// -----------------------------------------------------------------------------------------------------------------
// I2C Masterbus for sensoring peripherals
//
i2c_port_t i2c_master_port = I2C_NUM_0;
i2c_config_t i2cConfig = {
.mode = I2C_MODE_MASTER,
.sda_io_num = (int)GPIO_I2C_SDA,
.scl_io_num = (int)GPIO_I2C_SCK,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = 400000,
.clk_flags = 0
};
ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &i2cConfig));
ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, i2cConfig.mode, 0, 0, 0));
i2c i2cSensor = i2c(&i2c_master_port);
i2cSensor.open();
ESP_LOGE("Test", "Logger System Rpintout");
vTaskDelay(100);
// // -----------------------------------------------------------------------------------------------------------------
// // I2C Masterbus for sensoring peripherals
// //
// i2c_port_t i2c_master_port = I2C_NUM_0;
//
// i2c_config_t i2cConfig = {
// .mode = I2C_MODE_MASTER,
// .sda_io_num = (int)2,
// .scl_io_num = (int)3,
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
// .master = 400000,
// .clk_flags = 0
// };
//
// ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &i2cConfig));
// ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, i2cConfig.mode, 0, 0, 0));
//
// i2c i2cSensor = i2c(&i2c_master_port);
// i2cSensor.open();
//
// // -----------------------------------------------------------------------------------------------------------------
// // I2C RGB Sensor on I2C MasterBus for sensors
// //
@@ -197,33 +185,27 @@ extern "C" void app_main(void)
// struct isl29125::rgb_t rgbValue;
// rgbSensor.getRGB(&rgbValue);
// // -----------------------------------------------------------------------------------------------------------------
// // I2C RGB Sensor on I2C MasterBus for sensors
// //
// bmp280 tempSensor = bmp280(0x76, i2cSensor);
// // Reset the sensor
// tempSensor.resetSensor();
// // Make sure to apply a wait cycle between reset and continuous use - 2ms is advised as minimum
// vTaskDelay(10);
// // Initialize the BMP280
// tempSensor.initialize();
// // Set the temperature Oversampling
// tempSensor.setSensorTemperatureOversampling(bmp280::BMP280_Oversampling_t::X1);
// // Set the sensor to NORMAL mode
// tempSensor.setSensorMode(bmp280::BMP280_Mode_t::NORMAL);
// -----------------------------------------------------------------------------------------------------------------
// I2C RGB Sensor on I2C MasterBus for sensors
//
bmp280 tempSensor = bmp280(0x76, i2cSensor);
// Reset the sensor
tempSensor.resetSensor();
// Make sure to apply a wait cycle between reset and continuous use - 2ms is advised as minimum
vTaskDelay(10);
// Initialize the BMP280
tempSensor.initialize();
// Set the temperature Oversampling
tempSensor.setSensorTemperatureOversampling(bmp280::BMP280_Oversampling_t::X1);
// Set the sensor to NORMAL mode
tempSensor.setSensorMode(bmp280::BMP280_Mode_t::NORMAL);
// -----------------------------------------------------------------------------------------------------------------
// Wifi create and connect
//
Wifi wifi = Wifi();
ESP_LOGE("Test", "Wifi object created");
vTaskDelay(100);
wifi.start_client();
ESP_LOGE("Test", "Wifi started");
vTaskDelay(100);
// -----------------------------------------------------------------------------------------------------------------
// Programmable LEDs in a strip
//
@@ -236,6 +218,11 @@ extern "C" void app_main(void)
//
Clock clk = Clock(Clock::Mode_t::TEN_BEFORE_HALF);
// -----------------------------------------------------------------------------------------------------------------
// The Temperature class that calculates temperature string and colour
//
temperature temp = temperature();
// -----------------------------------------------------------------------------------------------------------------
// Wordmaps for clock(time), clock(day) and temperature
//
@@ -245,6 +232,8 @@ extern "C" void app_main(void)
DayWordmap daywords = DayWordmap(&matrix);
daywords.setColour(0xFF, 0x00, 0x80);
temperaturewordmap tempwords = temperaturewordmap(&matrix);
// -----------------------------------------------------------------------------------------------------------------
// OTA handler
@@ -255,6 +244,7 @@ extern "C" void app_main(void)
xTaskCreate(otaTask, (const char*)"OTATask", 4000, &otaUpdater, 3, &otaTaskHandle);
std::list<std::string> clockWordlist;
std::list<std::string> tempWordList;
while(1)
@@ -269,6 +259,20 @@ extern "C" void app_main(void)
daywords.setWord(wordmap::Language_t::NL, *it, true);
}
// Get the temperature from sensor
int currentTemperature = tempSensor.getTemperature() / 100;
LOGGER_INFO("The current temperature is: %i (%s)", currentTemperature, std::to_string(21));
// Generate temperature wordlist
temp.generateWordlist(currentTemperature, &tempWordList);
for(it = tempWordList.begin(); it != tempWordList.end(); it++)
{
tempwords.setWord(wordmap::Language_t::NL, *it, true);
}
uint8_t tRed, tGreen, tBlue;
temp.calculateRGB(currentTemperature, &tRed, &tGreen, &tBlue);
tempwords.setColour(tRed, tGreen, tBlue);
matrix.update();
vTaskDelay(1000);
}
@@ -292,7 +296,7 @@ void otaTask(void* parameters)
ota* otaHandler = (ota*) parameters;
while (1)
{
otaHandler->task();
// otaHandler->task();
vTaskDelay(otaHandler->checkInterval_ms);
}
}