Skip to content

Commit

Permalink
0.8.113
Browse files Browse the repository at this point in the history
* code cleanup
* fix ESP32-C3 compile
  • Loading branch information
lumapu committed Apr 25, 2024
1 parent d75ba1b commit 177420f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Development Changes

## 0.8.113 - 2024-04-25
* code cleanup
* fix ESP32-C3 compile

## 0.8.112 - 2024-04-24
* improved wizard
* converted ePaper and Ethernet to hal-SPI
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 112
#define VERSION_PATCH 113
//-------------------------------------
typedef struct {
uint8_t ch;
Expand Down
34 changes: 18 additions & 16 deletions src/hm/hmInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct record_t {
byteAssign_t* assign = nullptr; // assignment of bytes in payload
uint8_t length = 0; // length of the assignment list
T *record = nullptr; // data pointer
uint32_t ts = 0; // timestamp of last received payload
uint32_t ts = 0; // Timestamp of last received payload
uint8_t pyldLen = 0; // expected payload length for plausibility check
MqttSentStatus mqttSentStatus = MqttSentStatus:: NEW_DATA; // indicates the current MqTT sent status
};
Expand Down Expand Up @@ -146,7 +146,7 @@ class Inverter {
statistics_t radioStatistics; // information about transmitted, failed, ... packets
HeuristicInv heuristics; // heuristic information / logic
uint8_t curCmtFreq = 0; // current used CMT frequency, used to check if freq. was changed during runtime
uint32_t tsMaxAcPower = 0; // holds the timestamp when the MaxAC power was seen
uint32_t tsMaxAcPower = 0; // holds the Timestamp when the MaxAC power was seen
bool commEnabled = true; // 'pause night communication' sets this field to false

public:
Expand Down Expand Up @@ -189,7 +189,7 @@ class Inverter {
cb(InverterDevInform_Simple, false); // get hardware version
} else if((alarmLastId != alarmMesIndex) && (alarmMesIndex != 0)) {
cb(AlarmData, false); // get last alarms
} else if((0 == mGridLen) && generalConfig->readGrid) { // read grid profile
} else if((0 == mGridLen) && GeneralConfig->readGrid) { // read grid profile
cb(GridOnProFilePara, false);
} else if (mGetLossInterval > AHOY_GET_LOSS_INTERVAL) { // get loss rate
mGetLossInterval = 1;
Expand All @@ -213,7 +213,7 @@ class Inverter {
if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) {
cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1
mIvRxCnt +=2;
} else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && generalConfig->readGrid) // read grid profile
} else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && GeneralConfig->readGrid) // read grid profile
cb(0x10, false); // legacy GPF command
}
}
Expand Down Expand Up @@ -270,16 +270,18 @@ class Inverter {
if(InverterStatus::OFF != status) {
mDevControlRequest = true;
devControlCmd = cmd;
//assert(App);
//App->triggerTickSend(0);
assert(App);
App->triggerTickSend(id);
return true;
}
return (InverterStatus::OFF != status);
return false;
}

bool setDevCommand(uint8_t cmd) {
if(InverterStatus::OFF != status)
bool retval = (InverterStatus::OFF != status);
if(retval)
devControlCmd = cmd;
return (InverterStatus::OFF != status);
return retval;
}

void addValue(uint8_t pos, const uint8_t buf[], record_t<> *rec) {
Expand Down Expand Up @@ -409,14 +411,14 @@ class Inverter {
if(recordMeas.ts == 0)
return false;

if(((*timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
if(((*Timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
avail = true;

if(avail) {
if(status < InverterStatus::PRODUCING)
status = InverterStatus::STARTING;
} else {
if(((*timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
if(((*Timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
if(status != InverterStatus::OFF) {
status = InverterStatus::OFF;
actPowerLimit = 0xffff; // power limit will be read once inverter becomes available
Expand Down Expand Up @@ -817,8 +819,8 @@ class Inverter {
}

public:
static uint32_t *timestamp; // system timestamp
static cfgInst_t *generalConfig; // general inverter configuration from setup
static uint32_t *Timestamp; // system timestamp
static cfgInst_t *GeneralConfig; // general inverter configuration from setup
static IApp *App;

uint16_t mDtuRxCnt = 0;
Expand All @@ -837,9 +839,9 @@ class Inverter {
};

template <class REC_TYP>
uint32_t *Inverter<REC_TYP>::timestamp {0};
uint32_t *Inverter<REC_TYP>::Timestamp {0};
template <class REC_TYP>
cfgInst_t *Inverter<REC_TYP>::generalConfig {0};
cfgInst_t *Inverter<REC_TYP>::GeneralConfig {0};
template <class REC_TYP>
IApp *Inverter<REC_TYP>::App {nullptr};

Expand Down Expand Up @@ -948,7 +950,7 @@ T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
}
}
if(acPower > acMaxPower) {
iv->tsMaxAcPower = *iv->timestamp;
iv->tsMaxAcPower = *iv->Timestamp;
return acPower;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/hm/hmSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class HmSystem {
HmSystem() {}

void setup(uint32_t *timestamp, cfgInst_t *config, IApp *app) {
INVERTERTYPE::timestamp = timestamp;
INVERTERTYPE::generalConfig = config;
INVERTERTYPE::Timestamp = timestamp;
INVERTERTYPE::GeneralConfig = config;
INVERTERTYPE::App = app;
//mInverter[0].app = app;
}
Expand All @@ -26,7 +26,7 @@ class HmSystem {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
INVERTERTYPE *iv = &mInverter[id];
iv->id = id;
iv->config = &mInverter[0].generalConfig->iv[id];
iv->config = &INVERTERTYPE::GeneralConfig->iv[id];
DPRINT(DBG_VERBOSE, "SERIAL: " + String(iv->config->serial.b[5], HEX));
DPRINTLN(DBG_VERBOSE, " " + String(iv->config->serial.b[4], HEX));
if((iv->config->serial.b[5] == 0x11) || (iv->config->serial.b[5] == 0x10)) {
Expand Down
2 changes: 1 addition & 1 deletion src/hm/nrfHal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
mHostDevice = SPI2_HOST;
#else
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI3_HOST;
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI_HOST_OTHER;
#endif

mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
Expand Down
2 changes: 1 addition & 1 deletion src/hms/cmtHal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class cmtHal : public SpiPatcherHandle {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
mHostDevice = SPI2_HOST;
#else
mHostDevice = (14 == clk) ? SPI2_HOST : SPI3_HOST;
mHostDevice = (14 == clk) ? SPI2_HOST : SPI_HOST_OTHER;
#endif

mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/Display/epdHal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <esp_rom_gpio.h>
#include <GxEPD2_BW.h>


#define EPD_DEFAULT_SPI_SPEED 4000000 // 4 MHz

class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
Expand Down Expand Up @@ -41,7 +42,7 @@ class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
mHostDevice = SPI3_HOST;
#else
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI3_HOST;
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI_HOST_OTHER;
#endif

mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
Expand Down
10 changes: 9 additions & 1 deletion src/utils/spiPatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include <driver/spi_master.h>
#include <freertos/semphr.h>

#if (SOC_SPI_PERIPH_NUM > 2)
#define SPI_HOST_OTHER SPI3_HOST
#else
#define SPI_HOST_OTHER SPI2_HOST
#endif

class SpiPatcher {
protected:
explicit SpiPatcher(spi_host_device_t dev) :
Expand Down Expand Up @@ -74,8 +80,10 @@ class SpiPatcher {
assert(mBusState == ESP_OK);
if(SPI2_HOST == host_id)
mHost2Cnt++;
#if (SOC_SPI_PERIPH_NUM > 2)
if(SPI3_HOST == host_id)
mHost3Cnt++;
#endif

if((mHost2Cnt > 3) || (mHost3Cnt > 3))
DPRINTLN(DBG_ERROR, F("maximum number of SPI devices reached (3)"));
Expand Down Expand Up @@ -112,7 +120,7 @@ class SpiPatcher {
SemaphoreHandle_t mutex;
StaticSemaphore_t mutex_buffer;
uint8_t mHost2Cnt = 0, mHost3Cnt = 0;
spi_host_device_t mDev = SPI3_HOST;
spi_host_device_t mDev = SPI2_HOST;
esp_err_t mBusState = ESP_FAIL;
spi_bus_config_t mBusConfig;
};
Expand Down
2 changes: 0 additions & 2 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,6 @@ class RestApi {
iv->powerLimit[1] = AbsolutNonPersistent;

accepted = iv->setDevControlRequest(ActivePowerContr);
if(accepted)
mApp->triggerTickSend(iv->id);
} else if(F("dev") == jsonIn[F("cmd")]) {
DPRINTLN(DBG_INFO, F("dev cmd"));
iv->setDevCommand(jsonIn[F("val")].as<int>());
Expand Down

0 comments on commit 177420f

Please sign in to comment.