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
+14 -28
View File
@@ -34,7 +34,8 @@
// CompilerIncludes // CompilerIncludes
// All include files that are provided by the compiler directly // All include files that are provided by the compiler directly
#include <string>
#include <list>
// ProjectIncludes // ProjectIncludes
@@ -57,45 +58,30 @@
// Function declarations // Function declarations
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
using namespace std;
class Clock class Clock
{ {
public: public:
enum FifthsIndication
{
None_FifthIndication = 0,
Five,
Ten,
Quarter
};
enum BeforeAfterIndication
{
None_BeforeAfter = 0,
Before,
After
};
struct TimeStructure
{
bool prefix;
bool almost;
FifthsIndication fifths;
BeforeAfterIndication beforeAfter;
bool half;
int hours;
bool hourPostfix;
};
Clock(); Clock();
TimeStructure updateTime(void); void generateWordlist(list<string>* wordlist);
time_t getTime(void);
private: private:
time_t currentTime; time_t currentTime;
void toString(TimeStructure* timestructure); string toNumbers[20] {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen",
"nineteen"};
// void toString(TimeStructure* timestructure);
int calculateHours(int hour); int calculateHours(int hour);
}; };
+101
View File
@@ -0,0 +1,101 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_WORDMAP_H_
#define MAIN_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
// --------------------------------------------------------------------------------------------------------------------
using namespace std;
class Wordmap
{
public:
typedef enum language
{
NL = 0,
EN,
NumberOfLanguages
} Language_t;
Wordmap(LEDMatrix* matrix);
bool setWord(Language_t lang, string identifier, bool value);
private:
struct word
{
string identifier;
LEDMatrix::coordinate position;
int length;
};
LEDMatrix* matrix;
language language;
list<struct word> wordlist[NumberOfLanguages];
void createList_NL(void);
void createList_EN(void);
};
/** @} */
#endif /* MAIN_INC_WORDMAP_H_ */
+25 -15
View File
@@ -97,7 +97,7 @@ static gptimer_handle_t matrixRefreshTimer = NULL;
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
// Simple countdown on display // Simple countdown on display
static void countdown(void); static void countdown(int delay);
// Timer Callback for the LEDMatrix refresh // Timer Callback for the LEDMatrix refresh
static bool timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data); static bool timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data);
@@ -211,14 +211,24 @@ extern "C" void app_main(void)
wifi.start_client(); wifi.start_client();
Clock clock; Clock clock;
Clock::TimeStructure time;
countdown(); countdown(200);
list<string> wordlist;
while (true) while (true)
{ {
time = clock.updateTime(); clock.generateWordlist(&wordlist);
LEDMatrix.clear();
std::list<string>::iterator it;
for(it = wordlist.begin(); it != wordlist.end(); it++)
{
map.setWord(Wordmap::Language_t::NL, *it, true);
}
// Add a seconds indicator
LEDMatrix.setPixelValue(10, 9, clock.getTime() % 2);
// Update the clock every second (1000 ms) // Update the clock every second (1000 ms)
vTaskDelay(1000); vTaskDelay(1000);
@@ -240,37 +250,37 @@ static void devTask(void* parameters)
} }
static void countdown(void) static void countdown(int delay)
{ {
map.setWord(Wordmap::Language_t::NL, "ten", true); map.setWord(Wordmap::Language_t::NL, "ten", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "ten", false); map.setWord(Wordmap::Language_t::NL, "ten", false);
map.setWord(Wordmap::Language_t::NL, "nine", true); map.setWord(Wordmap::Language_t::NL, "nine", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "nine", false); map.setWord(Wordmap::Language_t::NL, "nine", false);
map.setWord(Wordmap::Language_t::NL, "eight", true); map.setWord(Wordmap::Language_t::NL, "eight", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "eight", false); map.setWord(Wordmap::Language_t::NL, "eight", false);
map.setWord(Wordmap::Language_t::NL, "seven", true); map.setWord(Wordmap::Language_t::NL, "seven", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "seven", false); map.setWord(Wordmap::Language_t::NL, "seven", false);
map.setWord(Wordmap::Language_t::NL, "six", true); map.setWord(Wordmap::Language_t::NL, "six", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "six", false); map.setWord(Wordmap::Language_t::NL, "six", false);
map.setWord(Wordmap::Language_t::NL, "five", true); map.setWord(Wordmap::Language_t::NL, "five", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "five", false); map.setWord(Wordmap::Language_t::NL, "five", false);
map.setWord(Wordmap::Language_t::NL, "four", true); map.setWord(Wordmap::Language_t::NL, "four", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "four", false); map.setWord(Wordmap::Language_t::NL, "four", false);
map.setWord(Wordmap::Language_t::NL, "three", true); map.setWord(Wordmap::Language_t::NL, "three", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "three", false); map.setWord(Wordmap::Language_t::NL, "three", false);
map.setWord(Wordmap::Language_t::NL, "two", true); map.setWord(Wordmap::Language_t::NL, "two", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "two", false); map.setWord(Wordmap::Language_t::NL, "two", false);
map.setWord(Wordmap::Language_t::NL, "one", true); map.setWord(Wordmap::Language_t::NL, "one", true);
vTaskDelay(1000); vTaskDelay(delay);
map.setWord(Wordmap::Language_t::NL, "one", false); map.setWord(Wordmap::Language_t::NL, "one", false);
} }
+180 -85
View File
@@ -64,124 +64,219 @@ Clock::Clock()
sntp_init(); sntp_init();
} }
Clock::TimeStructure Clock::updateTime(void) void Clock::generateWordlist(list<string>* wordlist)
{ {
struct tm tm; struct tm tm;
time(&currentTime); time(&currentTime);
// currentTime += 10;
localtime_r(&currentTime, &tm); localtime_r(&currentTime, &tm);
LOGGER_INFO("%lld\n\r", currentTime); LOGGER_INFO("%lld\n\r", currentTime);
LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec); LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
// Construct the time structure wordlist->clear();
TimeStructure timeStructure; wordlist->push_back("it");
// Show the prefix wordlist->push_back("is");
timeStructure.prefix = true; wordlist->push_back(toNumbers[calculateHours(tm.tm_hour)]);
if (tm.tm_min < 4) if (tm.tm_min < 4)
{ {
timeStructure.fifths = None_FifthIndication; wordlist->push_back("hours");
timeStructure.beforeAfter = None_BeforeAfter;
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = true;
} }
else if (tm.tm_min < 9) else if (tm.tm_min < 9)
{ {
timeStructure.fifths = Five; wordlist->push_back("ind_five");
timeStructure.beforeAfter = After; wordlist->push_back("after");
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 14) else if (tm.tm_min < 14)
{ {
timeStructure.fifths = Ten; wordlist->push_back("ind_ten");
timeStructure.beforeAfter = After; wordlist->push_back("after");
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 19) else if (tm.tm_min < 19)
{ {
timeStructure.fifths = Quarter; wordlist->push_back("ind_quart");
timeStructure.beforeAfter = After; wordlist->push_back("after");
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 24) else if (tm.tm_min < 24)
{ {
timeStructure.fifths = Ten; wordlist->push_back("ind_ten");
timeStructure.beforeAfter = Before; wordlist->push_back("before");
timeStructure.half = true; wordlist->push_back("half");
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 29) else if (tm.tm_min < 28)
{ {
timeStructure.fifths = Five; wordlist->push_back("ind_five");
timeStructure.beforeAfter = Before; wordlist->push_back("before");
timeStructure.half = true; wordlist->push_back("half");
timeStructure.hours = calculateHours(tm.tm_hour + 1); }
timeStructure.hourPostfix = false; else if (tm.tm_min < 30)
{
wordlist->push_back("almost");
wordlist->push_back("half");
} }
else if (tm.tm_min < 34) else if (tm.tm_min < 34)
{ {
timeStructure.fifths = None_FifthIndication; wordlist->push_back("half");
timeStructure.beforeAfter = None_BeforeAfter;
timeStructure.half = true;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 39) else if (tm.tm_min < 39)
{ {
timeStructure.fifths = Five; wordlist->push_back("ind_five");
timeStructure.beforeAfter = After; wordlist->push_back("after");
timeStructure.half = true; wordlist->push_back("half");
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 44) else if (tm.tm_min < 44)
{ {
timeStructure.fifths = Ten; wordlist->push_back("ind_ten");
timeStructure.beforeAfter = After; wordlist->push_back("after");
timeStructure.half = true; wordlist->push_back("half");
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 49) else if (tm.tm_min < 49)
{ {
timeStructure.fifths = Quarter; wordlist->push_back("ind_quart");
timeStructure.beforeAfter = Before; wordlist->push_back("before");
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 54) else if (tm.tm_min < 54)
{ {
timeStructure.fifths = Ten; wordlist->push_back("ind_ten");
timeStructure.beforeAfter = Before; wordlist->push_back("before");
timeStructure.half = false;
timeStructure.hours = calculateHours(tm.tm_hour + 1);
timeStructure.hourPostfix = false;
} }
else if (tm.tm_min < 59) else if (tm.tm_min < 58)
{ {
timeStructure.fifths = Five; wordlist->push_back("ind_five");
timeStructure.beforeAfter = Before; wordlist->push_back("before");
timeStructure.half = false; }
timeStructure.hours = calculateHours(tm.tm_hour + 1); else
timeStructure.hourPostfix = false; {
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 Clock::calculateHours(int hour)
{ {
int hours; int hours;
@@ -197,17 +292,17 @@ int Clock::calculateHours(int hour)
return hours; return hours;
} }
void Clock::toString(TimeStructure* timestructure) //void Clock::toString(TimeStructure* timestructure)
{ //{
LOGGER_SUCCESS("%s%s%s%s%d%s", timestructure->prefix ? "Het is " : "", // LOGGER_SUCCESS("%s%s%s%s%d%s", timestructure->prefix ? "Het is " : "",
timestructure->fifths == Five ? "Vijf " : // timestructure->fifths == Five ? "Vijf " :
timestructure->fifths == Ten ? "Tien " : // timestructure->fifths == Ten ? "Tien " :
timestructure->fifths == Quarter ? "kwart ": "", // timestructure->fifths == Quarter ? "kwart ": "",
timestructure->beforeAfter == Before ? "voor " : // timestructure->beforeAfter == Before ? "voor " :
timestructure->beforeAfter == After ? "over " : "", // timestructure->beforeAfter == After ? "over " : "",
timestructure->half ? "half " : "", // timestructure->half ? "half " : "",
timestructure->hours, // timestructure->hours,
timestructure->hourPostfix ? " uur" : "" // 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});
}