From 81c007ead4d673c2e7c1eaa82850c0bac0498ed9 Mon Sep 17 00:00:00 2001 From: Rene 'Renne' Bartsch Date: Thu, 12 Jul 2018 17:36:55 +0200 Subject: [PATCH] Layout optimization. --- Sensor-API.md | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/Sensor-API.md b/Sensor-API.md index 602816ff..587f5559 100644 --- a/Sensor-API.md +++ b/Sensor-API.md @@ -142,62 +142,65 @@ It should be wrapped in `#ifdef USE_WEBSERVER ... #endif // USE_WEBSERVER` ## Useful functions -### void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, boolean retained) +### MQTT +#### void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, boolean retained) This function publishes MQTT messages immediately, e.g. ``` snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"MPR121%c\":{\"Button%i\":%i}}"), pS->id[i], j, BITC(i,j)); MqttPublishPrefixTopic_P(RESULT_OR_STAT, mqtt_data); ``` -### void AddLog(byte loglevel) +### Logging +#### void AddLog(byte loglevel) This function adds log messages to the local logging system, e.g. ``` snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "MPR121(%c) " D_FOUND_AT " 0x%X"), pS->id[i], pS->i2c_addr[i]); AddLog(LOG_LEVEL_INFO); ``` -### void AddLogSerial(byte loglevel) +#### void AddLogSerial(byte loglevel) This function adds log messages to the serial UART, e.g. ``` snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "MPR121(%c) " D_FOUND_AT " 0x%X"), pS->id[i], pS->i2c_addr[i]); AddLogSerial(LOG_LEVEL_INFO); ``` -### void AddLogMissed(char *sensor, uint8_t misses) +#### void AddLogMissed(char *sensor, uint8_t misses) ??? -### bool I2cValidRead8(uint8_t *data, uint8_t addr, uint8_t reg) -### bool I2cValidRead16(uint16_t *data, uint8_t addr, uint8_t reg) -### bool I2cValidReadS16(int16_t *data, uint8_t addr, uint8_t reg) -### bool I2cValidRead16LE(uint16_t *data, uint8_t addr, uint8_t reg) -### bool I2cValidReadS16_LE(int16_t *data, uint8_t addr, uint8_t reg) -### bool I2cValidRead24(int32_t *data, uint8_t addr, uint8_t reg) -### bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size) +### I2C interface +#### bool I2cValidRead8(uint8_t *data, uint8_t addr, uint8_t reg) +#### bool I2cValidRead16(uint16_t *data, uint8_t addr, uint8_t reg) +#### bool I2cValidReadS16(int16_t *data, uint8_t addr, uint8_t reg) +#### bool I2cValidRead16LE(uint16_t *data, uint8_t addr, uint8_t reg) +#### bool I2cValidReadS16_LE(int16_t *data, uint8_t addr, uint8_t reg) +#### bool I2cValidRead24(int32_t *data, uint8_t addr, uint8_t reg) +#### bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size) These functions return `true` if 1, 2, 3 or `size` bytes can be read from the I2C address `addr` and register `reg` into `*data`. Functions with a `S` read signed data types while functions without a `S` read unsigned data types. Functions with LE read little endian byte order while functions without LE read machine byte order. -### uint8_t I2cRead8(uint8_t addr, uint8_t reg) -### uint16_t I2cRead16(uint8_t addr, uint8_t reg) -### int16_t I2cReadS16(uint8_t addr, uint8_t reg) -### uint16_t I2cRead16LE(uint8_t addr, uint8_t reg) -### int16_t I2cReadS16_LE(uint8_t addr, uint8_t reg) -### int32_t I2cRead24(uint8_t addr, uint8_t reg) +#### uint8_t I2cRead8(uint8_t addr, uint8_t reg) +#### uint16_t I2cRead16(uint8_t addr, uint8_t reg) +#### int16_t I2cReadS16(uint8_t addr, uint8_t reg) +#### uint16_t I2cRead16LE(uint8_t addr, uint8_t reg) +#### int16_t I2cReadS16_LE(uint8_t addr, uint8_t reg) +#### int32_t I2cRead24(uint8_t addr, uint8_t reg) These functions return 1, 2 or 3 bytes from the I2C address `addr` and register `reg`. Functions with a `S` read signed data types while functions without a `S` read unsigned data types. Functions with LE read little endian byte order while functions without LE read machine byte order. -### bool I2cWrite8(uint8_t addr, uint8_t reg, uint16_t val) -### bool I2cWrite16(uint8_t addr, uint8_t reg, uint16_t val) -### bool I2cWrite(uint8_t addr, uint8_t reg, uint32_t val, uint8_t size) +#### bool I2cWrite8(uint8_t addr, uint8_t reg, uint16_t val) +#### bool I2cWrite16(uint8_t addr, uint8_t reg, uint16_t val) +#### bool I2cWrite(uint8_t addr, uint8_t reg, uint32_t val, uint8_t size) These functions return true after successfully writing 1, 2 or `size` bytes to the I2C address `addr` and register `reg`. -### int8_t I2cReadBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len) -### int8_t I2cWriteBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len) +#### int8_t I2cReadBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len) +#### int8_t I2cWriteBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len) These functions copy `len` bytes from/to `*reg_data` starting at I2C address `addr` and register `reg`. -### void I2cScan(char *devs, unsigned int devs_len) +#### void I2cScan(char *devs, unsigned int devs_len) This functions writes a list of I2C addresses in use into the string `*dev` with maximum length `devs_len`. -### boolean I2cDevice(byte addr) +#### boolean I2cDevice(byte addr) This functions checks if the I2C address `addr` is in use.