Skip to content

Commit

Permalink
Version 2.4.3
Browse files Browse the repository at this point in the history
Changes since 2.4.2:

Fix: improve I2C stability and multi-master checking before every I2C master call
Feat: add (hidden) setting to prevent PWM2I2C init
  • Loading branch information
arjenhiemstra committed Oct 27, 2022
1 parent ac385f5 commit d402e94
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 146 deletions.
16 changes: 8 additions & 8 deletions compiled_firmware_files/firmware.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"link_beta": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_1/nrgitho-hw1-v2.2.4.bin"
},
"2": {
"latest_fw": "2.4.2",
"link": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.4.2.bin",
"latest_beta_fw": "2.4.3-beta2",
"link_beta": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.4.3-beta2.bin"
"latest_fw": "2.4.3",
"link": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.4.3.bin",
"latest_beta_fw": "2.4.3-beta3",
"link_beta": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/hardware_rev_2/nrgitho-hw2-v2.4.3-beta3.bin"
},
"NON-CVE 1": {
"latest_fw": "2.4.2",
"link": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.4.2.bin",
"latest_beta_fw": "2.4.3-beta2",
"link_beta": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.4.3-beta2.bin"
"latest_fw": "2.4.3",
"link": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.4.3.bin",
"latest_beta_fw": "2.4.3-beta3",
"link_beta": "https://github.com/arjenhiemstra/ithowifi/raw/master/compiled_firmware_files/non-cve_rev_1/nrgitho-noncve-v2.4.3-beta3.bin"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions software/NRG_itho_wifi/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

[platformio]
default_envs =
; dev
dev
; debug
beta_cve
beta_noncve
; beta_cve
; beta_noncve
; release_cve
; release_noncve

[env]
; Global data for all [env:***]
build_flags =
-D FWVERSION=2.4.3-beta2
-D FWVERSION=2.4.4-beta1
#upload_port = /dev/cu.usbserial-1420 #optional, only needed if PlatformIO autodetect is not working
framework = arduino
lib_ldf_mode = chain+
Expand Down
113 changes: 33 additions & 80 deletions software/NRG_itho_wifi/src/IthoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ void sendI2CPWMinit()

command[sizeof(command) - 1] = checksum(command, sizeof(command) - 1);

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));
}

Expand Down Expand Up @@ -591,17 +589,13 @@ void sendRemoteCmd(const uint8_t remoteIndex, const IthoCommand command, IthoRem
Serial.print(str);
#endif

checkI2Cbus();

i2c_sendBytes(i2c_command, i2c_command_len);
}

void sendQueryDevicetype(bool updateweb)
{
uint8_t command[] = {0x82, 0x80, 0x90, 0xE0, 0x04, 0x00, 0x8A};

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));
uint8_t i2cbuf[512]{};

Expand Down Expand Up @@ -638,8 +632,6 @@ void sendQueryStatusFormat(bool updateweb)

uint8_t command[] = {0x82, 0x80, 0x24, 0x00, 0x04, 0x00, 0xD6};

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));

uint8_t i2cbuf[512]{};
Expand Down Expand Up @@ -728,8 +720,6 @@ void sendQueryStatus(bool updateweb)

uint8_t command[] = {0x82, 0x80, 0x24, 0x01, 0x04, 0x00, 0xD5};

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));

uint8_t i2cbuf[512]{};
Expand Down Expand Up @@ -759,31 +749,56 @@ void sendQueryStatus(bool updateweb)

if (ithoStat.type == ithoDeviceStatus::is_byte)
{
ithoStat.value.byteval = (byte)tempVal;
if(ithoStat.value.byteval == (byte)tempVal) {
ithoStat.updated = 0;
}
else {
ithoStat.updated = 1;
ithoStat.value.byteval = (byte)tempVal;
}
}
if (ithoStat.type == ithoDeviceStatus::is_uint)
{
ithoStat.value.uintval = tempVal;
if(ithoStat.value.uintval == tempVal) {
ithoStat.updated = 0;
}
else {
ithoStat.updated = 1;
ithoStat.value.uintval = tempVal;
}

}
if (ithoStat.type == ithoDeviceStatus::is_int)
{
if (ithoStat.length == 4)
{
tempVal = (int32_t)tempVal;
tempVal = static_cast<int32_t>(tempVal);
}
if (ithoStat.length == 2)
{
tempVal = (int16_t)tempVal;
tempVal = static_cast<int16_t>(tempVal);
}
if (ithoStat.length == 1)
{
tempVal = (int8_t)tempVal;
tempVal = static_cast<int8_t>(tempVal);
}
if(ithoStat.value.intval == tempVal) {
ithoStat.updated = 0;
}
else {
ithoStat.updated = 1;
ithoStat.value.intval = tempVal;
}
ithoStat.value.intval = tempVal;
}
if (ithoStat.type == ithoDeviceStatus::is_float)
{
ithoStat.value.floatval = static_cast<double>(tempVal) / ithoStat.divider;
if(static_cast<uint32_t>(ithoStat.value.floatval*ithoStat.divider) == tempVal) {
ithoStat.updated = 0;
}
else {
ithoStat.updated = 1;
ithoStat.value.floatval = static_cast<double>(tempVal) / ithoStat.divider;
}
}

statusPos += ithoStat.length;
Expand Down Expand Up @@ -856,8 +871,6 @@ void sendQuery31DA(bool updateweb)

uint8_t command[] = {0x82, 0x80, 0x31, 0xDA, 0x04, 0x00, 0xEF};

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));

uint8_t i2cbuf[512]{};
Expand Down Expand Up @@ -1242,8 +1255,6 @@ void sendQuery31D9(bool updateweb)

uint8_t command[] = {0x82, 0x80, 0x31, 0xD9, 0x04, 0x00, 0xF0};

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));

uint8_t i2cbuf[512]{};
Expand Down Expand Up @@ -1348,8 +1359,6 @@ int32_t *sendQuery2410(bool &updateweb)
command[23] = index2410;
command[sizeof(command) - 1] = checksum(command, sizeof(command) - 1);

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));

uint8_t i2cbuf[512]{};
Expand Down Expand Up @@ -1583,8 +1592,6 @@ void setSetting2410(bool &updateweb)

jsonSysmessage("itho2410set", i2cbuf2string(command, sizeof(command)).c_str());

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));

uint8_t i2cbuf[512]{};
Expand Down Expand Up @@ -1636,8 +1643,6 @@ void filterReset(const int remoteIndex, IthoRemote &remotes)

command[sizeof(command) - 1] = checksum(command, sizeof(command) - 1);

checkI2Cbus();

i2c_sendBytes(command, sizeof(command));
}

Expand Down Expand Up @@ -1667,9 +1672,8 @@ void IthoPWMcommand(uint16_t value, volatile uint16_t *ithoCurrentVal, bool *upd
// command[8] = 0 - (67 + b);
command[sizeof(command) - 1] = checksum(command, sizeof(command) - 1);

if (checkI2Cbus())
if (i2c_sendBytes(command, sizeof(command)))
{
i2c_sendBytes(command, sizeof(command));
*updateIthoMQTT = true;
}
else
Expand All @@ -1679,58 +1683,7 @@ void IthoPWMcommand(uint16_t value, volatile uint16_t *ithoCurrentVal, bool *upd
}
}

bool checkI2Cbus() {

unsigned int timeout = 1000;
unsigned int startread = millis();
unsigned int cntr = 0;
bool log_i2cbus_busy = true;

while ((digitalRead(SCLPIN) == LOW || digitalRead(SDAPIN) == LOW) && cntr < 10)
{
if(log_i2cbus_busy) {
log_i2cbus_busy = false;
logInput("Info: I2C bus busy");
}
if (millis() - startread > timeout)
{
cntr++;
startread = millis();
}
yield();
delay(1);
}
if (cntr > 9) {
logInput("Warning: I2C timeout, trying I2C bus reset...");
int result = I2C_ClearBus();
if (result != 0)
{
if (result == 1)
{
logInput("I2C bus could not clear: SCL clock line held low");
}
else if (result == 2)
{
logInput("I2C bus could not clear: SCL clock line held low by slave clock stretch");
}
else if (result == 3)
{
logInput("I2C bus could not clear: SDA data line held low");
}
}
else
{ // bus clear
// re-enable Wire
// now can start Wire Arduino master
logInput("I2C bus cleared");
return true;
}
return false;
}
else {
return true;
}
}

int quick_pow10(int n)
{
Expand Down
4 changes: 3 additions & 1 deletion software/NRG_itho_wifi/src/IthoSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct ithoDeviceStatus
const char *stringval;
} value;
uint32_t divider;
uint8_t updated;
ithoDeviceStatus():updated(0) {};
};

struct ithoDeviceMeasurements
Expand All @@ -76,6 +78,7 @@ struct ithoDeviceMeasurements
double floatval;
const char *stringval;
} value;
uint8_t updated;
};

extern std::vector<ithoDeviceStatus> ithoStatus;
Expand Down Expand Up @@ -141,6 +144,5 @@ int32_t *sendQuery2410(bool &updateweb);
void setSetting2410(bool &updateweb);
void filterReset(const int remoteIndex, IthoRemote &remotes);
void IthoPWMcommand(uint16_t value, volatile uint16_t *ithoCurrentVal, bool *updateIthoMQTT);
bool checkI2Cbus();
int quick_pow10(int n);
std::string i2cbuf2string(const uint8_t *data, size_t len);
7 changes: 7 additions & 0 deletions software/NRG_itho_wifi/src/SystemConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SystemConfig::SystemConfig()
itho_numvrem = 1;
itho_updatefreq = 10;
itho_sendjoin = 0;
itho_pwminit_en = 1;
itho_forcemedium = 0;
itho_vremoteapi = 0;
itho_rf_support = 0;
Expand Down Expand Up @@ -257,6 +258,11 @@ bool SystemConfig::set(JsonObjectConst obj)
updated = true;
itho_sendjoin = obj["itho_sendjoin"];
}
if (!(const char *)obj["itho_pwminit_en"].isNull())
{
updated = true;
itho_pwminit_en = obj["itho_pwminit_en"];
}
if (!(const char *)obj["itho_forcemedium"].isNull())
{
updated = true;
Expand Down Expand Up @@ -315,6 +321,7 @@ void SystemConfig::get(JsonObject obj) const
obj["itho_updatefreq"] = itho_updatefreq;
obj["itho_numvrem"] = itho_numvrem;
obj["itho_sendjoin"] = itho_sendjoin;
obj["itho_pwminit_en"] = itho_pwminit_en;
obj["itho_forcemedium"] = itho_forcemedium;
obj["itho_vremoteapi"] = itho_vremoteapi;
obj["nonQ_cmd_clearsQ"] = nonQ_cmd_clearsQ;
Expand Down
1 change: 1 addition & 0 deletions software/NRG_itho_wifi/src/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SystemConfig
uint16_t itho_updatefreq;
uint8_t itho_numvrem;
uint8_t itho_sendjoin;
uint8_t itho_pwminit_en;
uint8_t itho_forcemedium;
uint8_t itho_vremoteapi;
uint8_t itho_rf_support;
Expand Down
4 changes: 0 additions & 4 deletions software/NRG_itho_wifi/src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#if defined(CVE)
#define HWREVISION "2"
#define SDAPIN 21
#define SCLPIN 22
#define WIFILED 17 // 17 / 2
#define STATUSPIN 16
#define BOOTSTATE 27
Expand All @@ -42,8 +40,6 @@

#elif defined(NON_CVE)
#define HWREVISION "NON-CVE 1"
#define SDAPIN 27
#define SCLPIN 26
#define WIFILED 17 // 17 / 2
#define STATUSPIN 16
#define ITHO_IRQ_PIN 4
Expand Down
Loading

0 comments on commit d402e94

Please sign in to comment.