mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-10-26 22:10:45 +00:00
Merge pull request #5629 from tonhuisman/bugfix/I2Cscan-pconfig-errors
[I2CScan] Avoid using PCONFIG() during I2CScan
This commit is contained in:
10 files changed
+42
-27
No files matched your search
@@ -30,7 +30,7 @@ boolean Plugin_022(uint8_t function, struct EventStruct *event, String& string)
|
||||
uint16_t freq = PCA9685_MAX_FREQUENCY;
|
||||
uint16_t range = PCA9685_MAX_PWM;
|
||||
|
||||
if ((event != nullptr) && (event->TaskIndex >= 0))
|
||||
if ((event != nullptr) && validTaskIndex(event->TaskIndex))
|
||||
{
|
||||
address = CONFIG_PORT;
|
||||
mode2 = PCONFIG(0);
|
||||
|
||||
+5
-2
@@ -7,6 +7,7 @@
|
||||
// #######################################################################################################
|
||||
|
||||
/** Changelog:
|
||||
* 2026-09-01 tonhuisman: Function PLUGIN_I2C_HAS_ADDRESS doesn't have a valid TaskIndex when called, so don't pass PCONFIG() value
|
||||
* 2024-08-17 tonhuisman: Disable preview of on-display content for LIMIT_BUILD_SIZE builds.
|
||||
* 2023-10-16 tonhuisman: Bugfix: Template parsing stopped after initial display since previous updates :-(
|
||||
* 2023-03-18 tonhuisman: Show current on-display content on Devices page (75% size, omits trailing empty lines)
|
||||
@@ -64,7 +65,7 @@ boolean Plugin_023(uint8_t function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_I2C_HAS_ADDRESS:
|
||||
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
|
||||
{
|
||||
success = OLedI2CAddressCheck(function, event->Par1, F("i2c_addr"), PCONFIG(0));
|
||||
success = OLedI2CAddressCheck(function, event->Par1, F("i2c_addr"), PLUGIN_I2C_HAS_ADDRESS == function ? -1 : PCONFIG(0));
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -162,7 +163,8 @@ boolean Plugin_023(uint8_t function, struct EventStruct *event, String& string)
|
||||
P023_data_struct::Spacing font_spacing = P023_data_struct::Spacing::normal;
|
||||
|
||||
|
||||
switch (PCONFIG(3)) {
|
||||
switch (PCONFIG(3))
|
||||
{
|
||||
case 1:
|
||||
// 128x64
|
||||
type = P023_data_struct::OLED_128x64;
|
||||
@@ -184,6 +186,7 @@ boolean Plugin_023(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
void *ptr = special_calloc(1, sizeof(P023_data_struct));
|
||||
|
||||
if (ptr) {
|
||||
initPluginTaskData(event->TaskIndex, new (ptr) P023_data_struct(PCONFIG(0), type, font_spacing, PCONFIG(2), PCONFIG(5)));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// #######################################################################################################
|
||||
|
||||
/** Changelog:
|
||||
* 2026-09-02 tonhuisman: Disable function PLUGIN_I2C_HAS_ADDRESS as it uses the wrong value, and it can be configured for many addresses
|
||||
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
|
||||
* 2024-08-17 tonhuisman: Show correct I2C address when non-default address is used (by setting a Port nr. 0..15)
|
||||
* 2023-11-23 tonhuisman: Add Device flag for I2CMax100kHz as this sensor won't work at 400 kHz
|
||||
@@ -64,11 +65,11 @@ boolean Plugin_024(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
# endif // if FEATURE_MQTT_DISCOVER
|
||||
|
||||
case PLUGIN_I2C_HAS_ADDRESS:
|
||||
{
|
||||
success = event->Par1 == (0x5a + CONFIG_PORT);
|
||||
break;
|
||||
}
|
||||
// case PLUGIN_I2C_HAS_ADDRESS:
|
||||
// {
|
||||
// success = event->Par1 == (0x5a + CONFIG_PORT);
|
||||
// break;
|
||||
// }
|
||||
|
||||
# if FEATURE_I2C_GET_ADDRESS
|
||||
case PLUGIN_I2C_GET_ADDRESS:
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// Added to the main repository with some optimizations and some limitations.
|
||||
// As long as the device is not enabled, no RAM is wasted.
|
||||
//
|
||||
// @tonhuisman: 2026-09-01
|
||||
// CHG: Function PLUGIN_I2C_HAS_ADDRESS doesn't have a valid TaskIndex when called, so don't pass PCONFIG() value
|
||||
// @andbad: 2026-07-09
|
||||
// ADD: 72x40 OLED size added to the the existing sizes (128x64, 128x32, 64x48)
|
||||
// @tonhuisman: 2025-03-03
|
||||
@@ -269,7 +271,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_I2C_HAS_ADDRESS:
|
||||
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
|
||||
{
|
||||
success = OLedI2CAddressCheck(function, event->Par1, F("i2c_addr"), P036_ADR);
|
||||
success = OLedI2CAddressCheck(function, event->Par1, F("i2c_addr"), PLUGIN_I2C_HAS_ADDRESS == function ? -1 : P036_ADR);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -758,6 +760,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
|
||||
# else
|
||||
const uint8_t i2cBus = 0;
|
||||
# endif // if FEATURE_I2C_MULTIPLE
|
||||
|
||||
if (!(P036_data->init(event->TaskIndex,
|
||||
get4BitFromUL(P036_FLAGS_0, P036_FLAG_SETTINGS_VERSION), // Bit23-20 Version CustomTaskSettings
|
||||
P036_CONTROLLER, // Type
|
||||
@@ -1100,6 +1103,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
# ifdef P036_CHECK_HEAP
|
||||
|
||||
void P036_CheckHeap(String dbgtxt) {
|
||||
addLog(LOG_LEVEL_INFO,
|
||||
strformat(F("%s FreeHeap:%d FreeStack:%d"),
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
//
|
||||
|
||||
/** Changelog:
|
||||
* 2026-09-01 tonhuisman: Disable function PLUGIN_I2C_HAS_ADDRESS as it uses the wrong value, and it can be configured for any address
|
||||
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
|
||||
* 2024-05-09 tonhuisman: Add support for BeFlE v3.x (low power) Moisture sensor
|
||||
* Code improvements
|
||||
@@ -38,7 +39,6 @@
|
||||
|
||||
# include "src/PluginStructs/P047_data_struct.h"
|
||||
|
||||
|
||||
boolean Plugin_047(uint8_t function, struct EventStruct *event, String& string)
|
||||
{
|
||||
boolean success = false;
|
||||
@@ -127,11 +127,11 @@ boolean Plugin_047(uint8_t function, struct EventStruct *event, String& string)
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_I2C_HAS_ADDRESS:
|
||||
{
|
||||
success = event->Par1 == P047_I2C_ADDR; // Show for currently configured address
|
||||
break;
|
||||
}
|
||||
// case PLUGIN_I2C_HAS_ADDRESS:
|
||||
// {
|
||||
// success = event->Par1 == P047_I2C_ADDR; // Show for currently configured address
|
||||
// break;
|
||||
// }
|
||||
|
||||
# if FEATURE_I2C_GET_ADDRESS
|
||||
case PLUGIN_I2C_GET_ADDRESS:
|
||||
@@ -170,7 +170,6 @@ boolean Plugin_047(uint8_t function, struct EventStruct *event, String& string)
|
||||
selector.default_index = static_cast<int>(P047_MODEL_CATNIP);
|
||||
selector.reloadonchange = true;
|
||||
selector.addFormSelector(F("Sensor model"), F("model"), P047_MODEL);
|
||||
// addFormNote(F("Changing the Sensor model will reload the page."));
|
||||
}
|
||||
|
||||
if ((P047_MODEL_CATNIP == static_cast<P047_SensorModels>(P047_MODEL))
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
------------------------------------------------------------------------------------------
|
||||
Copyleft Nagy Sándor 2018 - https://bitekmindenhol.blog.hu/
|
||||
------------------------------------------------------------------------------------------
|
||||
2026-09-01 tonhuisman: Function PLUGIN_I2C_HAS_ADDRESS doesn't have a valid TaskIndex when called, so don't pass PCONFIG() value
|
||||
2025-06-14 tonhuisman: Add support for Custom Value Type per task value
|
||||
2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported ThermOLED)
|
||||
2022-12-08 tonhuisman: Add Relay invert state option, reorder config option Contrast
|
||||
@@ -78,7 +79,6 @@
|
||||
# define PLUGIN_VALUENAME3_109 "mode"
|
||||
# define PLUGIN_VALUENAME4_109 "timeout"
|
||||
|
||||
|
||||
boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
|
||||
{
|
||||
boolean success = false;
|
||||
@@ -139,7 +139,7 @@ boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_I2C_HAS_ADDRESS:
|
||||
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
|
||||
{
|
||||
success = OLedI2CAddressCheck(function, event->Par1, F("pi2caddr"), P109_CONFIG_I2CADDRESS);
|
||||
success = OLedI2CAddressCheck(function, event->Par1, F("pi2caddr"), PLUGIN_I2C_HAS_ADDRESS == function ? -1 : P109_CONFIG_I2CADDRESS);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ boolean Plugin_178(uint8_t function, struct EventStruct *event, String& string)
|
||||
int address = LU9685_ADDRESS;
|
||||
uint16_t freq = LU9685_DEFAULT_FREQUENCY;
|
||||
|
||||
if (event != nullptr) {
|
||||
if ((event != nullptr) && validTaskIndex(event->TaskIndex)) {
|
||||
address = P178_I2C_ADDR;
|
||||
freq = P178_FREQ;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ void OLedFormController(const __FlashStringHelper *id,
|
||||
NR_ELEMENTS(controllerOptions),
|
||||
controllerOptions,
|
||||
values == nullptr ? controllerValues : values);
|
||||
|
||||
selector.addFormSelector(F("Controller"), id, selectedIndex);
|
||||
}
|
||||
|
||||
@@ -34,6 +35,7 @@ void OLedFormRotation(const __FlashStringHelper *id,
|
||||
const FormSelectorOptions selector(
|
||||
NR_ELEMENTS(rotationOptions),
|
||||
rotationOptions, rotationValues);
|
||||
|
||||
selector.addFormSelector(F("Rotation"), id, selectedIndex);
|
||||
}
|
||||
|
||||
@@ -74,6 +76,7 @@ void OLedFormSizes(const __FlashStringHelper *id,
|
||||
F("64x48"),
|
||||
F("72x40") };
|
||||
FormSelectorOptions selector(optionsSize, options3, values);
|
||||
|
||||
selector.reloadonchange = reloadOnChange;
|
||||
selector.addFormSelector(
|
||||
F("Display Size"),
|
||||
@@ -93,15 +96,19 @@ void OLedSetContrast(OLEDDisplay *_display,
|
||||
char precharge = 241;
|
||||
char comdetect = 64;
|
||||
|
||||
switch (OLED_contrast) {
|
||||
switch (OLED_contrast)
|
||||
{
|
||||
case OLED_CONTRAST_OFF:
|
||||
_display->displayOff();
|
||||
return; // Done
|
||||
case OLED_CONTRAST_LOW:
|
||||
contrast = 10; precharge = 5; comdetect = 0;
|
||||
contrast = 10;
|
||||
precharge = 5;
|
||||
comdetect = 0;
|
||||
break;
|
||||
case OLED_CONTRAST_MED:
|
||||
contrast = OLED_CONTRAST_MED; precharge = 0x1F;
|
||||
contrast = OLED_CONTRAST_MED;
|
||||
precharge = 0x1F;
|
||||
break;
|
||||
case OLED_CONTRAST_HIGH:
|
||||
default:
|
||||
@@ -119,7 +126,7 @@ void OLedSetContrast(OLEDDisplay *_display,
|
||||
bool OLedI2CAddressCheck(uint8_t function,
|
||||
int checkI2cAddress,
|
||||
const __FlashStringHelper *id,
|
||||
int8_t deviceAddress) {
|
||||
int16_t deviceAddress) {
|
||||
bool success = false;
|
||||
const uint8_t i2cAddressValues[] = { 0x3c, 0x3d };
|
||||
|
||||
@@ -130,4 +137,5 @@ bool OLedI2CAddressCheck(uint8_t function,
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // if defined(USES_P023) || defined(USES_P036) || defined(USES_P109)
|
||||
@@ -38,7 +38,7 @@ void OLedSetContrast(OLEDDisplay *_display,
|
||||
bool OLedI2CAddressCheck(uint8_t function,
|
||||
int checkI2cAddress,
|
||||
const __FlashStringHelper *id,
|
||||
int8_t deviceAddress);
|
||||
int16_t deviceAddress);
|
||||
|
||||
#endif
|
||||
#endif // if defined(USES_P023) || defined(USES_P036) || defined(USES_P109)
|
||||
#endif // ifndef HELPERS_OLED_HELPER_H
|
||||
@@ -172,7 +172,7 @@ String getKnownI2Cdevice(uint8_t address) {
|
||||
String result;
|
||||
|
||||
#if FEATURE_I2C_DEVICE_SCAN
|
||||
deviceIndex_t x;
|
||||
deviceIndex_t x{};
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
const deviceIndex_t deviceIndex = getDeviceIndex_sorted(x);
|
||||
|
||||
Reference in new issue
Block a user