Skip to content

Commit e6ab258

Browse files
authored
Merge pull request #5446 from tonhuisman/feature/P180-enable-extra-device-flags
[P180] Enable CustomVTypeVar and MQTTStateClass device flags
2 parents 2d5181b + b765b25 commit e6ab258

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

docs/source/Plugin/P180.rst

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ This enables the implementation of yet unsupported I2C devices or use I2C device
3030

3131
.. warning:: This plugin is in the 'pro' category of plugins (i.o.w. not really *Easy* to use), and requires in-depth studying of the datasheet for the device, extracting the required commands and calculation(s) for implementing correct usage. (Some examples available below)
3232

33+
Example device configurations
34+
-----------------------------
35+
36+
* :ref:`aht2x-temperature-humidity-sensor`
37+
* :ref:`m5stack-ain4-20ma-unit-module`
38+
* :ref:`bosch-bmp58x-temp-baro`
39+
* :ref:`tiny-code-reader-qr-code-reader`
40+
* :ref:`sensirion-sdp-810-differential-pressure-sensor`
41+
* :ref:`tf-luna-lidar-distance-sensor`
42+
* :ref:`qmc6310-3-axis-magnetic-sensor`
43+
3344
Configuration
3445
-------------
3546

@@ -189,6 +200,8 @@ A few warnings though:
189200
Example I2C command sequences
190201
-----------------------------
191202

203+
.. _aht2x-temperature-humidity-sensor:
204+
192205
AHT2x Temperature / Humidity sensor
193206
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194207

@@ -231,6 +244,8 @@ Command sequence explanation:
231244

232245
|
233246
247+
.. _m5stack-ain4-20ma-unit-module:
248+
234249
M5Stack AIN4-20mA Unit / Module
235250
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236251

@@ -277,6 +292,8 @@ This device supports adjusting the calibration to the current current that is fl
277292

278293
|
279294
295+
.. _bosch-bmp58x-temp-baro:
296+
280297
Bosch BMP58x Temp/Baro
281298
^^^^^^^^^^^^^^^^^^^^^^
282299

@@ -341,6 +358,8 @@ Command sequence explanation:
341358

342359
|
343360
361+
.. _tiny-code-reader-qr-code-reader:
362+
344363
Tiny Code Reader (QR-code reader)
345364
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
346365

@@ -409,6 +428,8 @@ This device needs a Rule to handle the result, as we can't store string values i
409428

410429
|
411430
431+
.. _sensirion-sdp-810-differential-pressure-sensor:
432+
412433
Sensirion SDP-810 Differential pressure sensor
413434
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
414435

@@ -472,12 +493,127 @@ This command sequence is nearly the same as with the Continuous measurement, exc
472493

473494
|
474495
496+
.. _tf-luna-lidar-distance-sensor:
497+
498+
TF-Luna Lidar distance sensor
499+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
500+
501+
The somewhat popular laser-distance sensor, with a range of 0.2 to 8 meter, TF-Luna, can be configured to use I2C as the communication protocol, instead of the default RS232 serial protocol, by connecting pin 5 of the sensor to GND on startup.
502+
503+
The command sequence is based on documentation from this `WaveShare page <https://www.waveshare.com/wiki/TF-Luna_LiDAR_Range_Sensor>`_
504+
505+
.. note:: The checksum available from the sensor measurements is ignored!
506+
507+
When only retrieving the ``distance`` from the sensor
508+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
509+
510+
The plugin should be configured with these settings:
511+
512+
* **I2C Address (Hex)**: ``0x10``
513+
514+
* **Output Data Type**: ``Single``
515+
516+
* **Interval**: can be set to 1 second to retrieve a measurement every second.
517+
518+
* **Values**: the name can be changed to Distance, and the number of decimals 0. Stats can be enabled, as desired. The Unit of Measure should he set to ``cm``, and the Value Type to ``Distance``
519+
520+
* **Cache-Name 1 (optional)**: Fill with a useable name, f.e. ``distance``, so the I2C Command sequence is cached for much improved execution-performance.
521+
522+
* **I2C Commands 1**:
523+
524+
``put.u8.0;delay.5;get.b.7;eval;calc.0x{substring:4:6:%h%}*256+0x{substring:2:4:%h%}``
525+
526+
Command sequence explanation:
527+
528+
* ``put.u8.0`` : Announce data fetch
529+
* ``delay.5`` : Give the sensor a few msec to prepare
530+
* ``get.b.7`` : Read 7 bytes (entire available buffer)
531+
* ``eval`` : Make data available for processing
532+
* ``calc.0x{substring:4:6:%h%}*256+0x{substring:2:4:%h%}`` : Fetch byte 1 (* 256) + byte 0 to calculate distance in cm, value is set to Values 1 field
533+
534+
When retrieving both ``distance`` and ``signal strength`` from the sensor
535+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536+
537+
The plugin should be configured with these settings:
538+
539+
* **I2C Address (Hex)**: ``0x10``
540+
541+
* **Output Data Type**: ``Dual``
542+
543+
* **Interval**: can be set to 1 second to retrieve a measurement every second.
544+
545+
* **Values**: the first name can be changed to ``Distance``, and the number of decimals 0. Stats can be enabled, as desired. The Unit of Measure should he set to ``cm``, and the Value Type to ``Distance``, the second name can be changed to f.e. ``SignalStrength``, and number of decimals to 0. Stats can be enabled, as desired. No further settings for this value, as it has an undefined unit and value type.
546+
547+
* **Cache-Name 1 (optional)**: Fill with a useable name, f.e. ``distance``, so the I2C Command sequence is cached for much improved execution-performance.
548+
549+
* **I2C Commands 1**:
550+
551+
``put.u8.0;delay.5;get.b.7;eval;calc.0x{substring:4:6:%h%}*256+0x{substring:2:4:%h%};value.1;calc.0x{substring:8:10:%h%}*256+0x{substring:6:8:%h%};value.2``
552+
553+
NB: The fields for **Cache-Name 2** and **I2C Commands 2** are left empty, the entire command sequence is combined into the first command sequence, as the complete data set is read and the separate values calculated and assigned in a single command sequence. This makes processing more efficient.
554+
555+
Command sequence explanation:
556+
557+
* ``put.u8.0`` : Announce data fetch
558+
* ``delay.5`` : Give the sensor a few msec to prepare
559+
* ``get.b.7`` : Read 7 bytes (entire available buffer)
560+
* ``eval`` : Make data available for processing
561+
* ``calc.0x{substring:4:6:%h%}*256+0x{substring:2:4:%h%}`` : Fetch byte 1 (* 256) + byte 0 to calculate distance in cm
562+
* ``value.1`` : current value, Distance, set to Values 1 field
563+
* ``calc.0x{substring:8:10:%h%}*256+0x{substring:6:8:%h%}`` : Fetch byte 3 (* 256) + byte 2 to calculate signal strength (unknown unit)
564+
* ``value.2`` : current value, Signal strength, set to Values 2 field
565+
566+
|
567+
568+
.. _qmc6310-3-axis-magnetic-sensor:
569+
570+
QMC6310 3-axis magnetic sensor
571+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
572+
573+
This sensor provides a 3-axis directional signal, as documented in the QST Corp `QMC6310 Datasheet <https://www.qstcorp.com/upload/pdf/202202/%EF%BC%88%E5%B7%B2%E4%BC%A0%EF%BC%8913-52-17%20QMC6310%20Datasheet%20Rev.C(1).pdf>`_ (url includes some Chinese characters).
574+
575+
The plugin should be configured with these settings:
576+
577+
* **I2C Address (Hex)**: ``0x1C``
578+
579+
* **Output Data Type**: ``Triple`` To activate this setting, the page must be submitted to show the extra input fields.
580+
581+
* **Interval**: Can be set in the seconds range to retrieve a measurement often.
582+
583+
* **Values**: The names can be changed to ``x``, ``y`` and ``z``, and the number of decimals to 0. Stats can be enabled, as desired. The Unit of Measure is undocumented.
584+
585+
* **I2C Init Commands** sequence for initializing the sensor:
586+
587+
``write.u8.0x29.0x06;write.u8.0x0B.0x00;write.u8.0x0A.0xCD``: Initialize the sensor according to the datasheet, Normal mode, field range 8 Gauss, output data rate 200 Hz, over-sample ratio 8, down-sample ratio 8.
588+
589+
* **I2C Exit Commands** sequence for shutting down the sensor:
590+
591+
``write.u8.0x0A.0x00``: Set sensor in Suspend mode.
592+
593+
* **Cache-Name 1 (optional)**: Fill with a useable name, f.e. ``x``, so the I2C Command sequence is cached for much improved execution-performance.
594+
595+
* **I2C Commands 1**: ``read.16le.0x01`` Read 2 bytes starting at register 1, the ``x`` value, and store in first Value field.
596+
597+
* **Cache-Name 2 (optional)**: Fill with a useable name, f.e. ``y``.
598+
599+
* **I2C Commands 2**: ``read.16le.0x03`` Read 2 bytes starting at register 3, the ``y`` value, and store in second Value field.
600+
601+
* **Cache-Name 3 (optional)**: Fill with a useable name, f.e. ``z``.
602+
603+
* **I2C Commands 3**: ``read.16le.0x05`` Read 2 bytes starting at register 5, the ``z`` value, and store in third Value field.
604+
605+
To reduce the logging content, **Single event with all values** can be enabled, to generate a single event ``<task-name>#All`` with all values as argument, and thus reduce the logging from 3 lines per Interval to a single line per Interval.
606+
607+
|
608+
475609
Change log
476610
----------
477611

478612
.. versionchanged:: 2.0
479613
...
480614

615+
|added| 2025-12-08 Add index to example configurations.
616+
481617
|added|
482618
2025-04-19 Initial release version.
483619

src/_P180_I2C_generic.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// #######################################################################################################
77

88
/** Changelog:
9+
* 2025-12-06 tonhuisman: Enable CustomVTypeVar and MQTTStateClass device options, as any type of sensor can be connected
910
* 2025-06-04 tonhuisman: Add [<taskname>#log] to Get Config to fetch the current Parsing and execution log setting
1011
* 2025-06-03 tonhuisman: Restore PLUGIN_GET_CONFIG_VALUE support, to allow I2C operations to be executed and return a value without
1112
* defining extra I2C Command definitions. Not available for LIMIT_BUILD_SIZE builds
@@ -135,6 +136,8 @@ boolean Plugin_180(uint8_t function, struct EventStruct *event, String& string)
135136
dev.TimerOptional = true;
136137
dev.FormulaOption = true;
137138
dev.PluginStats = true;
139+
dev.CustomVTypeVar = true;
140+
dev.MqttStateClass = true;
138141
break;
139142
}
140143

src/src/PluginStructs/P180_data_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool P180_data_struct::plugin_write(struct EventStruct *event,
152152
} else if (equals(sub, F("exec")) && hasPar3 && hasBusCmd) { // genI2c,exec,<cache_name>[,<TaskValueIndex>]
153153
cmds = busCmd_Helper->parseBusCmdCommands(par3, EMPTY_STRING); // Fetch commands from cache by name
154154
} else if (equals(sub, F("log")) && hasPar3) { // genI2c,log,<1|0>
155-
_showLog = event->Par3 != 0;
155+
_showLog = event->Par2 != 0;
156156
P180_LOG_DEBUG = _showLog ? 1 : 0;
157157

158158
if (hasBusCmd) {

0 commit comments

Comments
 (0)