Browse Source

Prep for esp32-owb PR4.

main
David Antliff 8 years ago
parent
commit
bde30e35f1
  1. 2
      components/esp32-ds18b20
  2. 33
      main/app_main.c

2
components/esp32-ds18b20

@ -1 +1 @@
Subproject commit db5b2630824e445b735725cfb99d634c50219100 Subproject commit 0926cf30719c8e214f1fba3f8c12ff6ba5a54c3f

33
main/app_main.c

@ -33,6 +33,7 @@
//#define USE_STATIC 1 //#define USE_STATIC 1
#include "owb.h" #include "owb.h"
#include "owb_rmt.h"
#include "ds18b20.h" #include "ds18b20.h"
@ -46,17 +47,20 @@ void app_main()
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);
// Stable readings require a brief period before communication // Stable readings require a brief period before communication
vTaskDelay(1000.0 / portTICK_PERIOD_MS); vTaskDelay(2000.0 / portTICK_PERIOD_MS);
// Create a 1-Wire bus // Create a 1-Wire bus
#ifdef USE_STATIC //#ifdef USE_STATIC
OneWireBus owb_static; // static allocation // OneWireBus owb_static; // static allocation
OneWireBus * owb = &owb_static; // OneWireBus * owb = &owb_static;
#else //#else
OneWireBus * owb = owb_malloc(); // heap allocation // OneWireBus * owb = owb_malloc(); // heap allocation
#endif //#endif
OneWireBus * owb;
owb_init(owb, GPIO_DS18B20_0); owb_rmt_driver_info rmt_driver_info;
owb = owb_rmt_initialize(&rmt_driver_info, GPIO_DS18B20_0, RMT_CHANNEL_1, RMT_CHANNEL_0);
// owb_init(owb, GPIO_DS18B20_0);
owb_use_crc(owb, true); // enable CRC check for ROM code owb_use_crc(owb, true); // enable CRC check for ROM code
// Find all connected devices // Find all connected devices
@ -64,7 +68,8 @@ void app_main()
OneWireBus_ROMCode device_rom_codes[MAX_DEVICES] = {0}; OneWireBus_ROMCode device_rom_codes[MAX_DEVICES] = {0};
int num_devices = 0; int num_devices = 0;
OneWireBus_SearchState search_state = {0}; OneWireBus_SearchState search_state = {0};
bool found = owb_search_first(owb, &search_state); bool found = false;
owb_search_first(owb, &search_state, &found);
while (found) while (found)
{ {
char rom_code_s[17]; char rom_code_s[17];
@ -72,7 +77,7 @@ void app_main()
printf(" %d : %s\n", num_devices, rom_code_s); printf(" %d : %s\n", num_devices, rom_code_s);
device_rom_codes[num_devices] = search_state.rom_code; device_rom_codes[num_devices] = search_state.rom_code;
++num_devices; ++num_devices;
found = owb_search_next(owb, &search_state); owb_search_next(owb, &search_state, &found);
} }
printf("Found %d devices\n", num_devices); printf("Found %d devices\n", num_devices);
@ -90,7 +95,9 @@ void app_main()
}; };
char rom_code_s[17]; char rom_code_s[17];
owb_string_from_rom_code(known_device, rom_code_s, sizeof(rom_code_s)); 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"); bool is_present = false;
owb_verify_rom(owb, known_device, &is_present);
printf("Device %s is %s\n", rom_code_s, is_present ? "present" : "not present");
// Create a DS18B20 device on the 1-Wire bus // Create a DS18B20 device on the 1-Wire bus
#ifdef USE_STATIC #ifdef USE_STATIC
@ -186,7 +193,7 @@ void app_main()
{ {
ds18b20_free(&devices[i]); ds18b20_free(&devices[i]);
} }
owb_free(&owb); // owb_free(&owb);
#endif #endif
printf("Restarting now.\n"); printf("Restarting now.\n");

Loading…
Cancel
Save