Version 1.0.0
Initial version.
This commit is contained in:
commit
b716b1e416
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.DS_Store
|
1
CMakeLists.txt
Normal file
1
CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
idf_component_register(SRCS "zh_config.c" INCLUDE_DIRS "include")
|
73
LICENSE
Normal file
73
LICENSE
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
18
README.md
Normal file
18
README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# ESP32 ESP-IDF and ESP8266 RTOS SDK component for all my projects
|
||||||
|
|
||||||
|
## Using
|
||||||
|
|
||||||
|
In an existing project, run the following command to install the component:
|
||||||
|
|
||||||
|
```text
|
||||||
|
cd ../your_project/components
|
||||||
|
git clone https://github.com/aZholtikov/zh_config.git
|
||||||
|
```
|
||||||
|
|
||||||
|
In the application, add the component:
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include "zh_config.h"
|
||||||
|
```
|
||||||
|
|
||||||
|
Any [feedback](mailto:github@azholtikov.ru) will be gladly accepted.
|
0
component.mk
Normal file
0
component.mk
Normal file
535
include/zh_config.h
Normal file
535
include/zh_config.h
Normal file
@ -0,0 +1,535 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
#define ZH_HIGH true
|
||||||
|
#define ZH_LOW false
|
||||||
|
|
||||||
|
#define ZH_ON true
|
||||||
|
#define ZH_OFF false
|
||||||
|
|
||||||
|
#define ZH_ONLINE true
|
||||||
|
#define ZH_OFFLINE false
|
||||||
|
|
||||||
|
#define ZH_NOT_USED 0xFF
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define ZH_DEVICE_TYPE \
|
||||||
|
DF(ZHDT_NONE, "") \
|
||||||
|
DF(ZHDT_GATEWAY, "gateway") \
|
||||||
|
DF(ZHDT_SWITCH, "espnow_switch") \
|
||||||
|
DF(ZHDT_LED, "espnow_led") \
|
||||||
|
DF(ZHDT_SENSOR, "espnow_sensor") \
|
||||||
|
DF(ZHDT_RF_GATEWAY, "espnow_rf_gateway") \
|
||||||
|
DF(ZHDT_CONTROL_PANEL, "espnow_control_panel") \
|
||||||
|
DF(ZHDT_DIMMER, "espnow_dimmer") \
|
||||||
|
DF(ZHDT_TERRARIUM, "espnow_terrarium") \
|
||||||
|
DF(ZHDT_RF_SENSOR, "rf_sensor") \
|
||||||
|
DF(ZHDT_BINARY_SENSOR, "espnow_sensor") \
|
||||||
|
DF(ZHDT_MAX, "")
|
||||||
|
|
||||||
|
typedef enum zh_device_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
ZH_DEVICE_TYPE
|
||||||
|
#undef DF
|
||||||
|
} zh_device_type_t;
|
||||||
|
|
||||||
|
char *zh_get_device_type_value_name(zh_device_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define ZH_PAYLOAD_TYPE \
|
||||||
|
DF(ZHPT_NONE, "") \
|
||||||
|
DF(ZHPT_ATTRIBUTES, "attributes") \
|
||||||
|
DF(ZHPT_KEEP_ALIVE, "status") \
|
||||||
|
DF(ZHPT_SET, "set") \
|
||||||
|
DF(ZHPT_STATE, "state") \
|
||||||
|
DF(ZHPT_UPDATE, "update") \
|
||||||
|
DF(ZHPT_RESTART, "restart") \
|
||||||
|
DF(ZHPT_SYSTEM, "system") \
|
||||||
|
DF(ZHPT_CONFIG, "config") \
|
||||||
|
DF(ZHPT_FORWARD, "forward") \
|
||||||
|
DF(ZHPT_UPDATE_BEGIN, "") \
|
||||||
|
DF(ZHPT_UPDATE_PROGRESS, "") \
|
||||||
|
DF(ZHPT_UPDATE_END, "") \
|
||||||
|
DF(ZHPT_UPDATE_ERROR, "") \
|
||||||
|
DF(ZHPT_UPDATE_FAIL, "") \
|
||||||
|
DF(ZHPT_UPDATE_SUCCESS, "") \
|
||||||
|
DF(ZHPT_BRIGHTNESS, "brightness") \
|
||||||
|
DF(ZHPT_TEMPERATURE, "temperature") \
|
||||||
|
DF(ZHPT_RGB, "rgb") \
|
||||||
|
DF(ZHPT_EFFECT, "effect") \
|
||||||
|
DF(ZHPT_HARDWARE, "hardware") \
|
||||||
|
DF(ZHPT_MAX, "")
|
||||||
|
|
||||||
|
typedef enum zh_payload_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
ZH_PAYLOAD_TYPE
|
||||||
|
#undef DF
|
||||||
|
} zh_payload_type_t;
|
||||||
|
|
||||||
|
char *zh_get_payload_type_value_name(zh_payload_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_COMPONENT_TYPE \
|
||||||
|
DF(HACT_NONE, "") \
|
||||||
|
DF(HACT_ALARM_CONTROL_PANEL, "alarm_control_panel") \
|
||||||
|
DF(HACT_BINARY_SENSOR, "binary_sensor") \
|
||||||
|
DF(HACT_BUTTON, "button") \
|
||||||
|
DF(HACT_CAMERA, "camera") \
|
||||||
|
DF(HACT_COVER, "cover") \
|
||||||
|
DF(HACT_DEVICE_TRACKER, "device_tracker") \
|
||||||
|
DF(HACT_FAN, "fan") \
|
||||||
|
DF(HACT_HUMIDIFIER, "humidifier") \
|
||||||
|
DF(HACT_CLIMATE_HVAC, "climate") \
|
||||||
|
DF(HACT_LIGHT, "light") \
|
||||||
|
DF(HACT_LOCK, "lock") \
|
||||||
|
DF(HACT_NUMBER, "number") \
|
||||||
|
DF(HACT_SCENE, "scene") \
|
||||||
|
DF(HACT_SELECT, "select") \
|
||||||
|
DF(HACT_SENSOR, "sensor") \
|
||||||
|
DF(HACT_SIREN, "siren") \
|
||||||
|
DF(HACT_SWITCH, "switch") \
|
||||||
|
DF(HACT_UPDATE, "update") \
|
||||||
|
DF(HACT_TEXT, "text") \
|
||||||
|
DF(HACT_VACUUM, "vacuum") \
|
||||||
|
DF(HACT_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_component_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_COMPONENT_TYPE
|
||||||
|
#undef DF
|
||||||
|
} ha_component_type_t;
|
||||||
|
|
||||||
|
char *zh_get_component_type_value_name(ha_component_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_BINARY_SENSOR_DEVICE_CLASS \
|
||||||
|
DF(HABSDC_NONE, "") \
|
||||||
|
DF(HABSDC_BATTERY, "battery") \
|
||||||
|
DF(HABSDC_BATTERY_CHARGING, "battery_charging") \
|
||||||
|
DF(HABSDC_CARBON_MONOXIDE, "carbon_monoxide") \
|
||||||
|
DF(HABSDC_COLD, "cold") \
|
||||||
|
DF(HABSDC_CONNECTIVITY, "connectivity") \
|
||||||
|
DF(HABSDC_DOOR, "door") \
|
||||||
|
DF(HABSDC_GARAGE_DOOR, "garage_door") \
|
||||||
|
DF(HABSDC_GAS, "gas") \
|
||||||
|
DF(HABSDC_HEAT, "heat") \
|
||||||
|
DF(HABSDC_LIGHT, "light") \
|
||||||
|
DF(HABSDC_LOCK, "lock") \
|
||||||
|
DF(HABSDC_MOISTURE, "moisture") \
|
||||||
|
DF(HABSDC_MOTION, "motion") \
|
||||||
|
DF(HABSDC_MOVING, "moving") \
|
||||||
|
DF(HABSDC_OCCUPANCY, "occupancy") \
|
||||||
|
DF(HABSDC_OPENING, "opening") \
|
||||||
|
DF(HABSDC_PLUG, "plug") \
|
||||||
|
DF(HABSDC_POWER, "power") \
|
||||||
|
DF(HABSDC_PRESENCE, "presence") \
|
||||||
|
DF(HABSDC_PROBLEM, "problem") \
|
||||||
|
DF(HABSDC_RUNNING, "running") \
|
||||||
|
DF(HABSDC_SAFETY, "safety") \
|
||||||
|
DF(HABSDC_SMOKE, "smoke") \
|
||||||
|
DF(HABSDC_SOUND, "sound") \
|
||||||
|
DF(HABSDC_TAMPER, "tamper") \
|
||||||
|
DF(HABSDC_UPDATE, "update") \
|
||||||
|
DF(HABSDC_VIBRATION, "vibration") \
|
||||||
|
DF(HABSDC_WINDOW, "window") \
|
||||||
|
DF(HABSDC_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_binary_sensor_device_class_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_BINARY_SENSOR_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
} ha_binary_sensor_device_class_t;
|
||||||
|
|
||||||
|
char *zh_get_binary_sensor_device_class_value_name(ha_binary_sensor_device_class_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_COVER_DEVICE_CLASS \
|
||||||
|
DF(HACDC_NONE, "") \
|
||||||
|
DF(HACDC_AWNING, "awning") \
|
||||||
|
DF(HACDC_BLIND, "blind") \
|
||||||
|
DF(HACDC_CURTAIN, "curtain") \
|
||||||
|
DF(HACDC_DAMPER, "damper") \
|
||||||
|
DF(HACDC_DOOR, "door") \
|
||||||
|
DF(HACDC_GARAGE, "garage") \
|
||||||
|
DF(HACDC_GATE, "gate") \
|
||||||
|
DF(HACDC_SHADE, "shade") \
|
||||||
|
DF(HACDC_SHUTTER, "shutter") \
|
||||||
|
DF(HACDC_WINDOW, "window") \
|
||||||
|
DF(HACDC_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_cover_device_class_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_COVER_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
} ha_cover_device_class_t;
|
||||||
|
|
||||||
|
char *zh_get_cover_device_class_value_name(ha_cover_device_class_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_SENSOR_DEVICE_CLASS \
|
||||||
|
DF(HASDC_NONE, "") \
|
||||||
|
DF(HASDC_APPARENT_POWER, "apparent_power") \
|
||||||
|
DF(HASDC_AQI, "aqi") \
|
||||||
|
DF(HASDC_BATTERY, "battery") \
|
||||||
|
DF(HASDC_CARBON_DIOXIDE, "carbon_dioxide") \
|
||||||
|
DF(HASDC_CARBON_MONOXIDE, "carbon_monoxide") \
|
||||||
|
DF(HASDC_CURRENT, "current") \
|
||||||
|
DF(HASDC_DATE, "date") \
|
||||||
|
DF(HASDC_DISTANCE, "distance") \
|
||||||
|
DF(HASDC_DURATION, "duration") \
|
||||||
|
DF(HASDC_ENERGY, "energy") \
|
||||||
|
DF(HASDC_FREQUENCY, "frequency") \
|
||||||
|
DF(HASDC_GAS, "gas") \
|
||||||
|
DF(HASDC_HUMIDITY, "humidity") \
|
||||||
|
DF(HASDC_ILLUMINANCE, "illuminance") \
|
||||||
|
DF(HASDC_MOISTURE, "moisture") \
|
||||||
|
DF(HASDC_MONETARY, "monetar") \
|
||||||
|
DF(HASDC_NITROGEN_DIOXIDE, "nitrogen_dioxide") \
|
||||||
|
DF(HASDC_NITROGEN_MONOXIDE, "nitrogen_monoxide") \
|
||||||
|
DF(HASDC_NITROUS_OXIDE, "nitrous_oxide") \
|
||||||
|
DF(HASDC_OZONE, "ozone") \
|
||||||
|
DF(HASDC_PM1, "pm1") \
|
||||||
|
DF(HASDC_PM10, "pm10") \
|
||||||
|
DF(HASDC_PM25, "pm25") \
|
||||||
|
DF(HASDC_POWER_FACTOR, "power_factor") \
|
||||||
|
DF(HASDC_POWER, "power") \
|
||||||
|
DF(HASDC_PRECIPITATION, "precipitation") \
|
||||||
|
DF(HASDC_PRECIPITATION_INTENSITY, "precipitation_intensity") \
|
||||||
|
DF(HASDC_PRESSURE, "pressure") \
|
||||||
|
DF(HASDC_REACTIVE_POWER, "reactive_power") \
|
||||||
|
DF(HASDC_SIGNAL_STRENGTH, "signal_strength") \
|
||||||
|
DF(HASDC_SPEED, "speed") \
|
||||||
|
DF(HASDC_SULPHUR_DIOXIDE, "sulphur_dioxide") \
|
||||||
|
DF(HASDC_TEMPERATURE, "temperature") \
|
||||||
|
DF(HASDC_TIMESTAMP, "timestamp") \
|
||||||
|
DF(HASDC_VOLATILE_ORGANIC_COMPOUNDS, "volatile_organic_compounds") \
|
||||||
|
DF(HASDC_VOLTAGE, "voltage") \
|
||||||
|
DF(HASDC_VOLUME, "volume") \
|
||||||
|
DF(HASDC_WATER, "water") \
|
||||||
|
DF(HASDC_WEIGHT, "weight") \
|
||||||
|
DF(HASDC_WIND_SPEED, "wind_speed") \
|
||||||
|
DF(HASDC_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_sensor_device_class_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_SENSOR_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
} ha_sensor_device_class_t;
|
||||||
|
|
||||||
|
char *zh_get_sensor_device_class_value_name(ha_sensor_device_class_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_SWITCH_DEVICE_CLASS \
|
||||||
|
DF(HASWDC_NONE, "") \
|
||||||
|
DF(HASWDC_OUTLET, "outlet") \
|
||||||
|
DF(HASWDC_SWITCH, "switch") \
|
||||||
|
DF(HASWDC_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_switch_device_class_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_SWITCH_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
} ha_switch_device_class_t;
|
||||||
|
|
||||||
|
char *zh_get_switch_device_class_value_name(ha_switch_device_class_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_ON_OFF_TYPE \
|
||||||
|
DF(HAONOFT_NONE, "") \
|
||||||
|
DF(HAONOFT_ON, "ON") \
|
||||||
|
DF(HAONOFT_OFF, "OFF") \
|
||||||
|
DF(HAONOFT_OPEN, "OPEN") \
|
||||||
|
DF(HAONOFT_CLOSE, "CLOSE") \
|
||||||
|
DF(HAONOFT_LOW, "LOW") \
|
||||||
|
DF(HAONOFT_MID, "MID") \
|
||||||
|
DF(HAONOFT_HIGH, "HIGH") \
|
||||||
|
DF(HAONOFT_ALARM, "ALARM") \
|
||||||
|
DF(HAONOFT_DRY, "DRY") \
|
||||||
|
DF(HAONOFT_MOTION, "MOTION") \
|
||||||
|
DF(HAONOFT_CONNECT, "CONNECT") \
|
||||||
|
DF(HAONOFT_LEAKAGE, "LEAKAGE") \
|
||||||
|
DF(HAONOFT_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_on_off_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_ON_OFF_TYPE
|
||||||
|
#undef DF
|
||||||
|
} ha_on_off_type_t;
|
||||||
|
|
||||||
|
char *zh_get_on_off_type_value_name(ha_on_off_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_CHIP_TYPE \
|
||||||
|
DF(HACHT_NONE, "") \
|
||||||
|
DF(HACHT_ESP32, "ESP32") \
|
||||||
|
DF(HACHT_ESP8266, "ESP8266") \
|
||||||
|
DF(HACHT_ESP32S2, "ESP32-S2") \
|
||||||
|
DF(HACHT_ESP32S3, "ESP32-S3") \
|
||||||
|
DF(HACHT_ESP32C2, "ESP32-C2") \
|
||||||
|
DF(HACHT_ESP32C3, "ESP32-C3") \
|
||||||
|
DF(HACHT_ESP32C6, "ESP32-C6") \
|
||||||
|
DF(HACHT_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_chip_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_CHIP_TYPE
|
||||||
|
#undef DF
|
||||||
|
} ha_chip_type_t;
|
||||||
|
|
||||||
|
char *zh_get_chip_type_value_name(ha_chip_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_LED_EFFECT_TYPE \
|
||||||
|
DF(HALET_NONE, "") \
|
||||||
|
DF(HALET_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_led_effect_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_LED_EFFECT_TYPE
|
||||||
|
#undef DF
|
||||||
|
} ha_led_effect_type_t;
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_LED_TYPE \
|
||||||
|
DF(HALT_NONE, "") \
|
||||||
|
DF(HALT_W, "W") \
|
||||||
|
DF(HALT_WW, "WW") \
|
||||||
|
DF(HALT_RGB, "RGB") \
|
||||||
|
DF(HALT_RGBW, "RGBW") \
|
||||||
|
DF(HALT_RGBWW, "RGBWW") \
|
||||||
|
DF(HALT_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_led_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_LED_TYPE
|
||||||
|
#undef DF
|
||||||
|
} ha_led_type_t;
|
||||||
|
|
||||||
|
char *zh_get_led_type_value_name(ha_led_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
#define HA_SENSOR_TYPE \
|
||||||
|
DF(HAST_NONE, "") \
|
||||||
|
DF(HAST_DS18B20, "DS18B20") \
|
||||||
|
DF(HAST_DHT11, "DHT11") \
|
||||||
|
DF(HAST_DHT22, "DHT22") \
|
||||||
|
DF(HAST_GATEWAY, "GATEWAY") \
|
||||||
|
DF(HAST_WINDOW, "WINDOW") \
|
||||||
|
DF(HAST_DOOR, "DOOR") \
|
||||||
|
DF(HAST_LEAKAGE, "LEAKAGE") \
|
||||||
|
DF(HAST_MAX, "")
|
||||||
|
|
||||||
|
typedef enum ha_sensor_type_t
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) _value,
|
||||||
|
HA_SENSOR_TYPE
|
||||||
|
#undef DF
|
||||||
|
} ha_sensor_type_t;
|
||||||
|
|
||||||
|
char *zh_get_sensor_type_value_name(ha_sensor_type_t value);
|
||||||
|
//***********************************************************************************//
|
||||||
|
typedef struct zh_sensor_config_message_t
|
||||||
|
{
|
||||||
|
uint8_t unique_id;
|
||||||
|
ha_sensor_device_class_t sensor_device_class;
|
||||||
|
char unit_of_measurement[5];
|
||||||
|
uint8_t suggested_display_precision;
|
||||||
|
uint16_t expire_after;
|
||||||
|
bool enabled_by_default;
|
||||||
|
bool force_update;
|
||||||
|
uint8_t qos;
|
||||||
|
bool retain;
|
||||||
|
} __attribute__((packed)) zh_sensor_config_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_sensor_hardware_config_message_t
|
||||||
|
{
|
||||||
|
ha_sensor_type_t sensor_type;
|
||||||
|
uint8_t sensor_pin_1;
|
||||||
|
uint8_t sensor_pin_2;
|
||||||
|
uint8_t power_pin;
|
||||||
|
uint16_t measurement_frequency;
|
||||||
|
bool battery_power;
|
||||||
|
} __attribute__((packed)) zh_sensor_hardware_config_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_binary_sensor_config_message_t
|
||||||
|
{
|
||||||
|
uint8_t unique_id;
|
||||||
|
ha_binary_sensor_device_class_t binary_sensor_device_class;
|
||||||
|
ha_on_off_type_t payload_on;
|
||||||
|
ha_on_off_type_t payload_off;
|
||||||
|
uint16_t expire_after;
|
||||||
|
uint16_t off_delay;
|
||||||
|
bool enabled_by_default;
|
||||||
|
bool force_update;
|
||||||
|
uint8_t qos;
|
||||||
|
bool retain;
|
||||||
|
} __attribute__((packed)) zh_binary_sensor_config_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_led_config_message_t
|
||||||
|
{
|
||||||
|
uint8_t unique_id;
|
||||||
|
ha_led_type_t led_type;
|
||||||
|
ha_on_off_type_t payload_on;
|
||||||
|
ha_on_off_type_t payload_off;
|
||||||
|
bool enabled_by_default;
|
||||||
|
bool optimistic;
|
||||||
|
uint8_t qos;
|
||||||
|
bool retain;
|
||||||
|
} __attribute__((packed)) zh_led_config_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_led_hardware_config_message_t
|
||||||
|
{
|
||||||
|
ha_led_type_t led_type;
|
||||||
|
uint8_t first_white_pin;
|
||||||
|
uint8_t second_white_pin;
|
||||||
|
uint8_t red_pin;
|
||||||
|
uint8_t green_pin;
|
||||||
|
uint8_t blue_pin;
|
||||||
|
} __attribute__((packed)) zh_led_hardware_config_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_switch_config_message_t
|
||||||
|
{
|
||||||
|
uint8_t unique_id;
|
||||||
|
ha_switch_device_class_t device_class;
|
||||||
|
ha_on_off_type_t payload_on;
|
||||||
|
ha_on_off_type_t payload_off;
|
||||||
|
bool enabled_by_default;
|
||||||
|
bool optimistic;
|
||||||
|
uint8_t qos;
|
||||||
|
bool retain;
|
||||||
|
} __attribute__((packed)) zh_switch_config_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_switch_hardware_config_message_t
|
||||||
|
{
|
||||||
|
uint8_t relay_pin;
|
||||||
|
bool relay_on_level;
|
||||||
|
uint8_t led_pin;
|
||||||
|
bool led_on_level;
|
||||||
|
uint8_t int_button_pin;
|
||||||
|
bool int_button_on_level;
|
||||||
|
uint8_t ext_button_pin;
|
||||||
|
bool ext_button_on_level;
|
||||||
|
uint8_t sensor_pin;
|
||||||
|
ha_sensor_type_t sensor_type;
|
||||||
|
} __attribute__((packed)) zh_switch_hardware_config_message_t;
|
||||||
|
//***********************************************************************************//
|
||||||
|
typedef struct zh_sensor_status_message_t
|
||||||
|
{
|
||||||
|
ha_sensor_type_t sensor_type;
|
||||||
|
float temperature;
|
||||||
|
float humidity;
|
||||||
|
float pressure;
|
||||||
|
float quality;
|
||||||
|
float voltage;
|
||||||
|
float reserved_1; // Reserved for future development.
|
||||||
|
float reserved_2; // Reserved for future development.
|
||||||
|
float reserved_3; // Reserved for future development.
|
||||||
|
float reserved_4; // Reserved for future development.
|
||||||
|
float reserved_5; // Reserved for future development.
|
||||||
|
} __attribute__((packed)) zh_sensor_status_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_binary_sensor_status_message_t
|
||||||
|
{
|
||||||
|
ha_sensor_type_t sensor_type;
|
||||||
|
ha_on_off_type_t connect;
|
||||||
|
ha_on_off_type_t open;
|
||||||
|
ha_on_off_type_t battery;
|
||||||
|
ha_on_off_type_t leakage;
|
||||||
|
ha_on_off_type_t reserved_1; // Reserved for future development.
|
||||||
|
ha_on_off_type_t reserved_2; // Reserved for future development.
|
||||||
|
ha_on_off_type_t reserved_3; // Reserved for future development.
|
||||||
|
ha_on_off_type_t reserved_4; // Reserved for future development.
|
||||||
|
ha_on_off_type_t reserved_5; // Reserved for future development.
|
||||||
|
} __attribute__((packed)) zh_binary_sensor_status_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_led_status_message_t
|
||||||
|
{
|
||||||
|
ha_on_off_type_t status;
|
||||||
|
uint8_t brightness;
|
||||||
|
uint16_t temperature;
|
||||||
|
uint8_t red;
|
||||||
|
uint8_t green;
|
||||||
|
uint8_t blue;
|
||||||
|
ha_led_effect_type_t effect; // Reserved for future development.
|
||||||
|
} __attribute__((packed)) zh_led_status_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_switch_status_message_t
|
||||||
|
{
|
||||||
|
ha_on_off_type_t status;
|
||||||
|
} __attribute__((packed)) zh_switch_status_message_t;
|
||||||
|
//***********************************************************************************//
|
||||||
|
typedef struct zh_attributes_message_t
|
||||||
|
{
|
||||||
|
ha_chip_type_t chip_type;
|
||||||
|
ha_sensor_type_t sensor_type;
|
||||||
|
char flash_size[5];
|
||||||
|
uint8_t cpu_frequency;
|
||||||
|
uint32_t heap_size;
|
||||||
|
uint32_t min_heap_size;
|
||||||
|
uint8_t reset_reason;
|
||||||
|
char app_name[32];
|
||||||
|
char app_version[32];
|
||||||
|
uint32_t uptime;
|
||||||
|
} __attribute__((packed)) zh_attributes_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_keep_alive_message_t
|
||||||
|
{
|
||||||
|
bool online_status;
|
||||||
|
uint8_t message_frequency;
|
||||||
|
} __attribute__((packed)) zh_keep_alive_message_t;
|
||||||
|
|
||||||
|
typedef union zh_config_message_t
|
||||||
|
{
|
||||||
|
zh_binary_sensor_config_message_t binary_sensor_config_message;
|
||||||
|
zh_sensor_config_message_t sensor_config_message;
|
||||||
|
zh_sensor_hardware_config_message_t sensor_hardware_config_message;
|
||||||
|
zh_led_config_message_t led_config_message;
|
||||||
|
zh_led_hardware_config_message_t led_hardware_config_message;
|
||||||
|
zh_switch_config_message_t switch_config_message;
|
||||||
|
zh_switch_hardware_config_message_t switch_hardware_config_message;
|
||||||
|
} __attribute__((packed)) zh_config_message_t;
|
||||||
|
|
||||||
|
typedef union zh_status_message_t
|
||||||
|
{
|
||||||
|
zh_binary_sensor_status_message_t binary_sensor_status_message;
|
||||||
|
zh_sensor_status_message_t sensor_status_message;
|
||||||
|
zh_led_status_message_t led_status_message;
|
||||||
|
zh_switch_status_message_t switch_status_message;
|
||||||
|
} __attribute__((packed)) zh_status_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_espnow_ota_message_t
|
||||||
|
{
|
||||||
|
ha_chip_type_t chip_type;
|
||||||
|
char app_name[32];
|
||||||
|
char app_version[32];
|
||||||
|
uint16_t part;
|
||||||
|
uint8_t data_len;
|
||||||
|
uint8_t data[128];
|
||||||
|
} __attribute__((packed)) zh_espnow_ota_message_t;
|
||||||
|
|
||||||
|
typedef struct zh_espnow_ota_data_t
|
||||||
|
{
|
||||||
|
ha_chip_type_t chip_type;
|
||||||
|
zh_device_type_t device_type;
|
||||||
|
char app_name[32];
|
||||||
|
char app_version[32];
|
||||||
|
uint8_t mac_addr[6];
|
||||||
|
} __attribute__((packed)) zh_espnow_ota_data_t;
|
||||||
|
|
||||||
|
typedef union zh_payload_data_t
|
||||||
|
{
|
||||||
|
zh_attributes_message_t attributes_message;
|
||||||
|
zh_keep_alive_message_t keep_alive_message;
|
||||||
|
zh_config_message_t config_message;
|
||||||
|
zh_status_message_t status_message;
|
||||||
|
zh_espnow_ota_message_t espnow_ota_message;
|
||||||
|
} __attribute__((packed)) zh_payload_data_t;
|
||||||
|
|
||||||
|
typedef struct zh_espnow_data_t
|
||||||
|
{
|
||||||
|
zh_device_type_t device_type;
|
||||||
|
zh_payload_type_t payload_type;
|
||||||
|
zh_payload_data_t payload_data;
|
||||||
|
} __attribute__((packed)) zh_espnow_data_t;
|
1
version.txt
Normal file
1
version.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1.0.0
|
177
zh_config.c
Normal file
177
zh_config.c
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
#include "zh_config.h"
|
||||||
|
|
||||||
|
char *zh_get_device_type_value_name(zh_device_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
ZH_DEVICE_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_payload_type_value_name(zh_payload_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
ZH_PAYLOAD_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_component_type_value_name(ha_component_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_COMPONENT_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_binary_sensor_device_class_value_name(ha_binary_sensor_device_class_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_BINARY_SENSOR_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_cover_device_class_value_name(ha_cover_device_class_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_COVER_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_sensor_device_class_value_name(ha_sensor_device_class_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_SENSOR_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_switch_device_class_value_name(ha_switch_device_class_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_SWITCH_DEVICE_CLASS
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_on_off_type_value_name(ha_on_off_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_ON_OFF_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_chip_type_value_name(ha_chip_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_CHIP_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_led_type_value_name(ha_led_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_LED_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *zh_get_sensor_type_value_name(ha_sensor_type_t value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
#define DF(_value, _name) \
|
||||||
|
case _value: \
|
||||||
|
return _name;
|
||||||
|
HA_SENSOR_TYPE
|
||||||
|
#undef DF
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user