Browse Source

Homogeneizing naming and I2C method wrappers

rfm69
Xose Pérez 6 years ago
parent
commit
2a439c570c
7 changed files with 39 additions and 57 deletions
  1. +1
    -1
      README.md
  2. +6
    -7
      code/espurna/config/prototypes.h
  3. +1
    -1
      code/espurna/config/version.h
  4. +18
    -35
      code/espurna/i2c.ino
  5. +5
    -4
      code/espurna/system.ino
  6. +7
    -7
      code/espurna/utils.ino
  7. +1
    -2
      code/espurna/ws.ino

+ 1
- 1
README.md View File

@ -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)


+ 6
- 7
code/espurna/config/prototypes.h View File

@ -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);


+ 1
- 1
code/espurna/config/version.h View File

@ -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

+ 18
- 35
code/espurna/i2c.ino View File

@ -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) {


+ 5
- 4
code/espurna/system.ino View File

@ -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;
}

+ 7
- 7
code/espurna/utils.ino View File

@ -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


+ 1
- 2
code/espurna/ws.ino View File

@ -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;
}


Loading…
Cancel
Save