Merge branch 'development' into sm16716

This commit is contained in:
Gabor Simon 2019-01-29 17:38:27 +04:00 committed by GitHub
commit e0033fbaa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
110 changed files with 8336 additions and 1105 deletions

View File

@ -33,6 +33,9 @@ A Sonoff device is not a toy. It uses Mains AC so there is a danger of electrocu
We don't take any responsibility nor liability for using this software nor for the installation or any tips, advice, videos, etc. given by any member of this site or any related site.
### Note
Please do not ask to add devices where you can't provide a basic working configuration (other than sonoff). Since there are thousands of them..
### Quick Install
Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki.
@ -41,7 +44,7 @@ If you want to compile Sonoff-Tasmota yourself keep in mind the following:
- Only Flash Mode **DOUT** is supported. Do not use Flash Mode DIO / QIO / QOUT as it might seem to brick your device. See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki/Theo's-Tasmota-Tips) for background information.
- Sonoff-Tasmota uses a 1M linker script WITHOUT spiffs **1M (no SPIFFS)** for optimal code space. If you compile using ESP/Arduino library 2.3.0 then download the provided new linker script to your Arduino IDE or Platformio base folder. Later version of ESP/Arduino library already contain the correct linker script. See [Wiki > Prerequisite](https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisite).
- To make compile time changes to Sonoff-Tasmota it can use the ``user_config_override.h`` file. It assures keeping your settings when you download and compile a new version. To use ``user_config.override.h`` you will have to make a copy of the provided ``user_config.override_sample.h`` file and add your setting overrides. To enable the override file you will need to use a compile define as documented in the ``user_config_override_sample.h`` file.
- To make compile time changes to Sonoff-Tasmota it can use the ``user_config_override.h`` file. It assures keeping your settings when you download and compile a new version. To use ``user_config.override.h`` you will have to make a copy of the provided ``user_config_override_sample.h`` file and add your setting overrides. To enable the override file you will need to use a compile define as documented in the ``user_config_override_sample.h`` file.
### Version Information
- Sonoff-Tasmota provides all (Sonoff) modules in one file and starts with module Sonoff Basic.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
# ESP8266 platform
# ------------------------------
# For more info:
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
name=ESP8266 Boards (2.5.0-beta3)
version=2.5.0-beta3
runtime.tools.signing={runtime.platform.path}/tools/signing.py
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra
build.lwip_lib=-llwip_gcc
build.lwip_include=lwip/include
build.lwip_flags=-DLWIP_OPEN_SRC
build.vtable_flags=-DVTABLES_IN_FLASH
build.exception_flags=-fno-exceptions
build.stdcpp_lib=-lstdc++
#build.float=-u _printf_float -u _scanf_float
build.float=
build.led=
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
compiler.sdk.path={runtime.platform.path}/tools/sdk
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
compiler.c.cmd=xtensa-lx106-elf-gcc
compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections {build.exception_flags}
compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc
compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections {build.exception_flags}
compiler.as.cmd=xtensa-lx106-elf-as
compiler.ar.cmd=xtensa-lx106-elf-ar
compiler.ar.flags=cru
compiler.elf2hex.cmd=esptool
compiler.elf2hex.flags=
compiler.size.cmd=xtensa-lx106-elf-size
compiler.esptool.cmd=esptool
compiler.esptool.cmd.windows=esptool.exe
# This can be overriden in boards.txt
build.extra_flags=-DESP8266
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=
## generate file with git version number
## needs bash, git, and echo
recipe.hooks.core.prebuild.1.pattern=python "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
## windows-compatible version without git
recipe.hooks.core.prebuild.1.pattern.windows=cmd.exe /c rem cannot sign on windows
## Build the app.ld linker file
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.exception_flags} -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}"
## Create eeprom
recipe.objcopy.eep.pattern=
## Create hex
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
recipe.objcopy.hex.1.pattern="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
recipe.objcopy.hex.2.pattern=python "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
# No signing on Windows
recipe.objcopy.hex.1.pattern.windows="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
recipe.objcopy.hex.2.pattern.windows=
## Save hex
recipe.output.tmp_file={build.project_name}.bin
recipe.output.save_file={build.project_name}.{build.variant}.bin
## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.irom0\.text|\.text|\.data|\.rodata|)\s+([0-9]+).*
recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
#recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
# ------------------------------
tools.esptool.cmd=esptool
tools.esptool.cmd.windows=esptool.exe
tools.esptool.path={runtime.tools.esptool.path}
tools.esptool.network_cmd=python
tools.esptool.network_cmd.windows=python.exe
tools.esptool.upload.protocol=esp
tools.esptool.upload.params.verbose=-vv
tools.esptool.upload.params.quiet=
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" {upload.erase_cmd} -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"
tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
tools.mkspiffs.cmd=mkspiffs
tools.mkspiffs.cmd.windows=mkspiffs.exe
tools.mkspiffs.path={runtime.tools.mkspiffs.path}
tools.espupload.cmd=python
tools.espupload.cmd.windows=python.exe
tools.espupload.path={runtime.platform.path}/tools
tools.espupload.upload.protocol=espupload
tools.espupload.upload.params.verbose=
tools.espupload.upload.params.quiet=
tools.espupload.upload.pattern="{cmd}" "{path}/espupload.py" -f "{build.path}/{build.project_name}.bin"

View File

@ -65,7 +65,7 @@ build_flags = ${esp82xx_defaults.build_flags}
-DVTABLES_IN_FLASH
[core_2_5_0]
; *** Esp8266 core for Arduino version Core 2.5.0 beta tested for Tasmota
; *** Esp8266 core for Arduino version Core 2.5.0 beta3 tested for Tasmota
platform = https://github.com/Jason2866/platform-espressif8266.git#Tasmota
build_flags = ${esp82xx_defaults.build_flags}
-Wl,-Teagle.flash.1m.ld
@ -81,7 +81,7 @@ build_flags = ${esp82xx_defaults.build_flags}
-DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
-DVTABLES_IN_FLASH
-fno-exceptions
-lstdc++-nox
-lstdc++
[core_stage]
; *** Esp8266 core for Arduino version latest beta

623
sonoff/Parsing.cpp Normal file
View File

@ -0,0 +1,623 @@
/*
Parsing.cpp - HTTP request parsing.
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
*/
// Use patched Parsing.cpp to fix ALEXA parsing issue in v2.4.2
#include <core_version.h>
#if defined(ARDUINO_ESP8266_RELEASE_2_4_2)
#warning **** Tasmota is using v2.4.2 patched Parsing.cpp as planned ****
#include <Arduino.h>
#include "WiFiServer.h"
#include "WiFiClient.h"
#include "ESP8266WebServer.h"
#include "detail/mimetable.h"
//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DEBUG_OUTPUT DEBUG_ESP_PORT
#else
#define DEBUG_OUTPUT Serial
#endif
static const char Content_Type[] PROGMEM = "Content-Type";
static const char filename[] PROGMEM = "filename";
static char* readBytesWithTimeout(WiFiClient& client, size_t maxLength, size_t& dataLength, int timeout_ms)
{
char *buf = nullptr;
dataLength = 0;
while (dataLength < maxLength) {
int tries = timeout_ms;
size_t newLength;
while (!(newLength = client.available()) && tries--) delay(1);
if (!newLength) {
break;
}
if (!buf) {
buf = (char *) malloc(newLength + 1);
if (!buf) {
return nullptr;
}
}
else {
char* newBuf = (char *) realloc(buf, dataLength + newLength + 1);
if (!newBuf) {
free(buf);
return nullptr;
}
buf = newBuf;
}
client.readBytes(buf + dataLength, newLength);
dataLength += newLength;
buf[dataLength] = '\0';
}
return buf;
}
bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
// Read the first line of HTTP request
String req = client.readStringUntil('\r');
client.readStringUntil('\n');
//reset header value
for (int i = 0; i < _headerKeysCount; ++i) {
_currentHeaders[i].value =String();
}
// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Invalid request: ");
DEBUG_OUTPUT.println(req);
#endif
return false;
}
String methodStr = req.substring(0, addr_start);
String url = req.substring(addr_start + 1, addr_end);
String versionEnd = req.substring(addr_end + 8);
_currentVersion = atoi(versionEnd.c_str());
String searchStr = "";
int hasSearch = url.indexOf('?');
if (hasSearch != -1){
searchStr = url.substring(hasSearch + 1);
url = url.substring(0, hasSearch);
}
_currentUri = url;
_chunked = false;
HTTPMethod method = HTTP_GET;
if (methodStr == F("POST")) {
method = HTTP_POST;
} else if (methodStr == F("DELETE")) {
method = HTTP_DELETE;
} else if (methodStr == F("OPTIONS")) {
method = HTTP_OPTIONS;
} else if (methodStr == F("PUT")) {
method = HTTP_PUT;
} else if (methodStr == F("PATCH")) {
method = HTTP_PATCH;
}
_currentMethod = method;
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("method: ");
DEBUG_OUTPUT.print(methodStr);
DEBUG_OUTPUT.print(" url: ");
DEBUG_OUTPUT.print(url);
DEBUG_OUTPUT.print(" search: ");
DEBUG_OUTPUT.println(searchStr);
#endif
//attach handler
RequestHandler* handler;
for (handler = _firstHandler; handler; handler = handler->next()) {
if (handler->canHandle(_currentMethod, _currentUri))
break;
}
_currentHandler = handler;
String formData;
// below is needed only when POST type request
if (method == HTTP_POST || method == HTTP_PUT || method == HTTP_PATCH || method == HTTP_DELETE){
String boundaryStr;
String headerName;
String headerValue;
bool isForm = false;
bool isEncoded = false;
uint32_t contentLength = 0;
//parse headers
while(1){
req = client.readStringUntil('\r');
client.readStringUntil('\n');
if (req == "") break;//no moar headers
int headerDiv = req.indexOf(':');
if (headerDiv == -1){
break;
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 1);
headerValue.trim();
_collectHeader(headerName.c_str(),headerValue.c_str());
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("headerName: ");
DEBUG_OUTPUT.println(headerName);
DEBUG_OUTPUT.print("headerValue: ");
DEBUG_OUTPUT.println(headerValue);
#endif
if (headerName.equalsIgnoreCase(FPSTR(Content_Type))){
using namespace mime;
if (headerValue.startsWith(FPSTR(mimeTable[txt].mimeType))){
isForm = false;
} else if (headerValue.startsWith(F("application/x-www-form-urlencoded"))){
isForm = false;
isEncoded = true;
} else if (headerValue.startsWith(F("multipart/"))){
boundaryStr = headerValue.substring(headerValue.indexOf('=') + 1);
boundaryStr.replace("\"","");
isForm = true;
}
} else if (headerName.equalsIgnoreCase(F("Content-Length"))){
contentLength = headerValue.toInt();
} else if (headerName.equalsIgnoreCase(F("Host"))){
_hostHeader = headerValue;
}
}
if (!isForm){
size_t plainLength;
char* plainBuf = readBytesWithTimeout(client, contentLength, plainLength, HTTP_MAX_POST_WAIT);
if (plainLength < contentLength) {
free(plainBuf);
return false;
}
if (contentLength > 0) {
if(isEncoded){
//url encoded form
if (searchStr != "") searchStr += '&';
searchStr += plainBuf;
}
_parseArguments(searchStr);
if(!isEncoded||(0==_currentArgCount)){ // @20180124OF01: Workarround for Alexa Bug
//plain post json or other data
RequestArgument& arg = _currentArgs[_currentArgCount++];
arg.key = F("plain");
arg.value = String(plainBuf);
}
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Plain: ");
DEBUG_OUTPUT.println(plainBuf);
#endif
free(plainBuf);
} else {
// No content - but we can still have arguments in the URL.
_parseArguments(searchStr);
}
}
if (isForm){
_parseArguments(searchStr);
if (!_parseForm(client, boundaryStr, contentLength)) {
return false;
}
}
} else {
String headerName;
String headerValue;
//parse headers
while(1){
req = client.readStringUntil('\r');
client.readStringUntil('\n');
if (req == "") break;//no moar headers
int headerDiv = req.indexOf(':');
if (headerDiv == -1){
break;
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
_collectHeader(headerName.c_str(),headerValue.c_str());
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("headerName: ");
DEBUG_OUTPUT.println(headerName);
DEBUG_OUTPUT.print("headerValue: ");
DEBUG_OUTPUT.println(headerValue);
#endif
if (headerName.equalsIgnoreCase("Host")){
_hostHeader = headerValue;
}
}
_parseArguments(searchStr);
}
client.flush();
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Request: ");
DEBUG_OUTPUT.println(url);
DEBUG_OUTPUT.print(" Arguments: ");
DEBUG_OUTPUT.println(searchStr);
#endif
return true;
}
bool ESP8266WebServer::_collectHeader(const char* headerName, const char* headerValue) {
for (int i = 0; i < _headerKeysCount; i++) {
if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) {
_currentHeaders[i].value=headerValue;
return true;
}
}
return false;
}
void ESP8266WebServer::_parseArguments(String data) {
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args: ");
DEBUG_OUTPUT.println(data);
#endif
if (_currentArgs)
delete[] _currentArgs;
_currentArgs = 0;
if (data.length() == 0) {
_currentArgCount = 0;
_currentArgs = new RequestArgument[1];
return;
}
_currentArgCount = 1;
for (int i = 0; i < (int)data.length(); ) {
i = data.indexOf('&', i);
if (i == -1)
break;
++i;
++_currentArgCount;
}
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args count: ");
DEBUG_OUTPUT.println(_currentArgCount);
#endif
_currentArgs = new RequestArgument[_currentArgCount+1];
int pos = 0;
int iarg;
for (iarg = 0; iarg < _currentArgCount;) {
int equal_sign_index = data.indexOf('=', pos);
int next_arg_index = data.indexOf('&', pos);
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("pos ");
DEBUG_OUTPUT.print(pos);
DEBUG_OUTPUT.print("=@ ");
DEBUG_OUTPUT.print(equal_sign_index);
DEBUG_OUTPUT.print(" &@ ");
DEBUG_OUTPUT.println(next_arg_index);
#endif
if ((equal_sign_index == -1) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1))) {
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("arg missing value: ");
DEBUG_OUTPUT.println(iarg);
#endif
if (next_arg_index == -1)
break;
pos = next_arg_index + 1;
continue;
}
RequestArgument& arg = _currentArgs[iarg];
arg.key = urlDecode(data.substring(pos, equal_sign_index));
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("arg ");
DEBUG_OUTPUT.print(iarg);
DEBUG_OUTPUT.print(" key: ");
DEBUG_OUTPUT.print(arg.key);
DEBUG_OUTPUT.print(" value: ");
DEBUG_OUTPUT.println(arg.value);
#endif
++iarg;
if (next_arg_index == -1)
break;
pos = next_arg_index + 1;
}
_currentArgCount = iarg;
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args count: ");
DEBUG_OUTPUT.println(_currentArgCount);
#endif
}
void ESP8266WebServer::_uploadWriteByte(uint8_t b){
if (_currentUpload->currentSize == HTTP_UPLOAD_BUFLEN){
if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, *_currentUpload);
_currentUpload->totalSize += _currentUpload->currentSize;
_currentUpload->currentSize = 0;
}
_currentUpload->buf[_currentUpload->currentSize++] = b;
}
uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
int res = client.read();
if(res == -1){
while(!client.available() && client.connected())
yield();
res = client.read();
}
return (uint8_t)res;
}
bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
(void) len;
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Parse Form: Boundary: ");
DEBUG_OUTPUT.print(boundary);
DEBUG_OUTPUT.print(" Length: ");
DEBUG_OUTPUT.println(len);
#endif
String line;
int retry = 0;
do {
line = client.readStringUntil('\r');
++retry;
} while (line.length() == 0 && retry < 3);
client.readStringUntil('\n');
//start reading the form
if (line == ("--"+boundary)){
RequestArgument* postArgs = new RequestArgument[32];
int postArgsLen = 0;
while(1){
String argName;
String argValue;
String argType;
String argFilename;
bool argIsFile = false;
line = client.readStringUntil('\r');
client.readStringUntil('\n');
if (line.length() > 19 && line.substring(0, 19).equalsIgnoreCase(F("Content-Disposition"))){
int nameStart = line.indexOf('=');
if (nameStart != -1){
argName = line.substring(nameStart+2);
nameStart = argName.indexOf('=');
if (nameStart == -1){
argName = argName.substring(0, argName.length() - 1);
} else {
argFilename = argName.substring(nameStart+2, argName.length() - 1);
argName = argName.substring(0, argName.indexOf('"'));
argIsFile = true;
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg FileName: ");
DEBUG_OUTPUT.println(argFilename);
#endif
//use GET to set the filename if uploading using blob
if (argFilename == F("blob") && hasArg(FPSTR(filename)))
argFilename = arg(FPSTR(filename));
}
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg Name: ");
DEBUG_OUTPUT.println(argName);
#endif
using namespace mime;
argType = FPSTR(mimeTable[txt].mimeType);
line = client.readStringUntil('\r');
client.readStringUntil('\n');
if (line.length() > 12 && line.substring(0, 12).equalsIgnoreCase(FPSTR(Content_Type))){
argType = line.substring(line.indexOf(':')+2);
//skip next line
client.readStringUntil('\r');
client.readStringUntil('\n');
}
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg Type: ");
DEBUG_OUTPUT.println(argType);
#endif
if (!argIsFile){
while(1){
line = client.readStringUntil('\r');
client.readStringUntil('\n');
if (line.startsWith("--"+boundary)) break;
if (argValue.length() > 0) argValue += "\n";
argValue += line;
}
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg Value: ");
DEBUG_OUTPUT.println(argValue);
DEBUG_OUTPUT.println();
#endif
RequestArgument& arg = postArgs[postArgsLen++];
arg.key = argName;
arg.value = argValue;
if (line == ("--"+boundary+"--")){
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("Done Parsing POST");
#endif
break;
}
} else {
_currentUpload.reset(new HTTPUpload());
_currentUpload->status = UPLOAD_FILE_START;
_currentUpload->name = argName;
_currentUpload->filename = argFilename;
_currentUpload->type = argType;
_currentUpload->totalSize = 0;
_currentUpload->currentSize = 0;
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Start File: ");
DEBUG_OUTPUT.print(_currentUpload->filename);
DEBUG_OUTPUT.print(" Type: ");
DEBUG_OUTPUT.println(_currentUpload->type);
#endif
if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, *_currentUpload);
_currentUpload->status = UPLOAD_FILE_WRITE;
uint8_t argByte = _uploadReadByte(client);
readfile:
while(argByte != 0x0D){
if (!client.connected()) return _parseFormUploadAborted();
_uploadWriteByte(argByte);
argByte = _uploadReadByte(client);
}
argByte = _uploadReadByte(client);
if (!client.connected()) return _parseFormUploadAborted();
if (argByte == 0x0A){
argByte = _uploadReadByte(client);
if (!client.connected()) return _parseFormUploadAborted();
if ((char)argByte != '-'){
//continue reading the file
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
goto readfile;
} else {
argByte = _uploadReadByte(client);
if (!client.connected()) return _parseFormUploadAborted();
if ((char)argByte != '-'){
//continue reading the file
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
goto readfile;
}
}
uint8_t endBuf[boundary.length()];
client.readBytes(endBuf, boundary.length());
if (strstr((const char*)endBuf, boundary.c_str()) != NULL){
if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, *_currentUpload);
_currentUpload->totalSize += _currentUpload->currentSize;
_currentUpload->status = UPLOAD_FILE_END;
if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, *_currentUpload);
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("End File: ");
DEBUG_OUTPUT.print(_currentUpload->filename);
DEBUG_OUTPUT.print(" Type: ");
DEBUG_OUTPUT.print(_currentUpload->type);
DEBUG_OUTPUT.print(" Size: ");
DEBUG_OUTPUT.println(_currentUpload->totalSize);
#endif
line = client.readStringUntil(0x0D);
client.readStringUntil(0x0A);
if (line == "--"){
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("Done Parsing POST");
#endif
break;
}
continue;
} else {
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
_uploadWriteByte((uint8_t)('-'));
uint32_t i = 0;
while(i < boundary.length()){
_uploadWriteByte(endBuf[i++]);
}
argByte = _uploadReadByte(client);
goto readfile;
}
} else {
_uploadWriteByte(0x0D);
goto readfile;
}
break;
}
}
}
}
int iarg;
int totalArgs = ((32 - postArgsLen) < _currentArgCount)?(32 - postArgsLen):_currentArgCount;
for (iarg = 0; iarg < totalArgs; iarg++){
RequestArgument& arg = postArgs[postArgsLen++];
arg.key = _currentArgs[iarg].key;
arg.value = _currentArgs[iarg].value;
}
if (_currentArgs) delete[] _currentArgs;
_currentArgs = new RequestArgument[postArgsLen];
for (iarg = 0; iarg < postArgsLen; iarg++){
RequestArgument& arg = _currentArgs[iarg];
arg.key = postArgs[iarg].key;
arg.value = postArgs[iarg].value;
}
_currentArgCount = iarg;
if (postArgs)
delete[] postArgs;
return true;
}
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Error: line: ");
DEBUG_OUTPUT.println(line);
#endif
return false;
}
String ESP8266WebServer::urlDecode(const String& text)
{
String decoded = "";
char temp[] = "0x00";
unsigned int len = text.length();
unsigned int i = 0;
while (i < len)
{
char decodedChar;
char encodedChar = text.charAt(i++);
if ((encodedChar == '%') && (i + 1 < len))
{
temp[2] = text.charAt(i++);
temp[3] = text.charAt(i++);
decodedChar = strtol(temp, NULL, 16);
}
else {
if (encodedChar == '+')
{
decodedChar = ' ';
}
else {
decodedChar = encodedChar; // normal ascii char
}
}
decoded += decodedChar;
}
return decoded;
}
bool ESP8266WebServer::_parseFormUploadAborted(){
_currentUpload->status = UPLOAD_FILE_ABORTED;
if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, *_currentUpload);
return false;
}
#endif // ARDUINO_ESP8266_RELEASE

View File

@ -1,4 +1,20 @@
/* 6.4.1.9 20190115
/* 6.4.1.12 20190128
* Change code use of boolean to bool and byte to uint8_t
* Change code uint8_t flags to bool flags
*
* 6.4.1.11 20190124
* Remove command SetOption14 as it has been superseded by command Interlock
* Remove command SetOption63 as it has been superseded by command Interlock
* Add command Interlock 0 / 1 / 1,2 3,4 .. to control interlock ON/OFF and add up to 8 relays in 1 to 4 interlock groups (#5014)
* Add core version conditional compile options to provided PWM files (#4917)
* Add support for inverted buttons and inverted buttons without pullup (#4914)
*
* 6.4.1.10 20190121
* Fix Hass discovery of MHZ19(B) sensors (#4992)
* Fix Hass Software Watchdog exception during discovery (#4988)
* Add support for MAX44009 Ambient Light sensor (#4907)
*
* 6.4.1.9 20190115
* Add support for Mi LED Desk Lamp with rotary switch (#4887)
* Fix mDNS addService (#4938, #4951)
* Fix allowable MAX_RULE_VARS to 16 (#4933)

View File

@ -19,10 +19,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Use PWM from core 2.4.0 as all other version produce LED flickering when settings are saved to flash. Still true for 2.5.0
//#include <core_version.h>
//#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
//#warning **** Tasmota is using v2.4.0 timer.c as planned ****
// Use PWM from core 2.4.0 as all versions below 2.5.0-beta3 produce LED flickering when settings are saved to flash
#include <core_version.h>
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
#warning **** Tasmota is using v2.4.0 timer.c as planned ****
#include "wiring_private.h"
#include "pins_arduino.h"
@ -108,4 +108,4 @@ void ICACHE_RAM_ATTR timer0_detachInterrupt(void) {
ETS_CCOMPARE0_DISABLE();
}
//#endif // ARDUINO_ESP8266_RELEASE
#endif // ARDUINO_ESP8266_RELEASE

View File

@ -19,10 +19,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Use PWM from core 2.4.0 as all other version produce LED flickering when settings are saved to flash. Still true for 2.5.0
//#include <core_version.h>
//#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
//#warning **** Tasmota is using v2.4.0 wiring_digital.c as planned ****
// Use PWM from core 2.4.0 as all versions below 2.5.0-beta3 produce LED flickering when settings are saved to flash
#include <core_version.h>
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
#warning **** Tasmota is using v2.4.0 wiring_digital.c as planned ****
#define ARDUINO_MAIN
#include "wiring_private.h"
@ -214,4 +214,4 @@ extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead")
extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt")));
extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt")));
//#endif // ARDUINO_ESP8266_RELEASE
#endif // ARDUINO_ESP8266_RELEASE

View File

@ -19,10 +19,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Use PWM from core 2.4.0 as all other version produce flicker when settings are saved to flash. Still true for 2.5.0
//#include <core_version.h>
//#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
//#warning **** Tasmota is using v2.4.0 wiring_pwm.c as planned ****
// Use PWM from core 2.4.0 as all versions below 2.5.0-beta3 produce LED flickering when settings are saved to flash
#include <core_version.h>
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
#warning **** Tasmota is using v2.4.0 wiring_pwm.c as planned ****
#include "wiring_private.h"
#include "pins_arduino.h"
@ -226,4 +226,4 @@ extern void analogWrite(uint8_t pin, int val) __attribute__ ((weak, alias("__ana
extern void analogWriteFreq(uint32_t freq) __attribute__ ((weak, alias("__analogWriteFreq")));
extern void analogWriteRange(uint32_t range) __attribute__ ((weak, alias("__analogWriteRange")));
//#endif // ARDUINO_ESP8266_RELEASE
#endif // ARDUINO_ESP8266_RELEASE

View File

@ -72,6 +72,7 @@
#define D_JSON_FROM "from"
#define D_JSON_GAS "Gas"
#define D_JSON_GATEWAY "Gateway"
#define D_JSON_GROUPS "Groups"
#define D_JSON_HEAPSIZE "Heap"
#define D_JSON_HIGH "High"
#define D_JSON_HOST_NOT_FOUND "Host not found"
@ -92,6 +93,7 @@
#define D_JSON_MAC "Mac"
#define D_JSON_MASK "Mask"
#define D_JSON_MINIMAL "minimal"
#define D_JSON_MODEL "Model"
#define D_JSON_NO "No"
#define D_JSON_NOISE "Noise"
#define D_JSON_NONE "None"
@ -240,6 +242,7 @@
#define D_WCFG_6_SERIAL "Serial"
#define D_CMND_FRIENDLYNAME "FriendlyName"
#define D_CMND_SWITCHMODE "SwitchMode"
#define D_CMND_INTERLOCK "Interlock"
#define D_CMND_TELEPERIOD "TelePeriod"
#define D_CMND_RESTART "Restart"
#define D_JSON_ONE_TO_RESTART "1 to restart"

View File

@ -62,7 +62,7 @@
#define D_BRIGHTLIGHT "Jasny"
#define D_BSSID "BSSId"
#define D_BUTTON "Przycisk"
#define D_BY "przez" // Written by me
#define D_BY "by" // Written by me
#define D_BYTES "Bajtow"
#define D_CELSIUS "Celsiusza"
#define D_CHANNEL "Kanał"
@ -139,7 +139,7 @@
#define D_RESTART_REASON "Przyczyna restartu"
#define D_RESTORE "Przywracanie"
#define D_RETAINED "Zachowane"
#define D_RULE "Rule"
#define D_RULE "Reguła"
#define D_SAVE "Zapisz"
#define D_SENSOR "Czujnik"
#define D_SSID "SSID"
@ -235,7 +235,7 @@
#define D_BUTTON_TOGGLE "Przełącznik"
#define D_CONFIGURATION "Konfiguracja"
#define D_INFORMATION "Informacje"
#define D_FIRMWARE_UPGRADE "Uaktualnienie oprogramowania"
#define D_FIRMWARE_UPGRADE "Aktualizacja oprogramowania"
#define D_CONSOLE "Konsola"
#define D_CONFIRM_RESTART "Potwierdź restart"
@ -248,10 +248,10 @@
#define D_CONFIRM_RESET_CONFIGURATION "Potwierdź reset ustawień"
#define D_RESET_CONFIGURATION "Reset ustawień"
#define D_BACKUP_CONFIGURATION "Kopia ustawień"
#define D_RESTORE_CONFIGURATION "Przywrócenie ustawień"
#define D_RESTORE_CONFIGURATION "Przywracanie ustawień"
#define D_MAIN_MENU "Menu główne"
#define D_MODULE_PARAMETERS "Parametery modułu"
#define D_MODULE_PARAMETERS "Parametry modułu"
#define D_MODULE_TYPE "Typ modułu"
#define D_PULLUP_ENABLE "No Button/Switch pull-up"
#define D_GPIO "GPIO"
@ -274,23 +274,23 @@
#define D_AP2_SSID "AP2 SSID"
#define D_AP2_PASSWORD "Hasło AP2"
#define D_MQTT_PARAMETERS "Parametery MQTT"
#define D_MQTT_PARAMETERS "Parametry MQTT"
#define D_CLIENT "Klient"
#define D_FULL_TOPIC "Pełen temat"
#define D_FULL_TOPIC "Pełny temat"
#define D_LOGGING_PARAMETERS "Opcje dziennika"
#define D_SERIAL_LOG_LEVEL "Serial poziom dziennika"
#define D_WEB_LOG_LEVEL "Web poziom dziennika"
#define D_SYS_LOG_LEVEL "System poziom dziennika"
#define D_MORE_DEBUG "Więcej informacji debugujacych"
#define D_MORE_DEBUG "Więcej informacji debug"
#define D_SYSLOG_HOST "Syslog host"
#define D_SYSLOG_PORT "Syslog port"
#define D_TELEMETRY_PERIOD "Okres telemetrii"
#define D_OTHER_PARAMETERS "Inne parametery"
#define D_OTHER_PARAMETERS "Inne parametry"
#define D_WEB_ADMIN_PASSWORD "Hasło administratora Web"
#define D_MQTT_ENABLE "MQTT aktywne"
#define D_FRIENDLY_NAME "Przyjazna nazwa"
#define D_FRIENDLY_NAME "Twoja nazwa"
#define D_BELKIN_WEMO "Belkin WeMo"
#define D_HUE_BRIDGE "Hue Bridge"
#define D_SINGLE_DEVICE "single device"
@ -391,18 +391,18 @@
#define D_DOMOTICZ_UPDATE_TIMER "Zaktualizuj czasomierz"
// xdrv_09_timers.ino
#define D_CONFIGURE_TIMER "Skonfiguruj harmonogram"
#define D_CONFIGURE_TIMER "Konfiguruj harmonogram"
#define D_TIMER_PARAMETERS "Parametry harmonogramów"
#define D_TIMER_ENABLE "Włącz Harmonogramy"
#define D_TIMER_ARM "Włącz"
#define D_TIMER_TIME "Czas"
#define D_TIMER_TIME "Według godziny"
#define D_TIMER_DAYS "Dni"
#define D_TIMER_REPEAT "Powtarzaj"
#define D_TIMER_OUTPUT "Wyjście"
#define D_TIMER_ACTION "Akcja"
// xdrv_10_knx.ino
#define D_CONFIGURE_KNX "Skonfiguruj KNX"
#define D_CONFIGURE_KNX "Konfiguruj KNX"
#define D_KNX_PARAMETERS "Parametry KNX"
#define D_KNX_GENERAL_CONFIG "Ogólne"
#define D_KNX_PHYSICAL_ADDRESS "Adres Fizyczny"

View File

@ -328,6 +328,7 @@
// #define USE_PN532_I2C // Enable PN532 - Near Field Communication (NFC) controller (+1k7 code, 164 bytes of mem)
// #define USE_PN532_DATA_FUNCTION // Enable PN532 DATA Usage using Sensor15 command (+1k6 code, 316 bytes of mem)
// #define USE_PN532_CAUSE_EVENTS // Enable PN532 driver to cause event's on card read in addition to immediate telemetry (+64 bytes code, 48 bytes mem)
// #define USE_MAX44009 // Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
// #define USE_DISPLAY // Add I2C Display Support (+2k code)
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0
@ -342,7 +343,6 @@
#define MTX_ADDRESS6 0x76 // [DisplayAddress6] I2C address of sixth 8x8 matrix module
#define MTX_ADDRESS7 0x00 // [DisplayAddress7] I2C address of seventh 8x8 matrix module
#define MTX_ADDRESS8 0x00 // [DisplayAddress8] I2C address of eigth 8x8 matrix module
#endif // USE_I2C
// -- SPI sensors ---------------------------------

View File

@ -76,7 +76,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t sleep_normal : 1; // bit 10 (v6.3.0.15) - SetOption60 - Enable normal sleep instead of dynamic sleep
uint32_t button_switch_force_local : 1;// bit 11 (v6.3.0.16) - SetOption61 - Force local operation when button/switch topic is set
uint32_t no_pullup : 1; // bit 12 (v6.4.1.7) - SetOption62 - Force no pull-up (0 = (no)pull-up, 1 = no pull-up)
uint32_t split_interlock : 1; // bit 13 (v6.4.1.8) - SetOption63 - Split interlock on CH4
uint32_t spare13 : 1;
uint32_t spare14 : 1;
uint32_t spare15 : 1;
uint32_t spare16 : 1;
@ -183,21 +183,21 @@ struct SYSCFG {
char ota_url[101]; // 017
char mqtt_prefix[3][11]; // 07C
uint8_t baudrate; // 09D
byte seriallog_level; // 09E
uint8_t seriallog_level; // 09E
uint8_t sta_config; // 09F
byte sta_active; // 0A0
uint8_t sta_active; // 0A0
char sta_ssid[2][33]; // 0A1 - Keep together with sta_pwd as being copied as one chunck with reset 4/5
char sta_pwd[2][65]; // 0E3 - Keep together with sta_ssid as being copied as one chunck with reset 4/5
char hostname[33]; // 165
char syslog_host[33]; // 186
uint8_t rule_stop; // 1A7
uint16_t syslog_port; // 1A8
byte syslog_level; // 1AA
uint8_t syslog_level; // 1AA
uint8_t webserver; // 1AB
byte weblog_level; // 1AC
uint8_t weblog_level; // 1AC
uint8_t mqtt_fingerprint[2][20]; // 1AD
byte free_1D5[20]; // 1D5 Free since 5.12.0e
uint8_t free_1D5[20]; // 1D5 Free since 5.12.0e
char mqtt_host[33]; // 1E9
uint16_t mqtt_port; // 20A
@ -271,9 +271,7 @@ struct SYSCFG {
uint8_t ws_color[4][3]; // 475
uint8_t ws_width[3]; // 481
myio my_gp; // 484
byte free_495[1]; // 495
uint8_t test_step; // 495
uint16_t light_pixels; // 496
uint8_t light_color[5]; // 498
uint8_t light_correction; // 49D
@ -284,15 +282,13 @@ struct SYSCFG {
uint8_t light_speed; // 4A2
uint8_t light_scheme; // 4A3
uint8_t light_width; // 4A4
byte knx_GA_registered; // 4A5 Number of Group Address to read
uint8_t knx_GA_registered; // 4A5 Number of Group Address to read
uint16_t light_wakeup; // 4A6
byte knx_CB_registered; // 4A8 Number of Group Address to write
uint8_t knx_CB_registered; // 4A8 Number of Group Address to write
char web_password[33]; // 4A9
uint8_t ex_switchmode[4]; // 4CA Free since 6.0.0a
uint8_t interlock[MAX_INTERLOCKS]; // 4CA
char ntp_server[3][33]; // 4CE
byte ina219_mode; // 531
uint8_t ina219_mode; // 531
uint16_t pulse_timer[MAX_PULSETIMERS]; // 532
uint16_t button_debounce; // 542
uint32_t ip_address[4]; // 544
@ -311,17 +307,17 @@ struct SYSCFG {
uint16_t knx_physsical_addr; // 6B8 (address_t is a uint16_t)
uint16_t knx_GA_addr[MAX_KNX_GA]; // 6BA (address_t is a uint16_t) x KNX_max_GA
uint16_t knx_CB_addr[MAX_KNX_CB]; // 6CE (address_t is a uint16_t) x KNX_max_CB
byte knx_GA_param[MAX_KNX_GA]; // 6E2 Type of Input (relay changed, button pressed, sensor read <-teleperiod)
byte knx_CB_param[MAX_KNX_CB]; // 6EC Type of Output (set relay, toggle relay, reply sensor value)
uint8_t knx_GA_param[MAX_KNX_GA]; // 6E2 Type of Input (relay changed, button pressed, sensor read <-teleperiod)
uint8_t knx_CB_param[MAX_KNX_CB]; // 6EC Type of Output (set relay, toggle relay, reply sensor value)
Mcp230xxCfg mcp230xx_config[16]; // 6F6
uint8_t mcp230xx_int_prio; // 716
byte free_717[1]; // 717
uint8_t free_717[1]; // 717
uint16_t mcp230xx_int_timer; // 718
uint8_t rgbwwTable[5]; // 71A
byte free_71F[117]; // 71F
uint8_t free_71F[117]; // 71F
uint32_t drivers[3]; // 794
uint32_t monitors; // 7A0
@ -330,7 +326,7 @@ struct SYSCFG {
uint32_t energy_kWhtotal_time; // 7B4
unsigned long weight_item; // 7B8 Weight of one item in gram * 10
byte free_7BC[2]; // 7BC
uint8_t free_7BC[2]; // 7BC
uint16_t weight_max; // 7BE Total max weight in kilogram
unsigned long weight_reference; // 7C0 Reference weight in gram
@ -350,7 +346,7 @@ struct RTCRBT {
struct RTCMEM {
uint16_t valid; // 290 (RTC memory offset 100)
byte oswatch_blocked_loop; // 292
uint8_t oswatch_blocked_loop; // 292
uint8_t ota_loader; // 293
unsigned long energy_kWhtoday; // 294
unsigned long energy_kWhtotal; // 298
@ -380,7 +376,7 @@ struct XDRVMAILBOX {
uint16_t data_len;
uint16_t payload16;
int16_t payload;
uint8_t grpflg;
bool grpflg;
uint8_t notused;
char *topic;
char *data;

View File

@ -97,7 +97,7 @@ void RtcSettingsLoad(void)
RtcSettings.valid = RTC_MEM_VALID;
RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday;
RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal;
for (byte i = 0; i < MAX_COUNTERS; i++) {
for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
RtcSettings.pulse_counter[i] = Settings.pulse_counter[i];
}
RtcSettings.power = Settings.power;
@ -106,7 +106,7 @@ void RtcSettingsLoad(void)
rtc_settings_crc = GetRtcSettingsCrc();
}
boolean RtcSettingsValid(void)
bool RtcSettingsValid(void)
{
return (RTC_MEM_VALID == RtcSettings.valid);
}
@ -147,7 +147,7 @@ void RtcRebootLoad(void)
rtc_reboot_crc = GetRtcRebootCrc();
}
boolean RtcRebootValid(void)
bool RtcRebootValid(void)
{
return (RTC_MEM_VALID == RtcReboot.valid);
}
@ -381,7 +381,7 @@ uint32_t GetSettingsAddress(void)
return settings_location * SPI_FLASH_SEC_SIZE;
}
void SettingsSave(byte rotate)
void SettingsSave(uint8_t rotate)
{
/* Save configuration in eeprom or one of 7 slots below
*
@ -430,7 +430,7 @@ void SettingsSave(byte rotate)
}
if (!stop_flash_rotate && rotate) {
for (byte i = 1; i < CFG_ROTATES; i++) {
for (uint8_t i = 1; i < CFG_ROTATES; i++) {
ESP.flashEraseSector(settings_location -i); // Delete previous configurations by resetting to 0xFF
delay(1);
}
@ -457,7 +457,7 @@ void SettingsLoad(void)
bool bad_crc = false;
settings_location = SETTINGS_LOCATION +1;
for (byte i = 0; i < CFG_ROTATES; i++) {
for (uint8_t i = 0; i < CFG_ROTATES; i++) {
settings_location--;
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
ESP.flashRead((settings_location -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_SettingsH, sizeof(SYSCFGH));
@ -495,7 +495,7 @@ void SettingsErase(uint8_t type)
_sectorEnd = SETTINGS_LOCATION +5;
}
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
bool _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_ERASE " %d " D_UNIT_SECTORS), _sectorEnd - _sectorStart);
AddLog(LOG_LEVEL_DEBUG);
@ -574,8 +574,9 @@ void SettingsDefaultSet2(void)
// Module
// Settings.flag.interlock = 0;
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
Settings.module = MODULE;
// for (byte i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
// for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
strlcpy(Settings.friendlyname[0], FRIENDLY_NAME, sizeof(Settings.friendlyname[0]));
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
@ -590,7 +591,7 @@ void SettingsDefaultSet2(void)
Settings.blinkcount = APP_BLINKCOUNT;
Settings.ledstate = APP_LEDSTATE;
Settings.pulse_timer[0] = APP_PULSETIME;
// for (byte i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; }
// for (uint8_t i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; }
// Serial
Settings.baudrate = APP_BAUDRATE / 1200;
@ -630,7 +631,7 @@ void SettingsDefaultSet2(void)
Settings.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
// Switch
for (byte i = 0; i < MAX_SWITCHES; i++) { Settings.switchmode[i] = SWITCH_MODE; }
for (uint8_t i = 0; i < MAX_SWITCHES; i++) { Settings.switchmode[i] = SWITCH_MODE; }
// MQTT
Settings.flag.mqtt_enabled = MQTT_USE;
@ -664,12 +665,12 @@ void SettingsDefaultSet2(void)
char fingerprint[60];
strlcpy(fingerprint, MQTT_FINGERPRINT1, sizeof(fingerprint));
char *p = fingerprint;
for (byte i = 0; i < 20; i++) {
for (uint8_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16);
}
strlcpy(fingerprint, MQTT_FINGERPRINT2, sizeof(fingerprint));
p = fingerprint;
for (byte i = 0; i < 20; i++) {
for (uint8_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[1][i] = strtol(p, &p, 16);
}
Settings.tele_period = TELE_PERIOD;
@ -705,17 +706,17 @@ void SettingsDefaultSet2(void)
RtcSettings.energy_kWhtotal = 0;
// RF Bridge
// for (byte i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
// for (uint8_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
// Domoticz
Settings.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
// for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
// for (uint8_t i = 0; i < MAX_DOMOTICZ_IDX; i++) {
// Settings.domoticz_relay_idx[i] = 0;
// Settings.domoticz_key_idx[i] = 0;
// Settings.domoticz_switch_idx[i] = 0;
// }
// for (byte i = 0; i < MAX_DOMOTICZ_SNS_IDX; i++) {
// for (uint8_t i = 0; i < MAX_DOMOTICZ_SNS_IDX; i++) {
// Settings.domoticz_sensor_idx[i] = 0;
// }
@ -730,7 +731,7 @@ void SettingsDefaultSet2(void)
// Rules
// Settings.rule_enabled = 0;
// Settings.rule_once = 0;
// for (byte i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
// for (uint8_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
Settings.flag2.calc_resolution = CALC_RESOLUTION;
// Home Assistant
@ -748,7 +749,7 @@ void SettingsDefaultSet2(void)
//Settings.flag.decimal_text = 0;
Settings.pwm_frequency = PWM_FREQ;
Settings.pwm_range = PWM_RANGE;
for (byte i = 0; i < MAX_PWMS; i++) {
for (uint8_t i = 0; i < MAX_PWMS; i++) {
Settings.light_color[i] = 255;
// Settings.pwm_value[i] = 0;
}
@ -777,8 +778,8 @@ void SettingsDefaultSet2(void)
strlcpy(Settings.ntp_server[0], NTP_SERVER1, sizeof(Settings.ntp_server[0]));
strlcpy(Settings.ntp_server[1], NTP_SERVER2, sizeof(Settings.ntp_server[1]));
strlcpy(Settings.ntp_server[2], NTP_SERVER3, sizeof(Settings.ntp_server[2]));
for (byte j = 0; j < 3; j++) {
for (byte i = 0; i < strlen(Settings.ntp_server[j]); i++) {
for (uint8_t j = 0; j < 3; j++) {
for (uint8_t i = 0; i < strlen(Settings.ntp_server[j]); i++) {
if (Settings.ntp_server[j][i] == ',') {
Settings.ntp_server[j][i] = '.';
}
@ -791,7 +792,7 @@ void SettingsDefaultSet2(void)
Settings.button_debounce = KEY_DEBOUNCE_TIME;
Settings.switch_debounce = SWITCH_DEBOUNCE_TIME;
for (byte j = 0; j < 5; j++) {
for (uint8_t j = 0; j < 5; j++) {
Settings.rgbwwTable[j] = 255;
}
@ -872,7 +873,7 @@ void SettingsDelta(void)
if (Settings.version != VERSION) { // Fix version dependent changes
if (Settings.version < 0x05050000) {
for (byte i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
for (uint8_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
}
if (Settings.version < 0x05080000) {
@ -894,12 +895,12 @@ void SettingsDelta(void)
Settings.altitude = 0;
}
if (Settings.version < 0x0508000B) {
for (byte i = 0; i < sizeof(Settings.my_gp); i++) { // Move GPIO_LEDs
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) { // Move GPIO_LEDs
if ((Settings.my_gp.io[i] >= 25) && (Settings.my_gp.io[i] <= 32)) { // Was GPIO_LED1
Settings.my_gp.io[i] += 23; // Move GPIO_LED1
}
}
for (byte i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
for (uint8_t i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
Settings.pwm_value[i] = Settings.pulse_timer[4 +i];
Settings.pulse_timer[4 +i] = 0;
}
@ -930,7 +931,7 @@ void SettingsDelta(void)
char fingerprint[60];
memcpy(fingerprint, Settings.mqtt_fingerprint, sizeof(fingerprint));
char *p = fingerprint;
for (byte i = 0; i < 20; i++) {
for (uint8_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16);
Settings.mqtt_fingerprint[1][i] = Settings.mqtt_fingerprint[0][i];
}
@ -965,7 +966,7 @@ void SettingsDelta(void)
SettingsDefaultSet_5_13_1c();
}
if (Settings.version < 0x050E0002) {
for (byte i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
for (uint8_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
Settings.rule_enabled = Settings.flag.mqtt_serial_raw; // Was rules_enabled until 5.14.0b
Settings.rule_once = Settings.flag.pressure_conversion; // Was rules_once until 5.14.0b
}
@ -974,14 +975,14 @@ void SettingsDelta(void)
Settings.cfg_crc = GetSettingsCrc();
}
if (Settings.version < 0x06000002) {
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (i < 4) {
Settings.switchmode[i] = Settings.ex_switchmode[i];
Settings.switchmode[i] = Settings.interlock[i];
} else {
Settings.switchmode[i] = SWITCH_MODE;
}
}
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1
Settings.my_gp.io[i] += 4;
}
@ -1000,7 +1001,7 @@ void SettingsDelta(void)
Settings.switch_debounce = SWITCH_DEBOUNCE_TIME;
}
if (Settings.version < 0x0602010A) {
for (byte j = 0; j < 5; j++) {
for (uint8_t j = 0; j < 5; j++) {
Settings.rgbwwTable[j] = 255;
}
}
@ -1022,6 +1023,10 @@ void SettingsDelta(void)
Settings.flag3.mdns_enabled = MDNS_ENABLED;
Settings.param[P_MDNS_DELAYED_START] = 0;
}
if (Settings.version < 0x0604010B) {
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
for (uint8_t i = 1; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; }
}
Settings.version = VERSION;
SettingsSave(1);

View File

@ -51,6 +51,7 @@ typedef unsigned long power_t; // Power (Relay) type
// Changes to the following MAX_ defines will impact settings layout
#define MAX_SWITCHES 8 // Max number of switches
#define MAX_RELAYS 8 // Max number of relays
#define MAX_INTERLOCKS 4 // Max number of interlock groups (MAX_RELAYS / 2)
#define MAX_LEDS 4 // Max number of leds
#define MAX_KEYS 4 // Max number of keys or buttons
#define MAX_PWMS 5 // Max number of PWM channels

View File

@ -75,7 +75,7 @@ enum TasmotaCommands {
CMND_MODULE, CMND_MODULES, CMND_GPIO, CMND_GPIOS, CMND_PWM, CMND_PWMFREQUENCY, CMND_PWMRANGE, CMND_COUNTER, CMND_COUNTERTYPE,
CMND_COUNTERDEBOUNCE, CMND_BUTTONDEBOUNCE, CMND_SWITCHDEBOUNCE, CMND_SLEEP, CMND_UPGRADE, CMND_UPLOAD, CMND_OTAURL, CMND_SERIALLOG, CMND_SYSLOG,
CMND_LOGHOST, CMND_LOGPORT, CMND_IPADDRESS, CMND_NTPSERVER, CMND_AP, CMND_SSID, CMND_PASSWORD, CMND_HOSTNAME,
CMND_WIFICONFIG, CMND_FRIENDLYNAME, CMND_SWITCHMODE,
CMND_WIFICONFIG, CMND_FRIENDLYNAME, CMND_SWITCHMODE, CMND_INTERLOCK,
CMND_TELEPERIOD, CMND_RESTART, CMND_RESET, CMND_TIMEZONE, CMND_TIMESTD, CMND_TIMEDST, CMND_ALTITUDE, CMND_LEDPOWER, CMND_LEDSTATE,
CMND_I2CSCAN, CMND_SERIALSEND, CMND_BAUDRATE, CMND_SERIALDELIMITER, CMND_DRIVER };
const char kTasmotaCommands[] PROGMEM =
@ -85,7 +85,7 @@ const char kTasmotaCommands[] PROGMEM =
D_CMND_MODULE "|" D_CMND_MODULES "|" D_CMND_GPIO "|" D_CMND_GPIOS "|" D_CMND_PWM "|" D_CMND_PWMFREQUENCY "|" D_CMND_PWMRANGE "|" D_CMND_COUNTER "|" D_CMND_COUNTERTYPE "|"
D_CMND_COUNTERDEBOUNCE "|" D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_SYSLOG "|"
D_CMND_LOGHOST "|" D_CMND_LOGPORT "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|"
D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|"
D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|"
D_CMND_TELEPERIOD "|" D_CMND_RESTART "|" D_CMND_RESET "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|" D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|"
D_CMND_I2CSCAN "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALDELIMITER "|" D_CMND_DRIVER;
@ -134,39 +134,39 @@ uint16_t seriallog_timer = 0; // Timer to disable Seriallog
uint16_t syslog_timer = 0; // Timer to re-enable syslog_level
int16_t save_data_counter; // Counter and flag for config save to Flash
RulesBitfield rules_flag; // Rule state flags (16 bits)
uint8_t serial_local = 0; // Handle serial locally;
uint8_t fallback_topic_flag = 0; // Use Topic or FallbackTopic
uint8_t state_250mS = 0; // State 250msecond per second flag
uint8_t latching_relay_pulse = 0; // Latching relay pulse timer
uint8_t backlog_index = 0; // Command backlog index
uint8_t backlog_pointer = 0; // Command backlog pointer
uint8_t backlog_mutex = 0; // Command backlog pending
uint8_t interlock_mutex = 0; // Interlock power command pending
uint8_t sleep; // Current copy of Settings.sleep
uint8_t stop_flash_rotate = 0; // Allow flash configuration rotation
uint8_t blinkstate = 0; // LED state
uint8_t blinkspeed = 1; // LED blink rate
uint8_t pin[GPIO_MAX]; // Possible pin configurations
uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off))
uint8_t pwm_inverted = 0; // PWM inverted flag (1 = inverted)
uint8_t counter_no_pullup = 0; // Counter input pullup flag (1 = No pullup)
uint8_t dht_flg = 0; // DHT configured
uint8_t energy_flg = 0; // Energy monitor configured
uint8_t i2c_flg = 0; // I2C configured
uint8_t spi_flg = 0; // SPI configured
uint8_t soft_spi_flg = 0; // Software SPI configured
uint8_t light_type = 0; // Light types
uint8_t ntp_force_sync = 0; // Force NTP sync
byte serial_in_byte; // Received byte
byte ota_retry_counter = OTA_ATTEMPTS; // OTA retry counter
byte web_log_index = 1; // Index in Web log buffer (should never be 0)
byte reset_web_log_flag = 0; // Reset web console log
byte devices_present = 0; // Max number of devices supported
byte seriallog_level; // Current copy of Settings.seriallog_level
byte syslog_level; // Current copy of Settings.syslog_level
//byte mdns_delayed_start = 0; // mDNS delayed start
boolean latest_uptime_flag = true; // Signal latest uptime
boolean pwm_present = false; // Any PWM channel configured with SetOption15 0
uint8_t serial_in_byte; // Received byte
uint8_t ota_retry_counter = OTA_ATTEMPTS; // OTA retry counter
uint8_t web_log_index = 1; // Index in Web log buffer (should never be 0)
uint8_t devices_present = 0; // Max number of devices supported
uint8_t seriallog_level; // Current copy of Settings.seriallog_level
uint8_t syslog_level; // Current copy of Settings.syslog_level
//uint8_t mdns_delayed_start = 0; // mDNS delayed start
bool serial_local = false; // Handle serial locally;
bool fallback_topic_flag = false; // Use Topic or FallbackTopic
bool backlog_mutex = false; // Command backlog pending
bool interlock_mutex = false; // Interlock power command pending
bool stop_flash_rotate = false; // Allow flash configuration rotation
bool blinkstate = false; // LED state
bool latest_uptime_flag = true; // Signal latest uptime
bool pwm_present = false; // Any PWM channel configured with SetOption15 0
bool dht_flg = false; // DHT configured
bool i2c_flg = false; // I2C configured
bool spi_flg = false; // SPI configured
bool soft_spi_flg = false; // Software SPI configured
bool ntp_force_sync = false; // Force NTP sync
bool reset_web_log_flag = false; // Reset web console log
myio my_module; // Active copy of Module GPIOs (17 x 8 bits)
gpio_flag my_module_flag; // Active copy of Module GPIO flags
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)
@ -214,7 +214,7 @@ char* Format(char* output, const char* input, int size)
}
}
}
if (!digits) strlcpy(output, input, size);
if (!digits) { strlcpy(output, input, size); }
return output;
}
@ -232,7 +232,7 @@ char* GetOtaUrl(char *otaurl, size_t otaurl_size)
return otaurl;
}
char* GetTopic_P(char *stopic, byte prefix, char *topic, const char* subtopic)
char* GetTopic_P(char *stopic, uint8_t prefix, char *topic, const char* subtopic)
{
/* prefix 0 = Cmnd
prefix 1 = Stat
@ -256,7 +256,7 @@ char* GetTopic_P(char *stopic, byte prefix, char *topic, const char* subtopic)
if ((0 == prefix) && (-1 == fulltopic.indexOf(F(MQTT_TOKEN_PREFIX)))) {
fulltopic += F("/" MQTT_TOKEN_PREFIX); // Need prefix for commands to handle mqtt topic loops
}
for (byte i = 0; i < 3; i++) {
for (uint8_t i = 0; i < 3; i++) {
if ('\0' == Settings.mqtt_prefix[i][0]) {
snprintf_P(Settings.mqtt_prefix[i], sizeof(Settings.mqtt_prefix[i]), kPrefixes[i]);
}
@ -275,14 +275,14 @@ char* GetTopic_P(char *stopic, byte prefix, char *topic, const char* subtopic)
return stopic;
}
char* GetFallbackTopic_P(char *stopic, byte prefix, const char* subtopic)
char* GetFallbackTopic_P(char *stopic, uint8_t prefix, const char* subtopic)
{
return GetTopic_P(stopic, prefix +4, NULL, subtopic);
}
char* GetStateText(byte state)
char* GetStateText(uint8_t state)
{
if (state > 3) state = 1;
if (state > 3) { state = 1; }
return Settings.state_text[state];
}
@ -300,7 +300,7 @@ void SetLatchingRelay(power_t lpower, uint8_t state)
latching_relay_pulse = 2; // max 200mS (initiated by stateloop())
}
for (byte i = 0; i < devices_present; i++) {
for (uint8_t i = 0; i < devices_present; i++) {
uint8_t port = (i << 1) + ((latching_power >> i) &1);
if (pin[GPIO_REL1 +port] < 99) {
digitalWrite(pin[GPIO_REL1 +port], bitRead(rel_inverted, port) ? !state : state);
@ -318,35 +318,21 @@ void SetDevicePower(power_t rpower, int source)
power = (1 << devices_present) -1;
rpower = power;
}
if (Settings.flag3.split_interlock) {
Settings.flag.interlock = 1; // prevent the situation where interlock is off and split-interlock is on
uint8_t mask = 0x01;
uint8_t count = 0;
byte result1 = 0;
byte result2 = 0;
for (byte i = 0; i < devices_present; i++) {
if (rpower & mask) {
if (i <2) { result1++;}//increment if low part is ON
if (i >1) { result2++;}//increment if high part is ON
if (Settings.flag.interlock) { // Allow only one or no relay set
for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) {
power_t mask = 1;
uint8_t count = 0;
for (uint8_t j = 0; j < devices_present; j++) {
if ((Settings.interlock[i] & mask) && (rpower & mask)) { count++; }
mask <<= 1;
}
if (count > 1) {
mask = ~Settings.interlock[i]; // Turn interlocked group off as there would be multiple relays on
power &= mask;
rpower &= mask;
}
mask <<= 1; // shift the bitmask one left (1,2,4,8) to find out what is on
}
if ((result1) >1 && (result2 >1)) {power = 0; rpower = 0;} // all 4 switch are on, something is wrong, so we turn all off
if ((result1) >1 && (result2 <2)) {power = power & 0x0C; rpower = power;} // 1/2 are both on and 3/4 max one is on
if ((result1) <2 && (result2 >1)) {power = power & 0x03; rpower = power;} // 1/2 max one is on and 3/4 both are on
} else {
if (Settings.flag.interlock) { // Allow only one or no relay set
power_t mask = 1;
uint8_t count = 0;
for (byte i = 0; i < devices_present; i++) {
if (rpower & mask) count++;
mask <<= 1;
}
if (count > 1) {
power = 0;
rpower = 0;
}
}
}
XdrvMailbox.index = rpower;
@ -369,7 +355,7 @@ void SetDevicePower(power_t rpower, int source)
SetLatchingRelay(rpower, 1);
}
else {
for (byte i = 0; i < devices_present; i++) {
for (uint8_t i = 0; i < devices_present; i++) {
state = rpower &1;
if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) {
digitalWrite(pin[GPIO_REL1 +i], bitRead(rel_inverted, i) ? !state : state);
@ -381,7 +367,7 @@ void SetDevicePower(power_t rpower, int source)
void SetLedPower(uint8_t state)
{
if (state) state = 1;
if (state) { state = 1; }
uint8_t led_pin = 0;
if (pin[GPIO_LED2] < 99) { led_pin = 1; }
@ -390,7 +376,7 @@ void SetLedPower(uint8_t state)
void SetLedLink(uint8_t state)
{
if (state) state = 1;
if (state) { state = 1; }
digitalWrite(pin[GPIO_LED1], (bitRead(led_inverted, 0)) ? !state : state);
}
@ -413,7 +399,7 @@ uint8_t GetFanspeed(void)
void SetFanspeed(uint8_t fanspeed)
{
for (byte i = 0; i < MAX_FAN_SPEED -1; i++) {
for (uint8_t i = 0; i < MAX_FAN_SPEED -1; i++) {
uint8_t state = kIFan02Speed[fanspeed][i];
// uint8_t state = pgm_read_byte(kIFan02Speed +(speed *3) +i);
ExecuteCommandPower(i +2, state, SRC_IGNORE); // Use relay 2, 3 and 4
@ -442,7 +428,7 @@ uint16_t GetPulseTimer(uint8_t index)
/********************************************************************************************/
void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
{
char *str;
@ -464,10 +450,10 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
char stemp1[TOPSZ];
char *p;
char *type = NULL;
byte jsflg = 0;
byte lines = 1;
uint8_t grpflg = 0;
// uint8_t user_append_index = 0;
uint8_t lines = 1;
bool jsflg = false;
bool grpflg = false;
// bool user_append_index = false;
uint16_t i = 0;
uint16_t index;
uint32_t address;
@ -476,7 +462,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
strlcpy(topicBuf, topic, sizeof(topicBuf));
for (i = 0; i < data_len; i++) {
if (!isspace(data[i])) break;
if (!isspace(data[i])) { break; }
}
data_len -= i;
memcpy(dataBuf, data +i, sizeof(dataBuf));
@ -487,9 +473,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_RESULT D_RECEIVED_TOPIC " %s, " D_DATA_SIZE " %d, " D_DATA " %s"),
topicBuf, data_len, dataBuf);
AddLog(LOG_LEVEL_DEBUG_MORE);
// if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) Serial.println(dataBuf);
// if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(dataBuf); }
if (XdrvMqttData(topicBuf, sizeof(topicBuf), dataBuf, sizeof(dataBuf))) return;
if (XdrvMqttData(topicBuf, sizeof(topicBuf), dataBuf, sizeof(dataBuf))) { return; }
grpflg = (strstr(topicBuf, Settings.mqtt_grptopic) != NULL);
@ -509,7 +495,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
}
if (i < strlen(type)) {
index = atoi(type +i);
// user_append_index = 1;
// user_append_index = true;
}
type[i] = '\0';
}
@ -520,9 +506,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
if (type != NULL) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}"));
if (Settings.ledstate &0x02) blinks++;
if (Settings.ledstate &0x02) { blinks++; }
if (!strcmp(dataBuf,"?")) data_len = 0;
if (!strcmp(dataBuf,"?")) { data_len = 0; }
int16_t payload = -99; // No payload
uint16_t payload16 = 0;
long payload32 = strtol(dataBuf, &p, 10);
@ -585,10 +571,10 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, bl_delay);
}
else if ((CMND_POWER == command_code) && (index > 0) && (index <= devices_present)) {
if ((payload < 0) || (payload > 4)) payload = 9;
if ((payload < 0) || (payload > 4)) { payload = 9; }
// Settings.flag.device_index_enable = user_append_index;
ExecuteCommandPower(index, payload, SRC_IGNORE);
fallback_topic_flag = 0;
fallback_topic_flag = false;
return;
}
else if ((CMND_FANSPEED == command_code) && (SONOFF_IFAN02 == Settings.module)) {
@ -610,7 +596,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
else if (CMND_STATUS == command_code) {
if ((payload < 0) || (payload > MAX_STATUS)) payload = 99;
PublishStatus(payload);
fallback_topic_flag = 0;
fallback_topic_flag = false;
return;
}
else if (CMND_STATE == command_code) {
@ -678,7 +664,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
if ((payload >= POWER_ALL_OFF) && (payload <= POWER_ALL_OFF_PULSETIME_ON)) {
Settings.poweronstate = payload;
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
for (byte i = 1; i <= devices_present; i++) {
for (uint8_t i = 1; i <= devices_present; i++) {
ExecuteCommandPower(i, POWER_ON, SRC_IGNORE);
}
}
@ -732,8 +718,8 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
}
}
else if ((CMND_SETOPTION == command_code) && (index < 82)) {
byte ptype;
byte pindex;
uint8_t ptype;
uint8_t pindex;
if (index <= 31) { // SetOption0 .. 31 = Settings.flag
ptype = 0;
pindex = index; // 0 .. 31
@ -754,6 +740,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
case 6: // mqtt_button_retain (CMND_BUTTONRETAIN)
case 7: // mqtt_switch_retain (CMND_SWITCHRETAIN)
case 9: // mqtt_sensor_retain (CMND_SENSORRETAIN)
case 14: // interlock (CMND_INTERLOCK)
case 22: // mqtt_serial (SerialSend and SerialLog)
case 23: // mqtt_serial_raw (SerialSend)
case 25: // knx_enabled (Web config)
@ -772,7 +759,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
}
#ifdef USE_HOME_ASSISTANT
if ((19 == pindex) || (30 == pindex)) {
HAssDiscovery(1); // hass_discovery or hass_light
HAssDiscover(); // Delayed execution to provide enough resources during hass_discovery or hass_light
}
#endif // USE_HOME_ASSISTANT
}
@ -873,7 +860,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
Settings.last_module = Settings.module;
Settings.module = payload;
if (Settings.last_module != payload) {
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
Settings.my_gp.io[i] = GPIO_NONE;
}
}
@ -882,18 +869,18 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SVALUE, command, Settings.module +1, ModuleName().c_str());
}
else if (CMND_MODULES == command_code) {
for (byte i = 0; i < MAXMODULE; i++) {
for (uint8_t i = 0; i < MAXMODULE; i++) {
if (!jsflg) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data);
}
jsflg = 1;
jsflg = true;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%d (%s)\""), mqtt_data, i +1, AnyModuleName(i).c_str());
if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == MAXMODULE -1)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]}"), mqtt_data);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
jsflg = 0;
jsflg = false;
lines++;
}
}
@ -904,12 +891,12 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
ModuleGpios(&cmodule);
if ((GPIO_USER == ValidGPIO(index, cmodule.io[index])) && (payload >= 0) && (payload < GPIO_SENSOR_END)) {
bool present = false;
for (byte i = 0; i < sizeof(kGpioNiceList); i++) {
for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) {
uint8_t midx = pgm_read_byte(kGpioNiceList + i);
if (midx == payload) { present = true; }
}
if (present) {
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
if ((GPIO_USER == ValidGPIO(i, cmodule.io[i])) && (Settings.my_gp.io[i] == payload)) {
Settings.my_gp.io[i] = GPIO_NONE;
}
@ -919,10 +906,10 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
}
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{"));
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (GPIO_USER == ValidGPIO(i, cmodule.io[i])) {
if (jsflg) snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data);
jsflg = 1;
jsflg = true;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_GPIO "%d\":\"%d (%s)\""),
mqtt_data, i, Settings.my_gp.io[i], GetTextIndexed(stemp1, sizeof(stemp1), Settings.my_gp.io[i], kSensorNames));
}
@ -937,7 +924,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
myio cmodule;
ModuleGpios(&cmodule);
uint8_t midx;
for (byte i = 0; i < sizeof(kGpioNiceList); i++) {
for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) {
midx = pgm_read_byte(kGpioNiceList + i);
if (!GetUsedInModule(midx, cmodule.io)) {
@ -946,12 +933,12 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data);
}
jsflg = 1;
jsflg = true;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%d (%s)\""), mqtt_data, midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames));
if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]}"), mqtt_data);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
jsflg = 0;
jsflg = false;
lines++;
}
}
@ -978,7 +965,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
else if (CMND_PWMRANGE == command_code) {
if ((1 == payload) || ((payload > 254) && (payload < 1024))) {
Settings.pwm_range = (1 == payload) ? PWM_RANGE : payload;
for (byte i = 0; i < MAX_PWMS; i++) {
for (uint8_t i = 0; i < MAX_PWMS; i++) {
if (Settings.pwm_value[i] > Settings.pwm_range) {
Settings.pwm_value[i] = Settings.pwm_range;
}
@ -1103,7 +1090,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
if (Settings.ntp_server[index -1][i] == ',') Settings.ntp_server[index -1][i] = '.';
}
// restart_flag = 2; // Issue #3890
ntp_force_sync = 1;
ntp_force_sync = true;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.ntp_server[index -1]);
}
@ -1181,6 +1168,74 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, index, Settings.switchmode[index-1]);
}
else if (CMND_INTERLOCK == command_code) { // Interlock 0 - Off, Interlock 1 - On, Interlock 1,2 3,4 5,6,7
uint8_t max_relays = devices_present;
if (light_type) { max_relays--; }
if (max_relays > sizeof(Settings.interlock[0]) * 8) { max_relays = sizeof(Settings.interlock[0]) * 8; }
if (max_relays > 1) { // Only interlock with more than 1 relay
if (data_len > 0) {
if (strstr(dataBuf, ",")) { // Interlock entry
for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; } // Reset current interlocks
char *group;
char *q;
uint8_t group_index = 0;
power_t relay_mask = 0;
for (group = strtok_r(dataBuf, " ", &q); group && group_index < MAX_INTERLOCKS; group = strtok_r(NULL, " ", &q)) {
char *str;
for (str = strtok_r(group, ",", &p); str; str = strtok_r(NULL, ",", &p)) {
int pbit = atoi(str);
if ((pbit > 0) && (pbit <= max_relays)) { // Only valid relays
pbit--;
if (!bitRead(relay_mask, pbit)) { // Only relay once
bitSet(relay_mask, pbit);
bitSet(Settings.interlock[group_index], pbit);
}
}
}
group_index++;
}
for (uint8_t i = 0; i < group_index; i++) {
uint8_t minimal_bits = 0;
for (uint8_t j = 0; j < max_relays; j++) {
if (bitRead(Settings.interlock[i], j)) { minimal_bits++; }
}
if (minimal_bits < 2) { Settings.interlock[i] = 0; } // Discard single relay as interlock
}
} else {
Settings.flag.interlock = payload &1; // Enable/disable interlock
if (Settings.flag.interlock) {
SetDevicePower(power, SRC_IGNORE); // Remove multiple relays if set
}
}
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_INTERLOCK "\":\"%s\",\"" D_JSON_GROUPS "\":\""), GetStateText(Settings.flag.interlock));
uint8_t anygroup = 0;
for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) {
if (Settings.interlock[i]) {
anygroup++;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s"), mqtt_data, (anygroup > 1) ? " " : "");
uint8_t anybit = 0;
power_t mask = 1;
for (uint8_t j = 0; j < max_relays; j++) {
if (Settings.interlock[i] & mask) {
anybit++;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d"), mqtt_data, (anybit > 1) ? "," : "", j +1);
}
mask <<= 1;
}
}
}
if (!anygroup) {
for (uint8_t j = 1; j <= max_relays; j++) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d"), mqtt_data, (j > 1) ? "," : "", j);
}
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data);
} else {
Settings.flag.interlock = 0;
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag.interlock));
}
}
else if (CMND_TELEPERIOD == command_code) {
if ((payload >= 0) && (payload < 3601)) {
Settings.tele_period = (1 == payload) ? TELE_PERIOD : payload;
@ -1222,7 +1277,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
} else {
Settings.timezone = 99;
}
ntp_force_sync = 1;
ntp_force_sync = true;
}
if (99 == Settings.timezone) {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.timezone);
@ -1257,7 +1312,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
value = strtol(p, &p, 10);
tpos++; // Next parameter
}
ntp_force_sync = 1;
ntp_force_sync = true;
} else {
if (0 == payload) {
if (0 == ts) {
@ -1266,7 +1321,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
SettingsResetDst();
}
}
ntp_force_sync = 1;
ntp_force_sync = true;
}
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"Hemisphere\":%d,\"Week\":%d,\"Month\":%d,\"Day\":%d,\"Hour\":%d,\"Offset\":%d}}"),
@ -1319,12 +1374,12 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
type = (char*)topicBuf;
}
if (mqtt_data[0] != '\0') MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
fallback_topic_flag = 0;
fallback_topic_flag = false;
}
/********************************************************************************************/
boolean SendKey(byte key, byte device, byte state)
bool SendKey(uint8_t key, uint8_t device, uint8_t state)
{
// key 0 = button_topic
// key 1 = switch_topic
@ -1337,7 +1392,7 @@ boolean SendKey(byte key, byte device, byte state)
char stopic[TOPSZ];
char scommand[CMDSZ];
char key_topic[sizeof(Settings.button_topic)];
boolean result = false;
bool result = false;
char *tmp = (key) ? Settings.switch_topic : Settings.button_topic;
Format(key_topic, tmp, sizeof(key_topic));
@ -1371,7 +1426,7 @@ boolean SendKey(byte key, byte device, byte state)
return result;
}
void ExecuteCommandPower(byte device, byte state, int source)
void ExecuteCommandPower(uint8_t device, uint8_t state, int source)
{
// device = Relay number 1 and up
// state 0 = Relay Off
@ -1400,41 +1455,30 @@ void ExecuteCommandPower(byte device, byte state, int source)
}
if ((device < 1) || (device > devices_present)) device = 1;
if (device <= MAX_PULSETIMERS) { SetPulseTimer(device -1, 0); }
power_t mask = 1 << (device -1);
power_t mask = 1 << (device -1); // Device to control
if (state <= POWER_TOGGLE) {
if ((blink_mask & mask)) {
blink_mask &= (POWER_MASK ^ mask); // Clear device mask
MqttPublishPowerBlinkState(device);
}
if (Settings.flag3.split_interlock && !Settings.flag.interlock ) Settings.flag.interlock=1; // ensure interlock is on, in case split_interlock is on
// check if channel 1/2 or 3/4 are to be changed
if (device <= 2 && Settings.flag3.split_interlock ) { // channel 1/2 are changed
if (Settings.flag3.split_interlock && !interlock_mutex) { // Clear all but masked relay, but only if we are not already doing something
interlock_mutex = 1;
for (byte i = 0; i < 2; i++) {
byte imask = 0x01 << i;
if ((power & imask) && (mask != imask)) { ExecuteCommandPower(i +1, POWER_OFF, SRC_IGNORE); delay(50); }// example, first power is ON but the pushed button is not the first, then powerOFF the first one
if (Settings.flag.interlock && !interlock_mutex) { // Clear all but masked relay in interlock group
interlock_mutex = true;
for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) {
if (Settings.interlock[i] & mask) { // Find interlock group
for (uint8_t j = 0; j < devices_present; j++) {
power_t imask = 1 << j;
if ((Settings.interlock[i] & imask) && (power & imask) && (mask != imask)) {
ExecuteCommandPower(j +1, POWER_OFF, SRC_IGNORE);
delay(50); // Add some delay to make sure never have more than one relay on
}
}
break; // An interlocked relay is only present in one group so quit
}
interlock_mutex = 0; // avoid infinite loop due to recursive requests
}
} else { // channel 3/4 are changed
if (Settings.flag3.split_interlock && !interlock_mutex) { // only start if we are on interlock split and have no re-call
interlock_mutex = 1;
for (byte i = 2; i < devices_present; i++) {
byte imask = 0x01 << i;
if ((power & imask) && (mask != imask)) ExecuteCommandPower(i +1, POWER_OFF, SRC_IGNORE);
}
interlock_mutex = 0;
}
}
if ( Settings.flag.interlock && !interlock_mutex && !Settings.flag3.split_interlock) { //execute regular interlock-mode as interlock-split is off
interlock_mutex = 1;
for (byte i = 0; i < devices_present; i++) {
power_t imask = 1 << i;
if ((power & imask) && (mask != imask)) ExecuteCommandPower(i +1, POWER_OFF, SRC_IGNORE);
}
interlock_mutex = 0;
interlock_mutex = false;
}
switch (state) {
case POWER_OFF: {
power &= (POWER_MASK ^ mask);
@ -1473,7 +1517,7 @@ void ExecuteCommandPower(byte device, byte state, int source)
return;
}
else if (POWER_BLINK_STOP == state) {
byte flag = (blink_mask & mask);
uint8_t flag = (blink_mask & mask);
blink_mask &= (POWER_MASK ^ mask); // Clear device mask
MqttPublishPowerBlinkState(device);
if (flag) ExecuteCommandPower(device, (blink_powersave >> (device -1))&1, SRC_IGNORE); // Restore state
@ -1486,7 +1530,7 @@ void StopAllPowerBlink(void)
{
power_t mask;
for (byte i = 1; i <= devices_present; i++) {
for (uint8_t i = 1; i <= devices_present; i++) {
mask = 1 << (i -1);
if (blink_mask & mask) {
blink_mask &= (POWER_MASK ^ mask); // Clear device mask
@ -1509,13 +1553,13 @@ void ExecuteCommand(char *cmnd, int source)
token = strtok(cmnd, " ");
if (token != NULL) {
start = strrchr(token, '/'); // Skip possible cmnd/sonoff/ preamble
if (start) token = start +1;
if (start) { token = start +1; }
}
snprintf_P(stopic, sizeof(stopic), PSTR("/%s"), (token == NULL) ? "" : token);
token = strtok(NULL, "");
// snprintf_P(svalue, sizeof(svalue), (token == NULL) ? "" : token); // Fails with command FullTopic home/%prefix%/%topic% as it processes %p of %prefix%
strlcpy(svalue, (token == NULL) ? "" : token, sizeof(svalue)); // Fixed 5.8.0b
MqttDataHandler(stopic, (byte*)svalue, strlen(svalue));
MqttDataHandler(stopic, (uint8_t*)svalue, strlen(svalue));
}
void PublishStatus(uint8_t payload)
@ -1525,20 +1569,20 @@ void PublishStatus(uint8_t payload)
char stemp2[MAX_SWITCHES * 3];
// Workaround MQTT - TCP/IP stack queueing when SUB_PREFIX = PUB_PREFIX
if (!strcmp(Settings.mqtt_prefix[0],Settings.mqtt_prefix[1]) && (!payload)) option++; // TELE
if (!strcmp(Settings.mqtt_prefix[0],Settings.mqtt_prefix[1]) && (!payload)) { option++; } // TELE
if ((!Settings.flag.mqtt_enabled) && (6 == payload)) payload = 99;
if (!energy_flg && (9 == payload)) payload = 99;
if ((!Settings.flag.mqtt_enabled) && (6 == payload)) { payload = 99; }
if (!energy_flg && (9 == payload)) { payload = 99; }
if ((0 == payload) || (99 == payload)) {
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
if (SONOFF_IFAN02 == Settings.module) { maxfn = 1; }
stemp[0] = '\0';
for (byte i = 0; i < maxfn; i++) {
for (uint8_t i = 0; i < maxfn; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%s%s\"%s\"" ), stemp, (i > 0 ? "," : ""), Settings.friendlyname[i]);
}
stemp2[0] = '\0';
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%s%d" ), stemp2, (i > 0 ? "," : ""), Settings.switchmode[i]);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS "\":{\"" D_CMND_MODULE "\":%d,\"" D_CMND_FRIENDLYNAME "\":[%s],\"" D_CMND_TOPIC "\":\"%s\",\"" D_CMND_BUTTONTOPIC "\":\"%s\",\"" D_CMND_POWER "\":%d,\"" D_CMND_POWERONSTATE "\":%d,\"" D_CMND_LEDSTATE "\":%d,\"" D_CMND_SAVEDATA "\":%d,\"" D_JSON_SAVESTATE "\":%d,\"" D_CMND_SWITCHTOPIC "\":\"%s\",\"" D_CMND_SWITCHMODE "\":[%s],\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_SWITCHRETAIN "\":%d,\"" D_CMND_SENSORRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
@ -1631,7 +1675,7 @@ void MqttShowPWMState(void)
{
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_PWM "\":{"), mqtt_data);
bool first = true;
for (byte i = 0; i < MAX_PWMS; i++) {
for (uint8_t i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 + i] < 99) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_PWM "%d\":%d"), mqtt_data, first ? "" : ",", i+1, Settings.pwm_value[i]);
first = false;
@ -1654,7 +1698,7 @@ void MqttShowState(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u"),
mqtt_data, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), sleep, loop_load_avg);
for (byte i = 0; i < devices_present; i++) {
for (uint8_t i = 0; i < devices_present; i++) {
if (i == light_device -1) {
LightState(1);
} else {
@ -1675,22 +1719,22 @@ void MqttShowState(void)
mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()));
}
boolean MqttShowSensor(void)
bool MqttShowSensor(void)
{
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str());
int json_data_start = strlen(mqtt_data);
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) {
#else
if (pin[GPIO_SWT1 +i] < 99) {
#endif // USE_TM1638
boolean swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]));
bool swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_SWITCH "%d\":\"%s\""), mqtt_data, i +1, GetStateText(swm ^ SwitchLastState(i)));
}
}
XsnsCall(FUNC_JSON_APPEND);
boolean json_data_available = (strlen(mqtt_data) - json_data_start);
bool json_data_available = (strlen(mqtt_data) - json_data_start);
if (strstr_P(mqtt_data, PSTR(D_JSON_PRESSURE))) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), mqtt_data, PressureUnit().c_str());
}
@ -1795,7 +1839,7 @@ void Every100mSeconds(void)
if (!latching_relay_pulse) SetLatchingRelay(0, 0);
}
for (byte i = 0; i < MAX_PULSETIMERS; i++) {
for (uint8_t i = 0; i < MAX_PULSETIMERS; i++) {
if (pulse_timer[i] != 0L) { // Timer active?
if (TimeReached(pulse_timer[i])) { // Timer finished?
pulse_timer[i] = 0L; // Turn off this timer
@ -1821,9 +1865,9 @@ void Every100mSeconds(void)
// Backlog
if (TimeReached(backlog_delay)) {
if ((backlog_pointer != backlog_index) && !backlog_mutex) {
backlog_mutex = 1;
backlog_mutex = true;
ExecuteCommand((char*)backlog[backlog_pointer].c_str(), SRC_BACKLOG);
backlog_mutex = 0;
backlog_mutex = false;
backlog_pointer++;
if (backlog_pointer >= MAX_BACKLOG) { backlog_pointer = 0; }
}
@ -1854,7 +1898,7 @@ void Every250mSeconds(void)
}
if (blinks || restart_flag || ota_state_flag) {
if (restart_flag || ota_state_flag) { // Overrule blinks and keep led lit
blinkstate = 1; // Stay lit
blinkstate = true; // Stay lit
} else {
blinkspeed--;
if (!blinkspeed) {
@ -1873,7 +1917,7 @@ void Every250mSeconds(void)
}
}
else if (Settings.ledstate &1) {
boolean tstate = power;
bool tstate = power;
if ((SONOFF_TOUCH == Settings.module) || (SONOFF_T11 == Settings.module) || (SONOFF_T12 == Settings.module) || (SONOFF_T13 == Settings.module)) {
tstate = (!power) ? 1 : 0; // As requested invert signal for Touch devices to find them in the dark
}
@ -1914,7 +1958,7 @@ void Every250mSeconds(void)
char *bch = strrchr(mqtt_data, '/'); // Only consider filename after last backslash prevent change of urls having "-" in it
char *pch = strrchr((bch != NULL) ? bch : mqtt_data, '-'); // Change from filename-DE.bin into filename-minimal.bin
char *ech = strrchr((bch != NULL) ? bch : mqtt_data, '.'); // Change from filename.bin into filename-minimal.bin
if (!pch) pch = ech;
if (!pch) { pch = ech; }
if (pch) {
mqtt_data[pch - mqtt_data] = '\0';
char *ech = strrchr(Settings.ota_url, '.'); // Change from filename.bin into filename-minimal.bin
@ -1964,7 +2008,7 @@ void Every250mSeconds(void)
if (save_data_counter <= 0) {
if (Settings.flag.save_state) {
power_t mask = POWER_MASK;
for (byte i = 0; i < MAX_PULSETIMERS; i++) {
for (uint8_t i = 0; i < MAX_PULSETIMERS; i++) {
if ((Settings.pulse_timer[i] > 0) && (Settings.pulse_timer[i] < 30)) { // 3 seconds
mask &= ~(1 << i);
}
@ -2035,18 +2079,18 @@ void ArduinoOTAInit(void)
{
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname(my_hostname);
if (Settings.web_password[0] !=0) ArduinoOTA.setPassword(Settings.web_password);
if (Settings.web_password[0] !=0) { ArduinoOTA.setPassword(Settings.web_password); }
ArduinoOTA.onStart([]()
{
SettingsSave(1); // Free flash for OTA update
#ifdef USE_WEBSERVER
if (Settings.webserver) StopWebserver();
if (Settings.webserver) { StopWebserver(); }
#endif // USE_WEBSERVER
#ifdef USE_ARILUX_RF
AriluxRfDisable(); // Prevent restart exception on Arilux Interrupt routine
#endif // USE_ARILUX_RF
if (Settings.flag.mqtt_enabled) MqttDisconnect();
if (Settings.flag.mqtt_enabled) { MqttDisconnect(); }
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "Arduino OTA " D_UPLOAD_STARTED));
AddLog(LOG_LEVEL_INFO);
arduino_ota_triggered = true;
@ -2059,7 +2103,7 @@ void ArduinoOTAInit(void)
if ((LOG_LEVEL_DEBUG <= seriallog_level)) {
arduino_ota_progress_dot_count++;
Serial.printf(".");
if (!(arduino_ota_progress_dot_count % 80)) Serial.println();
if (!(arduino_ota_progress_dot_count % 80)) { Serial.println(); }
}
});
@ -2071,7 +2115,7 @@ void ArduinoOTAInit(void)
*/
char error_str[100];
if ((LOG_LEVEL_DEBUG <= seriallog_level) && arduino_ota_progress_dot_count) Serial.println();
if ((LOG_LEVEL_DEBUG <= seriallog_level) && arduino_ota_progress_dot_count) { Serial.println(); }
switch (error) {
case OTA_BEGIN_ERROR: strncpy_P(error_str, PSTR(D_UPLOAD_ERR_2), sizeof(error_str)); break;
case OTA_RECEIVE_ERROR: strncpy_P(error_str, PSTR(D_UPLOAD_ERR_5), sizeof(error_str)); break;
@ -2086,7 +2130,7 @@ void ArduinoOTAInit(void)
ArduinoOTA.onEnd([]()
{
if ((LOG_LEVEL_DEBUG <= seriallog_level)) Serial.println();
if ((LOG_LEVEL_DEBUG <= seriallog_level)) { Serial.println(); }
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "Arduino OTA " D_SUCCESSFUL ". " D_RESTARTING));
AddLog(LOG_LEVEL_INFO);
EspRestart();
@ -2166,7 +2210,7 @@ void SerialInput(void)
else if (!Settings.flag.mqtt_serial && (serial_in_byte == '\n')) {
serial_in_buffer[serial_in_byte_counter] = 0; // serial data completed
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (byte)LOG_LEVEL_INFO : Settings.seriallog_level;
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings.seriallog_level;
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), serial_in_buffer);
AddLog(LOG_LEVEL_INFO);
ExecuteCommand(serial_in_buffer, SRC_SERIAL);
@ -2210,7 +2254,7 @@ void GpioInit(void)
myio def_gp;
ModuleGpios(&def_gp);
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (Settings.my_gp.io[i] > GPIO_NONE) {
my_module.io[i] = Settings.my_gp.io[i];
}
@ -2220,10 +2264,10 @@ void GpioInit(void)
}
my_module_flag = ModuleFlag();
for (byte i = 0; i < GPIO_MAX; i++) {
for (uint8_t i = 0; i < GPIO_MAX; i++) {
pin[i] = 99;
}
for (byte i = 0; i < sizeof(my_module.io); i++) {
for (uint8_t i = 0; i < sizeof(my_module.io); i++) {
mpin = ValidGPIO(i, my_module.io[i]);
// snprintf_P(log_data, sizeof(log_data), PSTR("DBG: gpio pin %d, mpin %d"), i, mpin);
@ -2235,9 +2279,18 @@ void GpioInit(void)
mpin -= (GPIO_SWT1_NP - GPIO_SWT1);
}
else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) {
ButtonPullupFlag(mpin - GPIO_KEY1_NP);
ButtonPullupFlag(mpin - GPIO_KEY1_NP); // 0 .. 3
mpin -= (GPIO_KEY1_NP - GPIO_KEY1);
}
else if ((mpin >= GPIO_KEY1_INV) && (mpin < (GPIO_KEY1_INV + MAX_KEYS))) {
ButtonInvertFlag(mpin - GPIO_KEY1_INV); // 0 .. 3
mpin -= (GPIO_KEY1_INV - GPIO_KEY1);
}
else if ((mpin >= GPIO_KEY1_INV_NP) && (mpin < (GPIO_KEY1_INV_NP + MAX_KEYS))) {
ButtonPullupFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3
ButtonInvertFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3
mpin -= (GPIO_KEY1_INV_NP - GPIO_KEY1);
}
else if ((mpin >= GPIO_REL1_INV) && (mpin < (GPIO_REL1_INV + MAX_RELAYS))) {
bitSet(rel_inverted, mpin - GPIO_REL1_INV);
mpin -= (GPIO_REL1_INV - GPIO_REL1);
@ -2257,7 +2310,7 @@ void GpioInit(void)
#ifdef USE_DHT
else if ((mpin >= GPIO_DHT11) && (mpin <= GPIO_SI7021)) {
if (DhtSetup(i, mpin)) {
dht_flg = 1;
dht_flg = true;
mpin = GPIO_DHT11;
} else {
mpin = 0;
@ -2276,7 +2329,7 @@ void GpioInit(void)
#ifdef USE_SPI
spi_flg = ((((pin[GPIO_SPI_CS] < 99) && (pin[GPIO_SPI_CS] > 14)) || (pin[GPIO_SPI_CS] < 12)) || (((pin[GPIO_SPI_DC] < 99) && (pin[GPIO_SPI_DC] > 14)) || (pin[GPIO_SPI_DC] < 12)));
if (spi_flg) {
for (byte i = 0; i < GPIO_MAX; i++) {
for (uint8_t i = 0; i < GPIO_MAX; i++) {
if ((pin[i] >= 12) && (pin[i] <=14)) pin[i] = 99;
}
my_module.io[12] = GPIO_SPI_MISO;
@ -2291,15 +2344,15 @@ void GpioInit(void)
#ifdef USE_I2C
i2c_flg = ((pin[GPIO_I2C_SCL] < 99) && (pin[GPIO_I2C_SDA] < 99));
if (i2c_flg) Wire.begin(pin[GPIO_I2C_SDA], pin[GPIO_I2C_SCL]);
if (i2c_flg) { Wire.begin(pin[GPIO_I2C_SDA], pin[GPIO_I2C_SCL]); }
#endif // USE_I2C
devices_present = 1;
light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
if (Settings.flag.pwm_control) {
for (byte i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 +i] < 99) light_type++; // Use Dimmer/Color control for all PWM as SetOption15 = 1
for (uint8_t i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 +i] < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
}
}
@ -2339,8 +2392,8 @@ void GpioInit(void)
light_type = LT_RGBWC;
}
else {
if (!light_type) devices_present = 0;
for (byte i = 0; i < MAX_RELAYS; i++) {
if (!light_type) { devices_present = 0; }
for (uint8_t i = 0; i < MAX_RELAYS; i++) {
if (pin[GPIO_REL1 +i] < 99) {
pinMode(pin[GPIO_REL1 +i], OUTPUT);
devices_present++;
@ -2352,7 +2405,7 @@ void GpioInit(void)
}
}
for (byte i = 0; i < MAX_LEDS; i++) {
for (uint8_t i = 0; i < MAX_LEDS; i++) {
if (pin[GPIO_LED1 +i] < 99) {
pinMode(pin[GPIO_LED1 +i], OUTPUT);
digitalWrite(pin[GPIO_LED1 +i], bitRead(led_inverted, i));
@ -2370,7 +2423,7 @@ void GpioInit(void)
}
#endif // USE_WS2812
if (!light_type) {
for (byte i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
for (uint8_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
if (pin[GPIO_PWM1 +i] < 99) {
pwm_present = true;
pinMode(pin[GPIO_PWM1 +i], OUTPUT);
@ -2435,7 +2488,7 @@ void setup(void)
if (RtcReboot.fast_reboot_count > 1) { // Restart twice
Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI
if (RtcReboot.fast_reboot_count > 2) { // Restart 3 times
for (byte i = 0; i < MAX_RULE_SETS; i++) {
for (uint8_t i = 0; i < MAX_RULE_SETS; i++) {
if (bitRead(Settings.rule_stop, i)) {
bitWrite(Settings.rule_enabled, i, 0); // Disable rules causing boot loop
}
@ -2445,12 +2498,14 @@ void setup(void)
Settings.rule_enabled = 0; // Disable all rules
}
if (RtcReboot.fast_reboot_count > 4) { // Restarted 5 times
Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic
// Settings.last_module = SONOFF_BASIC;
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors
}
}
if (RtcReboot.fast_reboot_count > 5) { // Restarted 6 times
Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic
// Settings.last_module = SONOFF_BASIC;
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcReboot.fast_reboot_count);
AddLog(LOG_LEVEL_DEBUG);
}
@ -2470,7 +2525,7 @@ void setup(void)
WifiConnect();
if (MOTOR == Settings.module) Settings.poweronstate = POWER_ALL_ON; // Needs always on else in limbo!
if (MOTOR == Settings.module) { Settings.poweronstate = POWER_ALL_ON; } // Needs always on else in limbo!
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
SetDevicePower(1, SRC_RESTART);
} else {
@ -2507,7 +2562,7 @@ void setup(void)
}
// Issue #526 and #909
for (byte i = 0; i < devices_present; i++) {
for (uint8_t i = 0; i < devices_present; i++) {
if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) {
bitWrite(power, i, digitalRead(pin[GPIO_REL1 +i]) ^ bitRead(rel_inverted, i));
}
@ -2568,7 +2623,7 @@ void loop(void)
XsnsCall(FUNC_EVERY_250_MSECOND);
}
if (!serial_local) SerialInput();
if (!serial_local) { SerialInput(); }
#ifdef USE_ARDUINO_OTA
MDNS.update();

View File

@ -93,6 +93,7 @@ void KNX_CB_Action(message_t const &msg, void *arg);
//#define USE_DS3231 // Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code)
//#define USE_MGC3130 // Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem)
//#define USE_PN532_I2C // Enable PN532 - Near Field Communication (NFC) controller (+1k6 code)
//#define USE_MAX44009 // Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code)
#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code)
#ifndef CO2_LOW
@ -227,6 +228,10 @@ void KNX_CB_Action(message_t const &msg, void *arg);
#define CODE_IMAGE 6
#undef USE_ENERGY_SENSOR // Disable energy sensors (-14k code)
#undef USE_PZEM004T // Disable PZEM004T energy sensor
#undef USE_PZEM_AC // Disable PZEM014,016 Energy monitor
#undef USE_PZEM_DC // Disable PZEM003,017 Energy monitor
#undef USE_MCP39F501 // Disable MCP39F501 Energy monitor as used in Shelly 2
#undef USE_EMULATION // Disable Belkin WeMo and Hue Bridge emulation for Alexa (-16k code, -2k mem)
#undef USE_DOMOTICZ // Disable Domoticz
#undef USE_HOME_ASSISTANT // Disable Home Assistant

View File

@ -146,6 +146,14 @@ enum UserSelectablePins {
GPIO_MAX31855CS, // MAX31855 Serial interface
GPIO_MAX31855CLK, // MAX31855 Serial interface
GPIO_MAX31855DO, // MAX31855 Serial interface
GPIO_KEY1_INV, // Inverted buttons
GPIO_KEY2_INV,
GPIO_KEY3_INV,
GPIO_KEY4_INV,
GPIO_KEY1_INV_NP, // Inverted buttons without pull-up
GPIO_KEY2_INV_NP,
GPIO_KEY3_INV_NP,
GPIO_KEY4_INV_NP,
GPIO_SM16716_CLK, // SM16716 CLK
GPIO_SM16716_DAT, // SM16716 DAT
GPIO_SENSOR_END };
@ -212,7 +220,10 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_RF_SENSOR "|"
D_SENSOR_AZ_TX "|" D_SENSOR_AZ_RX "|"
D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO "|"
D_SENSOR_SM16716_CLK "|" D_SENSOR_SM16716_DAT;
D_SENSOR_BUTTON "1i|" D_SENSOR_BUTTON "2i|" D_SENSOR_BUTTON "3i|" D_SENSOR_BUTTON "4i|"
D_SENSOR_BUTTON "1in|" D_SENSOR_BUTTON "2in|" D_SENSOR_BUTTON "3in|" D_SENSOR_BUTTON "4in"
D_SENSOR_SM16716_CLK "|" D_SENSOR_SM16716_DAT
;
/********************************************************************************************/
@ -335,12 +346,20 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_NONE, // Not used
GPIO_KEY1, // Buttons
GPIO_KEY1_NP,
GPIO_KEY1_INV,
GPIO_KEY1_INV_NP,
GPIO_KEY2,
GPIO_KEY2_NP,
GPIO_KEY2_INV,
GPIO_KEY2_INV_NP,
GPIO_KEY3,
GPIO_KEY3_NP,
GPIO_KEY3_INV,
GPIO_KEY3_INV_NP,
GPIO_KEY4,
GPIO_KEY4_NP,
GPIO_KEY4_INV,
GPIO_KEY4_INV_NP,
GPIO_SWT1, // User connected external switches
GPIO_SWT1_NP,
GPIO_SWT2,
@ -1813,6 +1832,27 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
/*
Optionals
{ "ESP RGBWWC", // esp rgbww controller https://github.com/pljakobs/esp_rgbww_controller/tree/v2.3
GPIO_KEY1, // GPIO00 Button
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
0, // GPIO02
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
GPIO_PWM5, // GPIO04 LED Warm White
GPIO_PWM4, // GPIO05 LED Cold White
// GPIO06 (SD_CLK Flash)
// GPIO07 (SD_DATA0 Flash QIO/DIO/DOUT)
// GPIO08 (SD_DATA1 Flash QIO/DIO/DOUT)
0, // GPIO09 (SD_DATA2 Flash QIO or ESP8285)
0, // GPIO10 (SD_DATA3 Flash QIO or ESP8285)
// GPIO11 (SD_CMD Flash)
GPIO_PWM2, // GPIO12 LED Green
GPIO_PWM1, // GPIO13 LED Red
GPIO_PWM3, // GPIO14 LED Blue
0, // GPIO15
GPIO_KEY2, // GPIO16 Button
0
}
{ "N0DY Relay", // N0DY Wifi Dual Relay (ESP-07)
// https://www.n0dy.com/product/web-controlled-dual-relay/
// https://www.amazon.com/dp/B072MKV8ZM

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06040109
#define VERSION 0x0604010C
#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"

View File

@ -31,7 +31,7 @@ Ticker tickerOSWatch;
#define OSWATCH_RESET_TIME 120
static unsigned long oswatch_last_loop_time;
byte oswatch_blocked_loop = 0;
uint8_t oswatch_blocked_loop = 0;
#ifndef USE_WS2812_DMA // Collides with Neopixelbus but solves exception
//void OsWatchTicker() ICACHE_RAM_ATTR;
@ -84,7 +84,7 @@ String GetResetReason(void)
}
}
boolean OsWatchBlockedLoop(void)
bool OsWatchBlockedLoop(void)
{
return oswatch_blocked_loop;
}
@ -374,10 +374,10 @@ uint8_t Shortcut(const char* str)
return result;
}
boolean ParseIp(uint32_t* addr, const char* str)
bool ParseIp(uint32_t* addr, const char* str)
{
uint8_t *part = (uint8_t*)addr;
byte i;
uint8_t i;
*addr = 0;
for (i = 0; i < 4; i++) {
@ -391,7 +391,7 @@ boolean ParseIp(uint32_t* addr, const char* str)
return (3 == i);
}
void MakeValidMqtt(byte option, char* str)
void MakeValidMqtt(uint8_t option, char* str)
{
// option 0 = replace by underscore
// option 1 = delete character
@ -701,7 +701,7 @@ int GetStateNumber(char *state_text)
return state_number;
}
boolean GetUsedInModule(byte val, uint8_t *arr)
bool GetUsedInModule(uint8_t val, uint8_t *arr)
{
int offset = 0;
@ -713,6 +713,12 @@ boolean GetUsedInModule(byte val, uint8_t *arr)
if ((val >= GPIO_KEY1_NP) && (val < GPIO_KEY1_NP + MAX_KEYS)) {
offset = -(GPIO_KEY1_NP - GPIO_KEY1);
}
if ((val >= GPIO_KEY1_INV) && (val < GPIO_KEY1_INV + MAX_KEYS)) {
offset = -(GPIO_KEY1_INV - GPIO_KEY1);
}
if ((val >= GPIO_KEY1_INV_NP) && (val < GPIO_KEY1_INV_NP + MAX_KEYS)) {
offset = -(GPIO_KEY1_INV_NP - GPIO_KEY1);
}
if ((val >= GPIO_SWT1) && (val < GPIO_SWT1 + MAX_SWITCHES)) {
offset = (GPIO_SWT1_NP - GPIO_SWT1);
@ -749,7 +755,7 @@ boolean GetUsedInModule(byte val, uint8_t *arr)
offset = -(GPIO_CNTR1_NP - GPIO_CNTR1);
}
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
for (uint8_t i = 0; i < MAX_GPIO_PIN; i++) {
if (arr[i] == val) { return true; }
if (arr[i] == val + offset) { return true; }
}
@ -774,7 +780,7 @@ void SetSerialBaudrate(int baudrate)
void ClaimSerial(void)
{
serial_local = 1;
serial_local = true;
AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial"));
SetSeriallog(LOG_LEVEL_NONE);
baudrate = Serial.baudRate();
@ -899,7 +905,7 @@ uint32_t i2c_buffer = 0;
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
{
byte x = I2C_RETRY_COUNTER;
uint8_t x = I2C_RETRY_COUNTER;
i2c_buffer = 0;
do {
@ -908,7 +914,7 @@ bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
if (0 == Wire.endTransmission(false)) { // Try to become I2C Master, send data and collect bytes, keep master status for next request...
Wire.requestFrom((int)addr, (int)size); // send data n-bytes read
if (Wire.available() == size) {
for (byte i = 0; i < size; i++) {
for (uint8_t i = 0; i < size; i++) {
i2c_buffer = i2c_buffer << 8 | Wire.read(); // receive DATA
}
}
@ -1000,7 +1006,7 @@ int32_t I2cRead24(uint8_t addr, uint8_t reg)
bool I2cWrite(uint8_t addr, uint8_t reg, uint32_t val, uint8_t size)
{
byte x = I2C_RETRY_COUNTER;
uint8_t x = I2C_RETRY_COUNTER;
do {
Wire.beginTransmission((uint8_t)addr); // start transmission to device
@ -1029,7 +1035,7 @@ int8_t I2cReadBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len)
Wire.beginTransmission((uint8_t)addr);
Wire.write((uint8_t)reg);
Wire.endTransmission();
if (len != Wire.requestFrom((uint8_t)addr, (byte)len)) {
if (len != Wire.requestFrom((uint8_t)addr, (uint8_t)len)) {
return 1;
}
while (len--) {
@ -1060,9 +1066,9 @@ void I2cScan(char *devs, unsigned int devs_len)
// I2C_SDA_HELD_LOW 3 = I2C bus error. SDA line held low by slave/another_master after n bits
// I2C_SDA_HELD_LOW_AFTER_INIT 4 = line busy. SDA again held low by another device. 2nd master?
byte error = 0;
byte address = 0;
byte any = 0;
uint8_t error = 0;
uint8_t address = 0;
uint8_t any = 0;
snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_DEVICES_FOUND_AT));
for (address = 1; address <= 127; address++) {
@ -1086,9 +1092,9 @@ void I2cScan(char *devs, unsigned int devs_len)
}
}
boolean I2cDevice(byte addr)
bool I2cDevice(uint8_t addr)
{
for (byte address = 1; address <= 127; address++) {
for (uint8_t address = 1; address <= 127; address++) {
Wire.beginTransmission(address);
if (!Wire.endTransmission() && (address == addr)) {
return true;
@ -1107,7 +1113,7 @@ boolean I2cDevice(byte addr)
*
\*********************************************************************************************/
void SetSeriallog(byte loglevel)
void SetSeriallog(uint8_t loglevel)
{
Settings.seriallog_level = loglevel;
seriallog_level = loglevel;
@ -1115,7 +1121,7 @@ void SetSeriallog(byte loglevel)
}
#ifdef USE_WEBSERVER
void GetLog(byte idx, char** entry_pp, size_t* len_p)
void GetLog(uint8_t idx, char** entry_pp, size_t* len_p)
{
char* entry_p = NULL;
size_t len = 0;
@ -1123,7 +1129,7 @@ void GetLog(byte idx, char** entry_pp, size_t* len_p)
if (idx) {
char* it = web_log;
do {
byte cur_idx = *it;
uint8_t cur_idx = *it;
it++;
size_t tmp = strchrspn(it, '\1');
tmp++; // Skip terminating '\1'
@ -1164,7 +1170,7 @@ void Syslog(void)
}
}
void AddLog(byte loglevel)
void AddLog(uint8_t loglevel)
{
char mxtime[10]; // "13:45:21 "
@ -1194,13 +1200,13 @@ void AddLog(byte loglevel)
if (!global_state.wifi_down && (loglevel <= syslog_level)) { Syslog(); }
}
void AddLog_P(byte loglevel, const char *formatP)
void AddLog_P(uint8_t loglevel, const char *formatP)
{
snprintf_P(log_data, sizeof(log_data), formatP);
AddLog(loglevel);
}
void AddLog_P(byte loglevel, const char *formatP, const char *formatP2)
void AddLog_P(uint8_t loglevel, const char *formatP, const char *formatP2)
{
char message[100];
@ -1210,7 +1216,7 @@ void AddLog_P(byte loglevel, const char *formatP, const char *formatP2)
AddLog(loglevel);
}
void AddLogBuffer(byte loglevel, uint8_t *buffer, int count)
void AddLogBuffer(uint8_t loglevel, uint8_t *buffer, int count)
{
snprintf_P(log_data, sizeof(log_data), PSTR("DMP:"));
for (int i = 0; i < count; i++) {
@ -1219,7 +1225,7 @@ void AddLogBuffer(byte loglevel, uint8_t *buffer, int count)
AddLog(loglevel);
}
void AddLogSerial(byte loglevel)
void AddLogSerial(uint8_t loglevel)
{
AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter);
}

View File

@ -32,8 +32,9 @@ uint8_t multiwindow[MAX_KEYS] = { 0 }; // Max time between button presses t
uint8_t multipress[MAX_KEYS] = { 0 }; // Number of button presses within multiwindow
uint8_t dual_hex_code = 0; // Sonoff dual input flag
uint8_t key_no_pullup = 0;
uint8_t buttons_found = 0;
uint8_t key_no_pullup = 0; // key no pullup flag (1 = no pullup)
uint8_t key_inverted = 0; // Key inverted flag (1 = inverted)
uint8_t buttons_found = 0; // Number of buttons found flag
/********************************************************************************************/
@ -42,6 +43,11 @@ void ButtonPullupFlag(uint8 button_bit)
bitSet(key_no_pullup, button_bit);
}
void ButtonInvertFlag(uint8 button_bit)
{
bitSet(key_inverted, button_bit);
}
void ButtonInit(void)
{
if (my_module_flag.pullup) {
@ -51,7 +57,7 @@ void ButtonInit(void)
}
buttons_found = 0;
for (byte i = 0; i < MAX_KEYS; i++) {
for (uint8_t i = 0; i < MAX_KEYS; i++) {
if (pin[GPIO_KEY1 +i] < 99) {
buttons_found++;
pinMode(pin[GPIO_KEY1 +i], bitRead(key_no_pullup, i) ? INPUT : ((16 == pin[GPIO_KEY1 +i]) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
@ -59,7 +65,7 @@ void ButtonInit(void)
}
}
byte ButtonSerial(byte serial_in_byte)
uint8_t ButtonSerial(uint8_t serial_in_byte)
{
if (dual_hex_code) {
dual_hex_code--;
@ -96,7 +102,7 @@ void ButtonHandler(void)
char scmnd[20];
uint8_t maxdev = (devices_present > MAX_KEYS) ? MAX_KEYS : devices_present;
for (byte button_index = 0; button_index < maxdev; button_index++) {
for (uint8_t button_index = 0; button_index < maxdev; button_index++) {
button = NOT_PRESSED;
button_present = 0;
@ -115,7 +121,7 @@ void ButtonHandler(void)
} else {
if (pin[GPIO_KEY1 +button_index] < 99) {
button_present = 1;
button = digitalRead(pin[GPIO_KEY1 +button_index]);
button = (digitalRead(pin[GPIO_KEY1 +button_index]) != bitRead(key_inverted, button_index));
}
}
@ -128,7 +134,7 @@ void ButtonHandler(void)
else if (SONOFF_4CHPRO == Settings.module) {
if (holdbutton[button_index]) { holdbutton[button_index]--; }
boolean button_pressed = false;
bool button_pressed = false;
if ((PRESSED == button) && (NOT_PRESSED == lastbutton[button_index])) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_LEVEL_10), button_index +1);
AddLog(LOG_LEVEL_DEBUG);
@ -194,7 +200,7 @@ void ButtonHandler(void)
multiwindow[button_index]--;
} else {
if (!restart_flag && !holdbutton[button_index] && (multipress[button_index] > 0) && (multipress[button_index] < MAX_BUTTON_COMMANDS +3)) {
boolean single_press = false;
bool single_press = false;
if (multipress[button_index] < 3) { // Single or Double press
if ((SONOFF_DUAL_R2 == Settings.module) || (SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) {
single_press = true;

View File

@ -379,7 +379,9 @@ void GetFeatures(void)
#ifdef USE_PN532_I2C
feature_sns2 |= 0x00100000; // xsns_40_pn532_i2c.ino
#endif
// feature_sns2 |= 0x00200000;
#ifdef USE_MAX44009
feature_sns2 |= 0x00200000;
#endif
// feature_sns2 |= 0x00400000;
// feature_sns2 |= 0x00800000;
// feature_sns2 |= 0x01000000;

View File

@ -60,7 +60,7 @@ String GetBuildDateAndTime(void)
int year = 0;
// sscanf(mdate, "%s %d %d", bdt, &day, &year); // Not implemented in 2.3.0 and probably too much code
byte i = 0;
uint8_t i = 0;
for (char *str = strtok_r(mdate, " ", &p); str && i < 3; str = strtok_r(NULL, " ", &p)) {
switch (i++) {
case 0: // Month
@ -112,7 +112,7 @@ String GetDT(uint32_t time)
* "2017-03-07T11:08:02-07:00" - if DT_LOCAL and SetOption52 = 1
* "2017-03-07T11:08:02" - otherwise
*/
String GetDateAndTime(byte time_type)
String GetDateAndTime(uint8_t time_type)
{
// "2017-03-07T11:08:02-07:00" - ISO8601:2004
uint32_t time = local_time;
@ -332,9 +332,9 @@ uint32_t Midnight(void)
return midnight;
}
boolean MidnightNow(void)
bool MidnightNow(void)
{
boolean mnflg = midnight_now;
bool mnflg = midnight_now;
if (mnflg) midnight_now = 0;
return mnflg;
}
@ -348,7 +348,7 @@ void RtcSecond(void)
if (!global_state.wifi_down && (offset == RtcTime.second) && ((RtcTime.year < 2016) || (ntp_sync_minute == RtcTime.minute) || ntp_force_sync)) {
ntp_time = sntp_get_current_timestamp();
if (ntp_time > 1451602800) { // Fix NTP bug in core 2.4.1/SDK 2.2.1 (returns Thu Jan 01 08:00:10 1970 after power on)
ntp_force_sync = 0;
ntp_force_sync = false;
utc_time = ntp_time;
ntp_sync_minute = 60; // Sync so block further requests
if (restart_time == 0) {

View File

@ -71,7 +71,7 @@ void SwitchProbe(void)
uint8_t force_high = (Settings.switch_debounce % 50) &1; // 51, 101, 151 etc
uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (pin[GPIO_SWT1 +i] < 99) {
// Olimex user_switch2.c code to fix 50Hz induced pulses
if (1 == digitalRead(pin[GPIO_SWT1 +i])) {
@ -117,7 +117,7 @@ void SwitchInit(void)
}
switches_found = 0;
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
lastwallswitch[i] = 1; // Init global to virtual switch state;
if (pin[GPIO_SWT1 +i] < 99) {
switches_found++;
@ -133,7 +133,7 @@ void SwitchInit(void)
* Switch handler
\*********************************************************************************************/
void SwitchHandler(byte mode)
void SwitchHandler(uint8_t mode)
{
if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
@ -141,7 +141,7 @@ void SwitchHandler(byte mode)
uint8_t switchflag;
uint16_t loops_per_second = 1000 / Settings.switch_debounce;
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if ((pin[GPIO_SWT1 +i] < 99) || (mode)) {
if (holdwallswitch[i]) {

View File

@ -32,6 +32,21 @@
#define WIFI_CHECK_SEC 20 // seconds
#define WIFI_RETRY_OFFSET_SEC 20 // seconds
/*
// This worked for 2_5_0_BETA2 but fails since then. Waiting for a solution from core team (#4952)
#ifdef USE_MQTT_TLS
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
#else
#define USING_AXTLS
#include <ESP8266WiFi.h>
// force use of AxTLS (BearSSL is now default) which uses less memory (#4952)
#include <WiFiClientSecureAxTLS.h>
using namespace axTLS;
#endif // ARDUINO_ESP8266_RELEASE prior to 2_5_0
#else
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
#endif // USE_MQTT_TLS
*/
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
uint8_t wifi_counter;
@ -60,7 +75,7 @@ int WifiGetRssiAsQuality(int rssi)
return quality;
}
boolean WifiConfigCounter(void)
bool WifiConfigCounter(void)
{
if (wifi_config_counter) {
wifi_config_counter = WIFI_CONFIG_SEC;
@ -95,12 +110,12 @@ void WifiWpsStatusCallback(wps_cb_status status)
}
}
boolean WifiWpsConfigDone(void)
bool WifiWpsConfigDone(void)
{
return (!wps_result);
}
boolean WifiWpsConfigBegin(void)
bool WifiWpsConfigBegin(void)
{
wps_result = 99;
if (!wifi_wps_disable()) { return false; }

View File

@ -349,7 +349,7 @@ enum HttpOptions {HTTP_OFF, HTTP_USER, HTTP_ADMIN, HTTP_MANAGER};
DNSServer *DnsServer;
ESP8266WebServer *WebServer;
boolean remove_duplicate_access_points = true;
bool remove_duplicate_access_points = true;
int minimum_signal_quality = -1;
uint8_t webserver_state = HTTP_OFF;
uint8_t upload_error = 0;
@ -415,7 +415,7 @@ void StartWebserver(int type, IPAddress ipweb)
XsnsCall(FUNC_WEB_ADD_HANDLER);
#endif // Not BE_MINIMAL
}
reset_web_log_flag = 0;
reset_web_log_flag = false;
WebServer->begin(); // Web server start
}
if (webserver_state != type) {
@ -640,13 +640,13 @@ void HandleRoot(void)
if (SONOFF_IFAN02 == Settings.module) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, "");
page += mqtt_data;
for (byte i = 0; i < MAX_FAN_SPEED; i++) {
for (uint8_t i = 0; i < MAX_FAN_SPEED; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, 16, i +2, stemp, "");
page += mqtt_data;
}
} else {
for (byte idx = 1; idx <= devices_present; idx++) {
for (uint8_t idx = 1; idx <= devices_present; idx++) {
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL,
100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : "");
@ -658,10 +658,10 @@ void HandleRoot(void)
if (SONOFF_BRIDGE == Settings.module) {
page += FPSTR(HTTP_TABLE100);
page += F("<tr>");
byte idx = 0;
for (byte i = 0; i < 4; i++) {
uint8_t idx = 0;
for (uint8_t i = 0; i < 4; i++) {
if (idx > 0) { page += F("</tr><tr>"); }
for (byte j = 0; j < 4; j++) {
for (uint8_t j = 0; j < 4; j++) {
idx++;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("<td style='width:25%'><button onclick='la(\"?k=%d\");'>%d</button></td>"), idx, idx); // ?k is related to WebGetArg("k", tmp, sizeof(tmp));
page += mqtt_data;
@ -744,7 +744,7 @@ void HandleAjaxStatusRefresh(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_STATE,
mqtt_data, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
} else {
for (byte idx = 1; idx <= devices_present; idx++) {
for (uint8_t idx = 1; idx <= devices_present; idx++) {
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, idx -1));
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_STATE,
mqtt_data, 100 / devices_present, (bitRead(power, idx -1)) ? "bold" : "normal", fsize, (devices_present < 5) ? GetStateText(bitRead(power, idx -1)) : svalue);
@ -755,7 +755,7 @@ void HandleAjaxStatusRefresh(void)
WebServer->send(200, FPSTR(HDR_CTYPE_HTML), mqtt_data);
}
boolean HttpCheckPriviledgedAccess(boolean autorequestauth = true)
bool HttpCheckPriviledgedAccess(bool autorequestauth = true)
{
if (HTTP_USER == webserver_state) {
HandleRoot();
@ -812,13 +812,13 @@ void HandleModuleConfiguration(void)
if (WebServer->hasArg("m")) {
String page = "";
for (byte i = 0; i < MAXMODULE; i++) {
for (uint8_t i = 0; i < MAXMODULE; i++) {
midx = pgm_read_byte(kModuleNiceList + i);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE3, midx, AnyModuleName(midx).c_str(), midx +1);
page += mqtt_data;
}
page += "}3"; // String separator means do not use "}3" in Module name and Sensor name
for (byte j = 0; j < sizeof(kGpioNiceList); j++) {
for (uint8_t j = 0; j < sizeof(kGpioNiceList); j++) {
midx = pgm_read_byte(kGpioNiceList + j);
if (!GetUsedInModule(midx, cmodule.io)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE3, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx);
@ -835,7 +835,7 @@ void HandleModuleConfiguration(void)
page.replace(F("{v}"), FPSTR(S_CONFIGURE_MODULE));
page += FPSTR(HTTP_SCRIPT_MODULE1);
page.replace(F("}4"), String(Settings.module));
for (byte i = 0; i < sizeof(cmodule); i++) {
for (uint8_t i = 0; i < sizeof(cmodule); i++) {
if (GPIO_USER == ValidGPIO(i, cmodule.io[i])) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16
page += mqtt_data;
@ -853,7 +853,7 @@ void HandleModuleConfiguration(void)
}
page += F("<br/><table>");
for (byte i = 0; i < sizeof(cmodule); i++) {
for (uint8_t i = 0; i < sizeof(cmodule); i++) {
if (GPIO_USER == ValidGPIO(i, cmodule.io[i])) {
snprintf_P(stemp, 3, PINS_WEMOS +i*2);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("<tr><td style='width:190px'>%s <b>" D_GPIO "%d</b> %s</td><td style='width:160px'><select id='g%d' name='g%d'></select></td></tr>"),
@ -873,7 +873,7 @@ void ModuleSaveSettings(void)
char stemp[TOPSZ];
WebGetArg("g99", tmp, sizeof(tmp));
byte new_module = (!strlen(tmp)) ? MODULE : atoi(tmp);
uint8_t new_module = (!strlen(tmp)) ? MODULE : atoi(tmp);
Settings.last_module = Settings.module;
Settings.module = new_module;
if (Settings.last_module == new_module) {
@ -884,7 +884,7 @@ void ModuleSaveSettings(void)
myio cmodule;
ModuleGpios(&cmodule);
String gpios = "";
for (byte i = 0; i < sizeof(cmodule); i++) {
for (uint8_t i = 0; i < sizeof(cmodule); i++) {
if (Settings.last_module != new_module) {
Settings.my_gp.io[i] = 0;
} else {
@ -1057,14 +1057,14 @@ void HandleLoggingConfiguration(void)
page += FPSTR(HTTP_HEAD_STYLE);
page += FPSTR(HTTP_FORM_LOG1);
for (byte idx = 0; idx < 3; idx++) {
for (uint8_t idx = 0; idx < 3; idx++) {
page += FPSTR(HTTP_FORM_LOG2);
switch (idx) {
case 0:
page.replace(F("{b0"), F(D_SERIAL_LOG_LEVEL));
page.replace(F("{b1"), STR(SERIAL_LOG_LEVEL));
page.replace(F("{b2"), F("ls"));
for (byte i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
for (uint8_t i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
page.replace("{a" + String(i), (i == Settings.seriallog_level) ? F(" selected ") : F(" "));
}
break;
@ -1072,7 +1072,7 @@ void HandleLoggingConfiguration(void)
page.replace(F("{b0"), F(D_WEB_LOG_LEVEL));
page.replace(F("{b1"), STR(WEB_LOG_LEVEL));
page.replace(F("{b2"), F("lw"));
for (byte i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
for (uint8_t i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
page.replace("{a" + String(i), (i == Settings.weblog_level) ? F(" selected ") : F(" "));
}
break;
@ -1080,7 +1080,7 @@ void HandleLoggingConfiguration(void)
page.replace(F("{b0"), F(D_SYS_LOG_LEVEL));
page.replace(F("{b1"), STR(SYS_LOG_LEVEL));
page.replace(F("{b2"), F("ll"));
for (byte i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
for (uint8_t i = LOG_LEVEL_NONE; i < LOG_LEVEL_ALL; i++) {
page.replace("{a" + String(i), (i == Settings.syslog_level) ? F(" selected ") : F(" "));
}
break;
@ -1145,7 +1145,7 @@ void HandleOtherConfiguration(void)
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
if (SONOFF_IFAN02 == Settings.module) { maxfn = 1; }
for (byte i = 0; i < maxfn; i++) {
for (uint8_t i = 0; i < maxfn; i++) {
page += FPSTR(HTTP_FORM_OTHER2);
page.replace(F("{1"), String(i +1));
snprintf_P(stemp, sizeof(stemp), PSTR(FRIENDLY_NAME"%d"), i +1);
@ -1154,7 +1154,7 @@ void HandleOtherConfiguration(void)
}
#ifdef USE_EMULATION
page += FPSTR(HTTP_FORM_OTHER3a);
for (byte i = 0; i < EMUL_MAX; i++) {
for (uint8_t i = 0; i < EMUL_MAX; i++) {
page += FPSTR(HTTP_FORM_OTHER3b);
page.replace(F("{1"), String(i));
page.replace(F("{2"), (i == Settings.flag2.emulation) ? F(" checked") : F(""));
@ -1183,7 +1183,7 @@ void OtherSaveSettings(void)
Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp);
#endif // USE_EMULATION
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation);
for (byte i = 0; i < MAX_FRIENDLYNAMES; i++) {
for (uint8_t i = 0; i < MAX_FRIENDLYNAMES; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("a%d"), i +1);
WebGetArg(stemp, tmp, sizeof(tmp));
snprintf_P(stemp2, sizeof(stemp2), PSTR(FRIENDLY_NAME"%d"), i +1);
@ -1313,7 +1313,7 @@ void HandleInformation(void)
func += F("}1" D_RESTART_REASON "}2"); func += GetResetReason();
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
if (SONOFF_IFAN02 == Settings.module) { maxfn = 1; }
for (byte i = 0; i < maxfn; i++) {
for (uint8_t i = 0; i < maxfn; i++) {
func += F("}1" D_FRIENDLY_NAME " "); func += i +1; func += F("}2"); func += Settings.friendlyname[i];
}
@ -1509,7 +1509,7 @@ void HandleUploadDone(void)
void HandleUploadLoop(void)
{
// Based on ESP8266HTTPUpdateServer.cpp uses ESP8266WebServer Parsing.cpp and Cores Updater.cpp (Update)
boolean _serialoutput = (LOG_LEVEL_DEBUG <= seriallog_level);
bool _serialoutput = (LOG_LEVEL_DEBUG <= seriallog_level);
if (HTTP_USER == webserver_state) { return; }
if (upload_error) {
@ -1729,13 +1729,13 @@ void HandleHttpCommand(void)
String message = F("{\"" D_RSLT_WARNING "\":\"");
if (valid) {
byte curridx = web_log_index;
uint8_t curridx = web_log_index;
WebGetArg("cmnd", svalue, sizeof(svalue));
if (strlen(svalue)) {
ExecuteWebCommand(svalue, SRC_WEBCOMMAND);
if (web_log_index != curridx) {
byte counter = curridx;
uint8_t counter = curridx;
message = F("{");
do {
char* tmp;
@ -1791,8 +1791,8 @@ void HandleAjaxConsoleRefresh(void)
if (!HttpCheckPriviledgedAccess()) { return; }
char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
byte cflg = 1;
byte counter = 0; // Initial start, should never be 0 again
bool cflg = true;
uint8_t counter = 0; // Initial start, should never be 0 again
WebGetArg("c1", svalue, sizeof(svalue));
if (strlen(svalue)) {
@ -1804,16 +1804,16 @@ void HandleAjaxConsoleRefresh(void)
WebGetArg("c2", svalue, sizeof(svalue));
if (strlen(svalue)) { counter = atoi(svalue); }
byte last_reset_web_log_flag = reset_web_log_flag;
bool last_reset_web_log_flag = reset_web_log_flag;
String message = F("}9"); // Cannot load mqtt_data here as <> will be encoded by replacements below
if (!reset_web_log_flag) {
counter = 0;
reset_web_log_flag = 1;
reset_web_log_flag = true;
}
if (counter != web_log_index) {
if (!counter) {
counter = web_log_index;
cflg = 0;
cflg = false;
}
do {
char* tmp;
@ -1823,7 +1823,7 @@ void HandleAjaxConsoleRefresh(void)
if (cflg) {
message += F("\n");
} else {
cflg = 1;
cflg = true;
}
strlcpy(mqtt_data, tmp, len);
message += mqtt_data;
@ -1870,7 +1870,7 @@ void HandleNotFound(void)
}
/* Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
boolean CaptivePortal(void)
bool CaptivePortal(void)
{
if ((HTTP_MANAGER == webserver_state) && !ValidIpAddress(WebServer->hostHeader())) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_REDIRECTED));
@ -1884,7 +1884,7 @@ boolean CaptivePortal(void)
}
/** Is this an IP? */
boolean ValidIpAddress(String str)
bool ValidIpAddress(String str)
{
for (uint16_t i = 0; i < str.length(); i++) {
int c = str.charAt(i);
@ -1984,7 +1984,7 @@ int WebSend(char *buffer)
WiFiClient client;
bool connected = false;
byte retry = 2;
uint8_t retry = 2;
while ((retry > 0) && !connected) {
--retry;
connected = client.connect(host_ip, nport);
@ -2085,9 +2085,9 @@ bool WebCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv01(byte function)
bool Xdrv01(uint8_t function)
{
boolean result = false;
bool result = false;
switch (function) {
case FUNC_LOOP:

View File

@ -76,6 +76,7 @@ const char kMqttCommands[] PROGMEM =
uint16_t mqtt_retry_counter = 1; // MQTT connection retry counter
uint8_t mqtt_initial_connection_state = 2; // MQTT connection messages state
bool mqtt_connected = false; // MQTT virtual connection status
bool mqtt_allowed = false; // MQTT enabled and parameters valid
/*********************************************************************************************\
* MQTT driver specific code need to provide the following functions:
@ -83,7 +84,7 @@ bool mqtt_connected = false; // MQTT virtual connection status
* bool MqttIsConnected()
* void MqttDisconnect()
* void MqttSubscribeLib(char *topic)
* bool MqttPublishLib(const char* topic, boolean retained)
* bool MqttPublishLib(const char* topic, bool retained)
* void MqttLoop()
\*********************************************************************************************/
@ -114,7 +115,7 @@ void MqttSubscribeLib(char *topic)
MqttClient.loop(); // Solve LmacRxBlk:1 messages
}
bool MqttPublishLib(const char* topic, boolean retained)
bool MqttPublishLib(const char* topic, bool retained)
{
bool result = MqttClient.publish(topic, mqtt_data, retained);
yield(); // #3313
@ -151,7 +152,7 @@ void MqttSubscribeLib(char *topic)
MqttClient.Subscribe(topic, 0);
}
bool MqttPublishLib(const char* topic, boolean retained)
bool MqttPublishLib(const char* topic, bool retained)
{
return MqttClient.Publish(topic, mqtt_data, strlen(mqtt_data), 0, retained);
}
@ -179,13 +180,13 @@ void MqttDisconnect(void)
void MqttMyDataCb(MQTTClient* client, char* topic, char* data, int data_len)
//void MqttMyDataCb(MQTTClient *client, char topic[], char data[], int data_len)
{
// MqttDataHandler((char*)topic, (byte*)data, data_len);
// MqttDataHandler((char*)topic, (uint8_t*)data, data_len);
}
*/
void MqttMyDataCb(String &topic, String &data)
{
MqttDataHandler((char*)topic.c_str(), (byte*)data.c_str(), data.length());
MqttDataHandler((char*)topic.c_str(), (uint8_t*)data.c_str(), data.length());
}
void MqttSubscribeLib(char *topic)
@ -193,7 +194,7 @@ void MqttSubscribeLib(char *topic)
MqttClient.subscribe(topic, 0);
}
bool MqttPublishLib(const char* topic, boolean retained)
bool MqttPublishLib(const char* topic, bool retained)
{
return MqttClient.publish(topic, mqtt_data, strlen(mqtt_data), retained, 0);
}
@ -210,9 +211,9 @@ void MqttLoop(void)
#ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY
boolean MqttDiscoverServer(void)
void MqttDiscoverServer(void)
{
if (!mdns_begun) { return false; }
if (!mdns_begun) { return; }
int n = MDNS.queryService("mqtt", "tcp"); // Search for mqtt service
@ -220,26 +221,21 @@ boolean MqttDiscoverServer(void)
AddLog(LOG_LEVEL_INFO);
if (n > 0) {
#ifdef MDNS_HOSTNAME
for (int i = 0; i < n; i++) {
uint8_t i = 0; // If the hostname isn't set, use the first record found.
#ifdef MDNS_HOSTNAME
for (i = n; i > 0; i--) { // Search from last to first and use first if not found
if (!strcmp(MDNS.hostname(i).c_str(), MDNS_HOSTNAME)) {
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(i).toString().c_str());
Settings.mqtt_port = MDNS.port(i);
break; // stop at the first matching record
break; // Stop at matching record
}
}
#else
// If the hostname isn't set, use the first record found.
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(0).toString().c_str());
Settings.mqtt_port = MDNS.port(0);
#endif // MDNS_HOSTNAME
#endif // MDNS_HOSTNAME
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(i).toString().c_str());
Settings.mqtt_port = MDNS.port(i);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"),
MDNS.hostname(0).c_str(), Settings.mqtt_host, Settings.mqtt_port);
MDNS.hostname(i).c_str(), Settings.mqtt_host, Settings.mqtt_port);
AddLog(LOG_LEVEL_INFO);
}
return n > 0;
}
#endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY
@ -261,7 +257,7 @@ void MqttSubscribe(char *topic)
MqttSubscribeLib(topic);
}
void MqttPublishDirect(const char* topic, boolean retained)
void MqttPublishDirect(const char* topic, bool retained)
{
char sretained[CMDSZ];
char slog_type[10];
@ -295,7 +291,7 @@ void MqttPublishDirect(const char* topic, boolean retained)
}
}
void MqttPublish(const char* topic, boolean retained)
void MqttPublish(const char* topic, bool retained)
{
char *me;
@ -313,7 +309,7 @@ void MqttPublish(const char* topic)
MqttPublish(topic, false);
}
void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, boolean retained)
void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, bool retained)
{
/* prefix 0 = cmnd using subtopic
* prefix 1 = stat using subtopic
@ -326,7 +322,7 @@ void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, boolean reta
char stopic[TOPSZ];
snprintf_P(romram, sizeof(romram), ((prefix > 3) && !Settings.flag.mqtt_response) ? S_RSLT_RESULT : subtopic);
for (byte i = 0; i < strlen(romram); i++) {
for (uint8_t i = 0; i < strlen(romram); i++) {
romram[i] = toupper(romram[i]);
}
prefix &= 3;
@ -339,7 +335,7 @@ void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic)
MqttPublishPrefixTopic_P(prefix, subtopic, false);
}
void MqttPublishPowerState(byte device)
void MqttPublishPowerState(uint8_t device)
{
char stopic[TOPSZ];
char scommand[33];
@ -368,7 +364,7 @@ void MqttPublishPowerState(byte device)
}
}
void MqttPublishPowerBlinkState(byte device)
void MqttPublishPowerBlinkState(uint8_t device)
{
char scommand[33];
@ -398,7 +394,7 @@ void MqttConnected(void)
{
char stopic[TOPSZ];
if (Settings.flag.mqtt_enabled) {
if (mqtt_allowed) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_CONNECTED));
mqtt_connected = true;
mqtt_retry_counter = 0;
@ -437,7 +433,7 @@ void MqttConnected(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_RESTARTREASON "\":\"%s\"}"),
(GetResetReason() == "Exception") ? ESP.getResetInfo().c_str() : GetResetReason().c_str());
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "3"));
for (byte i = 1; i <= devices_present; i++) {
for (uint8_t i = 1; i <= devices_present; i++) {
MqttPublishPowerState(i);
if (SONOFF_IFAN02 == Settings.module) { break; } // Report status of light relay only
}
@ -454,15 +450,15 @@ void MqttConnected(void)
}
#ifdef USE_MQTT_TLS
boolean MqttCheckTls(void)
bool MqttCheckTls(void)
{
char fingerprint1[60];
char fingerprint2[60];
boolean result = false;
bool result = false;
fingerprint1[0] = '\0';
fingerprint2[0] = '\0';
for (byte i = 0; i < sizeof(Settings.mqtt_fingerprint[0]); i++) {
for (uint8_t i = 0; i < sizeof(Settings.mqtt_fingerprint[0]); i++) {
snprintf_P(fingerprint1, sizeof(fingerprint1), PSTR("%s%s%02X"), fingerprint1, (i) ? " " : "", Settings.mqtt_fingerprint[0][i]);
snprintf_P(fingerprint2, sizeof(fingerprint2), PSTR("%s%s%02X"), fingerprint2, (i) ? " " : "", Settings.mqtt_fingerprint[1][i]);
}
@ -495,7 +491,19 @@ boolean MqttCheckTls(void)
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_VERIFIED "2"));
result = true;
}
#endif
#ifdef MDNS_HOSTNAME
// If the hostname is set, check that as well.
// This lets certs with the hostname for the CN be used.
else if (EspClient.verify(fingerprint1, MDNS_HOSTNAME)) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_VERIFIED "1"));
result = true;
}
else if (EspClient.verify(fingerprint2, MDNS_HOSTNAME)) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_VERIFIED "2"));
result = true;
}
#endif // MDNS_HOSTNAME
#endif // USE_MQTT_TLS_CA_CERT
}
if (!result) AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_FAILED));
EspClient.stop();
@ -508,7 +516,18 @@ void MqttReconnect(void)
{
char stopic[TOPSZ];
if (!Settings.flag.mqtt_enabled) {
mqtt_allowed = Settings.flag.mqtt_enabled;
if (mqtt_allowed) {
#ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY
MqttDiscoverServer();
#endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY
if (!strlen(Settings.mqtt_host) || !Settings.mqtt_port) {
mqtt_allowed = false;
}
}
if (!mqtt_allowed) {
MqttConnected();
return;
}
@ -523,12 +542,6 @@ void MqttReconnect(void)
mqtt_retry_counter = Settings.mqtt_retry;
global_state.mqtt_down = 1;
#ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY
if (!MqttDiscoverServer() && !strlen(Settings.mqtt_host)) { return; }
#endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY
char *mqtt_user = NULL;
char *mqtt_pwd = NULL;
if (strlen(Settings.mqtt_user) > 0) mqtt_user = Settings.mqtt_user;
@ -625,7 +638,7 @@ bool MqttCommand(void)
uint16_t data_len = XdrvMailbox.data_len;
uint16_t payload16 = XdrvMailbox.payload16;
int16_t payload = XdrvMailbox.payload;
uint8_t grpflg = XdrvMailbox.grpflg;
bool grpflg = XdrvMailbox.grpflg;
char *type = XdrvMailbox.topic;
char *dataBuf = XdrvMailbox.data;
@ -669,13 +682,13 @@ bool MqttCommand(void)
if ((data_len > 0) && (data_len < sizeof(fingerprint))) {
strlcpy(fingerprint, (SC_CLEAR == Shortcut(dataBuf)) ? "" : (SC_DEFAULT == Shortcut(dataBuf)) ? (1 == index) ? MQTT_FINGERPRINT1 : MQTT_FINGERPRINT2 : dataBuf, sizeof(fingerprint));
char *p = fingerprint;
for (byte i = 0; i < 20; i++) {
for (uint8_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[index -1][i] = strtol(p, &p, 16);
}
restart_flag = 2;
}
fingerprint[0] = '\0';
for (byte i = 0; i < sizeof(Settings.mqtt_fingerprint[index -1]); i++) {
for (uint8_t i = 0; i < sizeof(Settings.mqtt_fingerprint[index -1]); i++) {
snprintf_P(fingerprint, sizeof(fingerprint), PSTR("%s%s%02X"), fingerprint, (i) ? " " : "", Settings.mqtt_fingerprint[index -1][i]);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, fingerprint);
@ -936,9 +949,9 @@ void MqttSaveSettings(void)
* Interface
\*********************************************************************************************/
boolean Xdrv02(byte function)
bool Xdrv02(uint8_t function)
{
boolean result = false;
bool result = false;
if (Settings.flag.mqtt_enabled) {
switch (function) {

View File

@ -72,24 +72,23 @@ uint8_t energy_power_delta = 0;
bool energy_type_dc = false;
bool energy_power_on = true;
bool energy_min_power_flag = false;
bool energy_max_power_flag = false;
bool energy_min_voltage_flag = false;
bool energy_max_voltage_flag = false;
bool energy_min_current_flag = false;
bool energy_max_current_flag = false;
byte energy_min_power_flag = 0;
byte energy_max_power_flag = 0;
byte energy_min_voltage_flag = 0;
byte energy_max_voltage_flag = 0;
byte energy_min_current_flag = 0;
byte energy_max_current_flag = 0;
byte energy_power_steady_cntr = 8; // Allow for power on stabilization
byte energy_max_energy_state = 0;
uint8_t energy_power_steady_cntr = 8; // Allow for power on stabilization
uint8_t energy_max_energy_state = 0;
#if FEATURE_POWER_LIMIT
byte energy_mplr_counter = 0;
uint8_t energy_mplr_counter = 0;
uint16_t energy_mplh_counter = 0;
uint16_t energy_mplw_counter = 0;
#endif // FEATURE_POWER_LIMIT
byte energy_fifth_second = 0;
uint8_t energy_fifth_second = 0;
Ticker ticker_energy;
int energy_command_code = 0;
@ -147,9 +146,9 @@ void EnergySaveState(void)
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
}
boolean EnergyMargin(byte type, uint16_t margin, uint16_t value, byte &flag, byte &save_flag)
bool EnergyMargin(bool type, uint16_t margin, uint16_t value, bool &flag, bool &save_flag)
{
byte change;
bool change;
if (!margin) return false;
change = save_flag;
@ -173,8 +172,8 @@ void EnergyMarginCheck(void)
uint16_t energy_power_u = 0;
uint16_t energy_voltage_u = 0;
uint16_t energy_current_u = 0;
boolean flag;
boolean jsonflg;
bool flag;
bool jsonflg;
if (energy_power_steady_cntr) {
energy_power_steady_cntr--;
@ -204,30 +203,30 @@ void EnergyMarginCheck(void)
// AddLog(LOG_LEVEL_DEBUG);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{"));
jsonflg = 0;
if (EnergyMargin(0, Settings.energy_min_power, energy_power_u, flag, energy_min_power_flag)) {
jsonflg = false;
if (EnergyMargin(false, Settings.energy_min_power, energy_power_u, flag, energy_min_power_flag)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERLOW "\":\"%s\""), mqtt_data, (jsonflg)?",":"", GetStateText(flag));
jsonflg = 1;
jsonflg = true;
}
if (EnergyMargin(1, Settings.energy_max_power, energy_power_u, flag, energy_max_power_flag)) {
if (EnergyMargin(true, Settings.energy_max_power, energy_power_u, flag, energy_max_power_flag)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERHIGH "\":\"%s\""), mqtt_data, (jsonflg)?",":"", GetStateText(flag));
jsonflg = 1;
jsonflg = true;
}
if (EnergyMargin(0, Settings.energy_min_voltage, energy_voltage_u, flag, energy_min_voltage_flag)) {
if (EnergyMargin(false, Settings.energy_min_voltage, energy_voltage_u, flag, energy_min_voltage_flag)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGELOW "\":\"%s\""), mqtt_data, (jsonflg)?",":"", GetStateText(flag));
jsonflg = 1;
jsonflg = true;
}
if (EnergyMargin(1, Settings.energy_max_voltage, energy_voltage_u, flag, energy_max_voltage_flag)) {
if (EnergyMargin(true, Settings.energy_max_voltage, energy_voltage_u, flag, energy_max_voltage_flag)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGEHIGH "\":\"%s\""), mqtt_data, (jsonflg)?",":"", GetStateText(flag));
jsonflg = 1;
jsonflg = true;
}
if (EnergyMargin(0, Settings.energy_min_current, energy_current_u, flag, energy_min_current_flag)) {
if (EnergyMargin(false, Settings.energy_min_current, energy_current_u, flag, energy_min_current_flag)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTLOW "\":\"%s\""), mqtt_data, (jsonflg)?",":"", GetStateText(flag));
jsonflg = 1;
jsonflg = true;
}
if (EnergyMargin(1, Settings.energy_max_current, energy_current_u, flag, energy_max_current_flag)) {
if (EnergyMargin(true, Settings.energy_max_current, energy_current_u, flag, energy_max_current_flag)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTHIGH "\":\"%s\""), mqtt_data, (jsonflg)?",":"", GetStateText(flag));
jsonflg = 1;
jsonflg = true;
}
if (jsonflg) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
@ -310,7 +309,7 @@ void EnergyMqttShow(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str());
int tele_period_save = tele_period;
tele_period = 2;
EnergyShow(1);
EnergyShow(true);
tele_period = tele_period_save;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
@ -321,12 +320,12 @@ void EnergyMqttShow(void)
* Commands
\*********************************************************************************************/
boolean EnergyCommand(void)
bool EnergyCommand(void)
{
char command [CMDSZ];
char sunit[CMDSZ];
boolean serviced = true;
uint8_t status_flag = 0;
bool serviced = true;
bool status_flag = false;
uint8_t unit = 0;
unsigned long nvalue = 0;
@ -417,7 +416,7 @@ boolean EnergyCommand(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"),
command, energy_total_chr, energy_yesterday_chr, energy_daily_chr);
status_flag = 1;
status_flag = true;
}
else if ((CMND_POWERCAL == command_code) && XnrgCall(FUNC_COMMAND)) { // microseconds
if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_power_calibration = XdrvMailbox.payload; }
@ -568,7 +567,7 @@ const char HTTP_ENERGY_SNS4[] PROGMEM = "%s"
"{s}" D_ENERGY_TOTAL "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void EnergyShow(boolean json)
void EnergyShow(bool json)
{
char speriod[20];
char sfrequency[20];
@ -681,9 +680,9 @@ void EnergyShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xdrv03(byte function)
bool Xdrv03(uint8_t function)
{
boolean result = false;
bool result = false;
if (FUNC_PRE_INIT == function) {
EnergyDrvInit();
@ -704,9 +703,9 @@ boolean Xdrv03(byte function)
return result;
}
boolean Xsns03(byte function)
bool Xsns03(uint8_t function)
{
boolean result = false;
bool result = false;
if (energy_flg) {
switch (function) {
@ -717,11 +716,11 @@ boolean Xsns03(byte function)
EnergyMarginCheck();
break;
case FUNC_JSON_APPEND:
EnergyShow(1);
EnergyShow(true);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_APPEND:
EnergyShow(0);
EnergyShow(false);
break;
#endif // USE_WEBSERVER
case FUNC_SAVE_BEFORE_RESTART:

View File

@ -367,7 +367,7 @@ void LightInit(void)
Settings.light_color[0] = 255; // One channel only supports Dimmer but needs max color
}
if (light_type < LT_PWM6) { // PWM
for (byte i = 0; i < light_type; i++) {
for (uint8_t i = 0; i < light_type; i++) {
Settings.pwm_value[i] = 0; // Disable direct PWM control
if (pin[GPIO_PWM1 +i] < 99) {
pinMode(pin[GPIO_PWM1 +i], OUTPUT);
@ -487,7 +487,7 @@ void LightSetDimmer(uint8_t myDimmer)
Settings.light_color[0] = 255; // One PWM channel only supports Dimmer but needs max color
}
float dimmer = 100 / (float)myDimmer;
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (Settings.flag.light_signal) {
temp = (float)light_signal_color[i] / dimmer;
} else {
@ -501,7 +501,7 @@ void LightSetColor(void)
{
uint8_t highest = 0;
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (highest < light_current_color[i]) {
highest = light_current_color[i];
}
@ -509,7 +509,7 @@ void LightSetColor(void)
float mDim = (float)highest / 2.55;
Settings.light_dimmer = (uint8_t)mDim;
float dimmer = 100 / mDim;
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
float temp = (float)light_current_color[i] * dimmer;
Settings.light_color[i] = (uint8_t)temp;
}
@ -547,7 +547,7 @@ char* LightGetColor(uint8_t type, char* scolor)
{
LightSetDimmer(Settings.light_dimmer);
scolor[0] = '\0';
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (!type && Settings.flag.decimal_text) {
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", light_current_color[i]);
} else {
@ -590,7 +590,7 @@ void LightState(uint8_t append)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_HSBCOLOR "\":\"%d,%d,%d\""), mqtt_data, h,s,b);
// Add status for each channel
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_CHANNEL "\":[" ), mqtt_data);
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d" ), mqtt_data, (i > 0 ? "," : ""), light_current_color[i] * 100 / 255);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]" ), mqtt_data);
@ -637,7 +637,7 @@ void LightPreparePower(void)
void LightFade(void)
{
if (0 == Settings.light_fade) {
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
light_new_color[i] = light_current_color[i];
}
} else {
@ -646,7 +646,7 @@ void LightFade(void)
shift = (strip_timer_counter % (Settings.light_speed -6)) ? 0 : 8;
}
if (shift) {
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (light_new_color[i] != light_current_color[i]) {
if (light_new_color[i] < light_current_color[i]) {
light_new_color[i] += ((light_current_color[i] - light_new_color[i]) >> shift) +1;
@ -681,7 +681,7 @@ void LightWheel(uint8_t wheel_pos)
light_entry_color[3] = 0;
light_entry_color[4] = 0;
float dimmer = 100 / (float)Settings.light_dimmer;
for (byte i = 0; i < LST_RGB; i++) {
for (uint8_t i = 0; i < LST_RGB; i++) {
float temp = (float)light_entry_color[i] / dimmer;
light_entry_color[i] = (uint8_t)temp;
}
@ -700,7 +700,7 @@ void LightCycleColor(int8_t direction)
void LightRandomColor(void)
{
uint8_t light_update = 0;
for (byte i = 0; i < LST_RGB; i++) {
for (uint8_t i = 0; i < LST_RGB; i++) {
if (light_new_color[i] != light_current_color[i]) {
light_update = 1;
}
@ -736,7 +736,7 @@ void LightAnimate(void)
if (!light_power) { // Power Off
sleep = Settings.sleep;
strip_timer_counter = 0;
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
light_still_on += light_new_color[i];
}
if (light_still_on && Settings.light_fade && (Settings.light_scheme < LS_MAX)) {
@ -744,19 +744,19 @@ void LightAnimate(void)
if (speed > 6) {
speed = 6;
}
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (light_new_color[i] > 0) {
light_new_color[i] -= (light_new_color[i] >> speed) +1;
}
}
} else {
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
light_new_color[i] = 0;
}
}
}
else {
sleep = 0;
sleep = (LS_POWER == Settings.light_scheme) ? Settings.sleep : 0; // If no animation then use sleep as is
switch (Settings.light_scheme) {
case LS_POWER:
LightSetDimmer(Settings.light_dimmer);
@ -765,7 +765,7 @@ void LightAnimate(void)
case LS_WAKEUP:
if (2 == light_wakeup_active) {
light_wakeup_active = 1;
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
light_new_color[i] = 0;
}
light_wakeup_counter = 0;
@ -777,7 +777,7 @@ void LightAnimate(void)
light_wakeup_dimmer++;
if (light_wakeup_dimmer <= Settings.light_dimmer) {
LightSetDimmer(light_wakeup_dimmer);
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
light_new_color[i] = light_current_color[i];
}
} else {
@ -807,14 +807,14 @@ void LightAnimate(void)
}
if ((Settings.light_scheme < LS_MAX) || !light_power) {
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (light_last_color[i] != light_new_color[i]) {
light_update = 1;
}
}
if (light_update) {
light_update = 0;
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
light_last_color[i] = light_new_color[i];
cur_col[i] = light_last_color[i]*Settings.rgbwwTable[i]/255;
cur_col[i] = (Settings.light_correction) ? ledTable[cur_col[i]] : cur_col[i];
@ -1012,7 +1012,7 @@ void LightSetHsb(float hue, float sat, float bri, uint16_t ct, bool gotct)
* Commands
\*********************************************************************************************/
boolean LightColorEntry(char *buffer, uint8_t buffer_length)
bool LightColorEntry(char *buffer, uint8_t buffer_length)
{
char scolor[10];
char *p;
@ -1048,7 +1048,7 @@ boolean LightColorEntry(char *buffer, uint8_t buffer_length)
entry_type = 2; // Decimal
}
else if (((2 * light_subtype) == buffer_length) || (buffer_length > 3)) { // Hexadecimal entry
for (byte i = 0; i < buffer_length / 2; i++) {
for (uint8_t i = 0; i < buffer_length / 2; i++) {
strlcpy(scolor, buffer + (i *2), 3);
light_entry_color[i] = (uint8_t)strtol(scolor, &p, 16);
}
@ -1081,12 +1081,12 @@ boolean LightColorEntry(char *buffer, uint8_t buffer_length)
/********************************************************************************************/
boolean LightCommand(void)
bool LightCommand(void)
{
char command [CMDSZ];
boolean serviced = true;
boolean coldim = false;
boolean valid_entry = false;
bool serviced = true;
bool coldim = false;
bool valid_entry = false;
char scolor[25];
char option = (1 == XdrvMailbox.data_len) ? XdrvMailbox.data[0] : '\0';
@ -1118,7 +1118,7 @@ boolean LightCommand(void)
Settings.light_scheme = 0;
coldim = true;
} else { // Color3, 4, 5 and 6
for (byte i = 0; i < LST_RGB; i++) {
for (uint8_t i = 0; i < LST_RGB; i++) {
Settings.ws_color[XdrvMailbox.index -3][i] = light_entry_color[i];
}
}
@ -1129,7 +1129,7 @@ boolean LightCommand(void)
}
if (XdrvMailbox.index >= 3) {
scolor[0] = '\0';
for (byte i = 0; i < LST_RGB; i++) {
for (uint8_t i = 0; i < LST_RGB; i++) {
if (Settings.flag.decimal_text) {
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", Settings.ws_color[XdrvMailbox.index -3][i]);
} else {
@ -1203,7 +1203,7 @@ boolean LightCommand(void)
if (LightColorEntry(color, strlen(color))) {
Ws2812SetColor(idx, light_entry_color[0], light_entry_color[1], light_entry_color[2], light_entry_color[3]);
idx++;
if (idx >= Settings.light_pixels) break;
if (idx > Settings.light_pixels) break;
} else {
break;
}
@ -1343,7 +1343,7 @@ boolean LightCommand(void)
light_update = 1;
}
scolor[0] = '\0';
for (byte i = 0; i < LST_RGBWC; i++) {
for (uint8_t i = 0; i < LST_RGBWC; i++) {
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", Settings.rgbwwTable[i]);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, XdrvMailbox.index, scolor);
@ -1402,9 +1402,9 @@ boolean LightCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv04(byte function)
bool Xdrv04(uint8_t function)
{
boolean result = false;
bool result = false;
if (light_type) {
switch (function) {

View File

@ -181,10 +181,10 @@ void IrReceiveCheck(void)
TOSHIBA
********************/
boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
bool IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Power, int HVAC_Temp)
{
uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2];
byte data[HVAC_TOSHIBA_DATALEN] = {0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};
uint8_t data[HVAC_TOSHIBA_DATALEN] = {0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};
char *p;
uint8_t mode;
@ -201,7 +201,7 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
data[6] = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00
if (!HVAC_Power) {
data[6] = (byte)0x07; // Turn OFF HVAC
data[6] = (uint8_t)0x07; // Turn OFF HVAC
}
if (HVAC_FanMode == NULL) {
@ -220,7 +220,7 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
mode = mode << 5; // AUTO = 0x00, SPEED = 0x40, 0x60, 0x80, 0xA0, 0xC0, SILENT = 0x00
data[6] = data[6] | mode;
byte Temp;
uint8_t Temp;
if (HVAC_Temp > 30) {
Temp = 30;
}
@ -230,15 +230,15 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
else {
Temp = HVAC_Temp;
}
data[5] = (byte)(Temp - 17) << 4;
data[5] = (uint8_t)(Temp - 17) << 4;
data[HVAC_TOSHIBA_DATALEN - 1] = 0;
for (int x = 0; x < HVAC_TOSHIBA_DATALEN - 1; x++) {
data[HVAC_TOSHIBA_DATALEN - 1] = (byte)data[x] ^ data[HVAC_TOSHIBA_DATALEN - 1]; // CRC is a simple bits addition
data[HVAC_TOSHIBA_DATALEN - 1] = (uint8_t)data[x] ^ data[HVAC_TOSHIBA_DATALEN - 1]; // CRC is a simple bits addition
}
int i = 0;
byte mask = 1;
uint8_t mask = 1;
//header
rawdata[i++] = HVAC_TOSHIBA_HDR_MARK;
@ -275,7 +275,7 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
MITSUBISHI
********************/
boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
bool IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Power, int HVAC_Temp)
{
char *p;
uint8_t mode;
@ -324,14 +324,14 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea
LG
********************/
boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
bool IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Power, int HVAC_Temp)
{
uint32_t LG_Code;
byte data[HVAC_LG_DATALEN];
static boolean hvacOn = false;
uint8_t data[HVAC_LG_DATALEN];
static bool hvacOn = false;
char *p;
uint8_t mode;
byte Temp;
uint8_t Temp;
// Constant data
data[0] = 0x08;
@ -339,11 +339,11 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P
data[2] = 0x00;
if (!HVAC_Power) {
data[2] = (byte)0x0C; // Turn OFF HVAC, code 0x88C0051
data[3] = (byte)0x00;
data[4] = (byte)0x00;
data[5] = (byte)0x05;
data[6] = (byte)0x01;
data[2] = (uint8_t)0x0C; // Turn OFF HVAC, code 0x88C0051
data[3] = (uint8_t)0x00;
data[4] = (uint8_t)0x00;
data[5] = (uint8_t)0x05;
data[6] = (uint8_t)0x01;
hvacOn = false;
}
@ -392,7 +392,7 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P
else {
Temp = HVAC_Temp;
}
data[4] = (byte)(Temp - 15);
data[4] = (uint8_t)(Temp - 15);
// Set code for HVAC fan mode - data[5]
if (HVAC_FanMode == NULL) {
@ -442,7 +442,7 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P
Fujitsu
********************/
boolean IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
bool IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, bool HVAC_Power, int HVAC_Temp)
{
const char kFujitsuHvacModeOptions[] = "HDCAF";
@ -457,8 +457,8 @@ boolean IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
return false;
}
byte modes[5] = {FUJITSU_AC_MODE_HEAT, FUJITSU_AC_MODE_DRY, FUJITSU_AC_MODE_COOL, FUJITSU_AC_MODE_AUTO, FUJITSU_AC_MODE_FAN};
byte fanModes[7] = {FUJITSU_AC_FAN_AUTO, FUJITSU_AC_FAN_LOW, FUJITSU_AC_FAN_MED, FUJITSU_AC_FAN_HIGH, FUJITSU_AC_FAN_HIGH, FUJITSU_AC_FAN_HIGH, FUJITSU_AC_FAN_QUIET};
uint8_t modes[5] = {FUJITSU_AC_MODE_HEAT, FUJITSU_AC_MODE_DRY, FUJITSU_AC_MODE_COOL, FUJITSU_AC_MODE_AUTO, FUJITSU_AC_MODE_FAN};
uint8_t fanModes[7] = {FUJITSU_AC_FAN_AUTO, FUJITSU_AC_FAN_LOW, FUJITSU_AC_FAN_MED, FUJITSU_AC_FAN_HIGH, FUJITSU_AC_FAN_HIGH, FUJITSU_AC_FAN_HIGH, FUJITSU_AC_FAN_QUIET};
ac.setCmd(FUJITSU_AC_CMD_TURN_ON);
ac.setSwing(FUJITSU_AC_SWING_VERT);
@ -505,11 +505,11 @@ boolean IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
{ "Vendor": "<Toshiba|Mitsubishi>", "Power": <0|1>, "Mode": "<Hot|Cold|Dry|Auto>", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> }
*/
boolean IrSendCommand(void)
bool IrSendCommand(void)
{
char command [CMDSZ];
boolean serviced = true;
boolean error = false;
bool serviced = true;
bool error = false;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kIrRemoteCommands);
if (-1 == command_code) {
@ -531,7 +531,7 @@ boolean IrSendCommand(void)
if (count) { // At least two raw data values
count++;
uint16_t raw_array[count]; // It's safe to use stack for up to 240 packets (limited by mqtt_data length)
byte i = 0;
uint8_t i = 0;
for (str = strtok_r(NULL, ", ", &p); str && i < count; str = strtok_r(NULL, ", ", &p)) {
raw_array[i++] = strtoul(str, NULL, 0); // Allow decimal (5246996) and hexadecimal (0x501014) input
}
@ -611,7 +611,7 @@ boolean IrSendCommand(void)
const char *HVAC_FanMode;
const char *HVAC_Vendor;
int HVAC_Temp = 21;
boolean HVAC_Power = true;
bool HVAC_Power = true;
if (XdrvMailbox.data_len) {
char dataBufUc[XdrvMailbox.data_len];
@ -666,9 +666,9 @@ boolean IrSendCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv05(byte function)
bool Xdrv05(uint8_t function)
{
boolean result = false;
bool result = false;
if ((pin[GPIO_IRSEND] < 99) || (pin[GPIO_IRRECV] < 99)) {
switch (function) {

View File

@ -251,7 +251,7 @@ void SonoffBridgeReceived(void)
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
if (low_time && high_time) {
for (byte i = 0; i < 9; i++) {
for (uint8_t i = 0; i < 9; i++) {
Settings.rf_code[sonoff_bridge_learn_key][i] = serial_in_buffer[i +1];
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, D_CMND_RFKEY, sonoff_bridge_learn_key, D_JSON_LEARNED);
@ -274,7 +274,7 @@ void SonoffBridgeReceived(void)
sonoff_bridge_last_received_id = received_id;
sonoff_bridge_last_time = now;
strncpy_P(rfkey, PSTR("\"" D_JSON_NONE "\""), sizeof(rfkey));
for (byte i = 1; i <= 16; i++) {
for (uint8_t i = 1; i <= 16; i++) {
if (Settings.rf_code[i][0]) {
uint32_t send_id = Settings.rf_code[i][6] << 16 | Settings.rf_code[i][7] << 8 | Settings.rf_code[i][8];
if (send_id == received_id) {
@ -300,7 +300,7 @@ void SonoffBridgeReceived(void)
}
}
boolean SonoffBridgeSerialInput(void)
bool SonoffBridgeSerialInput(void)
{
// iTead Rf Universal Transceiver Module Serial Protocol Version 1.0 (20170420)
static int8_t receive_len = 0;
@ -352,7 +352,7 @@ boolean SonoffBridgeSerialInput(void)
return 0;
}
void SonoffBridgeSendCommand(byte code)
void SonoffBridgeSendCommand(uint8_t code)
{
Serial.write(0xAA); // Start of Text
Serial.write(code); // Command or Acknowledge
@ -370,7 +370,7 @@ void SonoffBridgeSendCode(uint32_t code)
{
Serial.write(0xAA); // Start of Text
Serial.write(0xA5); // Send following code
for (byte i = 0; i < 6; i++) {
for (uint8_t i = 0; i < 6; i++) {
Serial.write(Settings.rf_code[0][i]);
}
Serial.write((code >> 16) & 0xff);
@ -387,7 +387,7 @@ void SonoffBridgeSend(uint8_t idx, uint8_t key)
key--; // Support 1 to 16
Serial.write(0xAA); // Start of Text
Serial.write(0xA5); // Send following code
for (byte i = 0; i < 8; i++) {
for (uint8_t i = 0; i < 8; i++) {
Serial.write(Settings.rf_code[idx][i]);
}
if (0 == idx) {
@ -418,10 +418,10 @@ void SonoffBridgeLearn(uint8_t key)
* Commands
\*********************************************************************************************/
boolean SonoffBridgeCommand(void)
bool SonoffBridgeCommand(void)
{
char command [CMDSZ];
boolean serviced = true;
bool serviced = true;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kSonoffBridgeCommands);
if (-1 == command_code) {
@ -485,7 +485,7 @@ boolean SonoffBridgeCommand(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, XdrvMailbox.index, D_JSON_SET_TO_DEFAULT);
}
else if (4 == XdrvMailbox.payload) { // Save RF data provided by RFSync, RfLow, RfHigh and last RfCode
for (byte i = 0; i < 6; i++) {
for (uint8_t i = 0; i < 6; i++) {
Settings.rf_code[XdrvMailbox.index][i] = Settings.rf_code[0][i];
}
Settings.rf_code[XdrvMailbox.index][6] = (sonoff_bridge_last_send_code >> 16) & 0xff;
@ -566,9 +566,9 @@ void SonoffBridgeInit(void)
* Interface
\*********************************************************************************************/
boolean Xdrv06(byte function)
bool Xdrv06(uint8_t function)
{
boolean result = false;
bool result = false;
if (SONOFF_BRIDGE == Settings.module) {
switch (function) {

View File

@ -41,8 +41,8 @@ const char S_JSON_DOMOTICZ_COMMAND_INDEX_LVALUE[] PROGMEM = "{\"" D_CMND_DOMOTIC
char domoticz_in_topic[] = DOMOTICZ_IN_TOPIC;
char domoticz_out_topic[] = DOMOTICZ_OUT_TOPIC;
boolean domoticz_subscribe = false;
byte domoticz_update_flag = 1;
bool domoticz_subscribe = false;
uint8_t domoticz_update_flag = 1;
int domoticz_update_timer = 0;
unsigned long fan_debounce = 0; // iFan02 state debounce timer
@ -95,7 +95,7 @@ void DomoticzUpdateFanState()
domoticz_update_flag = 1;
}
void MqttPublishDomoticzPowerState(byte device)
void MqttPublishDomoticzPowerState(uint8_t device)
{
if (Settings.flag.mqtt_enabled) {
if ((device < 1) || (device > devices_present)) { device = 1; }
@ -114,7 +114,7 @@ void MqttPublishDomoticzPowerState(byte device)
}
}
void DomoticzUpdatePowerState(byte device)
void DomoticzUpdatePowerState(uint8_t device)
{
if (domoticz_update_flag) {
MqttPublishDomoticzPowerState(device);
@ -128,7 +128,7 @@ void DomoticzMqttUpdate(void)
domoticz_update_timer--;
if (domoticz_update_timer <= 0) {
domoticz_update_timer = Settings.domoticz_update_timer;
for (byte i = 1; i <= devices_present; i++) {
for (uint8_t i = 1; i <= devices_present; i++) {
if ((SONOFF_IFAN02 == Settings.module) && (i > 1)) {
MqttPublishDomoticzFanState();
break;
@ -143,7 +143,7 @@ void DomoticzMqttUpdate(void)
void DomoticzMqttSubscribe(void)
{
uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present;
for (byte i = 0; i < maxdev; i++) {
for (uint8_t i = 0; i < maxdev; i++) {
if (Settings.domoticz_relay_idx[i]) {
domoticz_subscribe = true;
}
@ -181,7 +181,7 @@ void DomoticzMqttSubscribe(void)
}
*/
boolean DomoticzMqttData(void)
bool DomoticzMqttData(void)
{
char stemp1[10];
unsigned long idx = 0;
@ -211,7 +211,7 @@ boolean DomoticzMqttData(void)
if ((idx > 0) && (nvalue >= 0) && (nvalue <= 15)) {
uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present;
for (byte i = 0; i < maxdev; i++) {
for (uint8_t i = 0; i < maxdev; i++) {
if (idx == Settings.domoticz_relay_idx[i]) {
bool iscolordimmer = strcmp_P(domoticz["dtype"],PSTR("Color Switch")) == 0;
snprintf_P(stemp1, sizeof(stemp1), PSTR("%d"), i +1);
@ -287,10 +287,10 @@ boolean DomoticzMqttData(void)
* Commands
\*********************************************************************************************/
boolean DomoticzCommand(void)
bool DomoticzCommand(void)
{
char command [CMDSZ];
boolean serviced = true;
bool serviced = true;
uint8_t dmtcz_len = strlen(D_CMND_DOMOTICZ); // Prep for string length change
if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_DOMOTICZ), dmtcz_len)) { // Prefix
@ -336,9 +336,9 @@ boolean DomoticzCommand(void)
return serviced;
}
boolean DomoticzSendKey(byte key, byte device, byte state, byte svalflg)
bool DomoticzSendKey(uint8_t key, uint8_t device, uint8_t state, uint8_t svalflg)
{
boolean result = 0;
bool result = 0;
if (device <= MAX_DOMOTICZ_IDX) {
if ((Settings.domoticz_key_idx[device -1] || Settings.domoticz_switch_idx[device -1]) && (svalflg)) {
@ -374,7 +374,7 @@ uint8_t DomoticzHumidityState(char *hum)
return (!h) ? 0 : (h < 40) ? 2 : (h > 70) ? 3 : 1;
}
void DomoticzSensor(byte idx, char *data)
void DomoticzSensor(uint8_t idx, char *data)
{
if (Settings.domoticz_sensor_idx[idx]) {
char dmess[90];
@ -392,7 +392,7 @@ void DomoticzSensor(byte idx, char *data)
}
}
void DomoticzSensor(byte idx, uint32_t value)
void DomoticzSensor(uint8_t idx, uint32_t value)
{
char data[16];
snprintf_P(data, sizeof(data), PSTR("%d"), value);
@ -497,7 +497,7 @@ void DomoticzSaveSettings(void)
char ssensor_indices[6 * MAX_DOMOTICZ_SNS_IDX];
char tmp[100];
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
for (uint8_t i = 0; i < MAX_DOMOTICZ_IDX; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i +1);
WebGetArg(stemp, tmp, sizeof(tmp));
Settings.domoticz_relay_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp);
@ -509,7 +509,7 @@ void DomoticzSaveSettings(void)
Settings.domoticz_switch_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp);
}
ssensor_indices[0] = '\0';
for (byte i = 0; i < DZ_MAX_SENSORS; i++) {
for (uint8_t i = 0; i < DZ_MAX_SENSORS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("l%d"), i +1);
WebGetArg(stemp, tmp, sizeof(tmp));
Settings.domoticz_sensor_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp);
@ -531,9 +531,9 @@ void DomoticzSaveSettings(void)
* Interface
\*********************************************************************************************/
boolean Xdrv07(byte function)
bool Xdrv07(uint8_t function)
{
boolean result = false;
bool result = false;
if (Settings.flag.mqtt_enabled) {
switch (function) {

View File

@ -42,7 +42,7 @@ void SerialBridgeInput(void)
{
while (SerialBridgeSerial->available()) {
yield();
uint8_t serial_in_byte = SerialBridgeSerial->read();
uint8_t serial_in_uint8_t = SerialBridgeSerial->read();
if (serial_in_byte > 127) { // binary data...
serial_bridge_in_byte_counter = 0;
@ -90,10 +90,10 @@ void SerialBridgeInit(void)
* Commands
\*********************************************************************************************/
boolean SerialBridgeCommand(void)
bool SerialBridgeCommand(void)
{
char command [CMDSZ];
boolean serviced = true;
bool serviced = true;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kSerialBridgeCommands);
if (-1 == command_code) {
@ -149,9 +149,9 @@ boolean SerialBridgeCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv08(byte function)
bool Xdrv08(uint8_t function)
{
boolean result = false;
bool result = false;
if (serial_bridge_active) {
switch (function) {

View File

@ -219,7 +219,7 @@ void ApplyTimerOffsets(Timer *duskdawn)
duskdawn->time = timeBuffer;
}
String GetSun(byte dawn)
String GetSun(uint8_t dawn)
{
char stime[6];
@ -232,7 +232,7 @@ String GetSun(byte dawn)
return String(stime);
}
uint16_t GetSunMinutes(byte dawn)
uint16_t GetSunMinutes(uint8_t dawn)
{
uint8_t hour[2];
uint8_t minute[2];
@ -246,7 +246,7 @@ uint16_t GetSunMinutes(byte dawn)
/*******************************************************************************************/
void TimerSetRandomWindow(byte index)
void TimerSetRandomWindow(uint8_t index)
{
timer_window[index] = 0;
if (Settings.timer[index].window) {
@ -256,7 +256,7 @@ void TimerSetRandomWindow(byte index)
void TimerSetRandomWindows(void)
{
for (byte i = 0; i < MAX_TIMERS; i++) { TimerSetRandomWindow(i); }
for (uint8_t i = 0; i < MAX_TIMERS; i++) { TimerSetRandomWindow(i); }
}
void TimerEverySecond(void)
@ -268,7 +268,7 @@ void TimerEverySecond(void)
int16_t time = (RtcTime.hour *60) + RtcTime.minute;
uint8_t days = 1 << (RtcTime.day_of_week -1);
for (byte i = 0; i < MAX_TIMERS; i++) {
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
// if (Settings.timer[i].device >= devices_present) Settings.timer[i].data = 0; // Reset timer due to change in devices present
Timer xtimer = Settings.timer[i];
uint16_t set_time = xtimer.time;
@ -308,7 +308,7 @@ void PrepShowTimer(uint8_t index)
Timer xtimer = Settings.timer[index -1];
for (byte i = 0; i < 7; i++) {
for (uint8_t i = 0; i < 7; i++) {
uint8_t mask = 1 << i;
snprintf(days, sizeof(days), "%s%d", days, ((xtimer.days & mask) > 0));
}
@ -337,11 +337,11 @@ void PrepShowTimer(uint8_t index)
* Commands
\*********************************************************************************************/
boolean TimerCommand(void)
bool TimerCommand(void)
{
char command[CMDSZ];
char dataBufUc[XdrvMailbox.data_len];
boolean serviced = true;
bool serviced = true;
uint8_t index = XdrvMailbox.index;
UpperCase(dataBufUc, XdrvMailbox.data);
@ -464,9 +464,9 @@ boolean TimerCommand(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag3.timers_enable));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, command);
byte jsflg = 0;
byte lines = 1;
for (byte i = 0; i < MAX_TIMERS; i++) {
uint8_t jsflg = 0;
uint8_t lines = 1;
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
if (!jsflg) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_TIMERS "%d\":{"), lines++);
} else {
@ -699,7 +699,7 @@ void HandleTimerConfiguration(void)
page.replace(F("</style>"), FPSTR(HTTP_TIMER_STYLE));
page += FPSTR(HTTP_FORM_TIMER);
page.replace(F("{e0"), (Settings.flag3.timers_enable) ? F(" checked") : F(""));
for (byte i = 0; i < MAX_TIMERS; i++) {
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
if (i > 0) { page += F(","); }
page += String(Settings.timer[i].data);
}
@ -725,7 +725,7 @@ void TimerSaveSettings(void)
WebGetArg("t0", tmp, sizeof(tmp));
char *p = tmp;
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT D_CMND_TIMERS " %d"), Settings.flag3.timers_enable);
for (byte i = 0; i < MAX_TIMERS; i++) {
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
timer.data = strtol(p, &p, 10);
p++; // Skip comma
if (timer.time < 1440) {
@ -744,9 +744,9 @@ void TimerSaveSettings(void)
* Interface
\*********************************************************************************************/
boolean Xdrv09(byte function)
bool Xdrv09(uint8_t function)
{
boolean result = false;
bool result = false;
switch (function) {
case FUNC_PRE_INIT:

View File

@ -106,7 +106,7 @@ uint8_t mems_event = 0;
/*******************************************************************************************/
bool RulesRuleMatch(byte rule_set, String &event, String &rule)
bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule)
{
// event = {"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}}
// event = {"System":{"Boot":1}}
@ -153,14 +153,14 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule)
double rule_value = 0;
if (pos > 0) {
String rule_param = rule_name.substring(pos + 1);
for (byte i = 0; i < MAX_RULE_VARS; i++) {
for (uint8_t i = 0; i < MAX_RULE_VARS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%VAR%d%%"), i +1);
if (rule_param.startsWith(stemp)) {
rule_param = vars[i];
break;
}
}
for (byte i = 0; i < MAX_RULE_MEMS; i++) {
for (uint8_t i = 0; i < MAX_RULE_MEMS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%MEM%d%%"), i +1);
if (rule_param.startsWith(stemp)) {
rule_param = Settings.mems[i];
@ -262,7 +262,7 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule)
/*******************************************************************************************/
bool RuleSetProcess(byte rule_set, String &event_saved)
bool RuleSetProcess(uint8_t rule_set, String &event_saved)
{
bool serviced = false;
char stemp[10];
@ -315,11 +315,11 @@ bool RuleSetProcess(byte rule_set, String &event_saved)
// if (!ucommand.startsWith("BACKLOG")) { commands = "backlog " + commands; } // Always use Backlog to prevent power race exception
if (ucommand.indexOf("EVENT ") != -1) { commands = "backlog " + commands; } // Always use Backlog with event to prevent rule event loop exception
commands.replace(F("%value%"), rules_event_value);
for (byte i = 0; i < MAX_RULE_VARS; i++) {
for (uint8_t i = 0; i < MAX_RULE_VARS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%var%d%%"), i +1);
commands.replace(stemp, vars[i]);
}
for (byte i = 0; i < MAX_RULE_MEMS; i++) {
for (uint8_t i = 0; i < MAX_RULE_MEMS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%mem%d%%"), i +1);
commands.replace(stemp, Settings.mems[i]);
}
@ -363,7 +363,7 @@ bool RulesProcessEvent(char *json_event)
//snprintf_P(log_data, sizeof(log_data), PSTR("RUL: Event %s"), event_saved.c_str());
//AddLog(LOG_LEVEL_DEBUG);
for (byte i = 0; i < MAX_RULE_SETS; i++) {
for (uint8_t i = 0; i < MAX_RULE_SETS; i++) {
if (strlen(Settings.rules[i]) && bitRead(Settings.rule_enabled, i)) {
if (RuleSetProcess(i, event_saved)) { serviced = true; }
}
@ -379,7 +379,7 @@ bool RulesProcess(void)
void RulesInit(void)
{
rules_flag.data = 0;
for (byte i = 0; i < MAX_RULE_SETS; i++) {
for (uint8_t i = 0; i < MAX_RULE_SETS; i++) {
if (Settings.rules[i][0] == '\0') {
bitWrite(Settings.rule_enabled, i, 0);
bitWrite(Settings.rule_once, i, 0);
@ -396,7 +396,7 @@ void RulesEvery50ms(void)
if (-1 == rules_new_power) { rules_new_power = power; }
if (rules_new_power != rules_old_power) {
if (rules_old_power != -1) {
for (byte i = 0; i < devices_present; i++) {
for (uint8_t i = 0; i < devices_present; i++) {
uint8_t new_state = (rules_new_power >> i) &1;
if (new_state != ((rules_old_power >> i) &1)) {
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Power%d\":{\"State\":%d}}"), i +1, new_state);
@ -405,19 +405,19 @@ void RulesEvery50ms(void)
}
} else {
// Boot time POWER OUTPUTS (Relays) Status
for (byte i = 0; i < devices_present; i++) {
for (uint8_t i = 0; i < devices_present; i++) {
uint8_t new_state = (rules_new_power >> i) &1;
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Power%d\":{\"Boot\":%d}}"), i +1, new_state);
RulesProcessEvent(json_event);
}
// Boot time SWITCHES Status
for (byte i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) {
#else
if (pin[GPIO_SWT1 +i] < 99) {
#endif // USE_TM1638
boolean swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]));
bool swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]));
snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (swm ^ SwitchLastState(i)));
RulesProcessEvent(json_event);
}
@ -454,7 +454,7 @@ void RulesEvery50ms(void)
}
}
else if (vars_event) {
for (byte i = 0; i < MAX_RULE_VARS-1; i++) {
for (uint8_t i = 0; i < MAX_RULE_VARS-1; i++) {
if (bitRead(vars_event, i)) {
bitClear(vars_event, i);
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Var%d\":{\"State\":%s}}"), i+1, vars[i]);
@ -464,7 +464,7 @@ void RulesEvery50ms(void)
}
}
else if (mems_event) {
for (byte i = 0; i < MAX_RULE_MEMS-1; i++) {
for (uint8_t i = 0; i < MAX_RULE_MEMS-1; i++) {
if (bitRead(mems_event, i)) {
bitClear(mems_event, i);
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Mem%d\":{\"State\":%s}}"), i+1, Settings.mems[i]);
@ -475,7 +475,7 @@ void RulesEvery50ms(void)
}
else if (rules_flag.data) {
uint16_t mask = 1;
for (byte i = 0; i < MAX_RULES_FLAG; i++) {
for (uint8_t i = 0; i < MAX_RULES_FLAG; i++) {
if (rules_flag.data & mask) {
rules_flag.data ^= mask;
json_event[0] = '\0';
@ -529,7 +529,7 @@ void RulesEverySecond(void)
RulesProcessEvent(json_event);
}
}
for (byte i = 0; i < MAX_RULE_TIMERS; i++) {
for (uint8_t i = 0; i < MAX_RULE_TIMERS; i++) {
if (rules_timer[i] != 0L) { // Timer active?
if (TimeReached(rules_timer[i])) { // Timer finished?
rules_timer[i] = 0L; // Turn off this timer
@ -553,10 +553,10 @@ void RulesTeleperiod(void)
rules_teleperiod = 0;
}
boolean RulesCommand(void)
bool RulesCommand(void)
{
char command[CMDSZ];
boolean serviced = true;
bool serviced = true;
uint8_t index = XdrvMailbox.index;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kRulesCommands);
@ -614,7 +614,7 @@ boolean RulesCommand(void)
rules_timer[index -1] = (XdrvMailbox.payload > 0) ? millis() + (1000 * XdrvMailbox.payload) : 0;
}
mqtt_data[0] = '\0';
for (byte i = 0; i < MAX_RULE_TIMERS; i++) {
for (uint8_t i = 0; i < MAX_RULE_TIMERS; i++) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%c\"T%d\":%d"), mqtt_data, (i) ? ',' : '{', i +1, (rules_timer[i]) ? (rules_timer[i] - millis()) / 1000 : 0);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
@ -700,9 +700,9 @@ double map_double(double x, double in_min, double in_max, double out_min, double
* Interface
\*********************************************************************************************/
boolean Xdrv10(byte function)
bool Xdrv10(uint8_t function)
{
boolean result = false;
bool result = false;
switch (function) {
case FUNC_PRE_INIT:

View File

@ -39,12 +39,12 @@ Variables in settings.h
bool Settings.flag.knx_enabled Enable/Disable KNX Protocol
uint16_t Settings.knx_physsical_addr Physical KNX address of this device
byte Settings.knx_GA_registered Number of group address to read
byte Settings.knx_CB_registered Number of group address to write
uint8_t Settings.knx_GA_registered Number of group address to read
uint8_t Settings.knx_CB_registered Number of group address to write
uint16_t Settings.knx_GA_addr[MAX_KNX_GA] Group address to read
uint16_t Settings.knx_CB_addr[MAX_KNX_CB] Group address to write
byte Settings.knx_GA_param[MAX_KNX_GA] Type of Input (relay changed, button pressed, sensor read)
byte Settings.knx_CB_param[MAX_KNX_CB] Type of Output (set relay, toggle relay, reply sensor value)
uint8_t Settings.knx_GA_param[MAX_KNX_GA] Type of Input (relay changed, button pressed, sensor read)
uint8_t Settings.knx_CB_param[MAX_KNX_CB] Type of Output (set relay, toggle relay, reply sensor value)
\*********************************************************************************************/
@ -61,11 +61,11 @@ address_t KNX_addr; // KNX Address converter variable
float last_temp;
float last_hum;
byte toggle_inhibit;
uint8_t toggle_inhibit;
typedef struct __device_parameters
{
byte type; // PARAMETER_ID. Used as type of GA = relay, button, sensor, etc, (INPUTS)
uint8_t type; // PARAMETER_ID. Used as type of GA = relay, button, sensor, etc, (INPUTS)
// used when an action on device triggers a MSG to send on KNX
// Needed because this is the value that the ESP_KNX_IP library will pass as parameter
// to identify the action to perform when a MSG is received
@ -200,9 +200,9 @@ enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL, CMND_KNX_ENABLED, CMND_KNX_ENH
const char kKnxCommands[] PROGMEM = D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|"
D_CMND_KNX_ENHANCED "|" D_CMND_KNX_PA "|" D_CMND_KNX_GA "|" D_CMND_KNX_CB ;
byte KNX_GA_Search( byte param, byte start = 0 )
uint8_t KNX_GA_Search( uint8_t param, uint8_t start = 0 )
{
for (byte i = start; i < Settings.knx_GA_registered; ++i)
for (uint8_t i = start; i < Settings.knx_GA_registered; ++i)
{
if ( Settings.knx_GA_param[i] == param )
{
@ -216,9 +216,9 @@ byte KNX_GA_Search( byte param, byte start = 0 )
}
byte KNX_CB_Search( byte param, byte start = 0 )
uint8_t KNX_CB_Search( uint8_t param, uint8_t start = 0 )
{
for (byte i = start; i < Settings.knx_CB_registered; ++i)
for (uint8_t i = start; i < Settings.knx_CB_registered; ++i)
{
if ( Settings.knx_CB_param[i] == param )
{
@ -232,7 +232,7 @@ byte KNX_CB_Search( byte param, byte start = 0 )
}
void KNX_ADD_GA( byte GAop, byte GA_FNUM, byte GA_AREA, byte GA_FDEF )
void KNX_ADD_GA( uint8_t GAop, uint8_t GA_FNUM, uint8_t GA_AREA, uint8_t GA_FDEF )
{
// Check if all GA were assigned. If yes-> return
if ( Settings.knx_GA_registered >= MAX_KNX_GA ) { return; }
@ -255,12 +255,12 @@ void KNX_ADD_GA( byte GAop, byte GA_FNUM, byte GA_AREA, byte GA_FDEF )
}
void KNX_DEL_GA( byte GAnum )
void KNX_DEL_GA( uint8_t GAnum )
{
byte dest_offset = 0;
byte src_offset = 0;
byte len = 0;
uint8_t dest_offset = 0;
uint8_t src_offset = 0;
uint8_t len = 0;
// Delete GA
Settings.knx_GA_param[GAnum-1] = 0;
@ -291,7 +291,7 @@ void KNX_DEL_GA( byte GAnum )
if (len > 0)
{
memmove(Settings.knx_GA_param + dest_offset, Settings.knx_GA_param + src_offset, len * sizeof(byte));
memmove(Settings.knx_GA_param + dest_offset, Settings.knx_GA_param + src_offset, len * sizeof(uint8_t));
memmove(Settings.knx_GA_addr + dest_offset, Settings.knx_GA_addr + src_offset, len * sizeof(uint16_t));
}
@ -303,7 +303,7 @@ void KNX_DEL_GA( byte GAnum )
}
void KNX_ADD_CB( byte CBop, byte CB_FNUM, byte CB_AREA, byte CB_FDEF )
void KNX_ADD_CB( uint8_t CBop, uint8_t CB_FNUM, uint8_t CB_AREA, uint8_t CB_FDEF )
{
// Check if all callbacks were assigned. If yes-> return
if ( Settings.knx_CB_registered >= MAX_KNX_CB ) { return; }
@ -338,12 +338,12 @@ void KNX_ADD_CB( byte CBop, byte CB_FNUM, byte CB_AREA, byte CB_FDEF )
}
void KNX_DEL_CB( byte CBnum )
void KNX_DEL_CB( uint8_t CBnum )
{
byte oldparam = Settings.knx_CB_param[CBnum-1];
byte dest_offset = 0;
byte src_offset = 0;
byte len = 0;
uint8_t oldparam = Settings.knx_CB_param[CBnum-1];
uint8_t dest_offset = 0;
uint8_t src_offset = 0;
uint8_t len = 0;
// Delete assigment
knx.callback_unassign(CBnum-1);
@ -375,7 +375,7 @@ void KNX_DEL_CB( byte CBnum )
if (len > 0)
{
memmove(Settings.knx_CB_param + dest_offset, Settings.knx_CB_param + src_offset, len * sizeof(byte));
memmove(Settings.knx_CB_param + dest_offset, Settings.knx_CB_param + src_offset, len * sizeof(uint8_t));
memmove(Settings.knx_CB_addr + dest_offset, Settings.knx_CB_addr + src_offset, len * sizeof(uint16_t));
}
@ -395,7 +395,7 @@ void KNX_DEL_CB( byte CBnum )
bool KNX_CONFIG_NOT_MATCH(void)
{
// Check for configured parameters that the device does not have (module changed)
for (byte i = 0; i < KNX_MAX_device_param; ++i)
for (uint8_t i = 0; i < KNX_MAX_device_param; ++i)
{
if ( !device_param[i].show ) { // device has this parameter ?
// if not, search for all registered group address to this parameter for deletion
@ -417,7 +417,7 @@ bool KNX_CONFIG_NOT_MATCH(void)
}
// Check for invalid or erroneous configuration (tasmota flashed without clearing the memory)
for (byte i = 0; i < Settings.knx_GA_registered; ++i)
for (uint8_t i = 0; i < Settings.knx_GA_registered; ++i)
{
if ( Settings.knx_GA_param[i] != 0 ) // the GA[i] have a parameter defined?
{
@ -427,7 +427,7 @@ bool KNX_CONFIG_NOT_MATCH(void)
}
}
}
for (byte i = 0; i < Settings.knx_CB_registered; ++i)
for (uint8_t i = 0; i < Settings.knx_CB_registered; ++i)
{
if ( Settings.knx_CB_param[i] != 0 ) // the CB[i] have a parameter defined?
{
@ -529,8 +529,8 @@ void KNX_INIT(void)
// Register Group Addresses to listen to
// Search on the settings if there is a group address set for receive KNX messages for the type: device_param[j].type
// If there is, register the group address on the KNX_IP Library to Receive data for Executing Callbacks
byte j;
for (byte i = 0; i < Settings.knx_CB_registered; ++i)
uint8_t j;
for (uint8_t i = 0; i < Settings.knx_CB_registered; ++i)
{
j = Settings.knx_CB_param[i];
if ( j > 0 )
@ -652,14 +652,14 @@ void KNX_CB_Action(message_t const &msg, void *arg)
}
void KnxUpdatePowerState(byte device, power_t state)
void KnxUpdatePowerState(uint8_t device, power_t state)
{
if (!(Settings.flag.knx_enabled)) { return; }
device_param[device -1].last_state = bitRead(state, device -1); // power state (on/off)
// Search all the registered GA that has that output (variable: device) as parameter
byte i = KNX_GA_Search(device);
uint8_t i = KNX_GA_Search(device);
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_1bit(KNX_addr, device_param[device -1].last_state);
@ -678,7 +678,7 @@ void KnxUpdatePowerState(byte device, power_t state)
}
void KnxSendButtonPower(byte key, byte device, byte state)
void KnxSendButtonPower(uint8_t key, uint8_t device, uint8_t state)
{
// key 0 = button_topic
// key 1 = switch_topic
@ -692,7 +692,7 @@ void KnxSendButtonPower(byte key, byte device, byte state)
// {
// Search all the registered GA that has that output (variable: device) as parameter
byte i = KNX_GA_Search(device + 8);
uint8_t i = KNX_GA_Search(device + 8);
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_1bit(KNX_addr, !(state == 0));
@ -712,7 +712,7 @@ void KnxSendButtonPower(byte key, byte device, byte state)
}
void KnxSensor(byte sensor_type, float value)
void KnxSensor(uint8_t sensor_type, float value)
{
if (sensor_type == KNX_TEMPERATURE)
{
@ -724,7 +724,7 @@ void KnxSensor(byte sensor_type, float value)
if (!(Settings.flag.knx_enabled)) { return; }
byte i = KNX_GA_Search(sensor_type);
uint8_t i = KNX_GA_Search(sensor_type);
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_2byte_float(KNX_addr, value);
@ -822,13 +822,13 @@ void HandleKNXConfiguration(void)
if ( WebServer->arg("btn_add") == "1" ) {
stmp = WebServer->arg("GAop"); //option selected
byte GAop = stmp.toInt();
uint8_t GAop = stmp.toInt();
stmp = WebServer->arg("GA_FNUM");
byte GA_FNUM = stmp.toInt();
uint8_t GA_FNUM = stmp.toInt();
stmp = WebServer->arg("GA_AREA");
byte GA_AREA = stmp.toInt();
uint8_t GA_AREA = stmp.toInt();
stmp = WebServer->arg("GA_FDEF");
byte GA_FDEF = stmp.toInt();
uint8_t GA_FDEF = stmp.toInt();
if (GAop) {
KNX_ADD_GA( GAop, GA_FNUM, GA_AREA, GA_FDEF );
@ -838,13 +838,13 @@ void HandleKNXConfiguration(void)
{
stmp = WebServer->arg("CBop"); //option selected
byte CBop = stmp.toInt();
uint8_t CBop = stmp.toInt();
stmp = WebServer->arg("CB_FNUM");
byte CB_FNUM = stmp.toInt();
uint8_t CB_FNUM = stmp.toInt();
stmp = WebServer->arg("CB_AREA");
byte CB_AREA = stmp.toInt();
uint8_t CB_AREA = stmp.toInt();
stmp = WebServer->arg("CB_FDEF");
byte CB_FDEF = stmp.toInt();
uint8_t CB_FDEF = stmp.toInt();
if (CBop) {
KNX_ADD_CB( CBop, CB_FNUM, CB_AREA, CB_FDEF );
@ -855,7 +855,7 @@ void HandleKNXConfiguration(void)
{
stmp = WebServer->arg("btn_del_ga");
byte GA_NUM = stmp.toInt();
uint8_t GA_NUM = stmp.toInt();
KNX_DEL_GA(GA_NUM);
@ -864,7 +864,7 @@ void HandleKNXConfiguration(void)
{
stmp = WebServer->arg("btn_del_cb");
byte CB_NUM = stmp.toInt();
uint8_t CB_NUM = stmp.toInt();
KNX_DEL_CB(CB_NUM);
@ -884,7 +884,7 @@ void HandleKNXConfiguration(void)
if ( Settings.flag.knx_enable_enhancement ) { page += F(" checked"); }
page += FPSTR(HTTP_FORM_KNX2);
for (byte i = 0; i < KNX_MAX_device_param ; i++)
for (uint8_t i = 0; i < KNX_MAX_device_param ; i++)
{
if ( device_param[i].show )
{
@ -911,7 +911,7 @@ void HandleKNXConfiguration(void)
page.replace(F("btndis"), F("disabled"));
}
page.replace(F("fncbtnadd"), F("GAwarning"));
for (byte i = 0; i < Settings.knx_GA_registered ; ++i)
for (uint8_t i = 0; i < Settings.knx_GA_registered ; ++i)
{
if ( Settings.knx_GA_param[i] )
{
@ -934,8 +934,8 @@ void HandleKNXConfiguration(void)
page.replace(F("GAarea"), F("CB_AREA"));
page.replace(F("GAfdef"), F("CB_FDEF"));
page += FPSTR(HTTP_FORM_KNX4);
byte j;
for (byte i = 0; i < KNX_MAX_device_param ; i++)
uint8_t j;
for (uint8_t i = 0; i < KNX_MAX_device_param ; i++)
{
// Check How many Relays are available and add: RelayX and TogleRelayX
if ( (i > 8) && (i < 16) ) { j=i-8; } else { j=i; }
@ -959,7 +959,7 @@ void HandleKNXConfiguration(void)
}
page.replace(F("fncbtnadd"), F("CBwarning"));
for (byte i = 0; i < Settings.knx_CB_registered ; ++i)
for (uint8_t i = 0; i < Settings.knx_CB_registered ; ++i)
{
if ( Settings.knx_CB_param[i] )
{
@ -1028,7 +1028,7 @@ void KNX_Save_Settings(void)
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "GA: %d"),
Settings.knx_GA_registered );
AddLog(LOG_LEVEL_DEBUG);
for (byte i = 0; i < Settings.knx_GA_registered ; ++i)
for (uint8_t i = 0; i < Settings.knx_GA_registered ; ++i)
{
KNX_addr.value = Settings.knx_GA_addr[i];
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "GA #%d: %s " D_TO " %d/%d/%d"),
@ -1040,7 +1040,7 @@ void KNX_Save_Settings(void)
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "CB: %d"),
Settings.knx_CB_registered );
AddLog(LOG_LEVEL_DEBUG);
for (byte i = 0; i < Settings.knx_CB_registered ; ++i)
for (uint8_t i = 0; i < Settings.knx_CB_registered ; ++i)
{
KNX_addr.value = Settings.knx_CB_addr[i];
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "CB #%d: %d/%d/%d " D_TO " %s"),
@ -1055,7 +1055,7 @@ void KNX_Save_Settings(void)
#endif // USE_WEBSERVER
boolean KnxCommand(void)
bool KnxCommand(void)
{
char command[CMDSZ];
uint8_t index = XdrvMailbox.index;
@ -1068,7 +1068,7 @@ boolean KnxCommand(void)
// XdrvMailbox.payload <- data to send
if (!(Settings.flag.knx_enabled)) { return false; }
// Search all the registered GA that has that output (variable: KNX SLOTx) as parameter
byte i = KNX_GA_Search(index + KNX_SLOT1 -1);
uint8_t i = KNX_GA_Search(index + KNX_SLOT1 -1);
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_1bit(KNX_addr, !(XdrvMailbox.payload == 0));
@ -1093,7 +1093,7 @@ boolean KnxCommand(void)
// XdrvMailbox.payload <- data to send
if (!(Settings.flag.knx_enabled)) { return false; }
// Search all the registered GA that has that output (variable: KNX SLOTx) as parameter
byte i = KNX_GA_Search(index + KNX_SLOT1 -1);
uint8_t i = KNX_GA_Search(index + KNX_SLOT1 -1);
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
@ -1288,9 +1288,9 @@ boolean KnxCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv11(byte function)
bool Xdrv11(uint8_t function)
{
boolean result = false;
bool result = false;
switch (function) {
case FUNC_PRE_INIT:
KNX_INIT();

View File

@ -133,6 +133,9 @@ const char HASS_DISCOVER_DEVICE_INFO[] PROGMEM =
const char HASS_DISCOVER_TOPIC_PREFIX[] PROGMEM =
"%s, \"~\":\"%s\"";
uint8_t hass_init_step = 0;
uint8_t hass_mode = 0;
static void FindPrefix(char* s1, char* s2, char* out)
{
int prefixlen = 0;
@ -247,7 +250,7 @@ void HAssAnnounceRelayLight(void)
}
}
void HAssAnnounceButtonSwitch(byte device, char* topic, byte present, byte key, byte toggle)
void HAssAnnounceButtonSwitch(uint8_t device, char* topic, uint8_t present, uint8_t key, uint8_t toggle)
{
// key 0 = button
// key 1 = switch
@ -303,9 +306,9 @@ void HAssAnnounceSwitches(void)
char *tmp = Settings.switch_topic;
Format(sw_topic, tmp, sizeof(sw_topic));
if ((strlen(sw_topic) != 0) && strcmp(sw_topic, "0")) {
for (byte switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) {
byte switch_present = 0;
byte toggle = 1;
for (uint8_t switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) {
uint8_t switch_present = 0;
uint8_t toggle = 1;
if (pin[GPIO_SWT1 + switch_index] < 99) {
switch_present = 1;
@ -332,9 +335,9 @@ void HAssAnnounceButtons(void)
char *tmp = Settings.button_topic;
Format(key_topic, tmp, sizeof(key_topic));
if ((strlen(key_topic) != 0) && strcmp(key_topic, "0")) {
for (byte button_index = 0; button_index < MAX_KEYS; button_index++) {
byte button_present = 0;
byte toggle = 1;
for (uint8_t button_index = 0; button_index < MAX_KEYS; button_index++) {
uint8_t button_present = 0;
uint8_t toggle = 1;
if (!button_index && ((SONOFF_DUAL == Settings.module) || (CH4 == Settings.module))) {
button_present = 1;
@ -423,6 +426,7 @@ void HAssAnnounceSensor(const char* sensorname, const char* subsensortype)
void HAssAnnounceSensors(void)
{
uint8_t hass_xsns_index = 0;
do {
mqtt_data[0] = '\0';
int tele_period_save = tele_period;
@ -430,14 +434,18 @@ void HAssAnnounceSensors(void)
XsnsNextCall(FUNC_JSON_APPEND, hass_xsns_index); // ,"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
tele_period = tele_period_save;
char sensordata[256]; // Copy because we need to write to mqtt_data
char sensordata[256]; // Copy because we need to write to mqtt_data
strlcpy(sensordata, mqtt_data, sizeof(sensordata));
if (strlen(sensordata)) {
sensordata[0] = '{'; // {"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
snprintf_P(sensordata, sizeof(sensordata), PSTR("%s}"), sensordata);
snprintf_P(sensordata, sizeof(sensordata), PSTR("%s}"), sensordata); // {"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}}
StaticJsonBuffer<256> jsonBuffer;
// JsonBuffer size calculation (https://arduinojson.org/v5/assistant/)
// 383 = {"MCP230XX":{"D0":0,"D1":0,"D2":0,"D3":0,"D4":0,"D5":0,"D6":0,"D7":0,"D8":0,"D9":0,"D10":0,"D11":0,"D12":0,"D13":0,"D14":0,"D15":0}}
// 381 = {"MPR121A":{"Button0":0,"Button1":0,"Button2":0,"Button3":0,"Button4":0,"Button5":0,"Button6":0,"Button7":0,"Button8":0,"Button9":0,"Button10":0,"Button11":0,"Button12":0}}
// 420 = {"ENERGY":{"TotalStartTime":"2018-10-30T17:09:47","Total":2.684,"Yesterday":0.020,"Today":0.006,"Period":0.04,"Power":0.49,"ApparentPower":4.71,"ReactivePower":4.70,"Factor":0.10,"Frequency":50.04,"Voltage":226.3,"Current":0.021}}
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(sensordata);
if (!root.success()) {
snprintf_P(log_data, sizeof(log_data), PSTR("HASS: failed to parse '%s'"), sensordata);
@ -461,29 +469,22 @@ void HAssAnnounceSensors(void)
} while (hass_xsns_index != 0);
}
static int string_ends_with(const char * str, const char * suffix)
{
int str_len = strlen(str);
int suffix_len = strlen(suffix);
return (str_len >= suffix_len) && (0 == strcmp(str + (str_len-suffix_len), suffix));
}
void HAssDiscovery(uint8_t mode)
void HAssDiscovery(void)
{
// Configure Tasmota for default Home Assistant parameters to keep discovery message as short as possible
if (Settings.flag.hass_discovery) {
Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command
Settings.flag.decimal_text = 1; // Respond with decimal color values
Settings.flag3.hass_tele_on_power = 1; // send tele/STATE message as stat/RESULT
// Settings.light_scheme = 0; // To just control color it needs to be Scheme 0
if (!string_ends_with(Settings.mqtt_fulltopic, "%prefix%/")) {
Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command
Settings.flag.decimal_text = 1; // Respond with decimal color values
Settings.flag3.hass_tele_on_power = 1; // send tele/STATE message as stat/RESULT
// Settings.light_scheme = 0; // To just control color it needs to be Scheme 0
if (strcmp_P(Settings.mqtt_fulltopic, PSTR("%topic%/%prefix%/"))) {
strncpy_P(Settings.mqtt_fulltopic, PSTR("%topic%/%prefix%/"), sizeof(Settings.mqtt_fulltopic));
restart_flag = 2;
return; // As full topic has changed do restart first before sending discovery data
}
}
if (Settings.flag.hass_discovery || (1 == mode)) {
if (Settings.flag.hass_discovery || (1 == hass_mode)) {
// Send info about relays and lights
HAssAnnounceRelayLight();
@ -498,68 +499,34 @@ void HAssDiscovery(uint8_t mode)
}
}
/*
#define D_CMND_HASSDISCOVER "HassDiscover"
enum HassCommands { CMND_HASSDISCOVER };
const char kHassCommands[] PROGMEM = D_CMND_HASSDISCOVER ;
boolean HassCommand(void)
void HAssDiscover(void)
{
char command[CMDSZ];
boolean serviced = true;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kHassCommands);
if (-1 == command_code) {
serviced = false; // Unknown command
}
else if (CMND_HASSDISCOVER == command_code) {
if (XdrvMailbox.data_len > 0) {
switch (XdrvMailbox.payload) {
case 0: // Off
case 1: // On
Settings.flag.hass_discovery = XdrvMailbox.payload;
break;
case 2: // Toggle
Settings.flag.hass_discovery ^= 1;
break;
case 4: // Off
case 5: // On
Settings.flag.hass_light = XdrvMailbox.payload &1;
break;
case 6: // Toggle
Settings.flag.hass_light ^= 1;
break;
}
HAssDiscovery(1);
}
snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\",\"Force light\":\"%s\"}"),
command, GetStateText(Settings.flag.hass_discovery), GetStateText(Settings.flag.hass_light));
}
else serviced = false; // Unknown command
return serviced;
hass_mode = 1; // Force discovery
hass_init_step = 1; // Delayed discovery
}
*/
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
boolean Xdrv12(byte function)
bool Xdrv12(uint8_t function)
{
boolean result = false;
bool result = false;
if (Settings.flag.mqtt_enabled) {
switch (function) {
case FUNC_MQTT_INIT:
HAssDiscovery(0);
hass_mode = 0; // Discovery only if Settings.flag.hass_discovery is set
hass_init_step = 2; // Delayed discovery
break;
/*
case FUNC_COMMAND:
result = HassCommand();
case FUNC_EVERY_SECOND:
if (hass_init_step) {
hass_init_step--;
if (!hass_init_step) {
HAssDiscovery(); // Scheduled discovery using available resources
}
}
break;
*/
}
}
return result;

View File

@ -495,7 +495,7 @@ void DisplayText(void)
void DisplayClearScreenBuffer(void)
{
if (disp_screen_buffer_cols) {
for (byte i = 0; i < disp_screen_buffer_rows; i++) {
for (uint8_t i = 0; i < disp_screen_buffer_rows; i++) {
memset(disp_screen_buffer[i], 0, disp_screen_buffer_cols);
}
}
@ -504,7 +504,7 @@ void DisplayClearScreenBuffer(void)
void DisplayFreeScreenBuffer(void)
{
if (disp_screen_buffer != NULL) {
for (byte i = 0; i < disp_screen_buffer_rows; i++) {
for (uint8_t i = 0; i < disp_screen_buffer_rows; i++) {
if (disp_screen_buffer[i] != NULL) { free(disp_screen_buffer[i]); }
}
free(disp_screen_buffer);
@ -519,7 +519,7 @@ void DisplayAllocScreenBuffer(void)
disp_screen_buffer_rows = Settings.display_rows;
disp_screen_buffer = (char**)malloc(sizeof(*disp_screen_buffer) * disp_screen_buffer_rows);
if (disp_screen_buffer != NULL) {
for (byte i = 0; i < disp_screen_buffer_rows; i++) {
for (uint8_t i = 0; i < disp_screen_buffer_rows; i++) {
disp_screen_buffer[i] = (char*)malloc(sizeof(*disp_screen_buffer[i]) * (Settings.display_cols[0] +1));
if (disp_screen_buffer[i] == NULL) {
DisplayFreeScreenBuffer();
@ -542,7 +542,7 @@ void DisplayReAllocScreenBuffer(void)
void DisplayFillScreen(uint8_t line)
{
byte len = disp_screen_buffer_cols - strlen(disp_screen_buffer[line]);
uint8_t len = disp_screen_buffer_cols - strlen(disp_screen_buffer[line]);
if (len) {
memset(disp_screen_buffer[line] + strlen(disp_screen_buffer[line]), 0x20, len);
disp_screen_buffer[line][disp_screen_buffer_cols -1] = 0;
@ -554,7 +554,7 @@ void DisplayFillScreen(uint8_t line)
void DisplayClearLogBuffer(void)
{
if (disp_log_buffer_cols) {
for (byte i = 0; i < DISPLAY_LOG_ROWS; i++) {
for (uint8_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
memset(disp_log_buffer[i], 0, disp_log_buffer_cols);
}
}
@ -563,7 +563,7 @@ void DisplayClearLogBuffer(void)
void DisplayFreeLogBuffer(void)
{
if (disp_log_buffer != NULL) {
for (byte i = 0; i < DISPLAY_LOG_ROWS; i++) {
for (uint8_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
if (disp_log_buffer[i] != NULL) { free(disp_log_buffer[i]); }
}
free(disp_log_buffer);
@ -576,7 +576,7 @@ void DisplayAllocLogBuffer(void)
if (!disp_log_buffer_cols) {
disp_log_buffer = (char**)malloc(sizeof(*disp_log_buffer) * DISPLAY_LOG_ROWS);
if (disp_log_buffer != NULL) {
for (byte i = 0; i < DISPLAY_LOG_ROWS; i++) {
for (uint8_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
disp_log_buffer[i] = (char*)malloc(sizeof(*disp_log_buffer[i]) * (Settings.display_cols[0] +1));
if (disp_log_buffer[i] == NULL) {
DisplayFreeLogBuffer();
@ -845,7 +845,7 @@ void DisplayMqttSubscribe(void)
}
}
boolean DisplayMqttData(void)
bool DisplayMqttData(void)
{
if (disp_subscribed) {
char stopic[TOPSZ];
@ -908,10 +908,10 @@ void DisplaySetPower(void)
* Commands
\*********************************************************************************************/
boolean DisplayCommand(void)
bool DisplayCommand(void)
{
char command [CMDSZ];
boolean serviced = true;
bool serviced = true;
uint8_t disp_len = strlen(D_CMND_DISPLAY); // Prep for string length change
if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_DISPLAY), disp_len)) { // Prefix
@ -1076,9 +1076,9 @@ boolean DisplayCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv13(byte function)
bool Xdrv13(uint8_t function)
{
boolean result = false;
bool result = false;
if ((i2c_flg || spi_flg || soft_spi_flg) && XdspPresent()) {
switch (function) {

View File

@ -178,9 +178,9 @@ void MP3_CMD(uint8_t mp3cmd,uint16_t val) {
* check the MP3 commands
\*********************************************************************************************/
boolean MP3PlayerCmd(void) {
bool MP3PlayerCmd(void) {
char command[CMDSZ];
boolean serviced = true;
bool serviced = true;
uint8_t disp_len = strlen(D_CMND_MP3);
if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_MP3), disp_len)) { // prefix
@ -226,9 +226,9 @@ boolean MP3PlayerCmd(void) {
* Interface
\*********************************************************************************************/
boolean Xdrv14(byte function)
bool Xdrv14(uint8_t function)
{
boolean result = false;
bool result = false;
if (pin[GPIO_MP3_DFR562] < 99) {
switch (function) {

View File

@ -103,8 +103,8 @@ void PCA9685_SetPWM(uint8_t pin, uint16_t pwm, bool inverted) {
bool PCA9685_Command(void)
{
boolean serviced = true;
boolean validpin = false;
bool serviced = true;
bool validpin = false;
uint8_t paramcount = 0;
if (XdrvMailbox.data_len > 0) {
paramcount=1;
@ -178,9 +178,9 @@ void PCA9685_OutputTelemetry(bool telemetry) {
}
}
boolean Xdrv15(byte function)
bool Xdrv15(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -47,7 +47,7 @@
TasmotaSerial *TuyaSerial = nullptr;
uint8_t tuya_new_dim = 0; // Tuya dimmer value temp
boolean tuya_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction
bool tuya_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction
uint8_t tuya_cmd_status = 0; // Current status of serial-read
uint8_t tuya_cmd_checksum = 0; // Checksum of tuya command
uint8_t tuya_data_len = 0; // Data lenght of command
@ -106,17 +106,17 @@ void TuyaSendState(uint8_t id, uint8_t type, uint8_t* value){
TuyaSendCmd(TUYA_CMD_SET_DP, payload_buffer, payload_len);
}
void TuyaSendBool(uint8_t id, boolean value){
TuyaSendState(id, TUYA_TYPE_BOOL, &value);
void TuyaSendBool(uint8_t id, bool value){
TuyaSendState(id, TUYA_TYPE_BOOL, (uint8_t*)&value);
}
void TuyaSendValue(uint8_t id, uint32_t value){
TuyaSendState(id, TUYA_TYPE_VALUE, (uint8_t*)(&value));
}
boolean TuyaSetPower(void)
bool TuyaSetPower(void)
{
boolean status = false;
bool status = false;
uint8_t rpower = XdrvMailbox.index;
int16_t source = XdrvMailbox.payload;
@ -133,7 +133,7 @@ boolean TuyaSetPower(void)
return status;
}
boolean TuyaSetChannels(void)
bool TuyaSetChannels(void)
{
LightSerialDuty(((uint8_t*)XdrvMailbox.data)[0]);
return true;
@ -246,9 +246,9 @@ void TuyaPacketProcess(void)
if (tuya_buffer[5] == 2) {
uint8_t led1_gpio = tuya_buffer[6];
uint8_t key1_gpio = tuya_buffer[7];
boolean key1_set = false;
boolean led1_set = false;
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
bool key1_set = false;
bool led1_set = false;
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true;
else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true;
}
@ -273,7 +273,7 @@ void TuyaPacketProcess(void)
* API Functions
\*********************************************************************************************/
boolean TuyaModuleSelected(void)
bool TuyaModuleSelected(void)
{
if (!(pin[GPIO_TUYA_RX] < 99) || !(pin[GPIO_TUYA_TX] < 99)) { // fallback to hardware-serial if not explicitly selected
pin[GPIO_TUYA_TX] = 1;
@ -309,7 +309,7 @@ void TuyaSerialInput(void)
{
while (TuyaSerial->available()) {
yield();
byte serial_in_byte = TuyaSerial->read();
uint8_t serial_in_byte = TuyaSerial->read();
if (serial_in_byte == 0x55) { // Start TUYA Packet
tuya_cmd_status = 1;
@ -361,7 +361,7 @@ void TuyaSerialInput(void)
}
boolean TuyaButtonPressed(void)
bool TuyaButtonPressed(void)
{
if (!XdrvMailbox.index && ((PRESSED == XdrvMailbox.payload) && (NOT_PRESSED == lastbutton[XdrvMailbox.index]))) {
snprintf_P(log_data, sizeof(log_data), PSTR("TYA: Reset GPIO triggered"));
@ -398,9 +398,9 @@ void TuyaSetWifiLed(void){
* Interface
\*********************************************************************************************/
boolean Xdrv16(byte function)
bool Xdrv16(uint8_t function)
{
boolean result = false;
bool result = false;
if (TUYA_DIMMER == Settings.module) {
switch (function) {

View File

@ -88,10 +88,10 @@ void RfInit(void)
* Commands
\*********************************************************************************************/
boolean RfSendCommand(void)
bool RfSendCommand(void)
{
boolean serviced = true;
boolean error = false;
bool serviced = true;
bool error = false;
if (!strcasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_RFSEND))) {
if (XdrvMailbox.data_len) {
@ -116,7 +116,7 @@ boolean RfSendCommand(void)
} else {
// RFsend data, bits, protocol, repeat, pulse
char *p;
byte i = 0;
uint8_t i = 0;
for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < 5; str = strtok_r(NULL, ", ", &p)) {
switch (i++) {
case 0:
@ -166,9 +166,9 @@ boolean RfSendCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv17(byte function)
bool Xdrv17(uint8_t function)
{
boolean result = false;
bool result = false;
if ((pin[GPIO_RFSEND] < 99) || (pin[GPIO_RFRECV] < 99)) {
switch (function) {

View File

@ -31,7 +31,7 @@
TasmotaSerial *ArmtronixSerial = nullptr;
boolean armtronix_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction
bool armtronix_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction
int8_t armtronix_wifi_state = -2; // Keep MCU wifi-status in sync with WifiState()
int8_t armtronix_dimState[2]; // Dimmer state values.
int8_t armtronix_knobState[2]; // Dimmer state values.
@ -40,7 +40,7 @@ int8_t armtronix_knobState[2]; // Dimmer state values.
* Internal Functions
\*********************************************************************************************/
boolean ArmtronixSetChannels(void)
bool ArmtronixSetChannels(void)
{
LightSerial2Duty(((uint8_t*)XdrvMailbox.data)[0], ((uint8_t*)XdrvMailbox.data)[1]);
return true;
@ -84,7 +84,7 @@ void ArmtronixRequestState(void)
* API Functions
\*********************************************************************************************/
boolean ArmtronixModuleSelected(void)
bool ArmtronixModuleSelected(void)
{
light_type = LT_SERIAL2;
return true;
@ -169,9 +169,9 @@ void ArmtronixSetWifiLed(void)
* Interface
\*********************************************************************************************/
boolean Xdrv18(byte function)
bool Xdrv18(uint8_t function)
{
boolean result = false;
bool result = false;
if (ARMTRONIX_DIMMERS == Settings.module) {
switch (function) {

View File

@ -31,7 +31,7 @@
TasmotaSerial *PS16DZSerial = nullptr;
boolean ps16dz_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction
bool ps16dz_ignore_dim = false; // Flag to skip serial send to prevent looping when processing inbound states from the faceplate interaction
//uint64_t ps16dz_seq = 0;
@ -75,9 +75,9 @@ void PS16DZSendCommand(char type = 0, uint8_t value = 0)
PS16DZSerial->flush();
}
boolean PS16DZSetPower(void)
bool PS16DZSetPower(void)
{
boolean status = false;
bool status = false;
uint8_t rpower = XdrvMailbox.index;
int16_t source = XdrvMailbox.payload;
@ -91,7 +91,7 @@ boolean PS16DZSetPower(void)
return status;
}
boolean PS16DZSetChannels(void)
bool PS16DZSetChannels(void)
{
PS16DZSerialDuty(((uint8_t*)XdrvMailbox.data)[0]);
return true;
@ -128,7 +128,7 @@ void PS16DZResetWifi(void)
* API Functions
\*********************************************************************************************/
boolean PS16DZModuleSelected(void)
bool PS16DZModuleSelected(void)
{
light_type = LT_SERIAL1;
return true;
@ -153,7 +153,7 @@ void PS16DZSerialInput(void)
char scmnd[20];
while (PS16DZSerial->available()) {
yield();
byte serial_in_byte = PS16DZSerial->read();
uint8_t serial_in_byte = PS16DZSerial->read();
if (serial_in_byte != 0x1B){
if (ps16dz_byte_counter >= PS16DZ_BUFFER_SIZE - 1) {
memset(ps16dz_rx_buffer, 0, PS16DZ_BUFFER_SIZE);
@ -176,7 +176,7 @@ void PS16DZSerialInput(void)
char* token2 = strtok_r(token, ":", &end_token);
char* token3 = strtok_r(NULL, ":", &end_token);
if(!strncmp(token2, "\"switch\"", 8)){
boolean ps16dz_power = !strncmp(token3, "\"on\"", 4)?true:false;
bool ps16dz_power = !strncmp(token3, "\"on\"", 4)?true:false;
snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: power received: %s"), token3);
AddLog(LOG_LEVEL_DEBUG);
if((power || Settings.light_dimmer > 0) && (power !=ps16dz_power)) {
@ -225,9 +225,9 @@ void PS16DZSerialInput(void)
* Interface
\*********************************************************************************************/
boolean Xdrv19(byte function)
bool Xdrv19(uint8_t function)
{
boolean result = false;
bool result = false;
if (PS_16_DZ == Settings.module) {
switch (function) {

View File

@ -71,7 +71,7 @@ uint8_t CPU_show_freemem = 0;
/*******************************************************************************************/
#ifdef DEBUG_THEO
void ExceptionTest(byte type)
void ExceptionTest(uint8_t type)
{
/*
Exception (28):
@ -334,11 +334,11 @@ void DebugCfgPeek(char* parms)
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + data16;
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), address);
for (byte i = 0; i < 4; i++) {
for (uint8_t i = 0; i < 4; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[address +i]);
}
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
for (byte i = 0; i < 4; i++) {
for (uint8_t i = 0; i < 4; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' ');
}
snprintf_P(log_data, sizeof(log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), log_data, data8, data8, data16, data16, data32, data32);
@ -359,7 +359,7 @@ void DebugCfgPoke(char* parms)
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + (buffer[address +1] << 8) + buffer[address];
uint8_t *nbuffer = (uint8_t *) &data;
for (byte i = 0; i < 4; i++) { buffer[address +i] = nbuffer[+i]; }
for (uint8_t i = 0; i < 4; i++) { buffer[address +i] = nbuffer[+i]; }
uint32_t ndata32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + (buffer[address +1] << 8) + buffer[address];
@ -433,10 +433,10 @@ void SetFlashMode(uint8_t mode)
/*******************************************************************************************/
boolean DebugCommand(void)
bool DebugCommand(void)
{
char command[CMDSZ];
boolean serviced = true;
bool serviced = true;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kDebugCommands);
if (-1 == command_code) {
@ -516,9 +516,9 @@ boolean DebugCommand(void)
* Interface
\*********************************************************************************************/
boolean Xdrv99(byte function)
bool Xdrv99(uint8_t function)
{
boolean result = false;
bool result = false;
switch (function) {
case FUNC_PRE_INIT:

View File

@ -18,9 +18,9 @@
*/
#ifdef XFUNC_PTR_IN_ROM
boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointers
bool (* const xdrv_func_ptr[])(uint8_t) PROGMEM = { // Driver Function Pointers
#else
boolean (* const xdrv_func_ptr[])(byte) = { // Driver Function Pointers
bool (* const xdrv_func_ptr[])(uint8_t) = { // Driver Function Pointers
#endif
#ifdef XDRV_01
@ -192,7 +192,7 @@ boolean (* const xdrv_func_ptr[])(byte) = { // Driver Function Pointers
const uint8_t xdrv_present = sizeof(xdrv_func_ptr) / sizeof(xdrv_func_ptr[0]); // Number of drivers found
boolean XdrvCommand(uint8_t grpflg, char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, uint16_t payload16)
bool XdrvCommand(bool grpflg, char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, uint16_t payload16)
{
// XdrvMailbox.valid = 1;
XdrvMailbox.index = index;
@ -206,7 +206,7 @@ boolean XdrvCommand(uint8_t grpflg, char *type, uint16_t index, char *dataBuf, u
return XdrvCall(FUNC_COMMAND);
}
boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
bool XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
{
XdrvMailbox.index = stopicBuf;
XdrvMailbox.data_len = sdataBuf;
@ -216,7 +216,7 @@ boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t
return XdrvCall(FUNC_MQTT_DATA);
}
boolean XdrvRulesProcess(void)
bool XdrvRulesProcess(void)
{
return XdrvCall(FUNC_RULES_PROCESS);
}
@ -233,11 +233,11 @@ void ShowFreeMem(const char *where)
* Function call to all xdrv
\*********************************************************************************************/
boolean XdrvCall(byte Function)
bool XdrvCall(uint8_t Function)
{
boolean result = false;
bool result = false;
for (byte x = 0; x < xdrv_present; x++) {
for (uint8_t x = 0; x < xdrv_present; x++) {
// WifiAddDelayWhenDisconnected();
result = xdrv_func_ptr[x](Function);

View File

@ -97,7 +97,7 @@ void LcdDisplayOnOff(uint8_t on)
#ifdef USE_DISPLAY_MODES1TO5
void LcdCenter(byte row, char* txt)
void LcdCenter(uint8_t row, char* txt)
{
int offset;
int len;
@ -112,9 +112,9 @@ void LcdCenter(byte row, char* txt)
lcd->print(line);
}
boolean LcdPrintLog(void)
bool LcdPrintLog(void)
{
boolean result = false;
bool result = false;
disp_refresh--;
if (!disp_refresh) {
@ -125,7 +125,7 @@ boolean LcdPrintLog(void)
if (txt != NULL) {
uint8_t last_row = Settings.display_rows -1;
for (byte i = 0; i < last_row; i++) {
for (uint8_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
lcd->setCursor(0, i); // Col 0, Row i
lcd->print(disp_screen_buffer[i +1]);
@ -181,9 +181,9 @@ void LcdRefresh(void) // Every second
* Interface
\*********************************************************************************************/
boolean Xdsp01(byte function)
bool Xdsp01(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
if (FUNC_DISPLAY_INIT_DRIVER == function) {

View File

@ -147,7 +147,7 @@ void Ssd1306PrintLog(void)
oled->clearDisplay();
oled->setTextSize(Settings.display_size);
oled->setCursor(0,0);
for (byte i = 0; i < last_row; i++) {
for (uint8_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
oled->println(disp_screen_buffer[i]);
}
@ -200,9 +200,9 @@ void Ssd1306Refresh(void) // Every second
* Interface
\*********************************************************************************************/
boolean Xdsp02(byte function)
bool Xdsp02(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
if (FUNC_DISPLAY_INIT_DRIVER == function) {

View File

@ -47,14 +47,14 @@ uint8_t mtx_done = 0;
void MatrixWrite(void)
{
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->writeDisplay();
}
}
void MatrixClear(void)
{
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
}
MatrixWrite();
@ -62,7 +62,7 @@ void MatrixClear(void)
void MatrixFixed(char* txt)
{
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
matrix[i]->setCursor(-i *8, 0);
matrix[i]->print(txt);
@ -77,7 +77,7 @@ void MatrixCenter(char* txt)
int len = strlen(txt);
offset = (len < 8) ? offset = ((mtx_matrices *8) - (len *6)) / 2 : 0;
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
matrix[i]->setCursor(-(i *8)+offset, 0);
matrix[i]->print(txt);
@ -102,7 +102,7 @@ void MatrixScrollLeft(char* txt, int loop)
disp_refresh--;
if (!disp_refresh) {
disp_refresh = Settings.display_refresh;
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
matrix[i]->setCursor(mtx_x - i *8, 0);
matrix[i]->print(txt);
@ -145,9 +145,9 @@ void MatrixScrollUp(char* txt, int loop)
words[wordcounter++] = p;
p = strtok(NULL, separators);
}
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
for (byte j = 0; j < wordcounter; j++) {
for (uint8_t j = 0; j < wordcounter; j++) {
matrix[i]->setCursor(-i *8, mtx_y + (j *8));
matrix[i]->println(words[j]);
}
@ -170,7 +170,7 @@ void MatrixScrollUp(char* txt, int loop)
void MatrixInitMode(void)
{
for (byte i = 0; i < mtx_matrices; i++) {
for (uint8_t i = 0; i < mtx_matrices; i++) {
matrix[i]->setRotation(Settings.display_rotate); // 1
matrix[i]->setBrightness(Settings.display_dimmer);
matrix[i]->blinkRate(0); // 0 - 3
@ -327,9 +327,9 @@ void MatrixRefresh(void) // Every second
* Interface
\*********************************************************************************************/
boolean Xdsp03(byte function)
bool Xdsp03(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
if (FUNC_DISPLAY_INIT_DRIVER == function) {

View File

@ -148,7 +148,7 @@ void Ili9341PrintLog(void)
char* txt = DisplayLogBuffer('\370');
if (txt != NULL) {
byte size = Settings.display_size;
uint8_t size = Settings.display_size;
uint16_t theight = size * TFT_FONT_HEIGTH;
tft->setTextSize(size);
@ -167,7 +167,7 @@ void Ili9341PrintLog(void)
tft_scroll = theight; // Start below header
tft->setCursor(0, tft_scroll);
for (byte i = 0; i < last_row; i++) {
for (uint8_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
// tft->fillRect(0, tft_scroll, tft->width(), theight, ILI9341_BLACK); // Erase line
tft->print(disp_screen_buffer[i]);
@ -222,9 +222,9 @@ void Ili9341Refresh(void) // Every second
* Interface
\*********************************************************************************************/
boolean Xdsp04(byte function)
bool Xdsp04(uint8_t function)
{
boolean result = false;
bool result = false;
if (spi_flg) {
if (FUNC_DISPLAY_INIT_DRIVER == function) {

View File

@ -165,6 +165,7 @@ void EpdDisplayFrame(void)
{
epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
epd.Sleep();
}
void EpdDrawStringAt(uint16_t x, uint16_t y, char *str, uint8_t color, uint8_t flag)
@ -202,7 +203,7 @@ void EpdPrintLog(void)
char* txt = DisplayLogBuffer('\040');
if (txt != NULL) {
byte size = Settings.display_size;
uint8_t size = Settings.display_size;
uint16_t theight = size * EPD_FONT_HEIGTH;
EpdSetFont(size);
@ -210,7 +211,7 @@ void EpdPrintLog(void)
// epd_scroll = theight; // Start below header
epd_scroll = 0; // Start at top with no header
for (byte i = 0; i < last_row; i++) {
for (uint8_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
EpdDrawStringAt(0, epd_scroll, disp_screen_buffer[i], COLORED, 0);
epd_scroll += theight;
@ -266,9 +267,9 @@ void EpdRefresh(void) // Every second
* Interface
\*********************************************************************************************/
boolean Xdsp05(byte function)
bool Xdsp05(uint8_t function)
{
boolean result = false;
bool result = false;
if (spi_flg || soft_spi_flg) {
if (FUNC_DISPLAY_INIT_DRIVER == function) {

View File

@ -20,9 +20,9 @@
#ifdef USE_DISPLAY
#ifdef XFUNC_PTR_IN_ROM
boolean (* const xdsp_func_ptr[])(byte) PROGMEM = { // Display Function Pointers
bool (* const xdsp_func_ptr[])(uint8_t) PROGMEM = { // Display Function Pointers
#else
boolean (* const xdsp_func_ptr[])(byte) = { // Display Function Pointers
bool (* const xdsp_func_ptr[])(uint8_t) = { // Display Function Pointers
#endif
#ifdef XDSP_01
@ -119,11 +119,11 @@ uint8_t XdspPresent(void)
return xdsp_present;
}
boolean XdspCall(byte Function)
bool XdspCall(uint8_t Function)
{
boolean result = false;
bool result = false;
for (byte x = 0; x < xdsp_present; x++) {
for (uint8_t x = 0; x < xdsp_present; x++) {
result = xdsp_func_ptr[x](Function);
if (result && (FUNC_DISPLAY_MODEL == Function)) {

View File

@ -62,11 +62,11 @@ unsigned long hlw_power_ratio = 0;
unsigned long hlw_voltage_ratio = 0;
unsigned long hlw_current_ratio = 0;
byte hlw_select_ui_flag = 0;
byte hlw_ui_flag = 1;
byte hlw_model_type = 0;
byte hlw_load_off = 1;
byte hlw_cf1_timer = 0;
uint8_t hlw_select_ui_flag = 0;
uint8_t hlw_ui_flag = 1;
uint8_t hlw_model_type = 0;
uint8_t hlw_load_off = 1;
uint8_t hlw_cf1_timer = 0;
#ifndef USE_WS2812_DMA // Collides with Neopixelbus but solves exception
void HlwCfInterrupt(void) ICACHE_RAM_ATTR;
@ -246,9 +246,9 @@ void HlwDrvInit(void)
}
}
boolean HlwCommand(void)
bool HlwCommand(void)
{
boolean serviced = true;
bool serviced = true;
if ((CMND_POWERCAL == energy_command_code) || (CMND_VOLTAGECAL == energy_command_code) || (CMND_CURRENTCAL == energy_command_code)) {
// Service in xdrv_03_energy.ino
@ -277,7 +277,7 @@ boolean HlwCommand(void)
* Interface
\*********************************************************************************************/
int Xnrg01(byte function)
int Xnrg01(uint8_t function)
{
int result = 0;

View File

@ -137,7 +137,7 @@ bool CseSerialInput(void)
AddLogSerial(LOG_LEVEL_DEBUG_MORE);
uint8_t checksum = 0;
for (byte i = 2; i < 23; i++) { checksum += serial_in_buffer[i]; }
for (uint8_t i = 2; i < 23; i++) { checksum += serial_in_buffer[i]; }
if (checksum == serial_in_buffer[23]) {
CseReceived();
cse_receive_flag = 0;
@ -199,9 +199,9 @@ void CseDrvInit(void)
}
}
boolean CseCommand(void)
bool CseCommand(void)
{
boolean serviced = true;
bool serviced = true;
if (CMND_POWERSET == energy_command_code) {
if (XdrvMailbox.data_len && power_cycle) {
@ -227,7 +227,7 @@ boolean CseCommand(void)
* Interface
\*********************************************************************************************/
int Xnrg02(byte function)
int Xnrg02(uint8_t function)
{
int result = 0;

View File

@ -226,7 +226,7 @@ void PzemDrvInit(void)
* Interface
\*********************************************************************************************/
int Xnrg03(byte function)
int Xnrg03(uint8_t function)
{
int result = 0;

View File

@ -112,7 +112,7 @@ uint8_t McpChecksum(uint8_t *data)
uint8_t offset = 0;
uint8_t len = data[1] -1;
for (byte i = offset; i < len; i++) { checksum += data[i]; }
for (uint8_t i = offset; i < len; i++) { checksum += data[i]; }
return checksum;
}
@ -121,7 +121,7 @@ unsigned long McpExtractInt(char *data, uint8_t offset, uint8_t size)
unsigned long result = 0;
unsigned long pow = 1;
for (byte i = 0; i < size; i++) {
for (uint8_t i = 0; i < size; i++) {
result = result + (uint8_t)data[offset + i] * pow;
pow = pow * 256;
}
@ -130,7 +130,7 @@ unsigned long McpExtractInt(char *data, uint8_t offset, uint8_t size)
void McpSetInt(unsigned long value, uint8_t *data, uint8_t offset, size_t size)
{
for (byte i = 0; i < size; i++) {
for (uint8_t i = 0; i < size; i++) {
data[offset + i] = ((value >> (i * 8)) & 0xFF);
}
}
@ -145,7 +145,7 @@ void McpSend(uint8_t *data)
// AddLogBuffer(LOG_LEVEL_DEBUG_MORE, data, data[1]);
for (byte i = 0; i < data[1]; i++) {
for (uint8_t i = 0; i < data[1]; i++) {
Serial.write(data[i]);
}
}
@ -562,9 +562,9 @@ void McpDrvInit(void)
}
}
boolean McpCommand(void)
bool McpCommand(void)
{
boolean serviced = true;
bool serviced = true;
unsigned long value = 0;
if (CMND_POWERSET == energy_command_code) {
@ -616,7 +616,7 @@ boolean McpCommand(void)
* Interface
\*********************************************************************************************/
int Xnrg04(byte function)
int Xnrg04(uint8_t function)
{
int result = 0;

View File

@ -104,7 +104,7 @@ void PzemAcDrvInit(void)
* Interface
\*********************************************************************************************/
int Xnrg05(byte function)
int Xnrg05(uint8_t function)
{
int result = 0;

View File

@ -103,7 +103,7 @@ void PzemDcDrvInit(void)
* Interface
\*********************************************************************************************/
int Xnrg06(byte function)
int Xnrg06(uint8_t function)
{
int result = 0;

View File

@ -20,9 +20,9 @@
#ifdef USE_ENERGY_SENSOR
#ifdef XFUNC_PTR_IN_ROM
int (* const xnrg_func_ptr[])(byte) PROGMEM = { // Energy driver Function Pointers
int (* const xnrg_func_ptr[])(uint8_t) PROGMEM = { // Energy driver Function Pointers
#else
int (* const xnrg_func_ptr[])(byte) = { // Energy driver Function Pointers
int (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers
#endif
#ifdef XNRG_01
@ -92,11 +92,11 @@ int (* const xnrg_func_ptr[])(byte) = { // Energy driver Function Pointers
const uint8_t xnrg_present = sizeof(xnrg_func_ptr) / sizeof(xnrg_func_ptr[0]); // Number of drivers found
int XnrgCall(byte Function)
int XnrgCall(uint8_t Function)
{
int result = 0;
for (byte x = 0; x < xnrg_present; x++) {
for (uint8_t x = 0; x < xnrg_present; x++) {
result = xnrg_func_ptr[x](Function);
if (result && ((FUNC_SERIAL == Function) ||

View File

@ -31,7 +31,7 @@
#include <Ticker.h>
Ticker TickerMSearch;
boolean udp_connected = false;
bool udp_connected = false;
char packet_buffer[UDP_BUFFER_SIZE]; // buffer to hold incoming UDP packet
IPAddress ipMulticast(239,255,255,250); // Simple Service Discovery Protocol (SSDP)
@ -197,7 +197,7 @@ void HueRespondToMSearch(void)
* Belkin WeMo and Philips Hue bridge UDP multicast support
\*********************************************************************************************/
boolean UdpDisconnect(void)
bool UdpDisconnect(void)
{
if (udp_connected) {
WiFiUDP::stopAll();
@ -207,7 +207,7 @@ boolean UdpDisconnect(void)
return udp_connected;
}
boolean UdpConnect(void)
bool UdpConnect(void)
{
if (!udp_connected) {
if (PortUdp.beginMulticast(WiFi.localIP(), ipMulticast, port_multicast)) {
@ -302,7 +302,7 @@ const char WEMO_EVENTSERVICE_XML[] PROGMEM =
"<serviceStateTable>"
"<stateVariable sendEvents=\"yes\">"
"<name>BinaryState</name>"
"<dataType>Boolean</dataType>"
"<dataType>bool</dataType>"
"<defaultValue>0</defaultValue>"
"</stateVariable>"
"<stateVariable sendEvents=\"yes\">"
@ -564,7 +564,7 @@ void HueConfig(String *path)
bool g_gotct = false;
void HueLightStatus1(byte device, String *response)
void HueLightStatus1(uint8_t device, String *response)
{
float hue = 0;
float sat = 0;
@ -584,7 +584,7 @@ void HueLightStatus1(byte device, String *response)
response->replace("{m}", g_gotct?"ct":"hs");
}
void HueLightStatus2(byte device, String *response)
void HueLightStatus2(uint8_t device, String *response)
{
*response += FPSTR(HUE_LIGHTS_STATUS_JSON2);
response->replace("{j1", Settings.friendlyname[device-1]);

View File

@ -172,7 +172,7 @@ void Ws2812Clock(void)
Ws2812UpdateHand((RtcTime.minute * 1000) / clksize, WS_MINUTE);
Ws2812UpdateHand(((RtcTime.hour % 12) * (5000 / clksize)) + ((RtcTime.minute * 1000) / (12 * clksize)), WS_HOUR);
if (Settings.ws_color[WS_MARKER][WS_RED] + Settings.ws_color[WS_MARKER][WS_GREEN] + Settings.ws_color[WS_MARKER][WS_BLUE]) {
for (byte i = 0; i < 12; i++) {
for (uint8_t i = 0; i < 12; i++) {
Ws2812UpdateHand((i * 5000) / clksize, WS_MARKER);
}
}
@ -395,7 +395,7 @@ char* Ws2812GetColor(uint16_t led, char* scolor)
sl_ledcolor[1] = lcolor.G;
sl_ledcolor[2] = lcolor.B;
scolor[0] = '\0';
for (byte i = 0; i < light_subtype; i++) {
for (uint8_t i = 0; i < light_subtype; i++) {
if (Settings.flag.decimal_text) {
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", sl_ledcolor[i]);
} else {

View File

@ -25,7 +25,7 @@
unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in micro seconds
void CounterUpdate(byte index)
void CounterUpdate(uint8_t index)
{
unsigned long counter_debounce_time = micros() - last_counter_timer[index -1];
if (counter_debounce_time > Settings.pulse_counter_debounce * 1000) {
@ -65,7 +65,7 @@ void CounterUpdate4(void)
void CounterSaveState(void)
{
for (byte i = 0; i < MAX_COUNTERS; i++) {
for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
Settings.pulse_counter[i] = RtcSettings.pulse_counter[i];
}
@ -77,7 +77,7 @@ void CounterInit(void)
typedef void (*function) () ;
function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 };
for (byte i = 0; i < MAX_COUNTERS; i++) {
for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
pinMode(pin[GPIO_CNTR1 +i], bitRead(counter_no_pullup, i) ? INPUT : INPUT_PULLUP);
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
@ -90,13 +90,13 @@ const char HTTP_SNS_COUNTER[] PROGMEM =
"%s{s}" D_COUNTER "%d{m}%s%s{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void CounterShow(boolean json)
void CounterShow(bool json)
{
char stemp[10];
byte dsxflg = 0;
byte header = 0;
for (byte i = 0; i < MAX_COUNTERS; i++) {
uint8_t dsxflg = 0;
uint8_t header = 0;
for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
char counter[33];
if (bitRead(Settings.pulse_counter_type, i)) {
@ -141,9 +141,9 @@ void CounterShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns01(byte function)
bool Xsns01(uint8_t function)
{
boolean result = false;
bool result = false;
switch (function) {
case FUNC_INIT:

View File

@ -29,7 +29,7 @@ uint16_t adc_last_value = 0;
uint16_t AdcRead(void)
{
uint16_t analog = 0;
for (byte i = 0; i < 32; i++) {
for (uint8_t i = 0; i < 32; i++) {
analog += analogRead(A0);
delay(1);
}
@ -50,7 +50,7 @@ void AdcEvery250ms(void)
}
#endif // USE_RULES
void AdcShow(boolean json)
void AdcShow(bool json)
{
uint16_t analog = AdcRead();
@ -67,9 +67,9 @@ void AdcShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns02(byte function)
bool Xsns02(uint8_t function)
{
boolean result = false;
bool result = false;
if (my_module_flag.adc0) {
switch (function) {

View File

@ -87,7 +87,7 @@ void SonoffScSerialInput(char *rcvstat)
value[i++] = atoi(str);
}
if (value[0] > 0) {
for (byte i = 0; i < 5; i++) {
for (uint8_t i = 0; i < 5; i++) {
sc_value[i] = value[i];
}
sc_value[2] = (11 - sc_value[2]) * 10; // Invert light level
@ -110,7 +110,7 @@ const char HTTP_SNS_SCPLUS[] PROGMEM =
"%s{s}" D_LIGHT "{m}%d%%{e}{s}" D_NOISE "{m}%d%%{e}{s}" D_AIR_QUALITY "{m}%d%%{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void SonoffScShow(boolean json)
void SonoffScShow(bool json)
{
if (sc_value[0] > 0) {
float t = ConvertTemp(sc_value[1]);
@ -154,9 +154,9 @@ void SonoffScShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns04(byte function)
bool Xsns04(uint8_t function)
{
boolean result = false;
bool result = false;
if (SONOFF_SC == Settings.module) {
switch (function) {

View File

@ -120,7 +120,7 @@ uint8_t OneWireRead(void)
return r;
}
boolean OneWireCrc8(uint8_t *addr)
bool OneWireCrc8(uint8_t *addr)
{
uint8_t crc = 0;
uint8_t len = 8;
@ -149,7 +149,7 @@ void Ds18b20Convert(void)
// delay(750); // 750ms should be enough for 12bit conv
}
boolean Ds18b20Read(void)
bool Ds18b20Read(void)
{
uint8_t data[9];
int8_t sign = 1;
@ -199,7 +199,7 @@ void Ds18b20EverySecond(void)
}
}
void Ds18b20Show(boolean json)
void Ds18b20Show(bool json)
{
if (ds18b20_valid) { // Check for valid temperature
char temperature[33];
@ -228,9 +228,9 @@ void Ds18b20Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns05(byte function)
bool Xsns05(uint8_t function)
{
boolean result = false;
bool result = false;
if (pin[GPIO_DSB] < 99) {
switch (function) {

View File

@ -233,7 +233,7 @@ uint8_t OneWireSearch(uint8_t *newAddr)
return search_result;
}
boolean OneWireCrc8(uint8_t *addr)
bool OneWireCrc8(uint8_t *addr)
{
uint8_t crc = 0;
uint8_t len = 8;
@ -424,7 +424,7 @@ void Ds18x20EverySecond(void)
}
}
void Ds18x20Show(boolean json)
void Ds18x20Show(bool json)
{
for (uint8_t i = 0; i < ds18x20_sensors; i++) {
uint8_t index = ds18x20_sensor[i].index;
@ -440,7 +440,7 @@ void Ds18x20Show(boolean json)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, ds18x20_types, temperature);
} else {
char address[17];
for (byte j = 0; j < 6; j++) {
for (uint8_t j = 0; j < 6; j++) {
sprintf(address+2*j, "%02X", ds18x20_sensor[index].address[6-j]); // Skip sensor type and crc
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, ds18x20_types, address, temperature);
@ -468,9 +468,9 @@ void Ds18x20Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns05(byte function)
bool Xsns05(uint8_t function)
{
boolean result = false;
bool result = false;
if (pin[GPIO_DSB] < 99) {
switch (function) {

View File

@ -65,11 +65,11 @@ void Ds18x20Search(void)
num_sensors++;
}
}
for (byte i = 0; i < num_sensors; i++) {
for (uint8_t i = 0; i < num_sensors; i++) {
ds18x20_index[i] = i;
}
for (byte i = 0; i < num_sensors; i++) {
for (byte j = i + 1; j < num_sensors; j++) {
for (uint8_t i = 0; i < num_sensors; i++) {
for (uint8_t j = i + 1; j < num_sensors; j++) {
if (uint32_t(ds18x20_address[ds18x20_index[i]]) > uint32_t(ds18x20_address[ds18x20_index[j]])) {
std::swap(ds18x20_index[i], ds18x20_index[j]);
}
@ -87,7 +87,7 @@ String Ds18x20Addresses(uint8_t sensor)
{
char address[20];
for (byte i = 0; i < 8; i++) {
for (uint8_t i = 0; i < 8; i++) {
sprintf(address+2*i, "%02X", ds18x20_address[ds18x20_index[sensor]][i]);
}
return String(address);
@ -101,9 +101,9 @@ void Ds18x20Convert(void)
// delay(750); // 750ms should be enough for 12bit conv
}
boolean Ds18x20Read(uint8_t sensor, float &t)
bool Ds18x20Read(uint8_t sensor, float &t)
{
byte data[12];
uint8_t data[12];
int8_t sign = 1;
uint16_t temp12 = 0;
int16_t temp14 = 0;
@ -116,7 +116,7 @@ boolean Ds18x20Read(uint8_t sensor, float &t)
ds->select(ds18x20_address[ds18x20_index[sensor]]);
ds->write(W1_READ_SCRATCHPAD); // Read Scratchpad
for (byte i = 0; i < 9; i++) {
for (uint8_t i = 0; i < 9; i++) {
data[i] = ds->read();
}
if (OneWire::crc8(data, 8) == data[8]) {
@ -168,13 +168,13 @@ void Ds18x20Type(uint8_t sensor)
}
}
void Ds18x20Show(boolean json)
void Ds18x20Show(bool json)
{
char stemp[10];
float t;
byte dsxflg = 0;
for (byte i = 0; i < Ds18x20Sensors(); i++) {
uint8_t dsxflg = 0;
for (uint8_t i = 0; i < Ds18x20Sensors(); i++) {
if (Ds18x20Read(i, t)) { // Check if read failed
Ds18x20Type(i);
char temperature[33];
@ -220,9 +220,9 @@ void Ds18x20Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns05(byte function)
bool Xsns05(uint8_t function)
{
boolean result = false;
bool result = false;
if (pin[GPIO_DSB] < 99) {
switch (function) {

View File

@ -33,11 +33,11 @@
uint32_t dht_max_cycles;
uint8_t dht_data[5];
byte dht_sensors = 0;
uint8_t dht_sensors = 0;
struct DHTSTRUCT {
byte pin;
byte type;
uint8_t pin;
uint8_t type;
char stype[12];
uint32_t lastreadtime;
uint8_t lastresult;
@ -47,12 +47,12 @@ struct DHTSTRUCT {
void DhtReadPrep(void)
{
for (byte i = 0; i < dht_sensors; i++) {
for (uint8_t i = 0; i < dht_sensors; i++) {
digitalWrite(Dht[i].pin, HIGH);
}
}
int32_t DhtExpectPulse(byte sensor, bool level)
int32_t DhtExpectPulse(uint8_t sensor, bool level)
{
int32_t count = 0;
@ -64,7 +64,7 @@ int32_t DhtExpectPulse(byte sensor, bool level)
return count;
}
boolean DhtRead(byte sensor)
bool DhtRead(uint8_t sensor)
{
int32_t cycles[80];
uint8_t error = 0;
@ -134,7 +134,7 @@ boolean DhtRead(byte sensor)
return true;
}
void DhtReadTempHum(byte sensor)
void DhtReadTempHum(uint8_t sensor)
{
if ((NAN == Dht[sensor].h) || (Dht[sensor].lastresult > DHT_MAX_RETRY)) { // Reset after 8 misses
Dht[sensor].t = NAN;
@ -162,9 +162,9 @@ void DhtReadTempHum(byte sensor)
}
}
boolean DhtSetup(byte pin, byte type)
bool DhtSetup(uint8_t pin, uint8_t type)
{
boolean success = false;
bool success = false;
if (dht_sensors < DHT_MAX_SENSORS) {
Dht[dht_sensors].pin = pin;
@ -181,7 +181,7 @@ void DhtInit(void)
{
dht_max_cycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for reading pulses from DHT sensor.
for (byte i = 0; i < dht_sensors; i++) {
for (uint8_t i = 0; i < dht_sensors; i++) {
pinMode(Dht[i].pin, INPUT_PULLUP);
Dht[i].lastreadtime = 0;
Dht[i].lastresult = 0;
@ -198,16 +198,16 @@ void DhtEverySecond(void)
// <1mS
DhtReadPrep();
} else {
for (byte i = 0; i < dht_sensors; i++) {
for (uint8_t i = 0; i < dht_sensors; i++) {
// DHT11 and AM2301 25mS per sensor, SI7021 5mS per sensor
DhtReadTempHum(i);
}
}
}
void DhtShow(boolean json)
void DhtShow(bool json)
{
for (byte i = 0; i < dht_sensors; i++) {
for (uint8_t i = 0; i < dht_sensors; i++) {
char temperature[33];
dtostrfd(Dht[i].t, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
@ -239,9 +239,9 @@ void DhtShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns06(byte function)
bool Xsns06(uint8_t function)
{
boolean result = false;
bool result = false;
if (dht_flg) {
switch (function) {

View File

@ -44,21 +44,21 @@ uint8_t sht_valid = 0;
float sht_temperature = 0;
float sht_humidity = 0;
boolean ShtReset(void)
bool ShtReset(void)
{
pinMode(sht_sda_pin, INPUT_PULLUP);
pinMode(sht_scl_pin, OUTPUT);
delay(11);
for (byte i = 0; i < 9; i++) {
for (uint8_t i = 0; i < 9; i++) {
digitalWrite(sht_scl_pin, HIGH);
digitalWrite(sht_scl_pin, LOW);
}
boolean success = ShtSendCommand(SHT1X_CMD_SOFT_RESET);
bool success = ShtSendCommand(SHT1X_CMD_SOFT_RESET);
delay(11);
return success;
}
boolean ShtSendCommand(const byte cmd)
bool ShtSendCommand(const uint8_t cmd)
{
pinMode(sht_sda_pin, OUTPUT);
// Transmission Start sequence
@ -72,7 +72,7 @@ boolean ShtSendCommand(const byte cmd)
// Send the command (address must be 000b)
shiftOut(sht_sda_pin, sht_scl_pin, MSBFIRST, cmd);
// Wait for ACK
boolean ackerror = false;
bool ackerror = false;
digitalWrite(sht_scl_pin, HIGH);
pinMode(sht_sda_pin, INPUT_PULLUP);
if (digitalRead(sht_sda_pin) != LOW) {
@ -90,10 +90,10 @@ boolean ShtSendCommand(const byte cmd)
return (!ackerror);
}
boolean ShtAwaitResult(void)
bool ShtAwaitResult(void)
{
// Maximum 320ms for 14 bit measurement
for (byte i = 0; i < 16; i++) {
for (uint8_t i = 0; i < 16; i++) {
if (LOW == digitalRead(sht_sda_pin)) {
return true;
}
@ -125,7 +125,7 @@ int ShtReadData(void)
return val;
}
boolean ShtRead(void)
bool ShtRead(void)
{
if (sht_valid) { sht_valid--; }
if (!ShtReset()) { return false; }
@ -185,7 +185,7 @@ void ShtEverySecond(void)
}
}
void ShtShow(boolean json)
void ShtShow(bool json)
{
if (sht_valid) {
char temperature[33];
@ -219,9 +219,9 @@ void ShtShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns07(byte function)
bool Xsns07(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -140,7 +140,7 @@ void HtuInit(void)
HtuSetResolution(HTU21_RES_RH12_T14);
}
boolean HtuRead(void)
bool HtuRead(void)
{
uint8_t checksum = 0;
uint16_t sensorval = 0;
@ -246,7 +246,7 @@ void HtuEverySecond(void)
}
}
void HtuShow(boolean json)
void HtuShow(bool json)
{
if (htu_valid) {
char temperature[33];
@ -280,9 +280,9 @@ void HtuShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns08(byte function)
bool Xsns08(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -101,7 +101,7 @@ typedef struct {
bmp180_cal_data_t *bmp180_cal_data = NULL;
boolean Bmp180Calibration(uint8_t bmp_idx)
bool Bmp180Calibration(uint8_t bmp_idx)
{
if (!bmp180_cal_data) {
bmp180_cal_data = (bmp180_cal_data_t*)malloc(BMP_MAX_SENSORS * sizeof(bmp180_cal_data_t));
@ -246,7 +246,7 @@ typedef struct {
Bme280CalibrationData_t *Bme280CalibrationData = NULL;
boolean Bmx280Calibrate(uint8_t bmp_idx)
bool Bmx280Calibrate(uint8_t bmp_idx)
{
// if (I2cRead8(bmp_address, BMP_REGISTER_CHIPID) != BME280_CHIPID) return false;
@ -351,7 +351,7 @@ static void BmeDelayMs(uint32_t ms)
delay(ms);
}
boolean Bme680Init(uint8_t bmp_idx)
bool Bme680Init(uint8_t bmp_idx)
{
if (!gas_sensor) {
gas_sensor = (bme680_dev*)malloc(BMP_MAX_SENSORS * sizeof(bme680_dev));
@ -455,14 +455,14 @@ void BmpDetect(void)
if (!bmp_sensors) { return; }
memset(bmp_sensors, 0, bmp_sensor_size); // Init defaults to 0
for (byte i = 0; i < BMP_MAX_SENSORS; i++) {
for (uint8_t i = 0; i < BMP_MAX_SENSORS; i++) {
uint8_t bmp_type = I2cRead8(bmp_addresses[i], BMP_REGISTER_CHIPID);
if (bmp_type) {
bmp_sensors[bmp_count].bmp_address = bmp_addresses[i];
bmp_sensors[bmp_count].bmp_type = bmp_type;
bmp_sensors[bmp_count].bmp_model = 0;
boolean success = false;
bool success = false;
switch (bmp_type) {
case BMP180_CHIPID:
success = Bmp180Calibration(bmp_count);
@ -494,7 +494,7 @@ void BmpRead(void)
{
if (!bmp_sensors) { return; }
for (byte bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
for (uint8_t bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
switch (bmp_sensors[bmp_idx].bmp_type) {
case BMP180_CHIPID:
Bmp180Read(bmp_idx);
@ -525,11 +525,11 @@ void BmpEverySecond(void)
}
}
void BmpShow(boolean json)
void BmpShow(bool json)
{
if (!bmp_sensors) { return; }
for (byte bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
for (uint8_t bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
if (bmp_sensors[bmp_idx].bmp_type) {
float bmp_sealevel = 0.0;
if (bmp_sensors[bmp_idx].bmp_pressure != 0.0) {
@ -621,9 +621,9 @@ void BmpShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns09(byte function)
bool Xsns09(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -44,8 +44,8 @@ bool Bh1750Read(void)
if (bh1750_valid) { bh1750_valid--; }
if (2 != Wire.requestFrom(bh1750_address, (uint8_t)2)) { return false; }
byte msb = Wire.read();
byte lsb = Wire.read();
uint8_t msb = Wire.read();
uint8_t lsb = Wire.read();
bh1750_illuminance = ((msb << 8) | lsb) / 1.2;
bh1750_valid = SENSOR_MAX_MISS;
return true;
@ -59,7 +59,7 @@ void Bh1750Detect(void)
return;
}
for (byte i = 0; i < sizeof(bh1750_addresses); i++) {
for (uint8_t i = 0; i < sizeof(bh1750_addresses); i++) {
bh1750_address = bh1750_addresses[i];
Wire.beginTransmission(bh1750_address);
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
@ -89,7 +89,7 @@ void Bh1750EverySecond(void)
}
}
void Bh1750Show(boolean json)
void Bh1750Show(bool json)
{
if (bh1750_valid) {
if (json) {
@ -111,9 +111,9 @@ void Bh1750Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns10(byte function)
bool Xsns10(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -187,7 +187,7 @@ void Veml6070EverySecond(void)
/********************************************************************************************/
void Veml6070ModeCmd(boolean mode_cmd)
void Veml6070ModeCmd(bool mode_cmd)
{
// mode_cmd 1 = on = 1[ms]
// mode_cmd 0 = off = 2[ms]
@ -270,7 +270,7 @@ double Veml6070UvPower(double uvrisk)
/********************************************************************************************/
void Veml6070Show(boolean json)
void Veml6070Show(bool json)
{
if (veml6070_type) {
// convert double values to string
@ -307,9 +307,9 @@ void Veml6070Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns11(byte function)
bool Xsns11(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -165,7 +165,7 @@ void Ads1115Detect(void)
return;
}
for (byte i = 0; i < sizeof(ads1115_addresses); i++) {
for (uint8_t i = 0; i < sizeof(ads1115_addresses); i++) {
ads1115_address = ads1115_addresses[i];
if (I2cValidRead16(&buffer, ads1115_address, ADS1115_REG_POINTER_CONVERT)) {
Ads1115StartComparator(i, ADS1115_REG_CONFIG_MODE_CONTIN);
@ -177,13 +177,13 @@ void Ads1115Detect(void)
}
}
void Ads1115Show(boolean json)
void Ads1115Show(bool json)
{
if (ads1115_type) {
char stemp[10];
byte dsxflg = 0;
for (byte i = 0; i < 4; i++) {
uint8_t dsxflg = 0;
for (uint8_t i = 0; i < 4; i++) {
int16_t adc_value = Ads1115GetConversion(i);
if (json) {
@ -212,9 +212,9 @@ void Ads1115Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns12(byte function)
bool Xsns12(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -55,7 +55,7 @@ uint8_t ads1115_addresses[] = {
ADS1115_ADDRESS_ADDR_SCL // address pin tied to SCL pin
};
int16_t Ads1115GetConversion(byte channel)
int16_t Ads1115GetConversion(uint8_t channel)
{
switch (channel) {
case 0:
@ -81,7 +81,7 @@ void Ads1115Detect(void)
return;
}
for (byte i = 0; i < sizeof(ads1115_addresses); i++) {
for (uint8_t i = 0; i < sizeof(ads1115_addresses); i++) {
ads1115_address = ads1115_addresses[i];
ADS1115 adc0(ads1115_address);
if (adc0.testConnection()) {
@ -97,13 +97,13 @@ void Ads1115Detect(void)
}
}
void Ads1115Show(boolean json)
void Ads1115Show(bool json)
{
if (ads1115_type) {
char stemp[10];
byte dsxflg = 0;
for (byte i = 0; i < 4; i++) {
uint8_t dsxflg = 0;
for (uint8_t i = 0; i < 4; i++) {
int16_t adc_value = Ads1115GetConversion(i);
if (json) {
@ -132,9 +132,9 @@ void Ads1115Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns12(byte function)
bool Xsns12(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -177,7 +177,7 @@ bool Ina219Read(void)
bool Ina219CommandSensor(void)
{
boolean serviced = true;
bool serviced = true;
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) {
Settings.ina219_mode = XdrvMailbox.payload;
@ -194,7 +194,7 @@ void Ina219Detect(void)
{
if (ina219_type) { return; }
for (byte i = 0; i < sizeof(ina219_addresses); i++) {
for (uint8_t i = 0; i < sizeof(ina219_addresses); i++) {
ina219_address = ina219_addresses[i];
if (Ina219SetCalibration(Settings.ina219_mode)) {
ina219_type = 1;
@ -229,7 +229,7 @@ const char HTTP_SNS_INA219_DATA[] PROGMEM = "%s"
"{s}INA219 " D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}";
#endif // USE_WEBSERVER
void Ina219Show(boolean json)
void Ina219Show(bool json)
{
if (ina219_valid) {
float fpower = ina219_voltage * ina219_current;
@ -261,9 +261,9 @@ void Ina219Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns13(byte function)
bool Xsns13(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -82,7 +82,7 @@ void Sht3xDetect(void)
float t;
float h;
for (byte i = 0; i < SHT3X_MAX_SENSORS; i++) {
for (uint8_t i = 0; i < SHT3X_MAX_SENSORS; i++) {
if (Sht3xRead(t, h, sht3x_addresses[i])) {
sht3x_sensors[sht3x_count].address = sht3x_addresses[i];
GetTextIndexed(sht3x_sensors[sht3x_count].types, sizeof(sht3x_sensors[sht3x_count].types), i, kShtTypes);
@ -93,13 +93,13 @@ void Sht3xDetect(void)
}
}
void Sht3xShow(boolean json)
void Sht3xShow(bool json)
{
if (sht3x_count) {
float t;
float h;
char types[11];
for (byte i = 0; i < sht3x_count; i++) {
for (uint8_t i = 0; i < sht3x_count; i++) {
if (Sht3xRead(t, h, sht3x_sensors[i].address)) {
if (0 == i) { SetGlobalValues(t, h); }
@ -140,9 +140,9 @@ void Sht3xShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns14(byte function)
bool Xsns14(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -70,7 +70,7 @@ enum MhzFilterOptions {MHZ19_FILTER_OFF, MHZ19_FILTER_OFF_ALLSAMPLES, MHZ19_FILT
TasmotaSerial *MhzSerial;
const char kMhzTypes[] PROGMEM = "MHZ19|MHZ19B";
const char kMhzModels[] PROGMEM = "|B";
enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET, MHZ_CMND_RANGE_1000, MHZ_CMND_RANGE_2000, MHZ_CMND_RANGE_3000, MHZ_CMND_RANGE_5000 };
const uint8_t kMhzCommands[][4] PROGMEM = {
@ -90,7 +90,6 @@ uint16_t mhz_last_ppm = 0;
uint8_t mhz_filter = MHZ19_FILTER_OPTION;
bool mhz_abc_enable = MHZ19_ABC_ENABLE;
bool mhz_abc_must_apply = false;
char mhz_types[7];
float mhz_temperature = 0;
uint8_t mhz_retry = MHZ19_RETRY_COUNT;
@ -99,17 +98,17 @@ uint8_t mhz_state = 0;
/*********************************************************************************************/
byte MhzCalculateChecksum(byte *array)
uint8_t MhzCalculateChecksum(uint8_t *array)
{
byte checksum = 0;
for (byte i = 1; i < 8; i++) {
uint8_t checksum = 0;
for (uint8_t i = 1; i < 8; i++) {
checksum += array[i];
}
checksum = 255 - checksum;
return (checksum +1);
}
size_t MhzSendCmd(byte command_id)
size_t MhzSendCmd(uint8_t command_id)
{
uint8_t mhz_send[9] = { 0 };
@ -205,7 +204,7 @@ void MhzEverySecond(void)
return;
}
byte crc = MhzCalculateChecksum(mhz_response);
uint8_t crc = MhzCalculateChecksum(mhz_response);
if (mhz_response[8] != crc) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "MH-Z19 crc error"));
return;
@ -271,7 +270,7 @@ void MhzEverySecond(void)
bool MhzCommandSensor(void)
{
boolean serviced = true;
bool serviced = true;
switch (XdrvMailbox.payload) {
case 2:
@ -320,21 +319,23 @@ void MhzInit(void)
}
}
void MhzShow(boolean json)
void MhzShow(bool json)
{
char types[7] = "MHZ19B"; // MHZ19B for legacy reasons. Prefered is MHZ19
char temperature[33];
dtostrfd(mhz_temperature, Settings.flag2.temperature_resolution, temperature);
GetTextIndexed(mhz_types, sizeof(mhz_types), mhz_type -1, kMhzTypes);
char model[3];
GetTextIndexed(model, sizeof(model), mhz_type -1, kMhzModels);
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, mhz_types, mhz_last_ppm, temperature);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_MODEL "\":\"%s\",\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, types, model, mhz_last_ppm, temperature);
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, mhz_last_ppm);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_CO2, mqtt_data, mhz_types, mhz_last_ppm);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, mhz_types, temperature, TempUnit());
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_CO2, mqtt_data, types, mhz_last_ppm);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, types, temperature, TempUnit());
#endif // USE_WEBSERVER
}
}
@ -343,9 +344,9 @@ void MhzShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns15(byte function)
bool Xsns15(uint8_t function)
{
boolean result = false;
bool result = false;
if (mhz_type) {
switch (function) {

View File

@ -48,7 +48,6 @@ bool Tsl2561Read(void)
uint16_t scaledFull, scaledIr;
uint32_t full, ir;
if (Tsl.available()) {
if (Tsl.on()) {
if (Tsl.id(id)
&& Tsl2561Util::autoGain(Tsl, gain, exposure, scaledFull, scaledIr)
@ -58,7 +57,6 @@ bool Tsl2561Read(void)
tsl2561_milliLux = 0;
}
}
}
tsl2561_valid = SENSOR_MAX_MISS;
return true;
}
@ -67,9 +65,9 @@ void Tsl2561Detect(void)
{
if (tsl2561_type) { return; }
if (!Tsl.available()) {
if (I2cDevice(0x29) || I2cDevice(0x39) || I2cDevice(0x49)) {
Tsl.begin();
if (Tsl.available()) {
if (Tsl.on()) {
tsl2561_type = 1;
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, tsl2561_types, Tsl.address());
AddLog(LOG_LEVEL_DEBUG);
@ -88,7 +86,7 @@ void Tsl2561EverySecond(void)
if (tsl2561_type) {
if (!Tsl2561Read()) {
AddLogMissed(tsl2561_types, tsl2561_valid);
// if (!tsl2561_valid) { tsl2561_type = 0; }
if (!tsl2561_valid) { tsl2561_type = 0; }
}
}
}
@ -99,7 +97,7 @@ const char HTTP_SNS_TSL2561[] PROGMEM =
"%s{s}TSL2561 " D_ILLUMINANCE "{m}%u.%03u " D_UNIT_LUX "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void Tsl2561Show(boolean json)
void Tsl2561Show(bool json)
{
if (tsl2561_valid) {
if (json) {
@ -120,9 +118,9 @@ void Tsl2561Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns16(byte function)
bool Xsns16(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -145,7 +145,7 @@ void SenseairInit(void)
}
}
void SenseairShow(boolean json)
void SenseairShow(bool json)
{
char temperature[33];
dtostrfd(senseair_temperature, Settings.flag2.temperature_resolution, temperature);
@ -177,9 +177,9 @@ void SenseairShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns17(byte function)
bool Xsns17(uint8_t function)
{
boolean result = false;
bool result = false;
if (senseair_type) {
switch (function) {

View File

@ -45,7 +45,7 @@ struct pms5003data {
/*********************************************************************************************/
boolean PmsReadData(void)
bool PmsReadData(void)
{
if (! PmsSerial->available()) {
return false;
@ -128,7 +128,7 @@ const char HTTP_PMS5003_SNS[] PROGMEM = "%s"
"{s}PMS5003 " D_PARTICALS_BEYOND " 10 " D_UNIT_MICROMETER "{m}%d " D_UNIT_PARTS_PER_DECILITER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void PmsShow(boolean json)
void PmsShow(bool json)
{
if (pms_valid) {
if (json) {
@ -158,9 +158,9 @@ void PmsShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns18(byte function)
bool Xsns18(uint8_t function)
{
boolean result = false;
bool result = false;
if (pms_type) {
switch (function) {

View File

@ -38,7 +38,7 @@ void MGSInit(void) {
gas.begin(MGS_SENSOR_ADDR);
}
boolean MGSPrepare(void)
bool MGSPrepare(void)
{
gas.begin(MGS_SENSOR_ADDR);
if (!gas.isError()) {
@ -61,7 +61,7 @@ char* measure_gas(int gas_type, char* buffer)
const char HTTP_MGS_GAS[] PROGMEM = "%s{s}MGS %s{m}%s " D_UNIT_PARTS_PER_MILLION "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void MGSShow(boolean json)
void MGSShow(bool json)
{
char buffer[33];
if (json) {
@ -91,9 +91,9 @@ void MGSShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns19(byte function)
bool Xsns19(uint8_t function)
{
boolean result = false;
bool result = false;
static int detected = false;
if (i2c_flg) {

View File

@ -21,7 +21,7 @@
/*********************************************************************************************\
* Nova Fitness SDS011 (and possibly SDS021) particle concentration sensor
* For background information see http://aqicn.org/sensor/sds011/
* For protocol specification see
* For protocol specification see
* https://cdn.sparkfun.com/assets/parts/1/2/2/7/5/Laser_Dust_Sensor_Control_Protocol_V1.3.pdf
*
* Hardware Serial will be selected if GPIO3 = [SDS0X01]
@ -74,12 +74,12 @@ struct sds011data {
#define NOVA_SDS_SLEEP 1 // Subcmnd "sleep mode"
bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensorid, byte *buffer)
bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensorid, uint8_t *buffer)
{
uint8_t novasds_cmnd[19] = {0xAA, 0xB4, byte1, byte2, byte3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (uint8_t)(sensorid & 0xFF), (uint8_t)((sensorid>>8) & 0xFF), 0x00, 0xAB};
// calc crc
for (byte i = 2; i < 17; i++) {
for (uint8_t i = 2; i < 17; i++) {
novasds_cmnd[17] += novasds_cmnd[i];
}
//~ snprintf_P(log_data, sizeof(log_data), PSTR("SDS: Send %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X"),
@ -97,7 +97,7 @@ bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensor
// timeout
return false;
}
byte recbuf[10];
uint8_t recbuf[10];
memset(recbuf, 0, sizeof(recbuf));
// sync to 0xAA header
while ( (TimePassedSince(cmndtime) < NOVA_SDS_RECDATA_TIMEOUT) && ( NovaSdsSerial->available() > 0) && (0xAA != (recbuf[0] = NovaSdsSerial->read())) );
@ -134,7 +134,7 @@ void NovaSdsSetWorkPeriod(void)
bool NovaSdsReadData(void)
{
byte d[10];
uint8_t d[10];
if ( ! NovaSdsCommand(NOVA_SDS_QUERY_DATA, 0, 0, NOVA_SDS_DEVICE_ID, d) ) {
return false;
}
@ -186,7 +186,7 @@ const char HTTP_SDS0X1_SNS[] PROGMEM = "%s"
"{s}SDS0X1 " D_ENVIRONMENTAL_CONCENTRATION " 10 " D_UNIT_MICROMETER "{m}%s " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void NovaSdsShow(boolean json)
void NovaSdsShow(bool json)
{
if (novasds_valid) {
float pm10f = (float)(novasds_data.pm100) / 10.0f;
@ -215,9 +215,9 @@ void NovaSdsShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns20(byte function)
bool Xsns20(uint8_t function)
{
boolean result = false;
bool result = false;
if (novasds_type) {
switch (function) {

View File

@ -70,7 +70,7 @@ const char HTTP_SNS_SGP30[] PROGMEM = "%s"
"{s}SGP30 " D_ECO2 "{m}%d " D_UNIT_PARTS_PER_MILLION "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}SGP30 " D_TVOC "{m}%d " D_UNIT_PARTS_PER_BILLION "{e}";
void Sgp30Show(boolean json)
void Sgp30Show(bool json)
{
if (sgp30_ready) {
if (json) {
@ -90,9 +90,9 @@ void Sgp30Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns21(byte function)
bool Xsns21(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -46,7 +46,7 @@ const char HTTP_SNS_DISTANCE[] PROGMEM =
"%s{s}SR04 " D_DISTANCE "{m}%s" D_UNIT_CENTIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void Sr04Show(boolean json)
void Sr04Show(bool json)
{
distance = (real64_t)(sonar->ping_median(5))/ US_ROUNDTRIP_CM;
@ -75,9 +75,9 @@ void Sr04Show(boolean json)
#define XSNS_22
boolean Xsns22(byte function)
bool Xsns22(uint8_t function)
{
boolean result = false;
bool result = false;
if ((pin[GPIO_SR04_ECHO] < 99) && (pin[GPIO_SR04_TRIG] < 99)) {
switch (function) {

View File

@ -281,7 +281,7 @@ const char HTTP_SNS_SDM120_DATA[] PROGMEM = "%s"
;
#endif // USE_WEBSERVER
void SDM120Show(boolean json)
void SDM120Show(bool json)
{
char voltage[33];
dtostrfd(sdm120_voltage, Settings.flag2.voltage_resolution, voltage);
@ -343,9 +343,9 @@ void SDM120Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns23(byte function)
bool Xsns23(uint8_t function)
{
boolean result = false;
bool result = false;
if (sdm120_type) {
switch (function) {

View File

@ -276,7 +276,7 @@ void Si1145DeInit(void)
Si1145WriteByte(SI114X_COMMAND, SI114X_PSALS_AUTO);
}
boolean Si1145Begin(void)
bool Si1145Begin(void)
{
if (!Si1145Present()) { return false; }
@ -323,14 +323,14 @@ const char HTTP_SNS_SI1145[] PROGMEM = "%s"
"{s}SI1145 " D_UV_INDEX "{m}%d.%d{e}";
#endif // USE_WEBSERVER
void Si1145Show(boolean json)
void Si1145Show(bool json)
{
if (si1145_type && Si1145Present()) {
uint16_t visible = Si1145ReadVisible();
uint16_t infrared = Si1145ReadIR();
uint16_t uvindex = Si1145ReadUV();
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SI1145\":{\"" D_JSON_ILLUMINANCE "\":%d,\"" D_JSON_INFRARED "\":%d,\"" D_JSON_UVINDEX "\":%d.%d}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SI1145\":{\"" D_JSON_ILLUMINANCE "\":%d,\"" D_JSON_INFRARED "\":%d,\"" D_JSON_UV_INDEX "\":%d.%d}"),
mqtt_data, visible, infrared, uvindex /100, uvindex %100);
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, visible);
@ -349,9 +349,9 @@ void Si1145Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns24(byte function)
bool Xsns24(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -267,7 +267,7 @@ const char HTTP_SNS_SDM630_DATA[] PROGMEM = "%s"
"{s}SDM630 " D_ENERGY_TOTAL "{m}%s " D_UNIT_KILOWATTHOUR "{e}";
#endif // USE_WEBSERVER
void SDM630Show(boolean json)
void SDM630Show(bool json)
{
char voltage_l1[33];
dtostrfd(sdm630_voltage[0], Settings.flag2.voltage_resolution, voltage_l1);
@ -326,9 +326,9 @@ void SDM630Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns25(byte function)
bool Xsns25(uint8_t function)
{
boolean result = false;
bool result = false;
if (sdm630_type) {
switch (function) {

View File

@ -53,7 +53,7 @@ void LM75ADDetect(void)
if (lm75ad_type) { return; }
uint16_t buffer;
for (byte i = 0; i < sizeof(lm75ad_addresses); i++) {
for (uint8_t i = 0; i < sizeof(lm75ad_addresses); i++) {
lm75ad_address = lm75ad_addresses[i];
if (I2cValidRead16(&buffer, lm75ad_address, LM75_THYST_REGISTER)) {
if (buffer == 0x4B00) {
@ -78,7 +78,7 @@ float LM75ADGetTemp(void) {
return ConvertTemp(sign * t * 0.125);
}
void LM75ADShow(boolean json)
void LM75ADShow(bool json)
{
if (lm75ad_type) {
float t = LM75ADGetTemp();
@ -102,9 +102,9 @@ void LM75ADShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns26(byte function)
bool Xsns26(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -1903,7 +1903,7 @@ bool APDS9960_detect(void)
return true;
}
boolean success = false;
bool success = false;
APDS9960type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID);
if (APDS9960type == APDS9960_CHIPID_1 || APDS9960type == APDS9960_CHIPID_2) {
@ -1935,7 +1935,7 @@ bool APDS9960_detect(void)
* Presentation
\*********************************************************************************************/
void APDS9960_show(boolean json)
void APDS9960_show(bool json)
{
if (!APDS9960type) {
return;
@ -1993,7 +1993,7 @@ void APDS9960_show(boolean json)
bool APDS9960CommandSensor(void)
{
boolean serviced = true;
bool serviced = true;
switch (XdrvMailbox.payload) {
case 0: // Off
@ -2039,9 +2039,9 @@ bool APDS9960CommandSensor(void)
* Interface
\*********************************************************************************************/
boolean Xsns27(byte function)
bool Xsns27(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
if (FUNC_INIT == function) {

View File

@ -46,7 +46,7 @@ uint8_t tm1638_state = 0;
* and from library https://github.com/MartyMacGyver/TM1638-demos-and-examples
\*********************************************************************************************/
void Tm16XXSend(byte data)
void Tm16XXSend(uint8_t data)
{
for (uint8_t i = 0; i < 8; i++) {
digitalWrite(tm1638_data_pin, !!(data & (1 << i)));
@ -56,14 +56,14 @@ void Tm16XXSend(byte data)
}
}
void Tm16XXSendCommand(byte cmd)
void Tm16XXSendCommand(uint8_t cmd)
{
digitalWrite(tm1638_strobe_pin, LOW);
Tm16XXSend(cmd);
digitalWrite(tm1638_strobe_pin, HIGH);
}
void TM16XXSendData(byte address, byte data)
void TM16XXSendData(uint8_t address, uint8_t data)
{
Tm16XXSendCommand(0x44);
digitalWrite(tm1638_strobe_pin, LOW);
@ -72,9 +72,9 @@ void TM16XXSendData(byte address, byte data)
digitalWrite(tm1638_strobe_pin, HIGH);
}
byte Tm16XXReceive(void)
uint8_t Tm16XXReceive(void)
{
byte temp = 0;
uint8_t temp = 0;
// Pull-up on
pinMode(tm1638_data_pin, INPUT);
@ -103,7 +103,7 @@ void Tm16XXClearDisplay(void)
}
}
void Tm1638SetLED(byte color, byte pos)
void Tm1638SetLED(uint8_t color, uint8_t pos)
{
TM16XXSendData((pos << 1) + 1, color);
}
@ -111,7 +111,7 @@ void Tm1638SetLED(byte color, byte pos)
void Tm1638SetLEDs(word leds)
{
for (int i = 0; i < tm1638_displays; i++) {
byte color = 0;
uint8_t color = 0;
if ((leds & (1 << i)) != 0) {
color |= TM1638_COLOR_RED;
@ -125,9 +125,9 @@ void Tm1638SetLEDs(word leds)
}
}
byte Tm1638GetButtons(void)
uint8_t Tm1638GetButtons(void)
{
byte keys = 0;
uint8_t keys = 0;
digitalWrite(tm1638_strobe_pin, LOW);
Tm16XXSend(0x42);
@ -174,10 +174,10 @@ void TmInit(void)
void TmLoop(void)
{
if (tm1638_state) {
byte buttons = Tm1638GetButtons();
for (byte i = 0; i < MAX_SWITCHES; i++) {
uint8_t buttons = Tm1638GetButtons();
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
SwitchSetVirtual(i, (buttons &1) ^1);
byte color = (SwitchGetVirtual(i)) ? TM1638_COLOR_NONE : TM1638_COLOR_RED;
uint8_t color = (SwitchGetVirtual(i)) ? TM1638_COLOR_NONE : TM1638_COLOR_RED;
Tm1638SetLED(color, i);
buttons >>= 1;
}
@ -186,7 +186,7 @@ void TmLoop(void)
}
/*
void TmShow(boolean json)
void TmShow(bool json)
{
if (tm1638_type) {
@ -198,9 +198,9 @@ void TmShow(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns28(byte function)
bool Xsns28(uint8_t function)
{
boolean result = false;
bool result = false;
if (tm1638_type) {
switch (function) {

View File

@ -325,7 +325,7 @@ void MCP230xx_CheckForInterrupt(void) {
}
}
void MCP230xx_Show(boolean json)
void MCP230xx_Show(bool json)
{
if (mcp230xx_type) {
if (json) {
@ -426,8 +426,8 @@ void MCP230xx_Reset(uint8_t pinmode) {
}
bool MCP230xx_Command(void) {
boolean serviced = true;
boolean validpin = false;
bool serviced = true;
bool validpin = false;
uint8_t paramcount = 0;
if (XdrvMailbox.data_len > 0) {
paramcount=1;
@ -781,9 +781,9 @@ void MCP230xx_Interrupt_Retain_Report(void) {
Interface
\*********************************************************************************************/
boolean Xsns29(byte function)
bool Xsns29(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -318,7 +318,7 @@ void Mpr121Init(struct mpr121 *pS)
* @post None.
*
*/
void Mpr121Show(struct mpr121 *pS, byte function)
void Mpr121Show(struct mpr121 *pS, uint8_t function)
{
// Loop through sensors
@ -384,7 +384,7 @@ void Mpr121Show(struct mpr121 *pS, byte function)
}
} // if->running
} // for-loop i
} // void Mpr121Show(byte function)
} // void Mpr121Show(uint8_t function)
/*********************************************************************************************\
* Interface
@ -400,15 +400,15 @@ void Mpr121Show(struct mpr121 *pS, byte function)
* FUNC_WEB_APPEND for displaying data in the Tasmota web-interface
*
* @param byte function Tasmota function ID.
* @return boolean ???
* @return bool ???
* @pre None.
* @post None.
*
*/
boolean Xsns30(byte function)
bool Xsns30(uint8_t function)
{
// ???
boolean result = false;
bool result = false;
// Sensor state/data struct
static struct mpr121 mpr121;
@ -440,7 +440,7 @@ boolean Xsns30(byte function)
#endif // USE_WEBSERVER
}
}
// Return boolean result
// Return bool result
return result;
}

View File

@ -83,7 +83,7 @@ const char HTTP_SNS_CCS811[] PROGMEM = "%s"
"{s}CCS811 " D_ECO2 "{m}%d " D_UNIT_PARTS_PER_MILLION "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}CCS811 " D_TVOC "{m}%d " D_UNIT_PARTS_PER_BILLION "{e}";
void CCS811Show(boolean json)
void CCS811Show(bool json)
{
if (CCS811_ready) {
if (json) {
@ -103,9 +103,9 @@ void CCS811Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns31(byte function)
bool Xsns31(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -120,7 +120,7 @@ void MPU_6050Detect(void)
return;
}
for (byte i = 0; i < sizeof(MPU_6050_addresses); i++)
for (uint8_t i = 0; i < sizeof(MPU_6050_addresses); i++)
{
if(!I2cDevice(MPU_6050_addresses[i]))
{
@ -171,7 +171,7 @@ const char HTTP_SNS_GZ_AXIS[] PROGMEM = "%s{s}%s " D_GZ_AXIS "{m}%s{e}";
#define D_JSON_AXIS_GY "GyroYAxis"
#define D_JSON_AXIS_GZ "GyroZAxis"
void MPU_6050Show(boolean json)
void MPU_6050Show(bool json)
{
if (MPU_6050_found) {
MPU_6050PerformReading();
@ -228,9 +228,9 @@ void MPU_6050Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns32(byte function)
bool Xsns32(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {

View File

@ -62,9 +62,9 @@
#define HR1224 6 //Hours register 12 or 24 hour mode (24 hour mode==0)
#define CENTURY 7 //Century bit in Month register
#define DYDT 6 //Day/Date flag bit in alarm Day/Date registers
boolean ds3231ReadStatus = false;
boolean ds3231WriteStatus = false; //flag, we want to wriet/write to DS3231 onlu once
boolean DS3231chipDetected = false;
bool ds3231ReadStatus = false;
bool ds3231WriteStatus = false; //flag, we want to wriet/write to DS3231 onlu once
bool DS3231chipDetected = false;
/*----------------------------------------------------------------------*
Detect the DS3231 Chip
@ -132,9 +132,9 @@ void SetDS3231Time (uint32_t epoch_time) {
Interface
\*********************************************************************************************/
boolean Xsns33(byte function)
bool Xsns33(uint8_t function)
{
boolean result = false;
bool result = false;
if (i2c_flg) {
switch (function) {
@ -144,7 +144,7 @@ boolean Xsns33(byte function)
case FUNC_EVERY_SECOND:
TIME_T tmpTime;
if (!ds3231ReadStatus && DS3231chipDetected && utc_time < 1451602800 ) { // We still did not sync with NTP (time not valid) , so, read time from DS3231
ntp_force_sync = 1; //force to sync with ntp
ntp_force_sync = true; //force to sync with ntp
utc_time = ReadFromDS3231(); //we read UTC TIME from DS3231
// from this line, we just copy the function from "void RtcSecond()" at the support.ino ,line 2143 and above
// We need it to set rules etc.

View File

@ -67,12 +67,12 @@ long hx_offset = 0;
long hx_scale = 1;
uint8_t hx_type = 1;
uint8_t hx_sample_count = 0;
uint8_t hx_tare_flg = 0;
uint8_t hx_calibrate_step = HX_CAL_END;
uint8_t hx_calibrate_timer = 0;
uint8_t hx_calibrate_msg = 0;
uint8_t hx_pin_sck;
uint8_t hx_pin_dout;
bool hx_tare_flg = false;
/*********************************************************************************************/
@ -118,7 +118,7 @@ long HxRead()
void HxReset(void)
{
hx_tare_flg = 1;
hx_tare_flg = true;
hx_sum_weight = 0;
hx_sample_count = 0;
}
@ -155,7 +155,7 @@ bool HxCommand(void)
bool show_parms = false;
char sub_string[XdrvMailbox.data_len +1];
for (byte ca = 0; ca < XdrvMailbox.data_len; ca++) {
for (uint8_t ca = 0; ca < XdrvMailbox.data_len; ca++) {
if ((' ' == XdrvMailbox.data[ca]) || ('=' == XdrvMailbox.data[ca])) { XdrvMailbox.data[ca] = ','; }
}
@ -257,7 +257,7 @@ void HxEvery100mSecond(void)
if (hx_weight < 0) { hx_weight = 0; }
if (hx_tare_flg) {
hx_tare_flg = 0;
hx_tare_flg = false;
hx_offset = average; // grams
}
@ -301,7 +301,7 @@ void HxEvery100mSecond(void)
if (HX_CAL_FAIL == hx_calibrate_step) { // Calibration failed
hx_calibrate_step--;
hx_tare_flg = 1; // Perform a reset using old scale
hx_tare_flg = true; // Perform a reset using old scale
HxCalibrationStateTextJson(0);
}
if (HX_CAL_FINISH == hx_calibrate_step) { // Calibration finished
@ -329,7 +329,7 @@ const char HTTP_HX711_CAL[] PROGMEM = "%s"
"{s}HX711 %s{m}{e}";
#endif // USE_WEBSERVER
void HxShow(boolean json)
void HxShow(bool json)
{
char scount[30] = { 0 };
@ -469,9 +469,9 @@ void HxLogUpdates(void)
* Interface
\*********************************************************************************************/
boolean Xsns34(byte function)
bool Xsns34(uint8_t function)
{
boolean result = false;
bool result = false;
if (hx_type) {
switch (function) {

View File

@ -78,7 +78,7 @@ float tx20_wind_sum = 0;
int tx20_count = 0;
uint8_t tx20_wind_direction = 0;
boolean tx20_available = false;
bool tx20_available = false;
void Tx20StartRead(void)
{
@ -170,7 +170,7 @@ void Tx20Init(void) {
attachInterrupt(pin[GPIO_TX20_TXD_BLACK], Tx20StartRead, RISING);
}
void Tx20Show(boolean json)
void Tx20Show(bool json)
{
char wind_speed_string[33];
dtostrfd(tx20_wind_speed_kmh, 2, wind_speed_string);
@ -195,9 +195,9 @@ void Tx20Show(boolean json)
* Interface
\*********************************************************************************************/
boolean Xsns35(byte function)
bool Xsns35(uint8_t function)
{
boolean result = false;
bool result = false;
if (pin[GPIO_TX20_TXD_BLACK] < 99) {
switch (function) {

Some files were not shown because too many files have changed in this diff Show More