Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V7.1.2 #8

Merged
merged 41 commits into from
Feb 24, 2021
Merged

V7.1.2 #8

merged 41 commits into from
Feb 24, 2021

Conversation

glynhudson
Copy link
Member

@glynhudson glynhudson commented Feb 19, 2021

Required for WiFi V4.x

lincomatic and others added 30 commits October 1, 2020 10:50
Remove this unnecessary global variable which is always set to `0`. This
saves 2 bytes of RAM and 2 bytes of Flash.
Remove unnecessary `m_CurrHour` and `m_CurrMin` fields from the
DelayTimer class. These were only used as local variables, so we can
make them private to `IsInAwakeTimeInterval`.

This saves 2 bytes of RAM and 8 bytes of Flash.
There is a chance this optimization is incorrect, so let me know if so.

Since '255' is the "off" value for these checks, we can assume we'll
never need to track more than 255 retries for either the GFI or No
Ground checks. Thus, use an 8-bit variable for each.

This saves 6 bytes of RAM and 116 bytes of Flash.
These were likely checked in inadvertently and are artifacts of
building the code.
Various cleanups while exploring the code
By avoiding as much 32-bit math and preferring 8-bit and 16-bit math, we
can generate smaller code, even if more local variables are needed.

Before:

    RAM:   [=======   ]  65.7% (used 1345 bytes from 2048 bytes)
    Flash: [========= ]  89.7% (used 29378 bytes from 32768 bytes)

After:

    RAM:   [=======   ]  65.7% (used 1345 bytes from 2048 bytes)
    Flash: [========= ]  89.5% (used 29314 bytes from 32768 bytes)

This change saves 64 bytes of flash.
When PP_TABLE_TESLA was removed in commit 7f772c4, this was left as
the only remaining table, and must always be defined if PP_AUTO_AMPACITY
is defined.
Code size optimization: smaller types in readAmmeter
This isn't used anywhere, and as of right now, not all declared methods
are implemented.

Since this isn't used, removal of this has no impact on binary size, but
it should help make the code easier to browse.
* Remove unused global `sec` variable
* Remove unimplemented `secondstime` declaration
* Remove no-op `RTC_DS1307::begin` method
* Mark `daysInMonth` static since it is only used in one file
There are a few global variables that seem to be unnecessary, and this
is one of them. In nearly every case this global was used, it was
initialized with a call to `g_RTC.now()`, and then unpacked into the
component date parts of year/month/day/hour/minute/second.

Replace all usages of this global with a local variable. For now, we
don't touch the global `g_month`, `g_year`, etc. but this might be a
future optimization possiblity.

Before:
    RAM:   [=======   ]  65.7% (used 1345 bytes from 2048 bytes)
    Flash: [========= ]  89.5% (used 29314 bytes from 32768 bytes)

After:
    RAM:   [=======   ]  65.4% (used 1339 bytes from 2048 bytes)
    Flash: [========= ]  88.9% (used 29130 bytes from 32768 bytes)

This change saves 6 bytes of RAM and 184 bytes of Flash.
Time.cpp and Time.h were used for a single purpose- calling `now()` at
the start and end of the charge and calculating an elapsed charge time
(in seconds).

We already track these same start and end times using our millis()
counter. Calculate the charge time via these instead, and drop the
entire now-unused time library.

The only concern might be "millis increments fast, what about
wraparound?" As long as a charge session isn't taking more than 49.7
days, this should be a non-issue, and I'm not even sure the `now()`
function in the removed time library would have handled it better, since
it used `millis()` under the hood.

https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover
gives a good description on when you do and don't need to think about
rollover. Since we are doing subtraction, this should not be an issue as
long as the charge session is < 49.7 days.

Before:
    RAM:   [=======   ]  65.4% (used 1339 bytes from 2048 bytes)
    Flash: [========= ]  88.9% (used 29130 bytes from 32768 bytes)

After:
    RAM:   [======    ]  64.6% (used 1323 bytes from 2048 bytes)
    Flash: [========= ]  88.5% (used 29000 bytes from 32768 bytes)

This saves 16 bytes of RAM and 130 bytes of Flash.
I honestly have no idea if anyone is using this anymore. Likely not, as
it hasn't compiled in a bit, but I wanted to do a quick sanity check of
my other changes on this branch. Here's the minimal amount of fixing I
needed to get this to successfully compile.
For amps and volt measurements with large decimal portions (e.g. 11.9
amps, or 119.9 volts), we were introducing a pretty serious truncation
error in our existing calcUsage function. This is due to using integer
math and the default behavior of truncation, and dividing earlier than
necessary, causing a loss of precision.

The new code is extensively commented to describe what it is doing and
how it works, so hopefully no one is confused in the future with the
rather odd coefficients involved. The important part to note is never
getting too close to the upper limits of what a uint32_t variable can
handle.
Recode energy meter usage calculation for better accuracy
A series of time-related cleanups
This has not been maintained in years, and is fully replaced by the RAPI
serial interface. Remove it to reduce the maintenance burden when making
other changes to the code, and gives us one less ifdef to maintain.
Remove the SERIALCLI code and references
Prior work in 2015 in this repository (commit 1c8ae71 and 52f3151)
had removed all uses of floating point, saving the flash memory needed
for floating point software routines.

More recently, floating point is used if HEARTBEAT_SUPERVISION is
enabled. By making a few small changes and adjusting things to use
integer math, we can save 600+ bytes of flash.

This also removes the deprecated function `HsDeactivate` which isn't
called from anywhere.
When the front pannel button is disabled via `$FF B 0` the button state is evented using `$AN` for processing on the external controller.

Also re-enabled eventing of the 10s WiFi mode press.

Missing part of #111 and needed for OpenEVSE/openevse_esp32_firmware#68 and OpenEVSE/openevse_esp32_firmware#5
Avoid using floating point in the heartbeat code
@glynhudson glynhudson merged commit 432c05c into openenergymonitor:master Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants