fixed colour maps and some matrix misalignments# Please enter the commit message for your changes. Lines starting

This commit is contained in:
Matthias Mitscherlich
2023-11-26 09:22:16 +01:00
parent d990b0563d
commit 29e2e14850
9 changed files with 1213 additions and 938 deletions
+9 -2
View File
@@ -120,13 +120,19 @@ class BMP280
uint8_t lsb;
uint8_t xlsb;
} pressure_raw;
struct
{
uint8_t t_sb: 3;
uint8_t filter: 3;
uint8_t unused: 1;
uint8_t spi3w_en: 1;
} config;
struct
{
uint8_t mode : 2;
uint8_t oversampling_pressure : 3;
uint8_t oversampling_temp : 3;
} config;
uint8_t ctrl_meas;
} ctrl_meas;
uint8_t status;
uint8_t reset;
uint8_t id;
@@ -144,6 +150,7 @@ class BMP280
// Communication with Device
void resetDevice(void);
void getDeviceID(void);
void setSensorControlMeasurement(void);
void setSensorConfiguration(void);
void getCompensationValues(void);
+4
View File
@@ -67,7 +67,11 @@ class Temperature
void generateWordlist(int temperature, list<string>* wordlist);
void calculateRGB(int temperature, uint8_t* red, uint8_t* green, uint8_t* blue);
private:
int minTemperature;
int maxTemperature;
};
+1
View File
@@ -61,6 +61,7 @@ class TemperatureWordmap: public Wordmap
{
public:
TemperatureWordmap(LEDMatrix* matrix);
protected:
void createList_NL(void);
// void createList_EN(void);
+14 -8
View File
@@ -17,7 +17,8 @@
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "string.h"
#include <string>
#include<cstring>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@@ -262,17 +263,19 @@ extern "C" void app_main(void)
Clock clock(Clock::mode::TEN_BEFORE_HALF);
clockWordmap.setColour(0xFF, 0x00, 0xFF);
dayWordmap.setColour(0x20, 0xFF, 0x80);
tempWordmap.setColour(0x40, 0x40, 0xFF);
clockWordmap.setColour(0x00, 0xFF, 0xFF);
dayWordmap.setColour(0x20, 0xCC, 0x80);
countdown(1000);
// countdown(1000);
list<string> clockWordlist;
list<string> tempWordList;
while (true)
{
clock.generateWordlist(&clockWordlist);
@@ -285,15 +288,18 @@ extern "C" void app_main(void)
}
// Get the temperature from sensor
int currentTemperature = bmp280.getTemperature();
currentTemperature = 19;
// LOGGER_INFO("The current temperature is: %i", temperature);
int currentTemperature = bmp280.getTemperature() / 100;
LOGGER_INFO("The current temperature is: %i (%s)", currentTemperature, to_string(21));
// Generate temperature wordlist
temperature.generateWordlist(currentTemperature, &tempWordList);
for(it = tempWordList.begin(); it != tempWordList.end(); it++)
{
tempWordmap.setWord(Wordmap::Language_t::NL, *it, true);
}
uint8_t tRed, tGreen, tBlue;
temperature.calculateRGB(currentTemperature, &tRed, &tGreen, &tBlue);
tempWordmap.setColour(tRed, tGreen, tBlue);
// Add a seconds indicator
matrix.setPixelValue(11, 11, clock.getTime() % 2);
+9 -4
View File
@@ -101,16 +101,16 @@ bool BMP280::initialize(void)
bool BMP280::setSensorMode(BMP280_Mode_t mode)
{
bool returnValue = true;
memorymap.config.mode = mode;
setSensorConfiguration();
memorymap.ctrl_meas.mode = mode;
setSensorControlMeasurement();
return returnValue;
}
bool BMP280::setSensorTemperatureOversampling(BMP280_Oversampling_t oversampling)
{
bool returnValue = true;
memorymap.config.oversampling_temp = oversampling;
setSensorConfiguration();
memorymap.ctrl_meas.oversampling_temp = oversampling;
setSensorControlMeasurement();
return returnValue;
}
@@ -149,6 +149,11 @@ void BMP280::resetDevice(void)
bus->write_register(slaveAddress, ADDRESS_REG_RESET, &resetValue, 1);
}
void BMP280::setSensorControlMeasurement(void)
{
bus->write_register(slaveAddress, ADDRESS_REG_CTRL_MEAS, (uint8_t*)&memorymap.ctrl_meas, 1);
}
void BMP280::setSensorConfiguration(void)
{
bus->write_register(slaveAddress, ADDRESS_REG_CONFIG, (uint8_t*)&memorymap.config, 1);
+51 -4
View File
@@ -19,6 +19,8 @@
#include "temperature.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
@@ -49,7 +51,8 @@
Temperature::Temperature()
{
Temperature::minTemperature = 14;
Temperature::maxTemperature = 29;
};
@@ -63,14 +66,58 @@ void Temperature::generateWordlist(int temperature, list<string>* wordlist)
wordlist->push_back("is");
// Temperature value to string
wordlist->push_back(to_string(temperature));
if (temperature < minTemperature)
{
wordlist->push_back("below");
wordlist->push_back(to_string(minTemperature));
}
else if (temperature > maxTemperature)
{
wordlist->push_back("above");
wordlist->push_back(to_string(maxTemperature));
}
else
{
wordlist->push_back(to_string(temperature));
}
// Add fixed postamble
wordlist->push_back("degrees");
}
void Temperature::calculateRGB(int temperature, uint8_t* red, uint8_t* green, uint8_t* blue)
{
int calcBlue = 0;
int calcRed = 0;
int factor = 100 / (maxTemperature - minTemperature);
LOGGER_INFO("Incoming Temperature is: %i (min: %i, max: %i", temperature, minTemperature, maxTemperature);
if (temperature < minTemperature)
{
calcBlue = 0xFF;
calcRed = 0x00;
}
else if (temperature > maxTemperature)
{
calcBlue = 0x00;
calcRed = 0xFF;
}
else
{
calcBlue = (((maxTemperature - temperature) * factor) * 0xFF) / 100;
calcRed = (((temperature - minTemperature) * factor) * 0xFF) / 100;
}
LOGGER_PRINT("\n\rRed %i %x (%i)", calcRed, calcRed, (temperature - minTemperature) * factor);
LOGGER_PRINT("\n\rGreen %i %x", 0, 0);
LOGGER_PRINT("\n\rBlue %i %x (%i)", calcBlue, calcBlue, (maxTemperature - temperature) * factor);
*red = calcRed & 0xFF;
*green = 0x00;
*blue = calcBlue & 0xFF;
}
+4 -3
View File
@@ -71,7 +71,7 @@ void TemperatureWordmap::createList_NL(void)
wordlist[NL].push_back((struct word){"14", {{11,4},{12,4},{13,4},{14,4},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"15", {{15,4},{16,4},{17,4},{18,4},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"16", {{11,5},{12,5},{13,5},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"17", {{14,4},{15,4},{16,4},{17,4},{18,4},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"17", {{14,5},{15,5},{16,5},{17,5},{18,5},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"18", {{11,6},{12,6},{13,6},{14,6},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"19", {{15,6},{16,6},{17,6},{18,6},{19,6},{16,7},{17,7},{18,7},{19,7}}});
@@ -79,11 +79,11 @@ void TemperatureWordmap::createList_NL(void)
wordlist[NL].push_back((struct word){"20", {{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"21", {{13,3},{14,3},{15,3},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"22", {{11,3},{12,3},{13,3},{14,3},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"23", {{16,3},{17,3},{18,3},{19,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"23", {{16,3},{17,3},{18,3},{19,3},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"24", {{11,4},{12,4},{13,4},{14,4},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"25", {{15,4},{16,4},{17,4},{18,4},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"26", {{11,5},{12,5},{13,5},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"27", {{14,4},{15,4},{16,4},{17,4},{18,4},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"27", {{14,5},{15,5},{16,5},{17,5},{18,5},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"28", {{11,6},{12,6},{13,6},{14,6},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"29", {{15,6},{16,6},{17,6},{18,6},{19,6},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
@@ -93,3 +93,4 @@ void TemperatureWordmap::createList_NL(void)