Layout optimization.

Rene 'Renne' Bartsch 2018-07-12 17:36:55 +02:00
parent b3861f7fdc
commit 81c007ead4
1 changed files with 27 additions and 24 deletions

@ -142,62 +142,65 @@ It should be wrapped in `#ifdef USE_WEBSERVER ... #endif // USE_WEBSERVER`
## Useful functions ## 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. 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)); 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); 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. 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]); 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); AddLog(LOG_LEVEL_INFO);
``` ```
### void AddLogSerial(byte loglevel) #### void AddLogSerial(byte loglevel)
This function adds log messages to the serial UART, e.g. 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]); 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); 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) ### I2C interface
### bool I2cValidRead16(uint16_t *data, uint8_t addr, uint8_t reg) #### bool I2cValidRead8(uint8_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidReadS16(int16_t *data, uint8_t addr, uint8_t reg) #### bool I2cValidRead16(uint16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead16LE(uint16_t *data, uint8_t addr, uint8_t reg) #### bool I2cValidReadS16(int16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidReadS16_LE(int16_t *data, uint8_t addr, uint8_t reg) #### bool I2cValidRead16LE(uint16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead24(int32_t *data, uint8_t addr, uint8_t reg) #### bool I2cValidReadS16_LE(int16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size) #### 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`. 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 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. 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) #### uint8_t I2cRead8(uint8_t addr, uint8_t reg)
### uint16_t I2cRead16(uint8_t addr, uint8_t reg) #### uint16_t I2cRead16(uint8_t addr, uint8_t reg)
### int16_t I2cReadS16(uint8_t addr, uint8_t reg) #### int16_t I2cReadS16(uint8_t addr, uint8_t reg)
### uint16_t I2cRead16LE(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) #### int16_t I2cReadS16_LE(uint8_t addr, uint8_t reg)
### int32_t I2cRead24(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`. 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 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. 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 I2cWrite8(uint8_t addr, uint8_t reg, uint16_t val)
### bool I2cWrite16(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 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`. 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 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 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`. 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`. 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. This functions checks if the I2C address `addr` is in use.