Skip to content

Commit

Permalink
0.8.76
Browse files Browse the repository at this point in the history
* revert changes from yesterday regarding snprintf and its size #1410, #1411
* reduced cppcheck linter warnings significantly
* try to improve ePaper (ghosting) #1107
  • Loading branch information
lumapu committed Feb 7, 2024
1 parent c447049 commit 7c532ca
Show file tree
Hide file tree
Showing 23 changed files with 164 additions and 158 deletions.
5 changes: 5 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Development Changes

## 0.8.76 - 2024-02-07
* revert changes from yesterday regarding snprintf and its size #1410, #1411
* reduced cppcheck linter warnings significantly
* try to improve ePaper (ghosting) #1107

## 0.8.75 - 2024-02-06
* fix active power control value #1406, #1409
* update Mqtt lib to version `1.6.0`
Expand Down
5 changes: 2 additions & 3 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,10 @@ void app::tickNtpUpdate(void) {
#endif
if (isOK) {
this->updateNtp();

nxtTrig = isOK ? (mConfig->ntp.interval * 60) : 60; // depending on NTP update success check again in 12h (depends on setting) or in 1 min
nxtTrig = mConfig->ntp.interval * 60; // check again in 12h

// immediately start communicating
if (isOK && mSendFirst) {
if (mSendFirst) {
mSendFirst = false;
once(std::bind(&app::tickSend, this), 1, "senOn");
}
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 75
#define VERSION_PATCH 76

//-------------------------------------
typedef struct {
Expand Down
14 changes: 8 additions & 6 deletions src/hm/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ class Communication : public CommQueue<> {
byte[23] to byte[26] Matching_APPFW_PN*/
DPRINT(DBG_INFO,F("HW_PartNo "));
DBGPRINTLN(String((uint32_t) (((p->packet[10] << 8) | p->packet[11]) << 8 | p->packet[12]) << 8 | p->packet[13]));
record_t<> *rec = q->iv->getRecordStruct(InverterDevInform_Simple); // choose the record structure
rec = q->iv->getRecordStruct(InverterDevInform_Simple); // choose the record structure
rec->ts = q->ts;
q->iv->setValue(0, rec, (uint32_t) ((((p->packet[10] << 8) | p->packet[11]) << 8 | p->packet[12]) << 8 | p->packet[13])/1);
rec->mqttSentStatus = MqttSentStatus::NEW_DATA;
Expand Down Expand Up @@ -899,14 +899,16 @@ class Communication : public CommQueue<> {
q->iv->alarmCnt = 1; // minimum...
stsok = false;
//sth is or was wrong?
if ( (q->iv->type != INV_TYPE_1CH) && ( (statusMi != 3)
|| ((q->iv->lastAlarm[stschan].code) && (statusMi == 3) && (q->iv->lastAlarm[stschan].code != 1)))
if ((q->iv->type != INV_TYPE_1CH)
&& ((statusMi != 3)
|| ((q->iv->lastAlarm[stschan].code) && (q->iv->lastAlarm[stschan].code != 1)))
) {
q->iv->lastAlarm[stschan+q->iv->type==INV_TYPE_2CH ? 2: 4] = alarm_t(q->iv->lastAlarm[stschan].code, q->iv->lastAlarm[stschan].start,q->ts);
q->iv->lastAlarm[stschan] = alarm_t(prntsts, q->ts,0);
q->iv->alarmCnt = q->iv->type == INV_TYPE_2CH ? 3 : 5;
} else if ( (q->iv->type == INV_TYPE_1CH) && ( (statusMi != 3)
|| ((q->iv->lastAlarm[stschan].code) && (statusMi == 3) && (q->iv->lastAlarm[stschan].code != 1)))
} else if ((q->iv->type == INV_TYPE_1CH)
&& ( (statusMi != 3)
|| ((q->iv->lastAlarm[stschan].code) && (q->iv->lastAlarm[stschan].code != 1)))
) {
q->iv->lastAlarm[stschan] = alarm_t(q->iv->lastAlarm[0].code, q->iv->lastAlarm[0].start,q->ts);
} else if (q->iv->type == INV_TYPE_1CH)
Expand Down Expand Up @@ -962,7 +964,7 @@ class Communication : public CommQueue<> {
iv->radioStatistics.ivLoss = iv->radioStatistics.ivSent - iv->mDtuRxCnt; // this is what we didn't receive
iv->radioStatistics.dtuLoss = iv->mIvTxCnt; // this is somehow the requests w/o answers in that periode
iv->radioStatistics.dtuSent = iv->mDtuTxCnt;
if (mSerialDebug) {
if (*mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN("DTU loss: " +
String (iv->radioStatistics.ivLoss) + "/" +
Expand Down
2 changes: 1 addition & 1 deletion src/hm/Heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Heuristic {
ih->lastRxFragments = rxFragments;
}

void printStatus(Inverter<> *iv) {
void printStatus(const Inverter<> *iv) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("Radio infos:"));
if((IV_HMS != iv->ivGen) && (IV_HMT != iv->ivGen)) {
Expand Down
6 changes: 3 additions & 3 deletions src/hm/hmRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ class HmRadio : public Radio {
#endif*/
if(*mPrintWholeTrace) {
if(*mPrivacyMode)
ah::dumpBuf(mTxBuf, len, 1, 4);
ah::dumpBuf(mTxBuf.data(), len, 1, 4);
else
ah::dumpBuf(mTxBuf, len);
ah::dumpBuf(mTxBuf.data(), len);
} else {
DHEX(mTxBuf[0]);
DBGPRINT(F(" "));
Expand All @@ -415,7 +415,7 @@ class HmRadio : public Radio {
}
mNrf24->setChannel(mRfChLst[mTxChIdx]);
mNrf24->openWritingPipe(reinterpret_cast<uint8_t*>(&iv->radioId.u64));
mNrf24->startWrite(mTxBuf, len, false); // false = request ACK response
mNrf24->startWrite(mTxBuf.data(), len, false); // false = request ACK response
mMillis = millis();

mLastIv = iv;
Expand Down
14 changes: 8 additions & 6 deletions src/hm/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define ALL_FRAMES 0x80
#define SINGLE_FRAME 0x81

#include <array>
#include <atomic>
#include "../utils/dbg.h"
#include "../utils/crc.h"
Expand All @@ -34,6 +35,8 @@ class Radio {
virtual std::pair<uint16_t,uint16_t> getFreqRangeMhz(void) { return std::make_pair(0, 0); }
virtual bool loop(void) = 0;

Radio() : mTxBuf{} {}

void handleIntr(void) {
mIrqRcvd = true;
mIrqOk = IRQ_OK;
Expand Down Expand Up @@ -107,7 +110,7 @@ class Radio {
mTxBuf[(*len)++] = (crc ) & 0xff;
}
// crc over all
mTxBuf[*len] = ah::crc8(mTxBuf, *len);
mTxBuf[*len] = ah::crc8(mTxBuf.data(), *len);
(*len)++;
}

Expand All @@ -129,12 +132,11 @@ class Radio {
mDtuSn |= 0x80000000; // the first digit is an 8 for DTU production year 2022, the rest is filled with the ESP chipID in decimal
}



uint32_t mDtuSn;
std::atomic<bool> mIrqRcvd;
protected:
uint32_t mDtuSn = 0;
std::atomic<bool> mIrqRcvd = false;
bool *mSerialDebug = nullptr, *mPrivacyMode = nullptr, *mPrintWholeTrace = nullptr;
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
std::array<uint8_t, MAX_RF_PAYLOAD_SIZE> mTxBuf;
};

#endif /*__RADIO_H__*/
6 changes: 3 additions & 3 deletions src/hm/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class Simulator {
}

private:
HMSYSTEM *mSys;
uint8_t mIvId;
uint32_t *mTimestamp;
HMSYSTEM *mSys = nullptr;
uint8_t mIvId = 0;
uint32_t *mTimestamp = nullptr;
payloadListenerType mCbPayload = nullptr;
uint8_t payloadCtrl = 0;

Expand Down
7 changes: 4 additions & 3 deletions src/hms/hmsRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CmtRadio : public Radio {
mPrivacyMode = privacyMode;
mSerialDebug = serialDebug;
mPrintWholeTrace = printWholeTrace;
mTxBuf.fill(0);
}

bool loop() override {
Expand Down Expand Up @@ -102,9 +103,9 @@ class CmtRadio : public Radio {
DBGPRINT(F("Mhz | "));
if(*mPrintWholeTrace) {
if(*mPrivacyMode)
ah::dumpBuf(mTxBuf, len, 1, 4);
ah::dumpBuf(mTxBuf.data(), len, 1, 4);
else
ah::dumpBuf(mTxBuf, len);
ah::dumpBuf(mTxBuf.data(), len);
} else {
DHEX(mTxBuf[0]);
DBGPRINT(F(" "));
Expand All @@ -114,7 +115,7 @@ class CmtRadio : public Radio {
}
}

CmtStatus status = mCmt.tx(mTxBuf, len);
CmtStatus status = mCmt.tx(mTxBuf.data(), len);
mMillis = millis();
if(CmtStatus::SUCCESS != status) {
DPRINT(DBG_WARN, F("CMT TX failed, code: "));
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/Display/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,21 @@ class Display {
}

// private member variables
IApp *mApp;
IApp *mApp = nullptr;
DisplayData mDisplayData;
bool mNewPayload;
uint8_t mLoopCnt;
uint32_t *mUtcTs;
display_t *mCfg;
HMSYSTEM *mSys;
RADIO *mHmRadio;
RADIO *mHmsRadio;
uint16_t mRefreshCycle;
bool mNewPayload = false;
uint8_t mLoopCnt = 0;
uint32_t *mUtcTs = nullptr;
display_t *mCfg = nullptr;
HMSYSTEM *mSys = nullptr;
RADIO *mHmRadio = nullptr;
RADIO *mHmsRadio = nullptr;
uint16_t mRefreshCycle = 0;

#if defined(ESP32) && !defined(ETHERNET)
DisplayEPaper mEpaper;
#endif
DisplayMono *mMono;
DisplayMono *mMono = nullptr;
};

#endif /*PLUGIN_DISPLAY*/
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/Display/Display_Mono_128X32.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class DisplayMono128X32 : public DisplayMono {
mExtra = 0;
}

void config(display_t *cfg) {
void config(display_t *cfg) override {
mCfg = cfg;
}

void init(DisplayData *displayData) {
void init(DisplayData *displayData) override {
u8g2_cb_t *rot = (u8g2_cb_t *)((mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0);
monoInit(new U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData);
calcLinePositions();
Expand All @@ -26,7 +26,7 @@ class DisplayMono128X32 : public DisplayMono {
mDisplay->sendBuffer();
}

void disp(void) {
void disp(void) override {
mDisplay->clearBuffer();

// calculate current pixelshift for pixelshift screensaver
Expand Down
39 changes: 17 additions & 22 deletions src/plugins/Display/Display_Mono_128X64.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class DisplayMono128X64 : public DisplayMono {
mExtra = 0;
}

void config(display_t *cfg) {
void config(display_t *cfg) override {
mCfg = cfg;
}

void init(DisplayData *displayData) {
void init(DisplayData *displayData) override {
u8g2_cb_t *rot = (u8g2_cb_t *)(( mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0);
switch (mCfg->type) {
case DISP_TYPE_T1_SSD1306_128X64:
Expand Down Expand Up @@ -68,9 +68,7 @@ class DisplayMono128X64 : public DisplayMono {
mDisplay->sendBuffer();
}

void disp(void) {
uint8_t pos, sun_pos, moon_pos;

void disp(void) override {
mDisplay->clearBuffer();

// Layout-Test
Expand Down Expand Up @@ -106,8 +104,8 @@ class DisplayMono128X64 : public DisplayMono {
}
// print status of inverters
else {
sun_pos = -1;
moon_pos = -1;
int8_t sun_pos = -1;
int8_t moon_pos = -1;
setLineFont(l_Status);
if (0 == mDisplayData->nrSleeping + mDisplayData->nrProducing)
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "no inverter");
Expand All @@ -128,11 +126,11 @@ class DisplayMono128X64 : public DisplayMono {
}
printText(mFmtText, l_Status, 0xff);

pos = (mDispWidth - mDisplay->getStrWidth(mFmtText)) / 2;
uint8_t pos = (mDispWidth - mDisplay->getStrWidth(mFmtText)) / 2;
mDisplay->setFont(u8g2_font_ncenB08_symbols8_ahoy);
if (sun_pos!=-1)
if (sun_pos != -1)
mDisplay->drawStr(pos + sun_pos + mPixelshift, mLineYOffsets[l_Status], "G"); // sun symbol
if (moon_pos!=-1)
if (moon_pos != -1)
mDisplay->drawStr(pos + moon_pos + mPixelshift, mLineYOffsets[l_Status], "H"); // moon symbol
}
}
Expand Down Expand Up @@ -181,12 +179,11 @@ class DisplayMono128X64 : public DisplayMono {
// draw dynamic RSSI bars
int rssi_bar_height = 9;
for (int i = 0; i < 4; i++) {
int radio_rssi_threshold = -60 - i * 10;
int wifi_rssi_threshold = -60 - i * 10;
int rssi_threshold = -60 - i * 10;
uint8_t barwidth = std::min(4 - i, 3);
if (mDisplayData->RadioRSSI > radio_rssi_threshold)
if (mDisplayData->RadioRSSI > rssi_threshold)
mDisplay->drawBox(widthShrink / 2 + mPixelshift, 8 + (rssi_bar_height + 1) * i, barwidth, rssi_bar_height);
if (mDisplayData->WifiRSSI > wifi_rssi_threshold)
if (mDisplayData->WifiRSSI > rssi_threshold)
mDisplay->drawBox(mDispWidth - barwidth - widthShrink / 2 + mPixelshift, 8 + (rssi_bar_height + 1) * i, barwidth, rssi_bar_height);
}
// draw dynamic antenna and WiFi symbols
Expand Down Expand Up @@ -223,23 +220,22 @@ class DisplayMono128X64 : public DisplayMono {
l_MAX_LINES = 5,
};

uint8_t graph_first_line;
uint8_t graph_last_line;
uint8_t graph_first_line = 0;
uint8_t graph_last_line = 0;

const uint8_t pixelShiftRange = 11; // number of pixels to shift from left to right (centered -> must be odd!)
uint8_t widthShrink;
uint8_t widthShrink = 0;

void calcLinePositions() {
uint8_t yOff = 0;
uint8_t i = 0;
uint8_t asc, dsc;

do {
setLineFont(i);
asc = mDisplay->getAscent();
uint8_t asc = mDisplay->getAscent();
yOff += asc;
mLineYOffsets[i] = yOff;
dsc = mDisplay->getDescent();
uint8_t dsc = mDisplay->getDescent();
yOff -= dsc;
if (l_Time == i) // prevent time and status line to touch
yOff++; // -> one pixels space
Expand All @@ -248,8 +244,7 @@ class DisplayMono128X64 : public DisplayMono {
}

inline void setLineFont(uint8_t line) {
if ((line == l_TotalPower) ||
(line == l_Ahoy))
if (line == l_TotalPower) // || (line == l_Ahoy) -> l_TotalPower == l_Ahoy == 2
mDisplay->setFont(u8g2_font_ncenB14_tr);
else if ((line == l_YieldDay) ||
(line == l_YieldTotal))
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/Display/Display_Mono_64X48.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class DisplayMono64X48 : public DisplayMono {
mExtra = 0;
}

void config(display_t *cfg) {
void config(display_t *cfg) override {
mCfg = cfg;
}

void init(DisplayData *displayData) {
void init(DisplayData *displayData) override {
u8g2_cb_t *rot = (u8g2_cb_t *)((mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0);
// Wemos OLed Shield is not defined in u8 lib -> use nearest compatible
monoInit(new U8G2_SSD1306_64X48_ER_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData);
Expand All @@ -28,7 +28,7 @@ class DisplayMono64X48 : public DisplayMono {
mDisplay->sendBuffer();
}

void disp(void) {
void disp(void) override {
mDisplay->clearBuffer();

// calculate current pixelshift for pixelshift screensaver
Expand Down
Loading

0 comments on commit 7c532ca

Please sign in to comment.