From f6349bb4e1c2ac81f986dd60441464554f1cb56c Mon Sep 17 00:00:00 2001 From: malarz Date: Wed, 26 Feb 2025 22:45:46 +0100 Subject: [PATCH 1/7] Create i2cscanner.h DeviceInfo I2C scanner --- src/supla/network/html/i2cscanner.h | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/supla/network/html/i2cscanner.h diff --git a/src/supla/network/html/i2cscanner.h b/src/supla/network/html/i2cscanner.h new file mode 100644 index 00000000..3242ceca --- /dev/null +++ b/src/supla/network/html/i2cscanner.h @@ -0,0 +1,51 @@ +/* + Copyright (C) malarz + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License898 + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef SRC_SUPLA_HTML_I2CSCANNER_H_ +#define SRC_SUPLA_HTML_I2CSCANNER_H_ + +namespace Supla { +namespace Html { + +class I2Cscanner : public Supla::HtmlElement { + public: + I2Cscanner() : HtmlElement(HTML_SECTION_DEVICE_INFO) {} + + void send(Supla::WebSender* sender) { + sender->send(""); + sender->send("
I2C: "); + for(byte address = 1; address < 127; address++ ) { + Wire.beginTransmission(address); + byte error = Wire.endTransmission(); + char buffer[2]; + if (error == 0) { + sender->send("0x"); + sprintf(buffer, "%2x", address); + sender->send(buffer, 2); + sender->send(" "); + } + } + sender->send("
"); + } + +}; // I2Cscanner + +}; // namespace Html +}; // namespace Supla + +#endif From 7ed2e0ca764a6b022fabe0e46b24025d2e06bc59 Mon Sep 17 00:00:00 2001 From: malarz Date: Wed, 26 Feb 2025 23:05:32 +0100 Subject: [PATCH 2/7] Update i2cscanner.h added include library --- src/supla/network/html/i2cscanner.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/supla/network/html/i2cscanner.h b/src/supla/network/html/i2cscanner.h index 3242ceca..f29e38f7 100644 --- a/src/supla/network/html/i2cscanner.h +++ b/src/supla/network/html/i2cscanner.h @@ -19,6 +19,8 @@ #ifndef SRC_SUPLA_HTML_I2CSCANNER_H_ #define SRC_SUPLA_HTML_I2CSCANNER_H_ +#include + namespace Supla { namespace Html { From e21be20d1affdd5884aeb85376c27a59ad8d2563 Mon Sep 17 00:00:00 2001 From: malarz Date: Wed, 26 Feb 2025 23:32:30 +0100 Subject: [PATCH 3/7] Update i2cscanner.h --- src/supla/network/html/i2cscanner.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/supla/network/html/i2cscanner.h b/src/supla/network/html/i2cscanner.h index f29e38f7..227549fd 100644 --- a/src/supla/network/html/i2cscanner.h +++ b/src/supla/network/html/i2cscanner.h @@ -11,7 +11,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License898 + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -24,30 +24,35 @@ namespace Supla { namespace Html { +/** + * class displaying all detected in device I2C addresses + * on Webinterface in DeviceInfo + * + * shuld be used after Wire.begin(...) + */ class I2Cscanner : public Supla::HtmlElement { public: I2Cscanner() : HtmlElement(HTML_SECTION_DEVICE_INFO) {} void send(Supla::WebSender* sender) { sender->send(""); - sender->send("
I2C: "); - for(byte address = 1; address < 127; address++ ) { + sender->send("
I2C:"); + for (uint8_t address = 1; address < 127; address++) { Wire.beginTransmission(address); byte error = Wire.endTransmission(); char buffer[2]; if (error == 0) { - sender->send("0x"); - sprintf(buffer, "%2x", address); + sender->send(" 0x"); + snprintf(buffer, 2, "%2x", address); sender->send(buffer, 2); - sender->send(" "); } } sender->send("
"); } -}; // I2Cscanner +}; // I2Cscanner -}; // namespace Html -}; // namespace Supla +}; // namespace Html +}; // namespace Supla -#endif +#endif // SRC_SUPLA_NETWORK_HTML_I2CSCANNER_H_ From 364f7609cd18e690e95dcbe21cc96e9263418f7b Mon Sep 17 00:00:00 2001 From: malarz Date: Wed, 26 Feb 2025 23:49:13 +0100 Subject: [PATCH 4/7] Update i2cscanner.h --- src/supla/network/html/i2cscanner.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/supla/network/html/i2cscanner.h b/src/supla/network/html/i2cscanner.h index 227549fd..82cc1b86 100644 --- a/src/supla/network/html/i2cscanner.h +++ b/src/supla/network/html/i2cscanner.h @@ -43,7 +43,7 @@ class I2Cscanner : public Supla::HtmlElement { char buffer[2]; if (error == 0) { sender->send(" 0x"); - snprintf(buffer, 2, "%2x", address); + snprintf(buffer, sizeof(buffer), "%2x", address); sender->send(buffer, 2); } } @@ -55,4 +55,4 @@ class I2Cscanner : public Supla::HtmlElement { }; // namespace Html }; // namespace Supla -#endif // SRC_SUPLA_NETWORK_HTML_I2CSCANNER_H_ +#endif // SRC_SUPLA_NETWORK_HTML_I2CSCANNER_H_ From 5bef29ee06560dae44848a6febb3a96e35b15393 Mon Sep 17 00:00:00 2001 From: malarz Date: Wed, 26 Feb 2025 23:50:37 +0100 Subject: [PATCH 5/7] Update i2cscanner.h From c7c65906d462c3fb91888b01cb1bdb8287a8e5a0 Mon Sep 17 00:00:00 2001 From: malarz Date: Thu, 27 Feb 2025 00:08:13 +0100 Subject: [PATCH 6/7] Update i2cscanner.h --- src/supla/network/html/i2cscanner.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/supla/network/html/i2cscanner.h b/src/supla/network/html/i2cscanner.h index 82cc1b86..61db8e76 100644 --- a/src/supla/network/html/i2cscanner.h +++ b/src/supla/network/html/i2cscanner.h @@ -49,7 +49,6 @@ class I2Cscanner : public Supla::HtmlElement { } sender->send(""); } - }; // I2Cscanner }; // namespace Html From 74d0c12ba3e507e7dff6022288171f7c8d37ac75 Mon Sep 17 00:00:00 2001 From: malarz Date: Thu, 27 Feb 2025 06:46:19 +0100 Subject: [PATCH 7/7] Update i2cscanner.h --- src/supla/network/html/i2cscanner.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/supla/network/html/i2cscanner.h b/src/supla/network/html/i2cscanner.h index 61db8e76..df8a44d8 100644 --- a/src/supla/network/html/i2cscanner.h +++ b/src/supla/network/html/i2cscanner.h @@ -16,8 +16,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef SRC_SUPLA_HTML_I2CSCANNER_H_ -#define SRC_SUPLA_HTML_I2CSCANNER_H_ +#ifndef SRC_SUPLA_NETWORK_HTML_I2CSCANNER_H_ +#define SRC_SUPLA_NETWORK_HTML_I2CSCANNER_H_ #include