Added clock and wordclock - functional
the matrix needs an update, though. Not all words are well put
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \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"
|
||||
|
||||
#include "logger.h"
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Clock::Clock()
|
||||
{
|
||||
Clock::currentTime = 0;
|
||||
|
||||
// Start NTP
|
||||
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
|
||||
tzset();
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, "pool.ntp.org");
|
||||
sntp_init();
|
||||
}
|
||||
|
||||
Clock::TimeStructure Clock::updateTime(void)
|
||||
{
|
||||
struct tm tm;
|
||||
time(¤tTime);
|
||||
// currentTime += 10;
|
||||
localtime_r(¤tTime, &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;
|
||||
// Calculate hours to 12hour system
|
||||
if (hour > 12)
|
||||
{
|
||||
hours = hour - 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = 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" : ""
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ LEDMatrix::LEDMatrix(LEDMatrix_Parameters_t* parameters)
|
||||
LEDMatrix::clear();
|
||||
}
|
||||
|
||||
bool LEDMatrix::setPixelValue(unsigned int row, unsigned int colum, bool value)
|
||||
bool LEDMatrix::setPixelValue(unsigned int colum, unsigned int row, bool value)
|
||||
{
|
||||
bool returnValue = true;
|
||||
|
||||
@@ -146,9 +146,9 @@ void LEDMatrix::clear(void)
|
||||
for (int i = 0; i < numberOfPixels; i++)
|
||||
{
|
||||
matrix[i].on = false;
|
||||
matrix[i].red = 0;
|
||||
matrix[i].green = 0;
|
||||
matrix[i].blue = 0;
|
||||
// matrix[i].red = 0;
|
||||
// matrix[i].green = 0;
|
||||
// matrix[i].blue = 0;
|
||||
}
|
||||
// Release the semaphore to trigger an matrix update
|
||||
xSemaphoreGive(LEDMatrix::taskSemaphore);
|
||||
@@ -167,6 +167,7 @@ void LEDMatrix::matrixTask(void* parameters)
|
||||
xSemaphoreTake(ledmatrix->taskSemaphore, 1000);
|
||||
for (int i = 0; i < ledmatrix->numberOfPixels; i++)
|
||||
{
|
||||
|
||||
if (ledmatrix->matrix[i].on)
|
||||
{
|
||||
matrix[i * 3 + LEDMATRIX_RED_INDEX] = ledmatrix->matrix[i].red;
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file wordclock.cpp
|
||||
/// \brief Description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "wordclock.h"
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Wordclock::Wordclock(LEDMatrix* matrix)
|
||||
{
|
||||
Wordclock::matrix = matrix;
|
||||
// Initial language set
|
||||
Wordclock::language = NL;
|
||||
}
|
||||
|
||||
|
||||
void Wordclock::update(Clock::TimeStructure* time)
|
||||
{
|
||||
// Clear the matrix before setting a new time
|
||||
matrix->clear();
|
||||
|
||||
if (time->prefix)
|
||||
{
|
||||
if (languagemaps[language].prefix.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].prefix.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].prefix.position.x + i, languagemaps[language].prefix.position.y, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (languagemaps[language].prefix_additional.length > 0)
|
||||
{
|
||||
// Enable Prefix addition on the matrix
|
||||
for (int i = 0; i < languagemaps[language].prefix_additional.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].prefix_additional.position.x + i, languagemaps[language].prefix_additional.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (time->almost)
|
||||
{
|
||||
if (languagemaps[language].almost.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].almost.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].almost.position.x + i, languagemaps[language].almost.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (time->fifths == Clock::Five)
|
||||
{
|
||||
if (languagemaps[language].five.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].five.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].five.position.x + i, languagemaps[language].five.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (time->fifths == Clock::Ten)
|
||||
{
|
||||
if (languagemaps[language].ten.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].ten.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].ten.position.x + i, languagemaps[language].ten.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (time->fifths == Clock::Quarter)
|
||||
{
|
||||
if (languagemaps[language].quarter.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].quarter.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].quarter.position.x + i, languagemaps[language].quarter.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (time->beforeAfter == Clock::Before)
|
||||
{
|
||||
if (languagemaps[language].before.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].before.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].before.position.x + i, languagemaps[language].before.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (time->beforeAfter == Clock::After)
|
||||
{
|
||||
if (languagemaps[language].after.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].after.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].after.position.x + i, languagemaps[language].after.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (time->half)
|
||||
{
|
||||
if (languagemaps[language].half.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].half.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].half.position.x + i, languagemaps[language].half.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((time->hours > 0) && (time->hours < 12))
|
||||
{
|
||||
if (languagemaps[language].hour[time->hours - 1].length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].hour[time->hours - 1].length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].hour[time->hours - 1].position.x + i, languagemaps[language].hour[time->hours - 1].position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (time->hourPostfix)
|
||||
{
|
||||
if (languagemaps[language].hourPostfix.length > 0)
|
||||
{
|
||||
// Enable Prefix on the matrix
|
||||
for (int i = 0; i < languagemaps[language].hourPostfix.length; i++)
|
||||
{
|
||||
matrix->setPixelValue(languagemaps[language].hourPostfix.position.x + i, languagemaps[language].hourPostfix.position.y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user