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

P021 state based extension #5085

Open
wants to merge 32 commits into
base: mega
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c896d23
Added state extension
flashmark Jul 13, 2024
c749ad7
Fix backwards compatibility issue and tidy up
flashmark Jul 13, 2024
29f882a
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Jul 20, 2024
e1d37d3
Reworked after pull request
flashmark Jul 20, 2024
fee1cbc
Rework after review
flashmark Jul 27, 2024
7cd2964
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Jul 27, 2024
5e0ff32
Merge branch 'P021-state_based_extension' of https://github.com/flash…
flashmark Jul 27, 2024
63e3183
Cleanup, fix init issue
flashmark Jul 28, 2024
642491e
Update documentation
flashmark Jul 28, 2024
6c6c211
Minor fixes
flashmark Jul 29, 2024
34b087d
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Aug 8, 2024
04f2b91
P021 Optimize memory footprint
flashmark Aug 11, 2024
8723941
P021 fixed issue in control algoritm
flashmark Aug 12, 2024
ae79c41
Merge branch 'mega' into P021-state_based_extension
flashmark Aug 14, 2024
6dff3fb
P021 Squeeze out some flash usage
flashmark Aug 14, 2024
27a9e03
P021 timer initialization
flashmark Aug 16, 2024
a08b248
P021 another set of shaving flash memory consumption
flashmark Aug 17, 2024
d68f3e9
P021 fixed an oops and reworked review comments
flashmark Aug 17, 2024
6160359
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Aug 17, 2024
68706df
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Aug 22, 2024
e78ef11
Merge branch 'mega' into P021-state_based_extension
TD-er Aug 22, 2024
c32734d
[P021] disable new feaures for low memory builds. Fix issues.
flashmark Sep 2, 2024
eb3ffda
[p021] fixed unused variable
flashmark Sep 2, 2024
99dd593
[P021] Documentataion update to refect limited build versions
flashmark Sep 3, 2024
da65e68
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Sep 16, 2024
2a4f0fe
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Sep 21, 2024
a1db7ae
[P021] Bugfix
flashmark Sep 21, 2024
111f8b0
Merge branch 'letscontrolit:mega' into P021-state_based_extension
flashmark Sep 27, 2024
7fd6bb4
Merge branch 'mega' into P021-state_based_extension
TD-er Sep 28, 2024
eff4b63
Merge branch 'mega' into P021-state_based_extension
TD-er Sep 28, 2024
2e7d662
Merge branch 'mega' into P021-state_based_extension
TD-er Oct 2, 2024
3478464
Merge branch 'mega' into P021-state_based_extension
TD-er Oct 3, 2024
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
67 changes: 37 additions & 30 deletions src/_P021_Level.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
// Simple conversion from parameter settings in hours/minutes to seconds (administration unit)
// And from seconds to the millis domain used for the actual control
// Note that these simple conversion may lose precision due to rough rounding
#define millis2seconds(x) ((x) / ((ulong)1000))
#define seconds2millis(x) ((x) * ((ulong)1000))
#define millis2seconds(x) ((x) / (1000))
#define seconds2millis(x) ((x) * (1000))
#define minutes2seconds(x) ((x) * 60)
#define hours2seconds(x) ((x) * 60 * 60)
#define seconds2minutes(x) ((x) / 60)
Expand Down Expand Up @@ -224,10 +224,12 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string)
const P021_control_state control_state = (P021_control_state)UserVar.getFloat(event->TaskIndex, P021_VALUE_STATE);

// Add some debug information
String msg = strformat(F(", State= %s "), P021_printControlState(control_state));
msg += strformat(F(", Output= %s"), (int)UserVar.getFloat(event->TaskIndex, P021_VALUE_OUTPUT) == 1 ? F("on") : F("off"));
msg += strformat(F(", Remote= %d"), P021_remote[event->TaskIndex]);
msg += strformat(F(", Timer= %d sec"), (millis2seconds(timePassedSince(P021_timestamp[event->TaskIndex]))));
String outpstring = (int)UserVar.getFloat(event->TaskIndex, P021_VALUE_OUTPUT) == 1 ? F("on") : F("off");
String msg = strformat(F("State= %s, Output= %s, Remote= %d, Timer= %d sec"),
P021_printControlState(control_state),
outpstring.c_str(),
P021_remote[event->TaskIndex],
millis2seconds(timePassedSince(P021_timestamp[event->TaskIndex])));
addFormNote(msg);
}
#endif // ifdef PLUGIN_021_DEBUG
Expand Down Expand Up @@ -273,11 +275,11 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string)
addFormSelector(F("Control mode"), F(P021_GUID_OPMODE), P021_OPMODE_SIZE, options, optionValues, P021_OPMODE);

{
ulong min_time = P021_MIN_TIME; // Value to display for minimum timer
ulong interval_time = P021_INTERVAL_TIME; // Value to display for max idling time
ulong force_time = P021_FORCE_TIME; // Value for forces run
String unit1 = F("seconds"); // use minutes or seconds
String unit2 = F("seconds"); // use hours or seconds
uint32_t min_time = P021_MIN_TIME; // Value to display for minimum timer
uint32_t interval_time = P021_INTERVAL_TIME; // Value to display for max idling time
uint32_t force_time = P021_FORCE_TIME; // Value for forces run
String unit1 = F("seconds"); // use minutes or seconds
String unit2 = F("seconds"); // use hours or seconds

if (bitRead(P021_FLAGS, P021_LONG_TIMER_UNIT))
{
Expand Down Expand Up @@ -475,9 +477,9 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string)
const String command = parseString(string, 1); // already converted to lowercase
const String subcmd = parseString(string, 2);
const String value = parseString(string, 3);
String log = F("P021 write: ");

if (equals(command, F("levelcontrol"))) {
String log = F("P021 write: ");
if (equals(subcmd, F("remote"))) {
log += F(" levelcontrol");

Expand All @@ -494,9 +496,12 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string)
success = true;
}
}
// If not successful rely upon ESPeasy framework to report
if (success) {
addLogMove(LOG_LEVEL_INFO, log);
}
}
P021_evaluate(event);
addLogMove(LOG_LEVEL_INFO, log);
break;
}

Expand Down Expand Up @@ -603,9 +608,9 @@ void P021_evaluate(struct EventStruct *event)
P021_control_state new_control_state = old_control_state;
const bool invert_input = bitRead(P021_FLAGS, P021_INV_INPUT);
const bool symetric_hyst = bitRead(P021_FLAGS, P021_SYM_HYSTERESIS);
bool relay_output = UserVar.getFloat(event->TaskIndex, P021_VALUE_OUTPUT);
bool remote_state = P021_remote[event->TaskIndex] != 0;
ulong timestamp = P021_timestamp[event->TaskIndex];
bool relay_output = UserVar.getFloat(event->TaskIndex, P021_VALUE_OUTPUT);
bool remote_state = P021_remote[event->TaskIndex] != 0;
uint32_t timestamp = P021_timestamp[event->TaskIndex];

// Get the control value from the external task. If task does not exist use the default
if (validTaskIndex(TaskIndex))
Expand Down Expand Up @@ -653,13 +658,13 @@ void P021_evaluate(struct EventStruct *event)

if (old_control_state == P021_STATE_IDLE) // Output was idling
{
if ((timePassedSince(timestamp) >= seconds2millis(P021_INTERVAL_TIME)) && ((ulong)P021_FORCE_TIME >= 1))
if ((timePassedSince(timestamp) >= (long)seconds2millis(P021_INTERVAL_TIME)) && ((uint32_t)P021_FORCE_TIME >= 1))
{
timestamp = millis();
new_control_state = P021_STATE_FORCE;
}
}
else if (timePassedSince(timestamp) < seconds2millis(P021_FORCE_TIME))
else if (timePassedSince(timestamp) < (long)seconds2millis(P021_FORCE_TIME))
{
// Output was active shorter than the forced on time
new_control_state = P021_STATE_FORCE; // Keep running in state FORCE
Expand Down Expand Up @@ -689,7 +694,7 @@ void P021_evaluate(struct EventStruct *event)
timestamp = millis();
new_control_state = P021_STATE_ACTIVE;
}
else if (timePassedSince(timestamp) >= seconds2millis(P021_INTERVAL_TIME))
else if (timePassedSince(timestamp) >= (long)seconds2millis(P021_INTERVAL_TIME))
{
// Inactive for a long period, forced maintenance run
timestamp = millis();
Expand All @@ -702,7 +707,7 @@ void P021_evaluate(struct EventStruct *event)

if (P021_check_off(value, P021_SETPOINT, P021_HYSTERESIS, invert_input, symetric_hyst, remote_state))
{
if (timePassedSince(timestamp) >= seconds2millis(P021_MIN_TIME))
if (timePassedSince(timestamp) >= (long)seconds2millis(P021_MIN_TIME))
{
timestamp = millis();
new_control_state = P021_STATE_IDLE;
Expand All @@ -726,7 +731,7 @@ void P021_evaluate(struct EventStruct *event)
{
new_control_state = P021_STATE_ACTIVE;
}
else if (timePassedSince(timestamp) >= seconds2millis(P021_MIN_TIME))
else if (timePassedSince(timestamp) >= (long)seconds2millis(P021_MIN_TIME))
flashmark marked this conversation as resolved.
Show resolved Hide resolved
{
timestamp = millis();
new_control_state = P021_STATE_IDLE;
Expand All @@ -741,7 +746,7 @@ void P021_evaluate(struct EventStruct *event)
// Keep timestamp from moment pump was swiched on
new_control_state = P021_STATE_ACTIVE;
}
else if (timePassedSince(timestamp) >= seconds2millis(P021_FORCE_TIME))
else if (timePassedSince(timestamp) >= (long)seconds2millis(P021_FORCE_TIME))
{
timestamp = millis();
new_control_state = P021_STATE_IDLE;
Expand Down Expand Up @@ -785,14 +790,16 @@ void P021_evaluate(struct EventStruct *event)

#ifdef PLUGIN_021_DEBUG

if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
String log = strformat(F("P021: Calculated State= %s"), P021_printControlState(new_control_state));
log += strformat(F("; GPIO= %d"), relay_output);
log += strformat(F("; timer= %d sec"), millis2seconds(timePassedSince(timestamp)));
log += strformat(F("; mode= %s"), P021_printControlMode(P021_OPMODE));
log += strformat(F("; value= %f"), value);
log += strformat(F("; remote= %d"), remote_state);
addLogMove(LOG_LEVEL_DEBUG, log);
if (loglevelActiveFor(LOG_LEVEL_DEBUG))
{
addLogMove(LOG_LEVEL_DEBUG,
strformat(F("P021: Calculated State= %s; GPIO= %d; timer= %d sec; mode= %s; value= %f; remote= %d"),
P021_printControlState(new_control_state),
relay_output,
millis2seconds(timePassedSince(timestamp)),
P021_printControlMode(P021_OPMODE),
value,
remote_state));
}
#endif // ifdef PLUGIN_021_DEBUG

Expand Down
Loading