TLA2528 - #5618
Conversation
There was a problem hiding this comment.
Please do not commit this file, it is included in .gitignore, but unfortunately not really ignored 😒
| |added| | ||
| Initial release version. |
There was a problem hiding this comment.
A date is missing here?
| #define P188_CAL_RAW2_P1 PCONFIG_LONG(4) | ||
| #define P188_CAL_RAW2_P2 PCONFIG_LONG(5) | ||
| #define P188_CAL_RAW3_P1 PCONFIG_LONG(6) | ||
| #define P188_CAL_RAW3_P2 PCONFIG_LONG(7) |
There was a problem hiding this comment.
There are only 4 PCONFIG_LONG available. This will overwrite the values for the next task (or be overwritten if the next task is saved). And it can't be extended as that will render all existing settings files incompatible.
| #define P188_CAL_OUT2_P1 PCONFIG_FLOAT(4) | ||
| #define P188_CAL_OUT2_P2 PCONFIG_FLOAT(5) | ||
| #define P188_CAL_OUT3_P1 PCONFIG_FLOAT(6) | ||
| #define P188_CAL_OUT3_P2 PCONFIG_FLOAT(7) |
There was a problem hiding this comment.
Ditto for PCONFIG_FLOAT.
| dev.Ports = 0; // Port to use when device has multiple I/O pins (N.B. not used much) | ||
| dev.ValueCount = 4; // The number of output values of a plugin. The value should match the number of keys PLUGIN_VALUENAME1_xxx | ||
| dev.OutputDataType = Output_Data_type_t::Simple; // Subset of selectable output data types (Default = no selection) | ||
| dev.PullUpOption = false; // Allow to set internal pull-up resistors. | ||
| dev.InverseLogicOption = false; // Allow to invert the boolean state (e.g. a switch) | ||
| dev.FormulaOption = true; // Allow to enter a formula to convert values during read. (not possible with Custom enabled) | ||
| dev.Custom = false; | ||
| dev.SendDataOption = true; // Allow to send data to a controller. | ||
| dev.GlobalSyncOption = false; // No longer used. Was used for ESPeasy values sync between nodes | ||
| dev.TimerOption = true; // Allow to set the "Interval" timer for the plugin. | ||
| dev.TimerOptional = false; // When taskdevice timer is not set and not optional, use default "Interval" delay (Settings.Delay) | ||
| dev.DecimalsOnly = false; // Allow to set the number of decimals (otherwise treated a 0 decimals) | ||
| dev.CustomVTypeVar = true; // Enable to allow the user to configure the Sensor_VType per Value that's available for the plugin | ||
| dev.PluginStats = true; // Support for PluginStats to record last N task values, show charts etc. | ||
| dev.MqttStateClass = true; |
There was a problem hiding this comment.
Please leave out any = 0 and = false assignment, as that's already taken care of in the constructor of the Device structure.
| #ifdef P188_FEATURE_RESISTOR_MEASUREMENT | ||
| tmp_config.R_Clip = 0.0f; | ||
| #endif |
There was a problem hiding this comment.
This can be solved by an initializer in the struct.
| #ifdef P188_FEATURE_RESISTOR_MEASUREMENT | ||
| uint32_t Rref[VARS_PER_TASK]; | ||
| uint32_t Rpar[VARS_PER_TASK]; | ||
| #endif // P188_FEATURE_RESISTOR_MEASUREMENT |
There was a problem hiding this comment.
These variables can be reset initially by using the {} initializer on them, like float R_Clip{};
|
changed code and documentation - please review. |
| if ((P188_OUTPUT_MAPPING_0 > 11) || (P188_OUTPUT_MAPPING_1 > 11) || (P188_OUTPUT_MAPPING_2 > 11) || (P188_OUTPUT_MAPPING_3 > 11)) | ||
| { |
There was a problem hiding this comment.
That magic number 11 should better be a #define or some enum value (also in the other places where it's used), this is very error-prone, and hard to comprehend.
| addFormCheckBox(F("Enable Calibration"), getPluginCustomArgName(i * 8 + 3), ((P188_configBits.en_cal >> i) & 0x01)); | ||
|
|
||
| addFormNumericBox(F("Point 1"), getPluginCustomArgName(i * 8 + 4), PCONFIG_LONG(P188_CAL_INDEX + 2*i), -32768, 32767); | ||
| addFormFloatNumberBox(F("Point 1"), getPluginCustomArgName(i * 8 + 4), tmp_config.CalIn[i][0], -1000000, 1000000, 2, 1.0f); |
There was a problem hiding this comment.
The min and max arguments are also floats, that like the .0f suffix.
| const uint8_t pconfigIndex = P188_OUTPUT_MAPPING_OFFSET + i; | ||
| const uint8_t choice = PCONFIG(pconfigIndex); | ||
| sensorTypeHelper_saveOutputSelector(event, pconfigIndex, i, Plugin_188_output_mapping_name(choice, false)); | ||
| if ((P188_OUTPUT_MAPPING_0 > 11) || (P188_OUTPUT_MAPPING_1 > 11) || (P188_OUTPUT_MAPPING_2 > 11) || (P188_OUTPUT_MAPPING_3 > 11)) |
| #ifdef P188_FEATURE_RESISTOR_MEASUREMENT | ||
| addFormNumericBox(F("Reference Resistor Value"), getPluginCustomArgName(i * 8 + 0), tmp_config.Rref[i], 100, 470000); | ||
| addFormNumericBox(F("Parallel Resistor Value"), getPluginCustomArgName(i * 8 + 1), tmp_config.Rpar[i], 0, 470000); | ||
| if (PCONFIG(i + P188_OUTPUT_MAPPING_OFFSET) > 11) |
There was a problem hiding this comment.
This also needs another check to make sure the index for PCONFIG(...) is within range.
I will make a separate PR for adding checks for these macros for builds without BUILD_NO_DEBUG enabled, so we can have a runtime check on nodes with a bit more headroom to do some runtime checks to see if there are clear programming errors.
| #ifdef P188_FEATURE_RESISTOR_MEASUREMENT | ||
| tmp_config.Rref[i] = getFormItemInt(getPluginCustomArgName(i * 8 + 0)); | ||
| tmp_config.Rpar[i] = getFormItemInt(getPluginCustomArgName(i * 8 + 1)); | ||
| if (PCONFIG(i + P188_OUTPUT_MAPPING_OFFSET) > 11) |
| @@ -312,10 +326,10 @@ boolean Plugin_188(uint8_t function, struct EventStruct *event, String& string) | |||
| { | |||
| if ((P188_configBits.en_cal >> i) & 0x01) | |||
There was a problem hiding this comment.
Yes this works, but using bitRead() and a properly named bit-index will have more meaning in 6 months...
| @@ -381,10 +395,10 @@ boolean Plugin_188(uint8_t function, struct EventStruct *event, String& string) | |||
|
|
|||
| if ((P188_configBits.en_cal >> i) & 0x01) | |||
| const float out1 = P188_data->P188_config.CalOut[i][0]; | ||
| const float out2 = P188_data->P188_config.CalOut[i][1]; | ||
|
|
||
| if (adc1 != adc2) |
There was a problem hiding this comment.
Now that adc1 and adc2 are float, using !essentiallyEqual() takes care of the inaccuracy of the float type.
| const float out1 = P188_data->P188_config.CalOut[i][0]; | ||
| const float out2 = P188_data->P188_config.CalOut[i][1]; | ||
|
|
||
| if (adc1 != adc2) |
|
You haven't included the plugin in the |
Here is the pull request for the TLA2528 Plugin...
Thanks