A couple of fixups prior to merging into main project
Changed the ds_sensor_t struct to just return a float instead of major/minor Renamed ds18b20.h functions to have consistent `ds18b20_*` naming. Removed some unnecessary LICENSE files. Clarified onewire origin/license.
This commit is contained in:
parent
6178865cc6
commit
d0ed5f03a2
9 changed files with 37 additions and 88 deletions
|
@ -1,22 +0,0 @@
|
||||||
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.
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ void broadcast_temperature(void *pvParameters)
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
// Search all DS18B20, return its amount and feed 't' structure with result data.
|
// Search all DS18B20, return its amount and feed 't' structure with result data.
|
||||||
amount = readDS18B20(GPIO_FOR_ONE_WIRE, t);
|
amount = ds18b20_read_all(GPIO_FOR_ONE_WIRE, t);
|
||||||
|
|
||||||
if (amount < sensors){
|
if (amount < sensors){
|
||||||
printf("Something is wrong, I expect to see %d sensors \nbut just %d was detected!\n", sensors, amount);
|
printf("Something is wrong, I expect to see %d sensors \nbut just %d was detected!\n", sensors, amount);
|
||||||
|
@ -66,8 +66,10 @@ void broadcast_temperature(void *pvParameters)
|
||||||
|
|
||||||
for (int i = 0; i < amount; ++i)
|
for (int i = 0; i < amount; ++i)
|
||||||
{
|
{
|
||||||
|
int intpart = (int)t[i].value;
|
||||||
|
int fraction = (int)((t[i].value - intpart) * 100);
|
||||||
// Multiple "" here is just to satisfy compiler and don`t raise 'hex escape sequence out of range' warning.
|
// Multiple "" here is just to satisfy compiler and don`t raise 'hex escape sequence out of range' warning.
|
||||||
sprintf(msg, "Sensor %d report: %d.%d ""\xC2""\xB0""C\n",t[i].id, t[i].major, t[i].minor);
|
sprintf(msg, "Sensor %d report: %d.%02d ""\xC2""\xB0""C\n",t[i].id, intpart, fraction);
|
||||||
printf("%s", msg);
|
printf("%s", msg);
|
||||||
|
|
||||||
struct netbuf* buf = netbuf_new();
|
struct netbuf* buf = netbuf_new();
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
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.
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ void print_temperature(void *pvParameters)
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// Search all DS18B20, return its amount and feed 't' structure with result data.
|
// Search all DS18B20, return its amount and feed 't' structure with result data.
|
||||||
amount = readDS18B20(GPIO_FOR_ONE_WIRE, t);
|
amount = ds18b20_read_all(GPIO_FOR_ONE_WIRE, t);
|
||||||
|
|
||||||
if (amount < sensors){
|
if (amount < sensors){
|
||||||
printf("Something is wrong, I expect to see %d sensors \nbut just %d was detected!\n", sensors, amount);
|
printf("Something is wrong, I expect to see %d sensors \nbut just %d was detected!\n", sensors, amount);
|
||||||
|
@ -38,8 +38,10 @@ void print_temperature(void *pvParameters)
|
||||||
|
|
||||||
for (int i = 0; i < amount; ++i)
|
for (int i = 0; i < amount; ++i)
|
||||||
{
|
{
|
||||||
|
int intpart = (int)t[i].value;
|
||||||
|
int fraction = (int)((t[i].value - intpart) * 100);
|
||||||
// Multiple "" here is just to satisfy compiler and don`t raise 'hex escape sequence out of range' warning.
|
// Multiple "" here is just to satisfy compiler and don`t raise 'hex escape sequence out of range' warning.
|
||||||
printf("Sensor %d report: %d.%d ""\xC2""\xB0""C\n",t[i].id, t[i].major, t[i].minor);
|
printf("Sensor %d report: %d.%02d ""\xC2""\xB0""C\n",t[i].id, intpart, fraction);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
vTaskDelay(delay / portTICK_RATE_MS);
|
vTaskDelay(delay / portTICK_RATE_MS);
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
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,7 +13,7 @@
|
||||||
#define DS1820_ALARMSEARCH 0xEC
|
#define DS1820_ALARMSEARCH 0xEC
|
||||||
#define DS1820_CONVERT_T 0x44
|
#define DS1820_CONVERT_T 0x44
|
||||||
|
|
||||||
uint8_t readDS18B20(uint8_t pin, ds_sensor_t *result){
|
uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
|
||||||
|
|
||||||
uint8_t addr[8];
|
uint8_t addr[8];
|
||||||
uint8_t sensor_id = 0;
|
uint8_t sensor_id = 0;
|
||||||
|
@ -55,18 +55,16 @@ uint8_t readDS18B20(uint8_t pin, ds_sensor_t *result){
|
||||||
float temperature;
|
float temperature;
|
||||||
|
|
||||||
temperature = (temp * 625.0)/10000;
|
temperature = (temp * 625.0)/10000;
|
||||||
//printf("Got a DS18B20 Reading: %d.%d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
|
//printf("Got a DS18B20 Reading: %d.%02d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
|
||||||
result[sensor_id].id = sensor_id;
|
result[sensor_id].id = sensor_id;
|
||||||
result[sensor_id].major = (int)temperature;
|
result[sensor_id].value = temperature;
|
||||||
result[sensor_id].minor = (int)(temperature) - (int)temperature * 100;
|
|
||||||
sensor_id++;
|
sensor_id++;
|
||||||
}
|
}
|
||||||
return sensor_id;
|
return sensor_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
float read_single_DS18B20(uint8_t pin){
|
float ds18b20_read_single(uint8_t pin) {
|
||||||
|
|
||||||
onewire_init(pin);
|
|
||||||
onewire_reset(pin);
|
onewire_reset(pin);
|
||||||
|
|
||||||
onewire_write(pin, DS1820_SKIP_ROM, ONEWIRE_DEFAULT_POWER);
|
onewire_write(pin, DS1820_SKIP_ROM, ONEWIRE_DEFAULT_POWER);
|
||||||
|
@ -101,5 +99,5 @@ float read_single_DS18B20(uint8_t pin){
|
||||||
|
|
||||||
temperature = (temp * 625.0)/10000;
|
temperature = (temp * 625.0)/10000;
|
||||||
return temperature;
|
return temperature;
|
||||||
//printf("Got a DS18B20 Reading: %d.%d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
|
//printf("Got a DS18B20 Reading: %d.%02d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
|
||||||
}
|
}
|
|
@ -3,18 +3,15 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
uint8_t major;
|
float value;
|
||||||
uint8_t minor;
|
|
||||||
} ds_sensor_t;
|
} ds_sensor_t;
|
||||||
|
|
||||||
// Scan all ds18b20 sensors on bus and return its amount.
|
// Scan all ds18b20 sensors on bus and return its amount.
|
||||||
// Result are saved in array of ds_sensor_t structure.
|
// Result are saved in array of ds_sensor_t structure.
|
||||||
// Cause printf in esp sdk don`t support float,
|
uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result);
|
||||||
// I split result as two number (major, minor).
|
|
||||||
uint8_t readDS18B20(uint8_t pin, ds_sensor_t *result);
|
|
||||||
|
|
||||||
// This method is just to demonstrate how to read
|
// This method is just to demonstrate how to read
|
||||||
// temperature from single dallas chip.
|
// temperature from single dallas chip.
|
||||||
float read_single_DS18B20(uint8_t pin);
|
float ds18b20_read_single(uint8_t pin);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,3 +20,12 @@ 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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Portions copyright (C) 2000 Dallas Semiconductor Corporation, under the
|
||||||
|
following additional terms:
|
||||||
|
|
||||||
|
Except as contained in this notice, the name of Dallas Semiconductor
|
||||||
|
shall not be used except as stated in the Dallas Semiconductor
|
||||||
|
Branding Policy.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
# Yet another one wire driver for the ESP8266
|
# Yet another one wire driver for the ESP8266
|
||||||
|
|
||||||
This is a port of bit banging one wire driver based on nodemcu implementaion.
|
This is a port of a bit-banging one wire driver based on the implementation
|
||||||
|
from NodeMCU.
|
||||||
|
|
||||||
Seams that they port it from https://www.pjrc.com/teensy/td_libs_OneWire.html
|
This, in turn, appears to have been based on the PJRC Teensy driver
|
||||||
|
(https://www.pjrc.com/teensy/td_libs_OneWire.html), by Jim Studt, Paul
|
||||||
|
Stoffregen, and a host of others.
|
||||||
|
|
||||||
For all aspect regarding license, please check LICENSE file and coresponding projects.
|
The original code is licensed under the MIT license. The CRC code was taken
|
||||||
|
(at least partially) from Dallas Semiconductor sample code, which was licensed
|
||||||
|
under an MIT license with an additional clause (prohibiting inappropriate use
|
||||||
|
of the Dallas Semiconductor name). See the accompanying LICENSE file for
|
||||||
|
details.
|
||||||
|
|
Loading…
Reference in a new issue