From c46d726f21e844ab578d771f05677ea1835493e3 Mon Sep 17 00:00:00 2001 From: TD-er Date: Mon, 14 Sep 2026 14:44:11 +0200 Subject: [PATCH] [Build] Change 'long' to 'int32_t' and fix some signed/unsigned issues --- src/_C002.cpp | 2 +- src/src/Helpers/Dallas1WireHelper.cpp | 14 ++++++------ src/src/Helpers/Dallas1WireHelper.h | 4 ++-- src/src/Helpers/ESPEasy_time_calc.h | 24 +++++++++++++-------- src/src/Helpers/Scheduler_IntervalTimer.cpp | 6 +++--- src/src/Helpers/Scheduler_RulesTimer.cpp | 2 +- src/src/Helpers/_CPlugin_DomoticzHelper.cpp | 6 +++--- src/src/Helpers/_CPlugin_DomoticzHelper.h | 2 +- src/src/Helpers/msecTimerHandlerStruct.cpp | 8 +++---- src/src/PluginStructs/P014_data_struct.cpp | 4 ++-- src/src/PluginStructs/P025_data_struct.cpp | 8 +++---- src/src/PluginStructs/P025_data_struct.h | 2 +- src/src/PluginStructs/P049_data_struct.cpp | 2 +- src/src/PluginStructs/P077_data_struct.cpp | 19 ++++++++-------- src/src/PluginStructs/P077_data_struct.h | 14 ++++++------ src/src/PluginStructs/P082_data_struct.cpp | 2 +- src/src/PluginStructs/P082_data_struct.h | 2 +- src/src/PluginStructs/P090_data_struct.cpp | 2 +- src/src/PluginStructs/P092_data_struct.cpp | 2 +- src/src/PluginStructs/P098_data_struct.cpp | 2 +- src/src/PluginStructs/P111_data_struct.cpp | 1 + src/src/PluginStructs/P118_data_struct.cpp | 2 +- src/src/PluginStructs/P128_data_struct.cpp | 4 ++-- src/src/PluginStructs/P145_data_struct.cpp | 4 ++-- src/src/PluginStructs/P147_data_struct.cpp | 2 +- src/src/PluginStructs/P147_data_struct.h | 2 +- src/src/PluginStructs/P165_data_struct.h | 2 +- src/src/PluginStructs/P169_data_struct.cpp | 4 ++-- 28 files changed, 79 insertions(+), 69 deletions(-) diff --git a/src/_C002.cpp b/src/_C002.cpp index e2fa84d88..4359a3eff 100644 --- a/src/_C002.cpp +++ b/src/_C002.cpp @@ -85,7 +85,7 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String& if (validControllerIndex(ControllerID)) { unsigned int idx; float nvalue; - long nvaluealt; + int32_t nvaluealt; String svalue1, switchtype; if (deserializeDomoticzJson(event->String2, idx, nvalue, nvaluealt, svalue1, switchtype)) { diff --git a/src/src/Helpers/Dallas1WireHelper.cpp b/src/src/Helpers/Dallas1WireHelper.cpp index ed9d86ba1..60bc9652f 100644 --- a/src/src/Helpers/Dallas1WireHelper.cpp +++ b/src/src/Helpers/Dallas1WireHelper.cpp @@ -382,7 +382,7 @@ void Dallas_plugin_set_addr(uint8_t addr[], taskIndex_t TaskIndex, uint8_t var_i uint32_t value = (uint32_t)ExtraTaskSettings.TaskDevicePluginConfigLong[x]; value &= mask; value += (static_cast(addr[x]) << (var_index * 8)); - ExtraTaskSettings.TaskDevicePluginConfigLong[x] = (long)value; + ExtraTaskSettings.TaskDevicePluginConfigLong[x] = (int32_t)value; } Cache.updateExtraTaskSettingsCache(); } @@ -771,7 +771,7 @@ bool Dallas_setResolution(const uint8_t ROM[8], uint8_t res, int8_t gpio_pin_rx, // save the newly written values to eeprom Dallas_write(0x48, gpio_pin_rx, gpio_pin_tx); - delay(100); // <--- added 20ms delay to allow 10ms long EEPROM write operation (as specified by datasheet) + delay(100); // <--- added 20ms delay to allow 10ms int32_t EEPROM write operation (as specified by datasheet) Dallas_reset(gpio_pin_rx, gpio_pin_tx); return true; // new value set @@ -860,7 +860,7 @@ uint8_t Dallas_reset(int8_t gpio_pin_rx, int8_t gpio_pin_tx) // t_PDL 60 ... 240 usec // Signal will rise only due to pull-up resistor - // Meaning measured duration may be off by usec_release (too long) + // Meaning measured duration may be off by usec_release (too int32_t) presence_end = Dallas_measureWaitForPinHigh(gpio_pin_rx, start, 60 + 240); // Set the pin high, just in case we have a (single) parasitic powered sensor @@ -1174,8 +1174,8 @@ void Dallas_write_bit(uint8_t v, int8_t gpio_pin_rx, int8_t gpio_pin_tx) // write 1: low 6 usec, high 64 usec (no less than 6 usec low, or else scanning will no longer work) // write 0: low 60 usec, high 20 usec // High time is based on the recovery time, which is detected during reset - const long low_time = (v & 1) ? 7 : 60; - const long high_time = (v & 1) ? (40 + usec_release) : (2 * usec_release + 20); // Recovery time + const int32_t low_time = (v & 1) ? 7 : 60; + const int32_t high_time = (v & 1) ? (40 + usec_release) : (2 * usec_release + 20); // Recovery time uint32_t start = 0; Dallas_write_bit_ISR(v, gpio_pin_rx, gpio_pin_tx, low_time, high_time, start); @@ -1191,8 +1191,8 @@ void Dallas_write_bit(uint8_t v, int8_t gpio_pin_rx, int8_t gpio_pin_tx) void DALLAS_IRAM_ATTR Dallas_write_bit_ISR(uint8_t v, int8_t gpio_pin_rx, int8_t gpio_pin_tx, - long low_time, - long high_time, + int32_t low_time, + int32_t high_time, uint32_t& start) { ISR_noInterrupts(); diff --git a/src/src/Helpers/Dallas1WireHelper.h b/src/src/Helpers/Dallas1WireHelper.h index cf3d81459..308c9c226 100644 --- a/src/src/Helpers/Dallas1WireHelper.h +++ b/src/src/Helpers/Dallas1WireHelper.h @@ -239,8 +239,8 @@ void Dallas_write_bit(uint8_t v, void Dallas_write_bit_ISR(uint8_t v, int8_t gpio_pin_rx, int8_t gpio_pin_tx, - long low_time, - long high_time, + int32_t low_time, + int32_t high_time, uint32_t& start); /*********************************************************************************************\ diff --git a/src/src/Helpers/ESPEasy_time_calc.h b/src/src/Helpers/ESPEasy_time_calc.h index 4e916f9a6..12a61c2fe 100644 --- a/src/src/Helpers/ESPEasy_time_calc.h +++ b/src/src/Helpers/ESPEasy_time_calc.h @@ -21,49 +21,55 @@ inline uint64_t getMicros64() { // Returned timediff for millis() is between -24.9 days and +24.9 days. // for micros() is between -35.79 and +35.79 minutes // Returned value is positive when "next" is after "prev" -inline int32_t timeDiff(const uint32_t prev, const uint32_t next) { +inline int32_t timeDiff(const uint32_t& prev, const uint32_t& next) { return ((int32_t) (next - prev)); } -inline int64_t timeDiff64(uint64_t prev, uint64_t next) { +inline int64_t timeDiff64(const uint64_t& prev, const uint64_t& next) { return ((int64_t) (next - prev)); } // Compute the number of milliSeconds passed since timestamp given. // N.B. value can be negative if the timestamp has not yet been reached. -inline long timePassedSince(const uint32_t& timestamp) { +inline int32_t timePassedSince(const uint32_t& timestamp) { return timeDiff(timestamp, millis()); } // Long term usec calculations -inline int64_t usecPassedSince(ESPEASY_VOLATILE(uint64_t)& timestamp) { - return timeDiff64(timestamp, getMicros64()); +inline int64_t usecPassedSince_volatile(ESPEASY_VOLATILE(uint64_t)& timestamp) { + const uint64_t timestamp_tmp(timestamp); + return timeDiff64(timestamp_tmp, getMicros64()); } inline int64_t usecPassedSince(const uint64_t& timestamp) { return timeDiff64(timestamp, getMicros64()); } +/* inline int64_t usecPassedSince(uint64_t& timestamp) { //-V669 return timeDiff64(timestamp, getMicros64()); } + */ // Fast short-term usec calculations -inline int32_t usecPassedSince_fast(ESPEASY_VOLATILE(uint32_t)& timestamp) { - return timeDiff(timestamp, micros()); + +inline int32_t usecPassedSince_fast_volatile(ESPEASY_VOLATILE(uint32_t)& timestamp) { + const uint32_t timestamp_tmp(timestamp); + return timeDiff(timestamp_tmp, micros()); } inline int32_t usecPassedSince_fast(const uint32_t& timestamp) { return timeDiff(timestamp, micros()); } - +/* inline int32_t usecPassedSince_fast(uint32_t& timestamp) { //-V669 return timeDiff(timestamp, micros()); } + */ // Check if a certain timeout has been reached. -inline bool timeOutReached(uint32_t timer) { +inline bool timeOutReached(const uint32_t& timer) { return timePassedSince(timer) >= 0; } diff --git a/src/src/Helpers/Scheduler_IntervalTimer.cpp b/src/src/Helpers/Scheduler_IntervalTimer.cpp index d4ee12e72..0ff4790e5 100644 --- a/src/src/Helpers/Scheduler_IntervalTimer.cpp +++ b/src/src/Helpers/Scheduler_IntervalTimer.cpp @@ -26,7 +26,7 @@ // For those it is more important to actually run it than keeping pace. void ESPEasy_Scheduler::setNextTimeInterval(uint32_t& timer, const uint32_t step) { timer += step; - const long passed = timePassedSince(timer); + const int32_t passed = timePassedSince(timer); if (passed < 0) { // Event has not yet happened, which is fine. @@ -48,7 +48,7 @@ void ESPEasy_Scheduler::setNextTimeInterval(uint32_t& timer, const uint32_t step void ESPEasy_Scheduler::setNextStrictTimeInterval(uint32_t & timer, const uint32_t step) { timer += step; - const long passed = timePassedSince(timer); + const int32_t passed = timePassedSince(timer); if (passed <= 0) { // Event has not yet happened, which is fine. @@ -101,7 +101,7 @@ void ESPEasy_Scheduler::setIntervalTimer(SchedulerIntervalTimer_e intervalTimer, case SchedulerIntervalTimer_e::TIMER_GRATUITOUS_ARP: interval = timer_gratuitous_arp_interval; break; // Fall-through for all DelayQueue, which are just the fall-back timers. - // The timers for all delay queues will be set according to their own settings as long as there is something to process. + // The timers for all delay queues will be set according to their own settings as int32_t as there is something to process. case SchedulerIntervalTimer_e::TIMER_MQTT_DELAY_QUEUE: case SchedulerIntervalTimer_e::TIMER_C001_DELAY_QUEUE: case SchedulerIntervalTimer_e::TIMER_C002_DELAY_QUEUE: diff --git a/src/src/Helpers/Scheduler_RulesTimer.cpp b/src/src/Helpers/Scheduler_RulesTimer.cpp index 939f9af8c..972686e58 100644 --- a/src/src/Helpers/Scheduler_RulesTimer.cpp +++ b/src/src/Helpers/Scheduler_RulesTimer.cpp @@ -101,7 +101,7 @@ bool ESPEasy_Scheduler::pause_rules_timer(uint32_t timerIndex) { #endif } else { // Store remainder of interval - const long timeLeft = timePassedSince(timer) * -1; + const int32_t timeLeft = timePassedSince(timer) * -1; if (timeLeft > 0) { it->second.setRemainder(timeLeft); diff --git a/src/src/Helpers/_CPlugin_DomoticzHelper.cpp b/src/src/Helpers/_CPlugin_DomoticzHelper.cpp index 99b3a548b..7551cf902 100644 --- a/src/src/Helpers/_CPlugin_DomoticzHelper.cpp +++ b/src/src/Helpers/_CPlugin_DomoticzHelper.cpp @@ -168,7 +168,7 @@ String formatDomoticzSensorType(struct EventStruct *event) { # include bool deserializeDomoticzJson(const String& json, - unsigned int& idx, float& nvalue, long& nvaluealt, + unsigned int& idx, float& nvalue, int32_t& nvaluealt, String& svalue1, String& switchtype) { uint16_t jsonlength = 512; @@ -180,8 +180,8 @@ bool deserializeDomoticzJson(const String& json, return false; } - // Use long here as intermediate object type to prevent ArduinoJSON from adding a new template variant to the code. - const long idx_long = root[F("idx")]; + // Use int32_t here as intermediate object type to prevent ArduinoJSON from adding a new template variant to the code. + const int32_t idx_long = root[F("idx")]; idx = idx_long; nvalue = root[F("nvalue")]; diff --git a/src/src/Helpers/_CPlugin_DomoticzHelper.h b/src/src/Helpers/_CPlugin_DomoticzHelper.h index 92eb47c5a..139be6d34 100644 --- a/src/src/Helpers/_CPlugin_DomoticzHelper.h +++ b/src/src/Helpers/_CPlugin_DomoticzHelper.h @@ -26,7 +26,7 @@ String formatDomoticzSensorType(struct EventStruct *event); bool deserializeDomoticzJson(const String& json, unsigned int& idx, float & nvalue, - long & nvaluealt, + int32_t & nvaluealt, String & svalue1, String & switchtype); diff --git a/src/src/Helpers/msecTimerHandlerStruct.cpp b/src/src/Helpers/msecTimerHandlerStruct.cpp index c1c412559..53c2238c8 100644 --- a/src/src/Helpers/msecTimerHandlerStruct.cpp +++ b/src/src/Helpers/msecTimerHandlerStruct.cpp @@ -39,14 +39,14 @@ return 0; } const timer_id_couple item = _timer_ids.front(); - const long passed = timePassedSince(item._timer); + const int32_t passed = timePassedSince(item._timer); if (passed < 0) { // No timeOutReached recordIdle(); if (eco_mode) { - long waitTime = (-1 * passed) - 1; // will be non negative + int32_t waitTime = (-1 * passed) - 1; // will be non negative if (waitTime > MAX_SCHEDULER_WAIT_TIME) { waitTime = MAX_SCHEDULER_WAIT_TIME; @@ -98,7 +98,7 @@ #endif void msecTimerHandlerStruct::updateIdleTimeStats() { - const long duration = timePassedSince(last_log_start_time) * 10; + const int32_t duration = timePassedSince(last_log_start_time) * 10; if (duration <= 1000) { // No need to recompute it over a small interval // Also makes sure duration != 0 as it is used in division @@ -149,7 +149,7 @@ // Stats are just some indication, don't need to be that exact. // std::forward_list doesn't have size() // for (; stats_it != _timer_ids.end(); ++stats_it, ++size) {} - if (size > max_queue_length) { max_queue_length = size; } + if (static_cast(size) > max_queue_length) { max_queue_length = size; } #endif } diff --git a/src/src/PluginStructs/P014_data_struct.cpp b/src/src/PluginStructs/P014_data_struct.cpp index bd45b013d..46cb7ed50 100644 --- a/src/src/PluginStructs/P014_data_struct.cpp +++ b/src/src/PluginStructs/P014_data_struct.cpp @@ -516,7 +516,7 @@ bool P014_data_struct::readHumidity(uint8_t i2caddr, uint8_t resolution) // Convert raw value to Humidity percent // pm-cz: it is possible to enable decimal places for humidity as well by multiplying the value in formula by 100 - int data = ((1250 * (long)raw) >> 16) - 60; + int data = ((1250 * (int32_t)raw) >> 16) - 60; // Datasheet says doing this check if (data>1000) data = 1000; @@ -571,7 +571,7 @@ bool P014_data_struct::readTemperatureFromHumidity(uint8_t i2caddr, uint8_t reso int16_t P014_data_struct::convertRawTemperature(uint16_t raw, uint8_t resolution){ // Convert raw value to Temperature (*100) // for 23.45C value will be 2345 - int16_t data = ((17572 * (long)raw) >> 16) - 4685; + int16_t data = ((17572 * (int32_t)raw) >> 16) - 4685; // pm-cz: We should probably check for precision here as well if (resolution != SI70xx_RESOLUTION_14T_12RH) { diff --git a/src/src/PluginStructs/P025_data_struct.cpp b/src/src/PluginStructs/P025_data_struct.cpp index b7454bbbf..d3601faae 100644 --- a/src/src/PluginStructs/P025_data_struct.cpp +++ b/src/src/PluginStructs/P025_data_struct.cpp @@ -203,7 +203,7 @@ P025_sensorType P025_data_struct::detectType(uint8_t i2cAddress) (0x8000); // Start a single conversion if (startMeasurement(i2cAddress, defaultValue)) { - const long sps = waitReady025(i2cAddress); + const int32_t sps = waitReady025(i2cAddress); if (sps > 0) { // Sample rate is either 250 (ADS1115) or 2400 (ADS1015) @@ -231,7 +231,7 @@ bool P025_data_struct::startMeasurement(uint8_t i2cAddress, uint16_t configRegis return false; } -long P025_data_struct::waitReady025(uint8_t i2cAddress) +int32_t P025_data_struct::waitReady025(uint8_t i2cAddress) { const uint32_t start = micros(); uint32_t timeout = millis(); @@ -257,8 +257,8 @@ long P025_data_struct::waitReady025(uint8_t i2cAddress) const bool ready = reg.operatingStatus == 1; if (ready && is_ok) { - const long res = usecPassedSince_fast(start); - const long sps = (res > 0) ? 1000000 / res : 0; + const int32_t res = usecPassedSince_fast(start); + const int32_t sps = (res > 0) ? 1000000 / res : 0; # ifndef BUILD_NO_DEBUG if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { diff --git a/src/src/PluginStructs/P025_data_struct.h b/src/src/PluginStructs/P025_data_struct.h index 547990bab..f188f227d 100644 --- a/src/src/PluginStructs/P025_data_struct.h +++ b/src/src/PluginStructs/P025_data_struct.h @@ -91,7 +91,7 @@ private: // Check to see if the sensor is ready for new values // @retval detected SPS, 0 if timeout - static long waitReady025(uint8_t i2cAddress); + static int32_t waitReady025(uint8_t i2cAddress); float _fullScaleFactor{}; uint16_t _configRegisterValue{}; diff --git a/src/src/PluginStructs/P049_data_struct.cpp b/src/src/PluginStructs/P049_data_struct.cpp index 0795e2e69..601979533 100644 --- a/src/src/PluginStructs/P049_data_struct.cpp +++ b/src/src/PluginStructs/P049_data_struct.cpp @@ -225,7 +225,7 @@ bool P049_data_struct::read_ppm(unsigned int& ppm, signed int& temp, unsigned in // get response memset(mhzResp, 0, sizeof(mhzResp)); - long timer = millis() + PLUGIN_READ_TIMEOUT; + uint32_t timer = millis() + PLUGIN_READ_TIMEOUT; int counter = 0; while (!timeOutReached(timer) && (counter < 9)) { diff --git a/src/src/PluginStructs/P077_data_struct.cpp b/src/src/PluginStructs/P077_data_struct.cpp index acc6d74b4..92be9cb65 100644 --- a/src/src/PluginStructs/P077_data_struct.cpp +++ b/src/src/PluginStructs/P077_data_struct.cpp @@ -4,7 +4,6 @@ # include - const __FlashStringHelper* Plugin_077_valuename(P077_query value_nr, bool displayString) { const __FlashStringHelper *strings[] = { @@ -27,6 +26,7 @@ const __FlashStringHelper* Plugin_077_valuename(P077_query value_nr, bool displa } # if FEATURE_MQTT_DISCOVER + int Plugin_077_QueryVType(uint8_t value_nr) { const Sensor_VType vtypes[] = { Sensor_VType::SENSOR_TYPE_VOLTAGE_ONLY, @@ -126,9 +126,9 @@ bool P077_data_struct::processCseReceived(struct EventStruct *event) { } // Get chip calibration data (coefficients) and use as initial defaults - long voltage_coefficient = 191200; // uSec - long current_coefficient = 16140; // uSec - long power_coefficient = 5364000; // uSec + int32_t voltage_coefficient = 191200; // uSec + int32_t current_coefficient = 16140; // uSec + int32_t power_coefficient = 5364000; // uSec // V1R = shunt resistor // V2R = Voltage resistor @@ -214,7 +214,7 @@ bool P077_data_struct::processCseReceived(struct EventStruct *event) { float activePower{}; if (!power_cycle_exceeds_range) { - const long power_cycle = get_24bit_value(17); + const int32_t power_cycle = get_24bit_value(17); if (0 == power_cycle_first) { power_cycle_first = power_cycle; // Skip first incomplete power_cycle @@ -286,8 +286,8 @@ bool P077_data_struct::processCseReceived(struct EventStruct *event) { } bool P077_data_struct::processSerialData() { - long t_start = millis(); - bool found = false; + const uint32_t t_start = millis(); + bool found = false; if (isInitialized()) { int available = easySerial->available(); @@ -306,7 +306,7 @@ bool P077_data_struct::processSerialData() { found = true; } } - long t_diff = timePassedSince(t_start); + int32_t t_diff = timePassedSince(t_start); t_all += t_diff; @@ -316,7 +316,7 @@ bool P077_data_struct::processSerialData() { if (found) { count_max = max(count_max, count_bytes); - t_pkt = t_start - t_pkt_tmp; + t_pkt = timeDiff(t_pkt_tmp, t_start); t_pkt_tmp = t_start; } } @@ -435,6 +435,7 @@ bool P077_data_struct::plugin_write(struct EventStruct *event, } # ifndef BUILD_NO_DEBUG + int P077_data_struct::serial_Available() { if (isInitialized()) { return easySerial->available(); diff --git a/src/src/PluginStructs/P077_data_struct.h b/src/src/PluginStructs/P077_data_struct.h index 7f57b1d69..dbde1ac6e 100644 --- a/src/src/PluginStructs/P077_data_struct.h +++ b/src/src/PluginStructs/P077_data_struct.h @@ -43,6 +43,7 @@ enum class P077_query : uint8_t { P077_QUERY_NR_OUTPUT_OPTIONS + }; const __FlashStringHelper* Plugin_077_valuename(P077_query value_nr, @@ -70,7 +71,7 @@ public: bool init(ESPEasySerialPort port, const int16_t serial_rx, const int16_t serial_tx, - uint32_t baudrate, + uint32_t baudrate, uint8_t config); bool plugin_read(struct EventStruct *event); @@ -94,7 +95,7 @@ public: uint8_t serial_in_buffer[24] = { 0 }; - long power_cycle_first = 0; + int32_t power_cycle_first = 0; uint32_t last_cf_pulses = 0; uint32_t cf_pulses = 0; float cf_frequency = (1e9f / 5364000); @@ -107,10 +108,10 @@ private: public: // stats - long t_max = 0; - long t_all = 0; - long t_pkt = 0; - long t_pkt_tmp = 0; + int32_t t_max = 0; + int32_t t_all = 0; + int32_t t_pkt = 0; + uint32_t t_pkt_tmp = 0; uint16_t count_bytes = 0; uint16_t count_max = 0; uint16_t count_pkt = 0; @@ -121,6 +122,7 @@ public: private: ESPeasySerial *easySerial = nullptr; + }; #endif // ifdef USES_P077 diff --git a/src/src/PluginStructs/P082_data_struct.cpp b/src/src/PluginStructs/P082_data_struct.cpp index 2c021e05b..be160626d 100644 --- a/src/src/PluginStructs/P082_data_struct.cpp +++ b/src/src/PluginStructs/P082_data_struct.cpp @@ -537,7 +537,7 @@ bool P082_data_struct::tryUpdateSystemTime() { if (hasFix(P082_TIMESTAMP_AGE)) { // Using PPS sync should be extremely stable without any significant time wander. // When we only can rely on keeping track of the timestamp at the start of a sentence, the fluctuation is significant. - if (usecPassedSince(_pps_time_micros) < 1000000ll) { + if (usecPassedSince_volatile(_pps_time_micros) < 1000000ll) { timeSource = timeSource_t::GPS_PPS_time_source; } else { timeSource = timeSource_t::GPS_time_source; diff --git a/src/src/PluginStructs/P082_data_struct.h b/src/src/PluginStructs/P082_data_struct.h index dee26732d..1e01fb414 100644 --- a/src/src/PluginStructs/P082_data_struct.h +++ b/src/src/PluginStructs/P082_data_struct.h @@ -265,7 +265,7 @@ public: // So we keep only track of the micros() % 1000000 so we have some offset from the system micros counter. // This will also be used to keep track of when the first sentence is received as the GPS will send those out in a burst at the start of a // new second. - ESPEASY_VOLATILE(int64_t) _pps_time_micros = -1; + ESPEASY_VOLATILE(uint64_t) _pps_time_micros = 0; int8_t _ppsPin = -1; }; diff --git a/src/src/PluginStructs/P090_data_struct.cpp b/src/src/PluginStructs/P090_data_struct.cpp index 61162ce64..e73ae8b5a 100644 --- a/src/src/PluginStructs/P090_data_struct.cpp +++ b/src/src/PluginStructs/P090_data_struct.cpp @@ -479,7 +479,7 @@ CCS811Core::status CCS811::readNTC(void) // Code from Milan Malesevic and Zoran Stupic, 2011, // Modified by Max Mayfield, - _temperature = log(static_cast(resistance)); + _temperature = log(static_cast(resistance)); _temperature = 1 / (0.001129148f + (0.000234125f * _temperature) + (0.0000000876741f * _temperature * _temperature * _temperature)); _temperature = _temperature - 273.15f; // Convert Kelvin to Celsius diff --git a/src/src/PluginStructs/P092_data_struct.cpp b/src/src/PluginStructs/P092_data_struct.cpp index 4f8935329..0eb6fa7f5 100644 --- a/src/src/PluginStructs/P092_data_struct.cpp +++ b/src/src/PluginStructs/P092_data_struct.cpp @@ -91,7 +91,7 @@ void IRAM_ATTR DLBus::ISR(void) void IRAM_ATTR DLBus::ISR_PinChanged(void) { - // long TimeDiff = usecPassedSince(ISR_TimeLastBitChange); // time difference to previous pulse in µs + // int32_t TimeDiff = usecPassedSince(ISR_TimeLastBitChange); // time difference to previous pulse in µs uint32_t _now = micros(); int32_t TimeDiff = (int32_t)(_now - ISR_TimeLastBitChange); diff --git a/src/src/PluginStructs/P098_data_struct.cpp b/src/src/PluginStructs/P098_data_struct.cpp index 4b18a5e47..5fd36b6bb 100644 --- a/src/src/PluginStructs/P098_data_struct.cpp +++ b/src/src/PluginStructs/P098_data_struct.cpp @@ -411,7 +411,7 @@ bool P098_data_struct::check_encoder_timeout(const P098_GPIO_config & gpio_confi if (enc_lastChanged_us == 0) { return false; } - const bool expired = usecPassedSince(enc_lastChanged_us) > static_cast(_config.encoder.timer_us); + const bool expired = usecPassedSince_volatile(enc_lastChanged_us) > static_cast(_config.encoder.timer_us); if (!expired) { return false; } diff --git a/src/src/PluginStructs/P111_data_struct.cpp b/src/src/PluginStructs/P111_data_struct.cpp index c00763c5e..b55d036b5 100644 --- a/src/src/PluginStructs/P111_data_struct.cpp +++ b/src/src/PluginStructs/P111_data_struct.cpp @@ -399,6 +399,7 @@ bool P111_data_struct::plugin_fifty_per_second(struct EventStruct *event) { } } + // TODO TD-er: We don't use the timestamp, would a simple boolean flag also be enough? if (_irq_pin_time_micros > _last_served_irq_pin_time_micros) { _last_served_irq_pin_time_micros = _irq_pin_time_micros; diff --git a/src/src/PluginStructs/P118_data_struct.cpp b/src/src/PluginStructs/P118_data_struct.cpp index 601da6281..064c47651 100644 --- a/src/src/PluginStructs/P118_data_struct.cpp +++ b/src/src/PluginStructs/P118_data_struct.cpp @@ -58,7 +58,7 @@ bool P118_data_struct::plugin_init(struct EventStruct *event) { _rf->setDeviceID(P118_CONFIG_DEVID1, P118_CONFIG_DEVID2, P118_CONFIG_DEVID3); _rf->init(); - const long duration = timePassedSince(startInit); + const int32_t duration = timePassedSince(startInit); if (duration > P118_TIMEOUT_LIMIT) { if (loglevelActiveFor(LOG_LEVEL_ERROR)) { diff --git a/src/src/PluginStructs/P128_data_struct.cpp b/src/src/PluginStructs/P128_data_struct.cpp index ca7dbe9fd..42c84c6a4 100644 --- a/src/src/PluginStructs/P128_data_struct.cpp +++ b/src/src/PluginStructs/P128_data_struct.cpp @@ -868,7 +868,7 @@ bool P128_data_struct::plugin_fifty_per_second(struct EventStruct *event) { void P128_data_struct::fade(void) { for (int pixel = 0; pixel < pixelCount; pixel++) { - long counter = 20 * (counter20ms - starttime[pixel]); + int32_t counter = 20 * (counter20ms - starttime[pixel]); float progress = (float)counter / (float)fadetime; progress = constrain(progress, 0.0f, 1.0f); @@ -1033,7 +1033,7 @@ void P128_data_struct::faketv(void) { * Cycles a rainbow over the entire string of LEDs. */ void P128_data_struct::rainbow(void) { - const long counter = 20 * (counter20ms - starttimerb); + const int32_t counter = 20 * (counter20ms - starttimerb); const float progress = (float)counter / (float)fadetime; if (fadeIn == true) { diff --git a/src/src/PluginStructs/P145_data_struct.cpp b/src/src/PluginStructs/P145_data_struct.cpp index 8dc19d4ce..c2d79a83d 100644 --- a/src/src/PluginStructs/P145_data_struct.cpp +++ b/src/src/PluginStructs/P145_data_struct.cpp @@ -829,7 +829,7 @@ int P145_data_struct::getNbrOfTypes() void P145_data_struct::calibrate(float currentRcal) { uint32_t now = millis(); - long time = timePassedSince(last_cal); + int32_t time = timePassedSince(last_cal); float lastRcal = cal_data; // Last calculated Rcal this calibration sequence if (currentRcal > lastRcal) @@ -874,7 +874,7 @@ void P145_data_struct::calibrate(float currentRcal) void P145_data_struct::heaterControl(void) { uint32_t now = millis(); - long time = timePassedSince(heaterChangeTime); // Time a state is active + int32_t time = timePassedSince(heaterChangeTime); // Time a state is active # ifdef P145_DEBUG P145_heaterState lastState = heaterState; // To detect a state change diff --git a/src/src/PluginStructs/P147_data_struct.cpp b/src/src/PluginStructs/P147_data_struct.cpp index 8499dae61..021c97d08 100644 --- a/src/src/PluginStructs/P147_data_struct.cpp +++ b/src/src/PluginStructs/P147_data_struct.cpp @@ -381,7 +381,7 @@ bool P147_data_struct::plugin_get_config_value(struct EventStruct *event, /***************************************************** * readCheckedWord : Read 2 data bytes from I2C and validate checksum (3rd byte) ****************************************************/ -uint16_t P147_data_struct::readCheckedWord(bool& is_ok, long extraDelay) { +uint16_t P147_data_struct::readCheckedWord(bool& is_ok, int32_t extraDelay) { uint16_t result = 0; uint8_t data[3] = { 0 }; const uint32_t timeOut = millis(); diff --git a/src/src/PluginStructs/P147_data_struct.h b/src/src/PluginStructs/P147_data_struct.h index 313a7933c..98e5e3f64 100644 --- a/src/src/PluginStructs/P147_data_struct.h +++ b/src/src/PluginStructs/P147_data_struct.h @@ -106,7 +106,7 @@ private: # endif // if P147_FEATURE_GASINDEXALGORITHM uint16_t readCheckedWord(bool& is_ok, - long extraDelay = 5); + int32_t extraDelay = 5); bool startSensorRead(uint16_t compensationRh, uint16_t compensationT); diff --git a/src/src/PluginStructs/P165_data_struct.h b/src/src/PluginStructs/P165_data_struct.h index 1754f7868..04c044501 100644 --- a/src/src/PluginStructs/P165_data_struct.h +++ b/src/src/PluginStructs/P165_data_struct.h @@ -191,7 +191,7 @@ private: uint32_t cclkw : 1; // number-plan counter-clockwise (tbd) uint32_t gstrt : 1; // start numbering at g-segment uint32_t unused : 2; - uint32_t aoffs : 16; // Add-on pixels offset (use uin32_t for better memory alignment) + uint32_t aoffs : 16; // Add-on pixels offset (use uint32_t for better memory alignment) uint32_t boffs : 16; // Before pixels offset }; diff --git a/src/src/PluginStructs/P169_data_struct.cpp b/src/src/PluginStructs/P169_data_struct.cpp index 5e2b3a628..af622198b 100644 --- a/src/src/PluginStructs/P169_data_struct.cpp +++ b/src/src/PluginStructs/P169_data_struct.cpp @@ -616,7 +616,7 @@ void P169_data_struct::adjustForDisturbances(struct EventStruct *event) F("AS3935: Watchdog Threshold and Spike Rejection settings are already maxed out. Freq = %d"), frequency)); } - } else if (timePassedSince(_sense_adj_last) > static_cast(_sense_increase_interval)) + } else if (timePassedSince(_sense_adj_last) > static_cast(_sense_increase_interval)) { if (loglevelActiveFor(LOG_LEVEL_INFO)) { addLog(LOG_LEVEL_INFO, strformat( @@ -692,7 +692,7 @@ void P169_data_struct::tryIncreasedSensitivity(struct EventStruct *event) // increase sensor sensitivity every once in a while. _sense_increase_interval controls how quickly the code // attempts to increase sensitivity. - if (timePassedSince(_sense_adj_last) > static_cast(_sense_increase_interval)) + if (timePassedSince(_sense_adj_last) > static_cast(_sense_increase_interval)) { _sense_adj_last = millis();