mirror of
https://github.com/rzajac/esp-drv.git
synced 2025-07-24 21:21:18 +03:00
Update documentation and fix small issues.
This commit is contained in:
@ -15,5 +15,5 @@
|
||||
|
||||
add_subdirectory(ds18b20_search)
|
||||
add_subdirectory(ds18b20_temp)
|
||||
add_subdirectory(dht22_temp_hum)
|
||||
add_subdirectory(sht21_example)
|
||||
add_subdirectory(dht22)
|
||||
add_subdirectory(sht21)
|
||||
|
@ -16,16 +16,16 @@
|
||||
find_package(esp_sdo REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(dht22_temp_hum main.c ${ESP_USER_CONFIG})
|
||||
add_executable(dht22_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(dht22_temp_hum PUBLIC
|
||||
target_include_directories(dht22_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(dht22_temp_hum
|
||||
target_link_libraries(dht22_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_dht22)
|
||||
|
||||
esp_gen_exec_targets(dht22_temp_hum)
|
||||
esp_gen_exec_targets(dht22_ex)
|
@ -7,6 +7,6 @@ Demonstrates how to get temperature and humidity from DHT22 sensor.
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make dht22_temp_hum_flash
|
||||
$ make dht22_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
@ -14,67 +14,16 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <user_interface.h>
|
||||
|
||||
#include <esp_gpio.h>
|
||||
#include <esp_dht22.h>
|
||||
#include <mem.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
#include <mem.h>
|
||||
|
||||
os_timer_t timer;
|
||||
|
||||
/**
|
||||
* Rise base to power of.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* @param base The number.
|
||||
* @param exp The exponent.
|
||||
*
|
||||
* @return Product.
|
||||
*/
|
||||
static int ICACHE_FLASH_ATTR
|
||||
power(int base, int exp)
|
||||
{
|
||||
int result = 1;
|
||||
while (exp) {
|
||||
result *= base;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string representation of float.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* Warning: limited to 15 chars & non-reentrant.
|
||||
* e.g., don't use more than once per os_printf call.
|
||||
*
|
||||
* @param num The float to convert to string.
|
||||
* @param decimals The number of decimal places.
|
||||
*
|
||||
* @return The float string representation.
|
||||
*/
|
||||
static char *ICACHE_FLASH_ATTR
|
||||
ftoa(float num, uint8_t decimals)
|
||||
{
|
||||
static char *buf[16];
|
||||
|
||||
int whole = (int) num;
|
||||
int decimal = (int) ((num - whole) * power(10, decimals));
|
||||
if (decimal < 0) {
|
||||
// get rid of sign on decimal portion
|
||||
decimal -= 2 * decimal;
|
||||
}
|
||||
|
||||
char *pattern[10]; // setup printf pattern for decimal portion
|
||||
os_sprintf((char *) pattern, "%%d.%%0%dd", decimals);
|
||||
os_sprintf((char *) buf, (const char *) pattern, whole, decimal);
|
||||
|
||||
return (char *) buf;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
sys_init_done(void* arg)
|
||||
@ -90,8 +39,8 @@ sys_init_done(void* arg)
|
||||
return;
|
||||
}
|
||||
|
||||
os_printf("Temp: %s\n", ftoa(dev->temp, 2));
|
||||
os_printf("Hum: %s\n", ftoa(dev->hum, 2));
|
||||
os_printf("Temp: %s\n", esp_util_ftoa(dev->temp, 3));
|
||||
os_printf("Hum: %s\n", esp_util_ftoa(dev->hum, 3));
|
||||
os_printf("--------------------\n");
|
||||
os_free(dev);
|
||||
}
|
@ -18,20 +18,20 @@ find_package(esp_ow REQUIRED)
|
||||
find_package(esp_eb REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(ds18b20_search main.c ${ESP_USER_CONFIG})
|
||||
add_executable(ds18b20_search_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(ds18b20_search PUBLIC
|
||||
target_include_directories(ds18b20_search_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_ow_INCLUDE_DIRS}
|
||||
${esp_eb_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(ds18b20_search
|
||||
target_link_libraries(ds18b20_search_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_ow_LIBRARIES}
|
||||
${esp_eb_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_ds18b20)
|
||||
|
||||
esp_gen_exec_targets(ds18b20_search)
|
||||
esp_gen_exec_targets(ds18b20_search_ex)
|
||||
|
@ -7,6 +7,6 @@ Demonstrates how to search OneWire bus for DS18b20.
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make ds18b20_search_flash
|
||||
$ make ds18b20_search_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
||||
|
@ -18,20 +18,20 @@ find_package(esp_ow REQUIRED)
|
||||
find_package(esp_eb REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(ds18b20_temp main.c ${ESP_USER_CONFIG})
|
||||
add_executable(ds18b20_temp_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(ds18b20_temp PUBLIC
|
||||
target_include_directories(ds18b20_temp_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_ow_INCLUDE_DIRS}
|
||||
${esp_eb_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(ds18b20_temp
|
||||
target_link_libraries(ds18b20_temp_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_ow_LIBRARIES}
|
||||
${esp_eb_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_ds18b20)
|
||||
|
||||
esp_gen_exec_targets(ds18b20_temp)
|
||||
esp_gen_exec_targets(ds18b20_temp_ex)
|
||||
|
@ -7,6 +7,6 @@ Demonstrates how to search OneWire bus for DS18b20.
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make ds18b20_temp_flash
|
||||
$ make ds18b20_temp_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
||||
|
@ -15,13 +15,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <user_interface.h>
|
||||
#include <osapi.h>
|
||||
#include <esp_ds18b20.h>
|
||||
#include <esp_gpio.h>
|
||||
#include <esp_eb.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
|
||||
// List of found devices on the OneWire bus.
|
||||
static esp_ow_device *root = NULL;
|
||||
|
@ -17,18 +17,18 @@ find_package(esp_sdo REQUIRED)
|
||||
find_package(esp_i2c REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(sht21_example main.c ${ESP_USER_CONFIG})
|
||||
add_executable(sht21_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(sht21_example PUBLIC
|
||||
target_include_directories(sht21_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_i2c_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(sht21_example
|
||||
target_link_libraries(sht21_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_i2c_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_sht21)
|
||||
|
||||
esp_gen_exec_targets(sht21_example)
|
||||
esp_gen_exec_targets(sht21_ex)
|
@ -10,6 +10,6 @@ Demonstrates how to:
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make sht21_example_flash
|
||||
$ make sht21_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
@ -14,70 +14,17 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <esp_sht21.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
#include <osapi.h>
|
||||
|
||||
#define SCL GPIO0
|
||||
#define SDA GPIO2
|
||||
|
||||
os_timer_t timer;
|
||||
|
||||
/**
|
||||
* Rise base to power of.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* @param base The number.
|
||||
* @param exp The exponent.
|
||||
*
|
||||
* @return Product.
|
||||
*/
|
||||
static int ICACHE_FLASH_ATTR
|
||||
power(int base, int exp)
|
||||
{
|
||||
int result = 1;
|
||||
while (exp) {
|
||||
result *= base;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string representation of float.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* Warning: limited to 15 chars & non-reentrant.
|
||||
* e.g., don't use more than once per os_printf call.
|
||||
*
|
||||
* @param num The float to convert to string.
|
||||
* @param decimals The number of decimal places.
|
||||
*
|
||||
* @return The float string representation.
|
||||
*/
|
||||
static char *ICACHE_FLASH_ATTR
|
||||
ftoa(float num, uint8_t decimals)
|
||||
{
|
||||
static char *buf[16];
|
||||
|
||||
int whole = (int) num;
|
||||
int decimal = (int) ((num - whole) * power(10, decimals));
|
||||
if (decimal < 0) {
|
||||
// get rid of sign on decimal portion
|
||||
decimal -= 2 * decimal;
|
||||
}
|
||||
|
||||
char *pattern[10]; // setup printf pattern for decimal portion
|
||||
os_sprintf((char *) pattern, "%%d.%%0%dd", decimals);
|
||||
os_sprintf((char *) buf, (const char *) pattern, whole, decimal);
|
||||
|
||||
return (char *) buf;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
run_sht21()
|
||||
{
|
||||
@ -107,12 +54,12 @@ run_sht21()
|
||||
err = esp_sht21_get_rh(&value);
|
||||
if (err != ESP_I2C_OK) os_printf("Get RH error: %d\n", err);
|
||||
|
||||
os_printf("Humidity: %s%%\n", ftoa(value, 2));
|
||||
os_printf("Humidity: %s%%\n", esp_util_ftoa(value, 2));
|
||||
|
||||
err = esp_sht21_get_temp_last(&value);
|
||||
if (err != ESP_I2C_OK) os_printf("Get TEMP error: %d\n", err);
|
||||
|
||||
os_printf("Temperature: %s deg. C\n", ftoa(value, 2));
|
||||
os_printf("Temperature: %s deg. C\n", esp_util_ftoa(value, 2));
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
Reference in New Issue
Block a user