From 4530a799500e2a35550a82bdd862b2b258f39daf Mon Sep 17 00:00:00 2001 From: David Antliff Date: Sat, 5 Aug 2017 13:38:32 +1200 Subject: [PATCH] Tidy up. --- README.md | 4 +++- main/ds18b20.c | 1 - main/ds18b20_main.c | 24 +++++++++--------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 31ea49f..3d84967 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ This is a ESP32-compatible C library for the Maxim Integrated DS18B20 Programmab It supports multiple devices on the same 1-Wire bus. +It is written and tested for the [ESP-IDF](https://github.com/espressif/esp-idf) environment, using the xtensa-esp32-elf toolchain (gcc version 5.2.0). + ## Supported Features * External power supply mode (parasitic mode not yet supported). @@ -17,7 +19,7 @@ It supports multiple devices on the same 1-Wire bus. ## Documentation -API documentation (doxygen) is available [here](https://...). +Automatically generated API documentation (doxygen) is available [here](https://davidantliff.github.io/ESP32-DS18B20/index.html). ## Source Code diff --git a/main/ds18b20.c b/main/ds18b20.c index 3cfd9bd..f4b118e 100644 --- a/main/ds18b20.c +++ b/main/ds18b20.c @@ -31,7 +31,6 @@ #include #include #include -#include // for PRIu64 #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/main/ds18b20_main.c b/main/ds18b20_main.c index 710939c..9d9e2d9 100644 --- a/main/ds18b20_main.c +++ b/main/ds18b20_main.c @@ -72,7 +72,11 @@ void app_main() } // known ROM codes (LSB first): - OneWireBus_ROMCode known_device = { { {0x28}, {0xee, 0xcc, 0x87, 0x2e, 0x16, 0x01}, {0x00} } }; + OneWireBus_ROMCode known_device = { + .fields.family = { 0x28 }, + .fields.serial_number = { 0xee, 0xcc, 0x87, 0x2e, 0x16, 0x01 }, + .fields.crc = { 0x00 }, + }; char rom_code_s[17]; owb_string_from_rom_code(known_device, rom_code_s, sizeof(rom_code_s)); printf("Device %s is %s\n", rom_code_s, owb_verify_rom(owb, known_device) ? "present" : "not present"); @@ -81,7 +85,6 @@ void app_main() //uint64_t rom_code = 0xf402162c6149ee28; // green //uint64_t rom_code = 0x1502162ca5b2ee28; // orange //uint64_t rom_code = owb_read_rom(owb); - //printf("1-Wire ROM code 0x%08" PRIx64 "\n", rom_code); // Create a DS18B20 device on the 1-Wire bus #ifdef USE_STATIC @@ -106,19 +109,12 @@ void app_main() DS18B20_Info * ds18b20_info = ds18b20_malloc(); // heap allocation devices[i] = ds18b20_info; #endif -// uint64_t rom_code = 0; -// for (int j = 7; j >= 0; --j) -// { -// rom_code |= ((uint64_t)device_rom_codes[i][j] << (8 * j)); -// } -// printf("1-Wire ROM code 0x%08" PRIx64 "\n", rom_code); - - //ds18b20_init(ds18b20_info, owb, rom_code); // associate with bus and device ds18b20_init(ds18b20_info, owb, device_rom_codes[i]); // associate with bus and device //ds18b20_init_solo(ds18b20_info, owb); // only one device on bus ds18b20_use_crc(ds18b20_info, true); // enable CRC check for temperature readings } + // read temperatures from all sensors while (1) { printf("\nTemperature readings (degrees C):\n"); @@ -130,13 +126,11 @@ void app_main() vTaskDelay(1000 / portTICK_PERIOD_MS); } - for (int i = 10; i >= 0; i--) { - printf("Restarting in %d seconds...\n", i); - vTaskDelay(1000 / portTICK_PERIOD_MS); - } - +#ifndef USE_STATIC + // clean up dynamically allocated data ds18b20_free(&ds18b20_info); owb_free(&owb); +#endif printf("Restarting now.\n"); fflush(stdout);