Initial commit

This commit is contained in:
Rafal Zajac
2017-11-12 22:49:10 +01:00
commit 74d0876c59
39 changed files with 2503 additions and 0 deletions

View File

@ -0,0 +1,37 @@
# Copyright 2017 Rafal Zajac <rzajac@gmail.com>.
#
# 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.
find_package(esp_sdo REQUIRED)
find_package(esp_ow REQUIRED)
find_package(esp_eb REQUIRED)
find_package(esp_util REQUIRED)
add_executable(ds18b20_temp main.c ${ESP_USER_CONFIG})
target_include_directories(ds18b20_temp 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
${esp_sdo_LIBRARIES}
${esp_ow_LIBRARIES}
${esp_eb_LIBRARIES}
${esp_util_LIBRARIES}
esp_ds18b20)
esp_gen_exec_targets(ds18b20_temp)

View File

@ -0,0 +1,12 @@
## Get temperature measured by DS18B20.
Demonstrates how to search OneWire bus for DS18b20.
## Flashing
```
$ cd build
$ cmake ..
$ make ds18b20_temp_flash
$ miniterm.py /dev/ttyUSB0 74880
```

View File

@ -0,0 +1,81 @@
/*
* Copyright 2017 Rafal Zajac <rzajac@gmail.com>.
*
* 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.
*/
#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>
// List of found devices on the OneWire bus.
static esp_ow_device *root = NULL;
// Handle temperature conversion callbacks.
static void ICACHE_FLASH_ATTR
temperature(const char *event, void *arg)
{
esp_ow_device *dev = arg;
esp_ds18b20_st *st = dev->custom;
if (st->last_temp == ESP_DS18B20_TEMP_ERR) {
os_printf("Temperature read error.\n");
} else {
os_printf("Temperature: %s\n", esp_util_ftoa(st->last_temp, 4));
}
}
static void ICACHE_FLASH_ATTR
sys_init_done()
{
esp_ow_err err;
if (esp_ds18b20_init(GPIO2) == false) {
os_printf("Error initializing DS18B20.\n");
return;
}
err = esp_ds18b20_search(GPIO2, false, &root);
if (err != ESP_OW_OK) {
os_printf("Search error: %d\n", err);
return;
}
if (root == NULL) {
os_printf("No devices found.\n");
}
// Callbacks will be called when conversion is finished.
esp_eb_attach(ESP_DS18B20_EV_TEMP_READY, temperature);
esp_eb_attach(ESP_DS18B20_EV_TEMP_ERROR, temperature);
// Get temperature from the first DS18B20 sensor.
esp_ds18b20_convert(root);
}
void ICACHE_FLASH_ATTR
user_init()
{
// No need for wifi for this examples.
wifi_station_disconnect();
wifi_set_opmode_current(NULL_MODE);
stdout_init(BIT_RATE_74880);
system_init_done_cb(sys_init_done);
}