Skip to content

Commit

Permalink
Merge pull request letscontrolit#5208 from tonhuisman/feature/Build-r…
Browse files Browse the repository at this point in the history
…educe-compiled-size-iteration-1000

[Build] Reduce code size to allow for some bugfixes in limited builds
  • Loading branch information
TD-er authored Jan 9, 2025
2 parents ed2535f + 465e6a0 commit 80d6d29
Show file tree
Hide file tree
Showing 169 changed files with 10,497 additions and 10,930 deletions.
25 changes: 12 additions & 13 deletions src/_P001_Switch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_001;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = true;
Device[deviceCount].InverseLogicOption = true;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].GlobalSyncOption = true;
auto& dev = Device[++deviceCount];
dev.Number = PLUGIN_ID_001;
dev.Type = DEVICE_TYPE_SINGLE;
dev.VType = Sensor_VType::SENSOR_TYPE_SWITCH;
dev.PullUpOption = true;
dev.InverseLogicOption = true;
dev.ValueCount = 1;
dev.SendDataOption = true;
dev.TimerOption = true;
dev.TimerOptional = true;
break;
}

Expand Down Expand Up @@ -87,7 +85,8 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
const __FlashStringHelper *options[] = { F("Switch"), F("Dimmer") };
const int optionValues[] = { PLUGIN_001_TYPE_SWITCH, PLUGIN_001_TYPE_DIMMER };
const uint8_t switchtype = P001_data_struct::P001_getSwitchType(event);
addFormSelector(F("Switch Type"), F("type"), NR_ELEMENTS(optionValues), options, optionValues, switchtype);
constexpr size_t optionCount = NR_ELEMENTS(optionValues);
addFormSelector(F("Switch Type"), F("type"), optionCount, options, optionValues, switchtype);

if (switchtype == PLUGIN_001_TYPE_DIMMER)
{
Expand Down
25 changes: 11 additions & 14 deletions src/_P002_ADC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_002;
Device[deviceCount].Type = DEVICE_TYPE_ANALOG;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].TaskLogsOwnPeaks = true;
auto& dev = Device[++deviceCount];
dev.Number = PLUGIN_ID_002;
dev.Type = DEVICE_TYPE_ANALOG;
dev.VType = Sensor_VType::SENSOR_TYPE_SINGLE;
dev.FormulaOption = true;
dev.ValueCount = 1;
dev.SendDataOption = true;
dev.TimerOption = true;
dev.PluginStats = true;
dev.TaskLogsOwnPeaks = true;
break;
}

Expand Down Expand Up @@ -133,7 +130,7 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string)

if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = strformat(
F("ADC : Analog value: %d = %s"),
F("ADC : Analog value: %d = %s"),
raw_value,
formatUserVarNoCheck(event, 0).c_str());

Expand Down
29 changes: 14 additions & 15 deletions src/_P003_Pulse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ boolean Plugin_003(uint8_t function, struct EventStruct *event, String& string)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_003;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = true;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = PLUGIN_NR_VALUENAMES_003;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].TaskLogsOwnPeaks = true;
auto& dev = Device[++deviceCount];
dev.Number = PLUGIN_ID_003;
dev.Type = DEVICE_TYPE_SINGLE;
dev.VType = Sensor_VType::SENSOR_TYPE_SINGLE;
dev.PullUpOption = true;
dev.FormulaOption = true;
dev.ValueCount = PLUGIN_NR_VALUENAMES_003;
dev.SendDataOption = true;
dev.TimerOption = true;
dev.TimerOptional = true;
dev.PluginStats = true;
dev.TaskLogsOwnPeaks = true;
break;
}

Expand Down Expand Up @@ -165,7 +163,8 @@ boolean Plugin_003(uint8_t function, struct EventStruct *event, String& string)
F("Time/Delta"),
# endif // if P003_USE_EXTRA_COUNTERTYPES
};
addFormSelector(F("Counter Type"), F("countertype"), NR_ELEMENTS(options), options, nullptr, choice);
constexpr size_t optionCount = NR_ELEMENTS(options);
addFormSelector(F("Counter Type"), F("countertype"), optionCount, options, nullptr, choice);

if (choice != 0) {
addHtml(F("<span style=\"color:red\">Total count is not persistent!</span>"));
Expand Down
41 changes: 20 additions & 21 deletions src/_P004_Dallas.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_004;
Device[deviceCount].Type = DEVICE_TYPE_DUAL;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].OutputDataType = Output_Data_type_t::Simple;
Device[deviceCount].PluginStats = true;
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
auto& dev = Device[++deviceCount];
dev.Number = PLUGIN_ID_004;
dev.Type = DEVICE_TYPE_DUAL;
dev.VType = Sensor_VType::SENSOR_TYPE_SINGLE;
dev.FormulaOption = true;
dev.ValueCount = 1;
dev.SendDataOption = true;
dev.TimerOption = true;
dev.OutputDataType = Output_Data_type_t::Simple;
dev.PluginStats = true;
dev.setPin2Direction(gpio_direction::gpio_output);
break;
}

Expand Down Expand Up @@ -139,18 +138,20 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string)
int resolutionChoice = P004_RESOLUTION;

if ((resolutionChoice < 9) || (resolutionChoice > 12)) { resolutionChoice = activeRes; }
const __FlashStringHelper *resultsOptions[4] = { F("9"), F("10"), F("11"), F("12") };
int resultsOptionValues[4] = { 9, 10, 11, 12 };
addFormSelector(F("Device Resolution"), F("res"), 4, resultsOptions, resultsOptionValues, resolutionChoice);
const __FlashStringHelper *resultsOptions[] = { F("9"), F("10"), F("11"), F("12") };
const int resultsOptionValues[] = { 9, 10, 11, 12 };
constexpr size_t optionCount = NR_ELEMENTS(resultsOptionValues);
addFormSelector(F("Device Resolution"), F("res"), optionCount, resultsOptions, resultsOptionValues, resolutionChoice);
addHtml(F(" Bit"));
}

{
// Value in case of Error
const __FlashStringHelper *resultsOptions[5] = { F("NaN"), F("-127"), F("0"), F("125"), F("Ignore") };
int resultsOptionValues[5] =
const __FlashStringHelper *resultsOptions[] = { F("NaN"), F("-127"), F("0"), F("125"), F("Ignore") };
int resultsOptionValues[] =
{ P004_ERROR_NAN, P004_ERROR_MIN_RANGE, P004_ERROR_ZERO, P004_ERROR_MAX_RANGE, P004_ERROR_IGNORE };
addFormSelector(F("Error State Value"), F("err"), 5, resultsOptions, resultsOptionValues, P004_ERROR_STATE_OUTPUT);
constexpr size_t optionCount = NR_ELEMENTS(resultsOptionValues);
addFormSelector(F("Error State Value"), F("err"), optionCount, resultsOptions, resultsOptionValues, P004_ERROR_STATE_OUTPUT);
}
addFormNote(F("External pull up resistor is needed, see docs!"));

Expand Down Expand Up @@ -338,9 +339,7 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string)
} else {
log += F("Error!");
}
log += F(" (");
log += P004_data->get_formatted_address(i);
log += ')';
log += strformat(F(" (%s)"), P004_data->get_formatted_address(i).c_str());
addLogMove(LOG_LEVEL_INFO, log);
}
}
Expand Down
131 changes: 64 additions & 67 deletions src/_P005_DHT.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "_Plugin_Helper.h"
#ifdef USES_P005
//#######################################################################################################
//######################## Plugin 005: Temperature and Humidity sensor DHT 11/22 ########################
//#######################################################################################################

#include "src/PluginStructs/P005_data_struct.h"
// #######################################################################################################
// ######################## Plugin 005: Temperature and Humidity sensor DHT 11/22 ########################
// #######################################################################################################

#define PLUGIN_005
#define PLUGIN_ID_005 5
#define PLUGIN_NAME_005 "Environment - DHT11/12/22 SONOFF2301/7021/MS01"
#define PLUGIN_VALUENAME1_005 "Temperature"
#define PLUGIN_VALUENAME1_005_MS01 "RAW"
#define PLUGIN_VALUENAME2_005 "Humidity"
# include "src/PluginStructs/P005_data_struct.h"

# define PLUGIN_005
# define PLUGIN_ID_005 5
# define PLUGIN_NAME_005 "Environment - DHT11/12/22 SONOFF2301/7021/MS01"
# define PLUGIN_VALUENAME1_005 "Temperature"
# define PLUGIN_VALUENAME1_005_MS01 "RAW"
# define PLUGIN_VALUENAME2_005 "Humidity"


boolean Plugin_005(uint8_t function, struct EventStruct *event, String& string)
Expand All @@ -22,85 +22,82 @@ boolean Plugin_005(uint8_t function, struct EventStruct *event, String& string)
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_005;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TEMP_HUM;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 2;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].PluginStats = true;
break;
}
{
auto& dev = Device[++deviceCount];
dev.Number = PLUGIN_ID_005;
dev.Type = DEVICE_TYPE_SINGLE;
dev.VType = Sensor_VType::SENSOR_TYPE_TEMP_HUM;
dev.FormulaOption = true;
dev.ValueCount = 2;
dev.SendDataOption = true;
dev.TimerOption = true;
dev.PluginStats = true;
break;
}

case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_005);
break;
}
{
string = F(PLUGIN_NAME_005);
break;
}

case PLUGIN_GET_DEVICEVALUENAMES:
{
if (PCONFIG(0) == P005_MS01) {
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_005_MS01));
} else {
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_005));
}
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_005));
break;
{
if (PCONFIG(0) == P005_MS01) {
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_005_MS01));
} else {
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_005));
}
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_005));
break;
}

case PLUGIN_GET_DEVICEGPIONAMES:
{
event->String1 = formatGpioName_bidirectional(F("Data"));
break;
}
{
event->String1 = formatGpioName_bidirectional(F("Data"));
break;
}

case PLUGIN_WEBFORM_LOAD:
{
const __FlashStringHelper * options[] = { F("DHT 11"), F("DHT 22"), F("DHT 12"), F("Sonoff am2301"), F("Sonoff si7021"), F("Sonoff MS01") };
const int indices[] = { P005_DHT11, P005_DHT22, P005_DHT12, P005_AM2301, P005_SI7021, P005_MS01 };
{
const __FlashStringHelper *options[] = { F("DHT 11"), F("DHT 22"), F("DHT 12"), F("Sonoff am2301"), F("Sonoff si7021"),
F("Sonoff MS01") };
const int indices[] = { P005_DHT11, P005_DHT22, P005_DHT12, P005_AM2301, P005_SI7021, P005_MS01 };

constexpr size_t nrElements = NR_ELEMENTS(indices);
constexpr size_t nrElements = NR_ELEMENTS(indices);

addFormSelector(F("Sensor model"), F("dhttype"), nrElements, options, indices, PCONFIG(0) );
addFormSelector(F("Sensor model"), F("dhttype"), nrElements, options, indices, PCONFIG(0));

success = true;
break;
}
success = true;
break;
}

case PLUGIN_WEBFORM_SAVE:
{
PCONFIG(0) = getFormItemInt(F("dhttype"));
{
PCONFIG(0) = getFormItemInt(F("dhttype"));

success = true;
break;
}
success = true;
break;
}

case PLUGIN_INIT:
{
success = initPluginTaskData(event->TaskIndex, new (std::nothrow) P005_data_struct(event));
break;
}
{
success = initPluginTaskData(event->TaskIndex, new (std::nothrow) P005_data_struct(event));
break;
}

case PLUGIN_READ:
{
P005_data_struct *P005_data =
static_cast<P005_data_struct *>(getPluginTaskData(event->TaskIndex));

if (nullptr != P005_data) {
success = P005_data->readDHT(event);
}
break;
{
P005_data_struct *P005_data =
static_cast<P005_data_struct *>(getPluginTaskData(event->TaskIndex));

if (nullptr != P005_data) {
success = P005_data->readDHT(event);
}
break;
}
}
return success;
}


#endif // USES_P005
21 changes: 9 additions & 12 deletions src/_P006_BMP085.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ boolean Plugin_006(uint8_t function, struct EventStruct *event, String& string)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_006;
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TEMP_BARO;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 2;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].PluginStats = true;
auto& dev = Device[++deviceCount];
dev.Number = PLUGIN_ID_006;
dev.Type = DEVICE_TYPE_I2C;
dev.VType = Sensor_VType::SENSOR_TYPE_TEMP_BARO;
dev.FormulaOption = true;
dev.ValueCount = 2;
dev.SendDataOption = true;
dev.TimerOption = true;
dev.PluginStats = true;
break;
}

Expand Down
Loading

0 comments on commit 80d6d29

Please sign in to comment.