diff --git a/README.md b/README.md index 80f2d960..9f8acbd7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smart switches, lights and sensors. It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. -[![version](https://img.shields.io/badge/version-1.12.5a-brightgreen.svg)](CHANGELOG.md) +[![version](https://img.shields.io/badge/version-1.12.5b-brightgreen.svg)](CHANGELOG.md) ![branch](https://img.shields.io/badge/branch-dev-orange.svg) [![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) [![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index 27c6c773..e044642f 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -74,13 +74,12 @@ bool i2cGetLock(unsigned char address); bool i2cReleaseLock(unsigned char address); unsigned char i2cFindAndLock(size_t size, unsigned char * addresses); -void i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len); -uint8_t i2c_write_buffer_ret(uint8_t address, uint8_t * buffer, size_t len); -void i2c_write_uint8(uint8_t address, uint8_t value); -void i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value); -uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value, uint8_t value2); -void i2c_write_uint16(uint8_t address, uint16_t value); -void i2c_write_uint16(uint8_t address, uint8_t reg, uint16_t value); +uint8_t i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len); +uint8_t i2c_write_uint8(uint8_t address, uint8_t value); +uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value); +uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value1, uint8_t value2); +uint8_t i2c_write_uint16(uint8_t address, uint16_t value); +uint8_t i2c_write_uint16(uint8_t address, uint8_t reg, uint16_t value); uint8_t i2c_read_uint8(uint8_t address); uint8_t i2c_read_uint8(uint8_t address, uint8_t reg); uint16_t i2c_read_uint16(uint8_t address); diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index bd6bf6ab..43682c59 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,5 +1,5 @@ #define APP_NAME "ESPURNA" -#define APP_VERSION "1.12.5a" +#define APP_VERSION "1.12.5b" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" #define CFG_VERSION 3 diff --git a/code/espurna/i2c.ino b/code/espurna/i2c.ino index b828754b..8300929a 100644 --- a/code/espurna/i2c.ino +++ b/code/espurna/i2c.ino @@ -110,29 +110,22 @@ int _i2cClearbus(int sda, int scl) { #if I2C_USE_BRZO -// simple i2c device wakeup void i2c_wakeup(uint8_t address) { brzo_i2c_start_transaction(_address, _i2c_scl_frequency); brzo_i2c_end_transaction(); } -uint8_t i2c_write_buffer_ret(uint8_t address, uint8_t * buffer, size_t len) { +uint8_t i2c_write_uint8(uint8_t address, uint8_t value) { + uint8_t buffer[1] = {value}; brzo_i2c_start_transaction(_address, _i2c_scl_frequency); - brzo_i2c_write_uint8(buffer, len, false); + brzo_i2c_write_uint8(buffer, 1, false); return brzo_i2c_end_transaction(); } -void i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len) { +uint8_t i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len) { brzo_i2c_start_transaction(_address, _i2c_scl_frequency); brzo_i2c_write_uint8(buffer, len, false); - brzo_i2c_end_transaction(); -} - -void i2c_write_uint8(uint8_t address, uint8_t value) { - uint8_t buffer[1] = {value}; - brzo_i2c_start_transaction(_address, _i2c_scl_frequency); - brzo_i2c_write_uint8(buffer, 1, false); - brzo_i2c_end_transaction(); + return brzo_i2c_end_transaction(); } uint8_t i2c_read_uint8(uint8_t address) { @@ -177,28 +170,21 @@ void i2c_read_buffer(uint8_t address, uint8_t * buffer, size_t len) { #else // not I2C_USE_BRZO -// simple i2c device wakeup void i2c_wakeup(uint8_t address) { Wire.beginTransmission((uint8_t) address); Wire.endTransmission(); } -uint8_t i2c_write_buffer_ret(uint8_t address, uint8_t * buffer, size_t len) { +uint8_t i2c_write_uint8(uint8_t address, uint8_t value) { Wire.beginTransmission((uint8_t) address); - Wire.write(buffer, len); + Wire.write((uint8_t) value); return Wire.endTransmission(); } -void i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len) { +uint8_t i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len) { Wire.beginTransmission((uint8_t) address); Wire.write(buffer, len); - Wire.endTransmission(); -} - -void i2c_write_uint8(uint8_t address, uint8_t value) { - Wire.beginTransmission((uint8_t) address); - Wire.write((uint8_t) value); - Wire.endTransmission(); + return Wire.endTransmission(); } uint8_t i2c_read_uint8(uint8_t address) { @@ -250,32 +236,29 @@ void i2c_read_buffer(uint8_t address, uint8_t * buffer, size_t len) { #endif // I2C_USE_BRZO -void i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value) { +uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value) { uint8_t buffer[2] = {reg, value}; - i2c_write_buffer(address, buffer, 2); + return i2c_write_buffer(address, buffer, 2); } -uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value, uint8_t value2) { - uint8_t buffer[3]; - buffer[0] = reg; - buffer[1] = value; - buffer[2] = value2; - return i2c_write_buffer_ret(address, buffer, 3); +uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value1, uint8_t value2) { + uint8_t buffer[3] = {reg, value1, value2}; + return i2c_write_buffer(address, buffer, 3); } -void i2c_write_uint16(uint8_t address, uint8_t reg, uint16_t value) { +uint8_t i2c_write_uint16(uint8_t address, uint8_t reg, uint16_t value) { uint8_t buffer[3]; buffer[0] = reg; buffer[1] = (value >> 8) & 0xFF; buffer[2] = (value >> 0) & 0xFF; - i2c_write_buffer(address, buffer, 3); + return i2c_write_buffer(address, buffer, 3); } -void i2c_write_uint16(uint8_t address, uint16_t value) { +uint8_t i2c_write_uint16(uint8_t address, uint16_t value) { uint8_t buffer[2]; buffer[0] = (value >> 8) & 0xFF; buffer[1] = (value >> 0) & 0xFF; - i2c_write_buffer(address, buffer, 2); + return i2c_write_buffer(address, buffer, 2); } uint16_t i2c_read_uint16_le(uint8_t address, uint8_t reg) { diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 866f03f3..46b5fa71 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -70,6 +70,11 @@ unsigned long systemLoopDelay() { return _loop_delay; } + +unsigned long systemLoadAverage() { + return _load_average; +} + void systemLoop() { // ------------------------------------------------------------------------- @@ -160,7 +165,3 @@ void systemSetup() { espurnaRegisterLoop(systemLoop); } - -unsigned long getLoadAverage() { - return _load_average; -} diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 11524bc4..74ece067 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -184,7 +184,7 @@ void heartbeat() { mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true); #endif #if (LOADAVG_REPORT) - mqttSend(MQTT_TOPIC_LOADAVG, String(getLoadAverage()).c_str()); + mqttSend(MQTT_TOPIC_LOADAVG, String(systemLoadAverage()).c_str()); #endif } #endif @@ -349,6 +349,9 @@ void info() { DEBUG_MSG_P(PSTR("\n")); DEBUG_MSG_P(PSTR("[INIT] SENSORS:")); + #if AM2320_SUPPORT + DEBUG_MSG_P(PSTR(" AM2320_I2C")); + #endif #if ANALOG_SUPPORT DEBUG_MSG_P(PSTR(" ANALOG")); #endif @@ -379,6 +382,9 @@ void info() { #if EVENTS_SUPPORT DEBUG_MSG_P(PSTR(" EVENTS")); #endif + #if GUVAS12SD_SUPPORT + DEBUG_MSG_P(PSTR(" GUVAS12SD")); + #endif #if HLW8012_SUPPORT DEBUG_MSG_P(PSTR(" HLW8012")); #endif @@ -400,12 +406,6 @@ void info() { #if V9261F_SUPPORT DEBUG_MSG_P(PSTR(" V9261F")); #endif - #if AM2320_SUPPORT - DEBUG_MSG_P(PSTR(" AM2320_I2C")); - #endif - #if GUVAS12SD_SUPPORT - DEBUG_MSG_P(PSTR(" GUVAS12SD")); - #endif #endif // SENSOR_SUPPORT diff --git a/code/espurna/ws.ino b/code/espurna/ws.ino index 35d99db7..67dc5399 100644 --- a/code/espurna/ws.ino +++ b/code/espurna/ws.ino @@ -220,7 +220,7 @@ void _wsUpdate(JsonObject& root) { root["heap"] = getFreeHeap(); root["uptime"] = getUptime(); root["rssi"] = WiFi.RSSI(); - root["loadaverage"] = getLoadAverage(); + root["loadaverage"] = systemLoadAverage(); root["vcc"] = ESP.getVcc(); #if NTP_SUPPORT if (ntpSynced()) root["now"] = now(); @@ -272,7 +272,6 @@ void _wsOnStart(JsonObject& root) { root["btnDelay"] = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt(); root["webPort"] = getSetting("webPort", WEB_PORT).toInt(); - root["wsAuth"] = getSetting("wsAuth", WS_AUTHENTICATION).toInt() == 1; }