Added wordmap and got the clock running

This commit is contained in:
Matthias Mitscherlich
2023-01-19 17:29:58 +01:00
parent 699b9ecce8
commit 5d5c45ee15
5 changed files with 463 additions and 128 deletions
+180 -85
View File
@@ -64,124 +64,219 @@ Clock::Clock()
sntp_init();
}
Clock::TimeStructure Clock::updateTime(void)
void Clock::generateWordlist(list<string>* wordlist)
{
struct tm tm;
time(&currentTime);
// currentTime += 10;
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);
// Construct the time structure
TimeStructure timeStructure;
// Show the prefix
timeStructure.prefix = true;
wordlist->clear();
wordlist->push_back("it");
wordlist->push_back("is");
wordlist->push_back(toNumbers[calculateHours(tm.tm_hour)]);
if (tm.tm_min < 4)
{
timeStructure.fifths = None_FifthIndication;
timeStructure.beforeAfter = None_BeforeAfter;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = true;
wordlist->push_back("hours");
}
else if (tm.tm_min < 9)
{
timeStructure.fifths = Five;
timeStructure.beforeAfter = After;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_five");
wordlist->push_back("after");
}
else if (tm.tm_min < 14)
{
timeStructure.fifths = Ten;
timeStructure.beforeAfter = After;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_ten");
wordlist->push_back("after");
}
else if (tm.tm_min < 19)
{
timeStructure.fifths = Quarter;
timeStructure.beforeAfter = After;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_quart");
wordlist->push_back("after");
}
else if (tm.tm_min < 24)
{
timeStructure.fifths = Ten;
timeStructure.beforeAfter = Before;
timeStructure.half = true;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_ten");
wordlist->push_back("before");
wordlist->push_back("half");
}
else if (tm.tm_min < 29)
else if (tm.tm_min < 28)
{
timeStructure.fifths = Five;
timeStructure.beforeAfter = Before;
timeStructure.half = true;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
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)
{
timeStructure.fifths = None_FifthIndication;
timeStructure.beforeAfter = None_BeforeAfter;
timeStructure.half = true;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("half");
}
else if (tm.tm_min < 39)
{
timeStructure.fifths = Five;
timeStructure.beforeAfter = After;
timeStructure.half = true;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_five");
wordlist->push_back("after");
wordlist->push_back("half");
}
else if (tm.tm_min < 44)
{
timeStructure.fifths = Ten;
timeStructure.beforeAfter = After;
timeStructure.half = true;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_ten");
wordlist->push_back("after");
wordlist->push_back("half");
}
else if (tm.tm_min < 49)
{
timeStructure.fifths = Quarter;
timeStructure.beforeAfter = Before;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_quart");
wordlist->push_back("before");
}
else if (tm.tm_min < 54)
{
timeStructure.fifths = Ten;
timeStructure.beforeAfter = Before;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_ten");
wordlist->push_back("before");
}
else if (tm.tm_min < 59)
else if (tm.tm_min < 58)
{
timeStructure.fifths = Five;
timeStructure.beforeAfter = Before;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
wordlist->push_back("ind_five");
wordlist->push_back("before");
}
else
{
wordlist->push_back("almost");
}
toString(&timeStructure);
return timeStructure;
}
time_t Clock::getTime(void)
{
time(&currentTime);
return currentTime;
}
//Clock::TimeStructure Clock::updateTime(void)
//{
// struct tm tm;
// time(&currentTime);
//// currentTime += 10;
// 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);
//
// // Construct the time structure
// TimeStructure timeStructure;
// // Show the prefix
// timeStructure.prefix = true;
//
// if (tm.tm_min < 4)
// {
// timeStructure.fifths = None_FifthIndication;
// timeStructure.beforeAfter = None_BeforeAfter;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour);
// timeStructure.hourPostfix = true;
// }
// else if (tm.tm_min < 9)
// {
// timeStructure.fifths = Five;
// timeStructure.beforeAfter = After;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 14)
// {
// timeStructure.fifths = Ten;
// timeStructure.beforeAfter = After;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 19)
// {
// timeStructure.fifths = Quarter;
// timeStructure.beforeAfter = After;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 24)
// {
// timeStructure.fifths = Ten;
// timeStructure.beforeAfter = Before;
// timeStructure.half = true;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 29)
// {
// timeStructure.fifths = Five;
// timeStructure.beforeAfter = Before;
// timeStructure.half = true;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 34)
// {
// timeStructure.fifths = None_FifthIndication;
// timeStructure.beforeAfter = None_BeforeAfter;
// timeStructure.half = true;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 39)
// {
// timeStructure.fifths = Five;
// timeStructure.beforeAfter = After;
// timeStructure.half = true;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 44)
// {
// timeStructure.fifths = Ten;
// timeStructure.beforeAfter = After;
// timeStructure.half = true;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 49)
// {
// timeStructure.fifths = Quarter;
// timeStructure.beforeAfter = Before;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 54)
// {
// timeStructure.fifths = Ten;
// timeStructure.beforeAfter = Before;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
// else if (tm.tm_min < 59)
// {
// timeStructure.fifths = Five;
// timeStructure.beforeAfter = Before;
// timeStructure.half = false;
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
// timeStructure.hourPostfix = false;
// }
//
// toString(&timeStructure);
//
// return timeStructure;
//}
int Clock::calculateHours(int hour)
{
int hours;
@@ -197,17 +292,17 @@ int Clock::calculateHours(int hour)
return hours;
}
void Clock::toString(TimeStructure* timestructure)
{
LOGGER_SUCCESS("%s%s%s%s%d%s", timestructure->prefix ? "Het is " : "",
timestructure->fifths == Five ? "Vijf " :
timestructure->fifths == Ten ? "Tien " :
timestructure->fifths == Quarter ? "kwart ": "",
timestructure->beforeAfter == Before ? "voor " :
timestructure->beforeAfter == After ? "over " : "",
timestructure->half ? "half " : "",
timestructure->hours,
timestructure->hourPostfix ? " uur" : ""
);
}
//void Clock::toString(TimeStructure* timestructure)
//{
// LOGGER_SUCCESS("%s%s%s%s%d%s", timestructure->prefix ? "Het is " : "",
// timestructure->fifths == Five ? "Vijf " :
// timestructure->fifths == Ten ? "Tien " :
// timestructure->fifths == Quarter ? "kwart ": "",
// timestructure->beforeAfter == Before ? "voor " :
// timestructure->beforeAfter == After ? "over " : "",
// timestructure->half ? "half " : "",
// timestructure->hours,
// timestructure->hourPostfix ? " uur" : ""
// );
//}
+143
View File
@@ -0,0 +1,143 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "wordmap.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
Wordmap::Wordmap(LEDMatrix* matrix)
{
Wordmap::matrix = matrix;
Wordmap::language = NL;
createList_NL();
}
bool Wordmap::setWord(Language_t lang, 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)
{
if (it->length > 0)
{
for (int i = 0; i < it->length; i++)
{
matrix->setPixelValue(it->position.x + i, it->position.y, value);
}
}
}
return returnValue;
}
void Wordmap::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}, 3});
wordlist[NL].push_back((struct word){"is", {4,0}, 2});
wordlist[NL].push_back((struct word){"ind_five", {7,0}, 4});
wordlist[NL].push_back((struct word){"ind_ten", {1,1}, 4});
wordlist[NL].push_back((struct word){"ind_quart", {6,1}, 5});
wordlist[NL].push_back((struct word){"ind_twenty", {0,2}, 7});
wordlist[NL].push_back((struct word){"before", {6,3}, 4});
wordlist[NL].push_back((struct word){"after", {1,3}, 4});
wordlist[NL].push_back((struct word){"almost", {1,4}, 5}),
wordlist[NL].push_back((struct word){"half", {7,4}, 4});
wordlist[NL].push_back((struct word){"one", {3,5}, 3});
wordlist[NL].push_back((struct word){"two", {1,5}, 4});
wordlist[NL].push_back((struct word){"three", {6,5}, 4});
wordlist[NL].push_back((struct word){"four", {7,6}, 4});
wordlist[NL].push_back((struct word){"five", {0,6}, 4});
wordlist[NL].push_back((struct word){"six", {4,6}, 3});
wordlist[NL].push_back((struct word){"seven", {0,7}, 5});
wordlist[NL].push_back((struct word){"eight", {0,8}, 4});
wordlist[NL].push_back((struct word){"nine", {6,7}, 5});
wordlist[NL].push_back((struct word){"ten", {4,8}, 4});
wordlist[NL].push_back((struct word){"eleven", {8,8}, 3});
wordlist[NL].push_back((struct word){"twelve", {0,9}, 6});
wordlist[NL].push_back((struct word){"hours", {7,9}, 3});
}