Add ds18b20 udp broadcaster example.
Add license and readme details. Rid of compile-time switches. Rid of lazy initialization of sensor. Minor code fixing.
This commit is contained in:
parent
1da8626e6e
commit
72f30ad950
13 changed files with 278 additions and 102 deletions
22
extras/ds18b20/LICENSE
Normal file
22
extras/ds18b20/LICENSE
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Grzegorz Hetman : ghetman@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
|
@ -13,14 +13,8 @@
|
|||
#define DS1820_ALARMSEARCH 0xEC
|
||||
#define DS1820_CONVERT_T 0x44
|
||||
|
||||
uint8_t readDS18B20(uint8_t pin, DSENSOR *result){
|
||||
static uint8_t one_time = 1;
|
||||
uint8_t readDS18B20(uint8_t pin, ds_sensor_t *result){
|
||||
|
||||
if (one_time){
|
||||
onewire_init(pin);
|
||||
one_time = 0;
|
||||
}
|
||||
|
||||
uint8_t addr[8];
|
||||
uint8_t sensor_id = 0;
|
||||
onewire_reset_search(pin);
|
||||
|
|
@ -34,11 +28,11 @@ uint8_t readDS18B20(uint8_t pin, DSENSOR *result){
|
|||
|
||||
onewire_reset(pin);
|
||||
onewire_select(pin, addr);
|
||||
onewire_write(pin, DS1820_CONVERT_T, owDefaultPower);
|
||||
onewire_write(pin, DS1820_CONVERT_T, ONEWIRE_DEFAULT_POWER);
|
||||
sdk_os_delay_us(750);
|
||||
onewire_reset(pin);
|
||||
onewire_select(pin, addr);
|
||||
onewire_write(pin, DS1820_READ_SCRATCHPAD, owDefaultPower);
|
||||
onewire_write(pin, DS1820_READ_SCRATCHPAD, ONEWIRE_DEFAULT_POWER);
|
||||
|
||||
uint8_t get[10];
|
||||
|
||||
|
|
@ -75,14 +69,14 @@ float read_single_DS18B20(uint8_t pin){
|
|||
onewire_init(pin);
|
||||
onewire_reset(pin);
|
||||
|
||||
onewire_write(pin, DS1820_SKIP_ROM, owDefaultPower);
|
||||
onewire_write(pin, DS1820_CONVERT_T, owDefaultPower);
|
||||
onewire_write(pin, DS1820_SKIP_ROM, ONEWIRE_DEFAULT_POWER);
|
||||
onewire_write(pin, DS1820_CONVERT_T, ONEWIRE_DEFAULT_POWER);
|
||||
|
||||
sdk_os_delay_us(750);
|
||||
|
||||
onewire_reset(pin);
|
||||
onewire_write(pin, DS1820_SKIP_ROM, owDefaultPower);
|
||||
onewire_write(pin, DS1820_READ_SCRATCHPAD, owDefaultPower);
|
||||
onewire_write(pin, DS1820_SKIP_ROM, ONEWIRE_DEFAULT_POWER);
|
||||
onewire_write(pin, DS1820_READ_SCRATCHPAD, ONEWIRE_DEFAULT_POWER);
|
||||
|
||||
uint8_t get[10];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
#ifndef DRIVER_DS18B20_H_
|
||||
#define DRIVER_DS18B20_H_
|
||||
|
||||
typedef struct DSENSOR {
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
} DSENSOR;
|
||||
} ds_sensor_t;
|
||||
|
||||
// Scan all ds18b20 sensors on bus and return its amount.
|
||||
// Result are saved in array of DSENSOR structure.
|
||||
// Result are saved in array of ds_sensor_t structure.
|
||||
// Cause printf in esp sdk don`t support float,
|
||||
// I split result as two number (major, minor).
|
||||
uint8_t readDS18B20(uint8_t pin, DSENSOR *result);
|
||||
uint8_t readDS18B20(uint8_t pin, ds_sensor_t *result);
|
||||
|
||||
// This method is just to demonstrate how to read
|
||||
// temperature from single dallas chip.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue