diff --git a/RodaiSensor.cpp b/RodaiSensor.cpp index 28a0bcc..4e7dc67 100644 --- a/RodaiSensor.cpp +++ b/RodaiSensor.cpp @@ -5,6 +5,8 @@ #include "driver/uart.h" #include "freertos/queue.h" #include "esp_log.h" +#include "driver/gpio.h" +#include "sdkconfig.h" #define CRC_START_MODBUS 0xFFFF #define CRC_POLY_16 0xA001 diff --git a/RodaiSensor.h b/RodaiSensor.h index 0c1b6bb..4d3ea07 100644 --- a/RodaiSensor.h +++ b/RodaiSensor.h @@ -1,11 +1,36 @@ -#pragma once +#ifndef RODAI_SENSOR_H_ +#define RODAI_SENSOR_H_ #include #include "driver/uart.h" +#include "driver/gpio.h" +#include "sdkconfig.h" + +#if CONFIG_IDF_TARGET_ESP32 +#define UART_PORT UART_NUM_1 +#define UART_TX GPIO_NUM_23 +#define UART_RX GPIO_NUM_22 +#define UART_DIR GPIO_NUM_4 +#elif CONFIG_IDF_TARGET_ESP32S2 +#define UART_PORT UART_NUM_1 +#define UART_TX GPIO_NUM_1 +#define UART_RX GPIO_NUM_2 +#define UART_DIR GPIO_NUM_3 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define UART_PORT UART_NUM_1 +#define UART_TX GPIO_NUM_4 +#define UART_RX GPIO_NUM_5 +#define UART_DIR GPIO_NUM_6 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define UART_PORT UART_NUM_1 +#define UART_TX GPIO_NUM_1 +#define UART_RX GPIO_NUM_2 +#define UART_DIR GPIO_NUM_3 +#endif class RodaiSensor { private: - uart_port_t _uart_num = UART_NUM_1; + uart_port_t _uart_num = UART_PORT; int _baud_rate = 9600; bool crc_tab16_init = false; uint16_t crc_tab16[256]; @@ -15,12 +40,14 @@ class RodaiSensor int readRegisters(uint8_t addr, uint8_t funcCode, uint16_t strAddr, uint16_t count, uint8_t *data, int tempBaudrate); public: - RodaiSensor(uart_port_t uart_num = UART_NUM_1, - int tx_io_num = GPIO_NUM_23, - int rx_io_num = GPIO_NUM_22, - int rts_io_num = GPIO_NUM_4, + RodaiSensor(uart_port_t uart_num = UART_PORT, + int tx_io_num = UART_TX, + int rx_io_num = UART_RX, + int rts_io_num = UART_DIR, int cts_io_num = UART_PIN_NO_CHANGE, int baud_rate = 9600); int getRodaiSoilWaterContentValue(uint8_t addr); }; + +#endif /* MAIN_DNS_SERVER_H_ */ diff --git a/library.properties b/library.properties index ad318f2..d2f0499 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=RodaiSensor -version=1.0.2 +version=1.0.3 author=Bunjong Yosapa maintainer=Bunjong Yosapa sentence=Read all sensor form Rodai.xyz. paragraph= category=Sensor url=https://github.com/bunjongy/RodaiSensor -architectures=esp32 +architectures=esp32,esp32s2,esp32s3 includes=RodaiSensor.h