Added the Matrix handling and clock/day wordmaps

Time and day display is functional again
This commit is contained in:
Matthias Mitscherlich
2024-03-21 16:39:20 +01:00
parent ac8505a157
commit 0fcd60ff57
17 changed files with 498 additions and 571 deletions
+108
View File
@@ -0,0 +1,108 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clock.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_APPLICATION_INC_CLOCK_H_
#define MAIN_APPLICATION_INC_CLOCK_H_
/**
* clock implementation
* \defgroup clock
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <string>
#include <list>
// ProjectIncludes
// All include files that are provided by the project
#include "time.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class Clock
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
typedef enum
{
TEN_BEFORE_HALF,
TWENTY_OVER
}Mode_t;
// Class Constructor
Clock(Mode_t mode);
void generateWordlist(std::list<std::string>* wordlist);
time_t getTime(void);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
Mode_t clockmode;
time_t currentTime;
std::string toNumbers[20] {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen",
"nineteen"};
int calculateHours(struct tm time);
};
/** @} */
#endif /* MAIN_APPLICATION_INC_CLOCK_H_ */
+73
View File
@@ -0,0 +1,73 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clockwordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_CLOCKWORDMAP_H_
#define MAIN_INC_CLOCKWORDMAP_H_
/**
* clockwordmap implementation
* \defgroup clockwordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "wordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class ClockWordmap: public wordmap
{
public:
ClockWordmap(ledmatrix* matrix);
~ClockWordmap();
protected:
void createList_NL(void);
void createList_EN(void);
};
/** @} */
#endif /* MAIN_INC_CLOCKWORDMAP_H_ */
+86
View File
@@ -0,0 +1,86 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file daywordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_APPLICATION_INC_DAYWORDMAP_H_
#define MAIN_APPLICATION_INC_DAYWORDMAP_H_
/**
* daywordmap implementation
* \defgroup daywordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "wordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class DayWordmap : public wordmap
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
// Class Constructor
DayWordmap(ledmatrix* matrix);
~DayWordmap();
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
void createList_NL(void);
void createList_EN(void);
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
};
/** @} */
#endif /* MAIN_APPLICATION_INC_DAYWORDMAP_H_ */
+112
View File
@@ -0,0 +1,112 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_APPLICATION_INC_WORDMAP_H_
#define MAIN_APPLICATION_INC_WORDMAP_H_
/**
* wordmap implementation
* \defgroup wordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <string>
#include <list>
// ProjectIncludes
// All include files that are provided by the project
#include "ledmatrix.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class wordmap
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
// Class Constructor
typedef enum
{
NL = 0,
EN,
NumberOfLanguages
} Language_t;
wordmap(ledmatrix* matrix);
virtual ~wordmap() {}
bool setColour(uint8_t red, uint8_t green, uint8_t blue);
bool setWord(Language_t lang, std::string& identifier, bool value);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
struct word
{
std::string identifier;
std::list<struct ledmatrix::coordinate> pixels;
};
ledmatrix* matrix;
Language_t language;
std::list<struct word> wordlist[NumberOfLanguages];
virtual void createList_NL(void) = 0;
virtual void createList_EN(void) = 0;
uint8_t red;
uint8_t green;
uint8_t blue;
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
};
/** @} */
#endif /* MAIN_APPLICATION_INC_WORDMAP_H_ */
+212
View File
@@ -0,0 +1,212 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clock.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <clock.h>
#include "esp_sntp.h"
#include "esp_wifi.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
Clock::Clock(Mode_t mode)
{
currentTime = 40000;
clockmode = mode;
// Start NTP
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
tzset();
esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL);
esp_sntp_setservername(0, "pool.ntp.org");
esp_sntp_init();
}
void Clock::generateWordlist(std::list<std::string>* wordlist)
{
struct tm tm;
time(&currentTime);
// currentTime += 100;
localtime_r(&currentTime, &tm);
// LOGGER_INFO("%lld\n\r", currentTime);
// LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
wordlist->clear();
wordlist->push_back("it");
wordlist->push_back("is");
wordlist->push_back(toNumbers[calculateHours(tm)]);
if (tm.tm_min < 4)
{
wordlist->push_back("hours");
}
else if (tm.tm_min < 9)
{
wordlist->push_back("ind_five");
wordlist->push_back("after");
}
else if (tm.tm_min < 14)
{
wordlist->push_back("ind_ten");
wordlist->push_back("after");
}
else if (tm.tm_min < 19)
{
wordlist->push_back("ind_quart");
wordlist->push_back("after");
}
else if (tm.tm_min < 24)
{
wordlist->push_back("ind_ten");
wordlist->push_back("before");
wordlist->push_back("half");
}
else if (tm.tm_min < 28)
{
wordlist->push_back("ind_five");
wordlist->push_back("before");
wordlist->push_back("half");
}
else if (tm.tm_min < 30)
{
wordlist->push_back("almost");
wordlist->push_back("half");
}
else if (tm.tm_min < 34)
{
wordlist->push_back("half");
}
else if (tm.tm_min < 39)
{
wordlist->push_back("ind_five");
wordlist->push_back("after");
wordlist->push_back("half");
}
else if (tm.tm_min < 44)
{
wordlist->push_back("ind_ten");
wordlist->push_back("after");
wordlist->push_back("half");
}
else if (tm.tm_min < 49)
{
wordlist->push_back("ind_quart");
wordlist->push_back("before");
}
else if (tm.tm_min < 54)
{
wordlist->push_back("ind_ten");
wordlist->push_back("before");
}
else if (tm.tm_min < 58)
{
wordlist->push_back("ind_five");
wordlist->push_back("before");
}
else
{
wordlist->push_back("almost");
wordlist->push_back("hours");
}
// Attach the day as a word, too
switch (tm.tm_wday)
{
case 0:
wordlist->push_back("sunday");
break;
case 1:
wordlist->push_back("monday");
break;
case 2:
wordlist->push_back("tuesday");
break;
case 3:
wordlist->push_back("wednesday");
break;
case 4:
wordlist->push_back("thursday");
break;
case 5:
wordlist->push_back("friday");
break;
case 6:
wordlist->push_back("saturday");
break;
default:
wordlist->push_back("sunday");
}
}
time_t Clock::getTime(void)
{
return currentTime;
}
int Clock::calculateHours(struct tm time)
{
int hours = time.tm_hour;
// Add one hour in case the clock is heading towards half
if (time.tm_min >= 19)
{
hours = hours + 1;
}
// Calculate hours to 12hour system
if (hours > 12)
{
hours = hours - 12;
}
// Start at 1, not 0
if (hours == 0)
{
hours++;
}
return hours;
}
+104
View File
@@ -0,0 +1,104 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clockwordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "clockwordmap.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
ClockWordmap::ClockWordmap(ledmatrix* matrix) : wordmap(matrix)
{
createList_NL();
createList_EN();
}
ClockWordmap::~ClockWordmap()
{
}
void ClockWordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
// Now lets add all relevant words
wordlist[NL].push_back((struct word){"it", {{0,0},{1,0},{2,0}}});
wordlist[NL].push_back((struct word){"is", {{4,0},{5,0}}});
wordlist[NL].push_back((struct word){"ind_five", {{7,0},{8,0},{9,0},{10,0}}});
wordlist[NL].push_back((struct word){"ind_ten", {{1,1},{2,1},{3,1},{4,1}}});
wordlist[NL].push_back((struct word){"ind_quart", {{6,1},{7,1},{8,1},{9,1},{10,1}}});
wordlist[NL].push_back((struct word){"ind_twenty", {{0,2},{1,2},{2,2},{3,2},{4,2},{5,2},{6,2}}});
wordlist[NL].push_back((struct word){"before", {{6,3},{7,3},{8,3},{9,3}}});
wordlist[NL].push_back((struct word){"after", {{1,3},{2,3},{3,3},{4,3}}});
wordlist[NL].push_back((struct word){"almost", {{0,4},{1,4},{2,4},{3,4},{4,4}}});
wordlist[NL].push_back((struct word){"half", {{7,4},{8,4},{9,4},{10,4}}});
wordlist[NL].push_back((struct word){"one", {{3,5},{4,5},{5,5}}});
wordlist[NL].push_back((struct word){"two", {{1,5},{2,5},{3,5},{4,5}}});
wordlist[NL].push_back((struct word){"three", {{6,5},{7,5},{8,5},{9,5}}});
wordlist[NL].push_back((struct word){"four", {{7,6},{8,6},{9,6},{10,6}}});
wordlist[NL].push_back((struct word){"five", {{0,6},{1,6},{2,6},{3,6}}});
wordlist[NL].push_back((struct word){"six", {{4,6},{5,6},{6,6}}});
wordlist[NL].push_back((struct word){"seven", {{0,7},{1,7},{2,7},{3,7},{4,7}}});
wordlist[NL].push_back((struct word){"eight", {{0,8},{1,8},{2,8},{3,8}}});
wordlist[NL].push_back((struct word){"nine", {{6,7},{7,7},{8,7},{9,7},{10,7}}});
wordlist[NL].push_back((struct word){"ten", {{4,8},{5,8},{6,8},{7,8}}});
wordlist[NL].push_back((struct word){"eleven", {{8,8},{9,8},{10,8}}});
wordlist[NL].push_back((struct word){"twelve", {{0,9},{1,9},{2,9},{3,9},{4,9},{5,9}}});
wordlist[NL].push_back((struct word){"hours", {{8,9},{9,9},{10,9}}});
}
void ClockWordmap::createList_EN(void)
{
}
+78
View File
@@ -0,0 +1,78 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file daywordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <daywordmap.h>
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
DayWordmap::DayWordmap(ledmatrix* matrix) : wordmap(matrix)
{
createList_NL();
createList_EN();
}
DayWordmap::~DayWordmap()
{
}
void DayWordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
// Now lets add all relevant words
wordlist[NL].push_back((struct word){"monday", {{0,12},{1,12},{2,12},{3,12},{4,12},{5,12},{6,12}}});
wordlist[NL].push_back((struct word){"tuesday", {{13,12},{14,12},{15,12},{16,12},{17,12},{18,12},{19,12}}});
wordlist[NL].push_back((struct word){"wednesday", {{11,10},{12,10},{13,10},{14,10},{15,10},{16,10},{17,10},{18,10}}});
wordlist[NL].push_back((struct word){"thursday", {{2,11},{3,11},{4,11},{5,11},{6,11},{7,11},{8,11},{9,11},{10,11}}});
wordlist[NL].push_back((struct word){"friday", {{12,11},{13,11},{14,11},{15,11},{16,11},{17,11},{18,11}}});
wordlist[NL].push_back((struct word){"saturday", {{0,10},{1,10},{2,10},{3,10},{4,10},{5,10},{6,10},{7,10}}});
wordlist[NL].push_back((struct word){"sunday", {{7,12},{8,12},{9,12},{10,12},{11,12},{12,12}}});
}
void DayWordmap::createList_EN(void)
{
}
+132
View File
@@ -0,0 +1,132 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <wordmap.h>
#include <algorithm>
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
wordmap::wordmap(ledmatrix* matrix)
{
wordmap::matrix = matrix;
wordmap::language = NL;
wordmap::red = 0xFF;
wordmap::green = 0xFF;
wordmap::blue = 0xFF;
}
bool wordmap::setWord(Language_t lang, std::string& identifier, bool value)
{
bool returnValue;
auto _compare = [&](struct word currentword)
{
if (identifier.compare(currentword.identifier) == 0)
{
return true;
}
else
{
return false;
}
};
// Create a list Iterator
std::list<struct word>::iterator it;
// Fetch the iterator of element with value 'the'
it = find_if(wordlist[lang].begin(), wordlist[lang].end(), _compare);
// Check if iterator points to end or not
if(it != wordlist[lang].end())
{
returnValue = true;
}
else
{
returnValue = false;
}
if (returnValue)
{
std::list<ledmatrix::coordinate>::iterator pixel;
for (pixel = it->pixels.begin(); pixel != it->pixels.end(); pixel++)
{
if (value)
{
matrix->setPixel(pixel->y, pixel->x, wordmap::red, wordmap::green, wordmap::blue);
}
else
{
matrix->setPixel(pixel->y, pixel->x, 0, 0, 0);
}
}
}
return returnValue;
}
bool wordmap::setColour(uint8_t red, uint8_t green, uint8_t blue)
{
bool returnValue = true;
wordmap::red = red;
wordmap::green = green;
wordmap::blue = blue;
return returnValue;
}
void wordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
}
void wordmap::createList_EN(void)
{
// First, clear the list
wordlist[EN].clear();
}