cleancode changes from cppcheck and cpplint

This commit is contained in:
Paul
2019-10-09 13:55:50 +02:00
parent fb1527eee1
commit d51e61fd1f
6 changed files with 18 additions and 42 deletions

View File

@@ -1228,7 +1228,7 @@ void MyESP::showSystemStats() {
} }
if (_ntp_enabled) { if (_ntp_enabled) {
myDebug_P(PSTR(" [NTP] Time in UTC is %02d:%02d:%02d"), hour(now()), minute(now()), second(now())); myDebug_P(PSTR(" [NTP] Time in UTC is %02d:%02d:%02d"), to_hour(now()), to_minute(now()), to_second(now()));
} }
#ifdef CRASH #ifdef CRASH
@@ -1590,12 +1590,11 @@ bool MyESP::_fs_validateLogFile(const char * filename) {
uint16_t char_count = 0; uint16_t char_count = 0;
bool abort = false; bool abort = false;
char char_buffer[MYESP_JSON_LOG_MAXSIZE]; char char_buffer[MYESP_JSON_LOG_MAXSIZE];
char c;
StaticJsonDocument<MYESP_JSON_LOG_MAXSIZE> doc; StaticJsonDocument<MYESP_JSON_LOG_MAXSIZE> doc;
// eventlog.seek(0); // eventlog.seek(0);
while (eventlog.available() && !abort) { while (eventlog.available() && !abort) {
c = eventlog.read(); // read a char char c = eventlog.read(); // read a char
// see if we have reached the end of the string // see if we have reached the end of the string
if (c == '\0' || c == '\n') { if (c == '\0' || c == '\n') {
@@ -1700,7 +1699,7 @@ bool MyESP::_fs_loadConfig() {
// returns true if successful // returns true if successful
bool MyESP::fs_setSettingValue(char ** setting, const char * value, const char * value_default) { bool MyESP::fs_setSettingValue(char ** setting, const char * value, const char * value_default) {
if (*setting == nullptr) { if (*setting == nullptr) {
free(setting); // first free any allocated memory free(*setting); // first free any allocated memory
} }
if (_hasValue(value)) { if (_hasValue(value)) {
@@ -2244,12 +2243,11 @@ void MyESP::_sendEventLog(uint8_t page) {
uint8_t line_count = 0; uint8_t line_count = 0;
bool abort = false; bool abort = false;
char char_buffer[MYESP_JSON_LOG_MAXSIZE]; char char_buffer[MYESP_JSON_LOG_MAXSIZE];
char c;
float pages; float pages;
// start at top and read until we find the page we want (sets of 10) // start at top and read until we find the page we want (sets of 10)
while (eventlog.available() && !abort) { while (eventlog.available() && !abort) {
c = eventlog.read(); char c = eventlog.read();
// see if we have reached the end of the string // see if we have reached the end of the string
if (c == '\0' || c == '\n') { if (c == '\0' || c == '\n') {

View File

@@ -242,9 +242,8 @@ size_t TelnetSpy::write(uint8_t data) {
sendBlock(); sendBlock();
} }
if (bufUsed == bufLen) { if (bufUsed == bufLen) {
char c;
while (bufUsed > 0) { while (bufUsed > 0) {
c = pullTelnetBuf(); char c = pullTelnetBuf();
if (c == '\n') { if (c == '\n') {
addTelnetBuf('\r'); addTelnetBuf('\r');
break; break;
@@ -573,7 +572,7 @@ void TelnetSpy::handle() {
return; return;
} }
if (!listening) { if (!listening) {
if ((WiFi.status() == WL_DISCONNECTED) && (WiFi.getMode() & WIFI_AP)) { if ((WiFi.status() == WL_DISCONNECTED) && (WiFi.getMode() & WIFI_AP)) {
if (usedSer) { if (usedSer) {
usedSer->println("[TELNET] in AP mode"); // added by Proddy usedSer->println("[TELNET] in AP mode"); // added by Proddy
} }

View File

@@ -73,7 +73,6 @@ void breakTime(time_t timeInput, tmElements_t & tm) {
days -= LEAP_YEAR(year) ? 366 : 365; days -= LEAP_YEAR(year) ? 366 : 365;
time -= days; // now it is days in this year, starting at 0 time -= days; // now it is days in this year, starting at 0
days = 0;
month = 0; month = 0;
monthLength = 0; monthLength = 0;
for (month = 0; month < 12; month++) { for (month = 0; month < 12; month++) {
@@ -104,36 +103,21 @@ void refreshCache(time_t t) {
} }
} }
int day(time_t t) { // the day for the given time (0-6) uint8_t to_second(time_t t) { // the second for the given time
refreshCache(t);
return tm.Day;
}
int month(time_t t) { // the month for the given time
refreshCache(t);
return tm.Month;
}
int second(time_t t) { // the second for the given time
refreshCache(t); refreshCache(t);
return tm.Second; return tm.Second;
} }
int minute(time_t t) { // the minute for the given time uint8_t to_minute(time_t t) { // the minute for the given time
refreshCache(t); refreshCache(t);
return tm.Minute; return tm.Minute;
} }
int hour(time_t t) { // the hour for the given time uint8_t to_hour(time_t t) { // the hour for the given time
refreshCache(t); refreshCache(t);
return tm.Hour; return tm.Hour;
} }
int year(time_t t) { // the year for the given time
refreshCache(t);
return tmYearToCalendar(tm.Year);
}
void setTime(time_t t) { void setTime(time_t t) {
sysTime = (uint32_t)t; sysTime = (uint32_t)t;
nextSyncTime = (uint32_t)t + syncInterval; nextSyncTime = (uint32_t)t + syncInterval;

View File

@@ -1,5 +1,5 @@
#ifndef _Time_h #ifndef _TimeLib_h
#define _Time_h #define _TimeLib_h
#include <Arduino.h> #include <Arduino.h>
@@ -27,7 +27,7 @@ typedef struct {
uint8_t Day; uint8_t Day;
uint8_t Month; uint8_t Month;
uint8_t Year; // offset from 1970; uint8_t Year; // offset from 1970;
} tmElements_t, TimeElements, *tmElementsPtr_t; } tmElements_t;
typedef time_t (*getExternalTime)(); typedef time_t (*getExternalTime)();
@@ -38,12 +38,8 @@ void setSyncProvider(getExternalTime getTimeFunction); // identify the e
void setSyncInterval(time_t interval); // set the number of seconds between re-sync void setSyncInterval(time_t interval); // set the number of seconds between re-sync
time_t makeTime(const tmElements_t & tm); // convert time elements into time_t time_t makeTime(const tmElements_t & tm); // convert time elements into time_t
int hour(time_t t); // the hour for the given time uint8_t to_hour(time_t t); // the hour for the given time
int minute(time_t t); // the minute for the given time uint8_t to_minute(time_t t); // the minute for the given time
int second(time_t t); // the second for the given time uint8_t to_second(time_t t); // the second for the given time
int day(time_t t); // the day for the given time
int month(time_t t); // the month for the given time
int weekday(time_t t); // the weekday for the given time
int year(time_t t); // the year for the given time
} }
#endif #endif

View File

@@ -97,8 +97,6 @@ void DS18::loop() {
char * DS18::getDeviceString(char * buffer, unsigned char index) { char * DS18::getDeviceString(char * buffer, unsigned char index) {
uint8_t size = 128; uint8_t size = 128;
if (index < _count) { if (index < _count) {
uint8_t * address = _devices[index].address;
unsigned char chip_id = chip(index); unsigned char chip_id = chip(index);
if (chip_id == DS18_CHIP_DS18S20) { if (chip_id == DS18_CHIP_DS18S20) {
strlcpy(buffer, "DS18S20", size); strlcpy(buffer, "DS18S20", size);
@@ -112,7 +110,8 @@ char * DS18::getDeviceString(char * buffer, unsigned char index) {
strlcpy(buffer, "Unknown", size); strlcpy(buffer, "Unknown", size);
} }
/* /*
uint8_t * address = _devices[index].address;
char a[30] = {0}; char a[30] = {0};
snprintf(a, snprintf(a,
sizeof(a), sizeof(a),

View File

@@ -220,7 +220,7 @@ _EMS_TX_STATUS ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
USF(EMSUART_UART) = buf[i]; USF(EMSUART_UART) = buf[i];
delayMicroseconds(EMSUART_TX_BRK_WAIT); // https://github.com/proddy/EMS-ESP/issues/23# delayMicroseconds(EMSUART_TX_BRK_WAIT); // https://github.com/proddy/EMS-ESP/issues/23#
} }
emsuart_tx_brk(); // send <BRK> emsuart_tx_brk(); // send <BRK>
} else if (EMS_Sys_Status.emsTxMode == EMS_TXMODE_HT3) { // Junkers logic by @philrich } else if (EMS_Sys_Status.emsTxMode == EMS_TXMODE_HT3) { // Junkers logic by @philrich
for (uint8_t i = 0; i < len; i++) { for (uint8_t i = 0; i < len; i++) {
TX_PULSE(EMSUART_BIT_TIME / 4); TX_PULSE(EMSUART_BIT_TIME / 4);