Added clang-format (#623)
* added .clang-format * added names to travis jobs removed deprecated travis option * check github action * added .gitignore
This commit is contained in:
1 parent
661ef9c55e
commit
10a9d00aaf
59 files changed
+2892
-3640
No files matched your search
+72
-100
@@ -26,8 +26,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorDS1820
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
# include <DallasTemperature.h>
|
||||
# include <OneWire.h>
|
||||
|
||||
OneWire owbus(DS1820_OWBUS_PIN);
|
||||
DallasTemperature ds1820(&owbus);
|
||||
@@ -38,10 +38,8 @@ static uint8_t ds1820_resolution[OW_MAX_SENSORS];
|
||||
static String ds1820_type[OW_MAX_SENSORS];
|
||||
static String ds1820_addr[OW_MAX_SENSORS];
|
||||
|
||||
|
||||
void setupZsensorDS1820()
|
||||
{
|
||||
Log.trace(F("DS1820: configured pin: %d for 1-wire bus" CR), DS1820_OWBUS_PIN );
|
||||
void setupZsensorDS1820() {
|
||||
Log.trace(F("DS1820: configured pin: %d for 1-wire bus" CR), DS1820_OWBUS_PIN);
|
||||
ds1820.begin();
|
||||
|
||||
// Search the OneWire bus for all devices
|
||||
@@ -51,57 +49,46 @@ void setupZsensorDS1820()
|
||||
Log.notice(F("DS1820: Found %d devices" CR), numDevicesOnBus);
|
||||
|
||||
// Cycle though all of the devices on the OneWire bus
|
||||
for (int deviceIndex = 0; deviceIndex < numDevicesOnBus && ds1820_count < OW_MAX_SENSORS; deviceIndex++)
|
||||
{
|
||||
for (int deviceIndex = 0; deviceIndex < numDevicesOnBus && ds1820_count < OW_MAX_SENSORS; deviceIndex++) {
|
||||
// get the next device on the OneWire bus and confirm it is a sensor the library can handle (Dallas DS18X20 1-wire devices)
|
||||
if ( ds1820.getAddress(ds1820_address, deviceIndex) && ds1820.validFamily(ds1820_address) )
|
||||
{
|
||||
if (ds1820.getAddress(ds1820_address, deviceIndex) && ds1820.validFamily(ds1820_address)) {
|
||||
ds1820_addr[ds1820_count] = String("0x");
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
if (ds1820_address[i] < 0x10) ds1820_addr[ds1820_count] += String("0");
|
||||
ds1820_devices[ds1820_count][i] = ds1820_address[i];
|
||||
ds1820_addr[ds1820_count] += String(ds1820_address[i], HEX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// set the resolution and thus conversion timing
|
||||
if (ds1820_address[0] == 0x10)
|
||||
{
|
||||
if (ds1820_address[0] == 0x10) {
|
||||
// DS1820/DS18S20 have no resolution configuration register,
|
||||
// both have a 9-bit temperature register. Resolutions greater
|
||||
// than 9-bit can be calculated using the data from the temperature,
|
||||
// both have a 9-bit temperature register. Resolutions greater
|
||||
// than 9-bit can be calculated using the data from the temperature,
|
||||
// and COUNT REMAIN and COUNT PER °C registers in the scratchpad.
|
||||
// The resolution of the calculation depends on the model.
|
||||
ds1820_type[ds1820_count] = String("DS1820/DS18S20");
|
||||
}
|
||||
else if (ds1820_address[0] == 0x28)
|
||||
{
|
||||
ds1820_type[ds1820_count] = String("DS1820/DS18S20");
|
||||
} else if (ds1820_address[0] == 0x28) {
|
||||
// DS18B20 and 18B22 are capable of different resolutions (9-12 bit)
|
||||
ds1820_type[ds1820_count] = String("DS18B20");
|
||||
ds1820.setResolution(ds1820_address, DS1820_RESOLUTION);
|
||||
}
|
||||
else if (ds1820_address[0] == 0x22)
|
||||
{
|
||||
} else if (ds1820_address[0] == 0x22) {
|
||||
ds1820_type[ds1820_count] = String("DS1822");
|
||||
ds1820.setResolution(ds1820_address, DS1820_RESOLUTION);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ds1820_type[ds1820_count] = String("DS1825");
|
||||
ds1820.setResolution(ds1820_address, DS1820_RESOLUTION);
|
||||
}
|
||||
}
|
||||
ds1820_resolution[ds1820_count] = ds1820.getResolution(ds1820_address);
|
||||
Log.trace(F("DS1820: Device %d, Type: %s, Address: %s, Resolution: %d" CR),
|
||||
ds1820_count,
|
||||
(char *)ds1820_type[ds1820_count].c_str(),
|
||||
(char *)ds1820_addr[ds1820_count].c_str(),
|
||||
ds1820_resolution[ds1820_count]);
|
||||
ds1820_count,
|
||||
(char*)ds1820_type[ds1820_count].c_str(),
|
||||
(char*)ds1820_addr[ds1820_count].c_str(),
|
||||
ds1820_resolution[ds1820_count]);
|
||||
ds1820_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (ds1820.getDS18Count() == 0)
|
||||
{
|
||||
|
||||
if (ds1820.getDS18Count() == 0) {
|
||||
Log.error(F("DS1820: Failed to enumerate sensors on 1-wire bus. Check your pin assignment!" CR));
|
||||
}
|
||||
|
||||
@@ -110,103 +97,88 @@ void setupZsensorDS1820()
|
||||
ds1820.setWaitForConversion(false);
|
||||
}
|
||||
|
||||
void pubOneWire_HADiscovery()
|
||||
{
|
||||
void pubOneWire_HADiscovery() {
|
||||
// If zmqttDiscovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
||||
#ifdef ZmqttDiscovery
|
||||
# ifdef ZmqttDiscovery
|
||||
Log.notice(F("CreateDiscoverySensor - Found %d" CR), ds1820_count);
|
||||
for (int index=0; index<ds1820_count; index++)
|
||||
{
|
||||
#if DS1820_FAHRENHEIT
|
||||
createDiscovery("sensor",
|
||||
(char *)(String(OW_TOPIC) + "/" + ds1820_addr[index]).c_str(),
|
||||
(char *)String("DS12B20_" + String(index+1)).c_str(),
|
||||
(char *)ds1820_addr[index].c_str(),
|
||||
will_Topic,
|
||||
"temperature",
|
||||
jsonTempf,
|
||||
"", "", "°F",
|
||||
0, "", "", true, "");
|
||||
#else
|
||||
createDiscovery("sensor",
|
||||
(char *)(String(OW_TOPIC) + "/" + ds1820_addr[index]).c_str(),
|
||||
(char *)String("DS12B20_" + String(index+1)).c_str(),
|
||||
(char *)ds1820_addr[index].c_str(),
|
||||
will_Topic,
|
||||
"temperature",
|
||||
jsonTemp,
|
||||
"", "", "°C",
|
||||
0, "", "", true, "");
|
||||
#endif
|
||||
for (int index = 0; index < ds1820_count; index++) {
|
||||
# if DS1820_FAHRENHEIT
|
||||
createDiscovery("sensor",
|
||||
(char*)(String(OW_TOPIC) + "/" + ds1820_addr[index]).c_str(),
|
||||
(char*)String("DS12B20_" + String(index + 1)).c_str(),
|
||||
(char*)ds1820_addr[index].c_str(),
|
||||
will_Topic,
|
||||
"temperature",
|
||||
jsonTempf,
|
||||
"", "", "°F",
|
||||
0, "", "", true, "");
|
||||
# else
|
||||
createDiscovery("sensor",
|
||||
(char*)(String(OW_TOPIC) + "/" + ds1820_addr[index]).c_str(),
|
||||
(char*)String("DS12B20_" + String(index + 1)).c_str(),
|
||||
(char*)ds1820_addr[index].c_str(),
|
||||
will_Topic,
|
||||
"temperature",
|
||||
jsonTemp,
|
||||
"", "", "°C",
|
||||
0, "", "", true, "");
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void MeasureDS1820Temp()
|
||||
{
|
||||
void MeasureDS1820Temp() {
|
||||
static float persisted_temp[OW_MAX_SENSORS];
|
||||
static unsigned long timeDS1820 = 0;
|
||||
static boolean triggeredConversion = false;
|
||||
float current_temp[OW_MAX_SENSORS];
|
||||
|
||||
// trigger temperature conversion some time before actually
|
||||
|
||||
// trigger temperature conversion some time before actually
|
||||
// calling getTempC() to make reading temperatures non-blocking
|
||||
if (!triggeredConversion && (millis() > (timeDS1820 + (DS1820_INTERVAL_SEC*1000) - DS1820_CONV_TIME)))
|
||||
{
|
||||
if (!triggeredConversion && (millis() > (timeDS1820 + (DS1820_INTERVAL_SEC * 1000) - DS1820_CONV_TIME))) {
|
||||
Log.trace(F("DS1820: Trigger temperature conversion..." CR));
|
||||
ds1820.requestTemperatures();
|
||||
triggeredConversion = true;
|
||||
}
|
||||
else if (triggeredConversion && (millis() > (timeDS1820 + (DS1820_INTERVAL_SEC*1000))))
|
||||
{
|
||||
} else if (triggeredConversion && (millis() > (timeDS1820 + (DS1820_INTERVAL_SEC * 1000)))) {
|
||||
timeDS1820 = millis();
|
||||
triggeredConversion = false;
|
||||
|
||||
if (ds1820_count < 1)
|
||||
{
|
||||
|
||||
if (ds1820_count < 1) {
|
||||
Log.error(F("DS1820: Failed to identify any temperature sensors on 1-wire bus during setup!" CR));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Log.trace(F("DS1820: Reading temperature(s) from %d sensor(s)..." CR), ds1820_count);
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject &DS1820data = jsonBuffer.createObject();
|
||||
JsonObject& DS1820data = jsonBuffer.createObject();
|
||||
|
||||
for (uint8_t i=0; i < ds1820_count; i++)
|
||||
{
|
||||
current_temp[i] = round(ds1820.getTempC(ds1820_devices[i])*10)/10.0;
|
||||
if (current_temp[i] == -127)
|
||||
{
|
||||
Log.error(F("DS1820: Device %s currently disconnected!" CR), (char *)ds1820_addr[i].c_str() );
|
||||
}
|
||||
else if (DS1820_ALWAYS || current_temp[i] != persisted_temp[i])
|
||||
{
|
||||
for (uint8_t i = 0; i < ds1820_count; i++) {
|
||||
current_temp[i] = round(ds1820.getTempC(ds1820_devices[i]) * 10) / 10.0;
|
||||
if (current_temp[i] == -127) {
|
||||
Log.error(F("DS1820: Device %s currently disconnected!" CR), (char*)ds1820_addr[i].c_str());
|
||||
} else if (DS1820_ALWAYS || current_temp[i] != persisted_temp[i]) {
|
||||
if (DS1820_FAHRENHEIT) {
|
||||
Log.notice(F("DS1820: Temperature %s %d F" CR),
|
||||
(char *)ds1820_addr[i].c_str(),
|
||||
DallasTemperature::toFahrenheit(current_temp[i]));
|
||||
Log.notice(F("DS1820: Temperature %s %d F" CR),
|
||||
(char*)ds1820_addr[i].c_str(),
|
||||
DallasTemperature::toFahrenheit(current_temp[i]));
|
||||
DS1820data.set("temp", (float)DallasTemperature::toFahrenheit(current_temp[i]));
|
||||
DS1820data.set("unit", "F");
|
||||
} else {
|
||||
Log.notice(F("DS1820: Temperature %s %d C" CR),
|
||||
(char *)ds1820_addr[i].c_str(),
|
||||
current_temp[i]);
|
||||
Log.notice(F("DS1820: Temperature %s %d C" CR),
|
||||
(char*)ds1820_addr[i].c_str(),
|
||||
current_temp[i]);
|
||||
DS1820data.set("temp", (float)DallasTemperature::toFahrenheit(current_temp[i]));
|
||||
DS1820data.set("unit", "F");
|
||||
DS1820data.set("temp", (float)current_temp[i]);
|
||||
DS1820data.set("unit", "C");
|
||||
}
|
||||
if (DS1820_DETAILS) {
|
||||
if (DS1820_DETAILS) {
|
||||
DS1820data.set("type", ds1820_type[i]);
|
||||
DS1820data.set("res", ds1820_resolution[i] + String("bit" CR));
|
||||
DS1820data.set("addr", ds1820_addr[i]);
|
||||
}
|
||||
pub((char *)(String(OW_TOPIC) + "/" + ds1820_addr[i]).c_str(), DS1820data);
|
||||
pub((char*)(String(OW_TOPIC) + "/" + ds1820_addr[i]).c_str(), DS1820data);
|
||||
delay(10);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.trace(F("DS1820: Temperature for device %s didn't change, don't publish it." CR), (char *)ds1820_addr[i].c_str());
|
||||
} else {
|
||||
Log.trace(F("DS1820: Temperature for device %s didn't change, don't publish it." CR), (char*)ds1820_addr[i].c_str());
|
||||
}
|
||||
persisted_temp[i] = current_temp[i];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user