Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Issue #177 #181

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/DateTimePlugin/src/DateTimePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool DateTimePlugin::setTopic(const String& topic, const JsonObjectConst& value)
JsonVariantConst jsonTimeFormat = value["timeFormat"];
JsonVariantConst jsonDateFormat = value["dateFormat"];
JsonVariantConst jsonTimeZone = value["timeZone"];
JsonVariantConst jsonStartOfWeek = value["startOfWeek"];
JsonVariantConst jsonDayOnColor = value["dayOnColor"];
JsonVariantConst jsonDayOffColor = value["dayOffColor"];

Expand Down Expand Up @@ -139,6 +140,12 @@ bool DateTimePlugin::setTopic(const String& topic, const JsonObjectConst& value)
jsonCfg["timeZone"] = jsonTimeZone.as<String>();
isSuccessful = true;
}

if (false == jsonStartOfWeek.isNull())
{
jsonCfg["startOfWeek"] = jsonStartOfWeek.as<uint8_t>();
isSuccessful = true;
}

if (false == jsonDayOnColor.isNull())
{
Expand Down Expand Up @@ -261,6 +268,7 @@ void DateTimePlugin::getConfiguration(JsonObject& jsonCfg) const
jsonCfg["timeFormat"] = m_timeFormat;
jsonCfg["dateFormat"] = m_dateFormat;
jsonCfg["timeZone"] = m_timeZone;
jsonCfg["startOfWeek"] = m_view.getStartOfWeek();
jsonCfg["dayOnColor"] = colorToHtml(m_view.getDayOnColor());
jsonCfg["dayOffColor"] = colorToHtml(m_view.getDayOffColor());
}
Expand All @@ -272,6 +280,7 @@ bool DateTimePlugin::setConfiguration(const JsonObjectConst& jsonCfg)
JsonVariantConst jsonTimeFormat = jsonCfg["timeFormat"];
JsonVariantConst jsonDateFormat = jsonCfg["dateFormat"];
JsonVariantConst jsonTimeZone = jsonCfg["timeZone"];
JsonVariantConst jsonStartOfWeek = jsonCfg["startOfWeek"];
JsonVariantConst jsonDayOnColor = jsonCfg["dayOnColor"];
JsonVariantConst jsonDayOffColor = jsonCfg["dayOffColor"];

Expand All @@ -292,6 +301,10 @@ bool DateTimePlugin::setConfiguration(const JsonObjectConst& jsonCfg)
{
LOG_WARNING("JSON timezone not found or invalid type.");
}
else if (false == jsonStartOfWeek.is<uint8_t>())
{
LOG_WARNING("JSON start of week not found or invalid type.");
}
else if (false == jsonDayOnColor.is<String>())
{
LOG_WARNING("JSON day on color not found or invalid type.");
Expand All @@ -309,6 +322,7 @@ bool DateTimePlugin::setConfiguration(const JsonObjectConst& jsonCfg)
m_dateFormat = jsonDateFormat.as<String>();
m_timeZone = jsonTimeZone.as<String>();

m_view.setStartOfWeek(jsonStartOfWeek.as<uint8_t>());
m_view.setDayOnColor(colorFromHtml(jsonDayOnColor.as<String>()));
m_view.setDayOffColor(colorFromHtml(jsonDayOffColor.as<String>()));

Expand Down
14 changes: 14 additions & 0 deletions lib/DateTimePlugin/web/DateTimePlugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ <h3>Display</h3>
<label class="form-label" for="timeFormat">Time zone:</label>
<input class="form-control" type="text" id="timeZone" name="timeZone" value="" />
</div>
<div class="form-group">
<label class="form-label" for="startOfWeek">Start of week:</label>
<select class="form-select" id="startOfWeek">
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="timeFormat">Color of actual day:</label>
<input class="form-control" type="text" id="dayOnColor" name="dayOnColor" value="" />
Expand Down Expand Up @@ -194,6 +206,7 @@ <h3>Display</h3>
$("#timeFormat").val(rsp.data.timeFormat);
$("#dateFormat").val(rsp.data.dateFormat);
$("#timeZone").val(rsp.data.timeZone);
$("#startOfWeek").val(rsp.data.startOfWeek);
$("#dayOnColor").val(rsp.data.dayOnColor);
$("#dayOffColor").val(rsp.data.dayOffColor);
}).catch(function(rsp) {
Expand All @@ -214,6 +227,7 @@ <h3>Display</h3>
timeFormat: $("#timeFormat").val(),
dateFormat: $("#dateFormat").val(),
timeZone: $("#timeZone").val(),
startOfWeek: $("#startOfWeek").val(),
dayOnColor: $("#dayOnColor").val(),
dayOffColor: $("#dayOffColor").val()
}
Expand Down
14 changes: 14 additions & 0 deletions lib/Views/src/IDateTimeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ class IDateTimeView
*/
virtual void setFormatText(const String& formatText) = 0;

/**
* Get the start of week configuration (Sunday = 0).
*
* @return uint8_t
*/
virtual uint8_t getStartOfWeek() const = 0;

/**
* Set the start of week configuration (Sunday = 0).
*
* @param[in] startOfWeek uint8_t offset for starting of week
*/
virtual void setStartOfWeek(uint8_t startOfWeek) = 0;

/**
* Get the color to show the actual day.
*
Expand Down
18 changes: 8 additions & 10 deletions lib/Views/src/layouts/DateTimeView32x8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,18 @@ void DateTimeView32x8::setCurrentTime(const tm& now)
{
/* update lamp widgets */

/* tm_wday starts at sunday, first lamp indicates monday.*/
uint8_t activeLamp = (0U < now.tm_wday) ? (now.tm_wday - 1U) : (MAX_LAMPS - 1U);

/* Last active lamp has to be deactivated. */
uint8_t lampToDeactivate = (0U < activeLamp) ? (activeLamp - 1U) : (MAX_LAMPS - 1U);

if (MAX_LAMPS > activeLamp)
/* tm_wday starts at sunday, first lamp specified via m_startOfWeek.*/
uint8_t activeLamp = now.tm_wday - m_startOfWeek;
if (MAX_LAMPS < activeLamp)
{
m_lampWidgets[activeLamp].setOnState(true);
activeLamp += 7U;
BlueAndi marked this conversation as resolved.
Show resolved Hide resolved
}

if (MAX_LAMPS > lampToDeactivate)
uint8_t index;

for(index = 0U; index < MAX_LAMPS; ++index)
{
m_lampWidgets[lampToDeactivate].setOnState(false);
m_lampWidgets[index].setOnState(index == activeLamp);
}
}

Expand Down
25 changes: 25 additions & 0 deletions lib/Views/src/layouts/DateTimeView32x8.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DateTimeView32x8 : public IDateTimeView
{LAMP_WIDTH, LAMP_HEIGHT, LAMP_4_X , LAMP_Y},
{LAMP_WIDTH, LAMP_HEIGHT, LAMP_5_X , LAMP_Y},
{LAMP_WIDTH, LAMP_HEIGHT, LAMP_6_X , LAMP_Y}},
m_startOfWeek(START_OF_WEEK),
m_dayOnColor(DAY_ON_COLOR),
m_dayOffColor(DAY_OFF_COLOR)
{
Expand Down Expand Up @@ -177,6 +178,26 @@ class DateTimeView32x8 : public IDateTimeView
m_textWidget.setFormatStr(formatText);
}

/**
* Get the start of week configuration (Sunday = 0).
*
* @return uint8_t
*/
uint8_t getStartOfWeek() const override
{
return m_startOfWeek;
}

/**
* Set the start of week configuration (Sunday = 0).
*
* @param[in] startOfWeek uint8_t offset for starting of week
*/
void setStartOfWeek(uint8_t startOfWeek) override
{
m_startOfWeek = startOfWeek;
ryannevell marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Get the color to show the actual day.
*
Expand Down Expand Up @@ -287,6 +308,9 @@ class DateTimeView32x8 : public IDateTimeView
*/
static const int16_t TEXT_Y = 0;

/** Start of week offset for the week bar (Sunday = 0). */
static const uint8_t START_OF_WEEK = 1U;

/** Color of the current day shown in the day of the week bar. */
static const Color DAY_ON_COLOR;

Expand All @@ -296,6 +320,7 @@ class DateTimeView32x8 : public IDateTimeView
Fonts::FontType m_fontType; /**< Font type which shall be used if there is no conflict with the layout. */
TextWidget m_textWidget; /**< Text widget, used for showing the text. */
LampWidget m_lampWidgets[MAX_LAMPS]; /**< Lamp widgets, used to signal the day of week. */
uint8_t m_startOfWeek; /**< Start of week offset for the week bar (Sunday = 0). */
Color m_dayOnColor; /**< Color of current day in the day of the week bar. */
Color m_dayOffColor; /**< Color of the other days in the day of the week bar. */

Expand Down
18 changes: 8 additions & 10 deletions lib/Views/src/layouts/DateTimeViewGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,18 @@ void DateTimeViewGeneric::setCurrentTime(const tm& now)

/* update lamp widgets */

/* tm_wday starts at sunday, first lamp indicates monday.*/
uint8_t activeLamp = (0U < m_now.tm_wday) ? (m_now.tm_wday - 1U) : (MAX_LAMPS - 1U);

/* Last active lamp has to be deactivated. */
uint8_t lampToDeactivate = (0U < activeLamp) ? (activeLamp - 1U) : (MAX_LAMPS - 1U);

if (MAX_LAMPS > activeLamp)
/* tm_wday starts at sunday, first lamp specified via m_startOfWeek.*/
uint8_t activeLamp = m_now.tm_wday - m_startOfWeek;
if (MAX_LAMPS < activeLamp)
{
m_lampWidgets[activeLamp].setOnState(true);
activeLamp += 7U;
BlueAndi marked this conversation as resolved.
Show resolved Hide resolved
}

if (MAX_LAMPS > lampToDeactivate)
uint8_t index;

for(index = 0U; index < MAX_LAMPS; ++index)
{
m_lampWidgets[lampToDeactivate].setOnState(false);
m_lampWidgets[index].setOnState(index == activeLamp);
}
}

Expand Down
25 changes: 25 additions & 0 deletions lib/Views/src/layouts/DateTimeViewGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DateTimeViewGeneric : public IDateTimeView
{LAMP_WIDTH, LAMP_HEIGHT, LAMP_4_X , LAMP_Y},
{LAMP_WIDTH, LAMP_HEIGHT, LAMP_5_X , LAMP_Y},
{LAMP_WIDTH, LAMP_HEIGHT, LAMP_6_X , LAMP_Y}},
m_startOfWeek(START_OF_WEEK),
m_dayOnColor(DAY_ON_COLOR),
m_dayOffColor(DAY_OFF_COLOR),
m_now()
Expand Down Expand Up @@ -178,6 +179,26 @@ class DateTimeViewGeneric : public IDateTimeView
m_textWidget.setFormatStr(formatText);
}

/**
* Get the start of week configuration (Sunday = 0).
*
* @return uint8_t
*/
uint8_t getStartOfWeek() const override
{
return m_startOfWeek;
}

/**
* Set the start of week configuration (Sunday = 0).
*
* @param[in] startOfWeek uint8_t offset for starting of week
*/
void setStartOfWeek(uint8_t startOfWeek) override
{
m_startOfWeek = startOfWeek;
BlueAndi marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Get the color to show the actual day.
*
Expand Down Expand Up @@ -288,6 +309,9 @@ class DateTimeViewGeneric : public IDateTimeView
*/
static const int16_t TEXT_Y = 0;

/** Start of week offset for the week bar (Sunday = 0). */
static const uint8_t START_OF_WEEK = 1U;

/** Color of the current day shown in the day of the week bar. */
static const Color DAY_ON_COLOR;

Expand All @@ -297,6 +321,7 @@ class DateTimeViewGeneric : public IDateTimeView
Fonts::FontType m_fontType; /**< Font type which shall be used if there is no conflict with the layout. */
TextWidget m_textWidget; /**< Text widget, used for showing the text. */
LampWidget m_lampWidgets[MAX_LAMPS]; /**< Lamp widgets, used to signal the day of week. */
uint8_t m_startOfWeek; /**< Start of week offset for the week bar (Sunday = 0). */
Color m_dayOnColor; /**< Color of current day in the day of the week bar. */
Color m_dayOffColor; /**< Color of the other days in the day of the week bar. */
tm m_now; /**< Latest time update */
Expand Down