v5.8.0k - Clean up

Add retain to ENERGY messages controlled by command SensorRetain (#1013)
This commit is contained in:
arendst 2017-10-12 14:09:19 +02:00
parent 804bd8fb53
commit 60426fca2f
4 changed files with 22 additions and 15 deletions

View File

@ -1,6 +1,7 @@
/* 5.8.0k /* 5.8.0k
* Add support for up to 8 relays (#995) * Add support for up to 8 relays (#995)
* Fix Blocked Loop when erasing large flash using command reset 2 (#1002) * Fix Blocked Loop when erasing large flash using command reset 2 (#1002)
* Add retain to ENERGY messages controlled by command SensorRetain (#1013)
* *
* 5.8.0j * 5.8.0j
* Set default altitude to 0 to be used with pressure sensors * Set default altitude to 0 to be used with pressure sensors

View File

@ -432,7 +432,7 @@ void CFG_DefaultSet2()
sysCfg.sleep = APP_SLEEP; sysCfg.sleep = APP_SLEEP;
sysCfg.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER; sysCfg.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
for (byte i = 0; i < 4; i++) { for (byte i = 0; i < MAX_SWITCHES; i++) {
sysCfg.switchmode[i] = SWITCH_MODE; sysCfg.switchmode[i] = SWITCH_MODE;
// sysCfg.domoticz_relay_idx[i] = 0; // sysCfg.domoticz_relay_idx[i] = 0;
// sysCfg.domoticz_key_idx[i] = 0; // sysCfg.domoticz_key_idx[i] = 0;
@ -477,7 +477,7 @@ void CFG_DefaultSet2()
sysCfg.pulsetime[0] = APP_PULSETIME; sysCfg.pulsetime[0] = APP_PULSETIME;
// 4.0.7 // 4.0.7
// for (byte i = 0; i < 5; i++) sysCfg.pwmvalue[i] = 0; // for (byte i = 0; i < MAX_PWMS; i++) sysCfg.pwmvalue[i] = 0;
// 4.0.9 // 4.0.9
CFG_DefaultSet_4_0_9(); CFG_DefaultSet_4_0_9();
@ -530,7 +530,7 @@ void CFG_DefaultSet_3_2_4()
void CFG_DefaultSet_3_9_3() void CFG_DefaultSet_3_9_3()
{ {
for (byte i = 0; i < 4; i++) { for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
sysCfg.domoticz_switch_idx[i] = 0; sysCfg.domoticz_switch_idx[i] = 0;
} }
for (byte i = 0; i < 12; i++) { for (byte i = 0; i < 12; i++) {
@ -543,7 +543,7 @@ void CFG_DefaultSet_3_9_3()
} }
sysCfg.led_pixels = WS2812_LEDS; sysCfg.led_pixels = WS2812_LEDS;
for (byte i = 0; i < 5; i++) { for (byte i = 0; i < MAX_PWMS; i++) {
sysCfg.led_color[i] = 255; sysCfg.led_color[i] = 255;
} }
sysCfg.led_table = 0; sysCfg.led_table = 0;
@ -560,7 +560,7 @@ void CFG_DefaultSet_4_0_4()
strlcpy(sysCfg.ntp_server[0], NTP_SERVER1, sizeof(sysCfg.ntp_server[0])); strlcpy(sysCfg.ntp_server[0], NTP_SERVER1, sizeof(sysCfg.ntp_server[0]));
strlcpy(sysCfg.ntp_server[1], NTP_SERVER2, sizeof(sysCfg.ntp_server[1])); strlcpy(sysCfg.ntp_server[1], NTP_SERVER2, sizeof(sysCfg.ntp_server[1]));
strlcpy(sysCfg.ntp_server[2], NTP_SERVER3, sizeof(sysCfg.ntp_server[2])); strlcpy(sysCfg.ntp_server[2], NTP_SERVER3, sizeof(sysCfg.ntp_server[2]));
for (byte j =0; j < 3; j++) { for (byte j = 0; j < 3; j++) {
for (byte i = 0; i < strlen(sysCfg.ntp_server[j]); i++) { for (byte i = 0; i < strlen(sysCfg.ntp_server[j]); i++) {
if (sysCfg.ntp_server[j][i] == ',') { if (sysCfg.ntp_server[j][i] == ',') {
sysCfg.ntp_server[j][i] = '.'; sysCfg.ntp_server[j][i] = '.';
@ -635,7 +635,9 @@ void CFG_Delta()
strlcpy(sysCfg.web_password, WEB_PASSWORD, sizeof(sysCfg.web_password)); strlcpy(sysCfg.web_password, WEB_PASSWORD, sizeof(sysCfg.web_password));
} }
if (sysCfg.version < 0x03091500) { if (sysCfg.version < 0x03091500) {
for (byte i = 0; i < 4; i++) sysCfg.switchmode[i] = SWITCH_MODE; for (byte i = 0; i < MAX_SWITCHES; i++) {
sysCfg.switchmode[i] = SWITCH_MODE;
}
} }
if (sysCfg.version < 0x04000400) { if (sysCfg.version < 0x04000400) {
CFG_DefaultSet_4_0_4(); CFG_DefaultSet_4_0_4();
@ -645,7 +647,7 @@ void CFG_Delta()
sysCfg.my_gp.io[MAX_GPIO_PIN -1] = 0; // Clear ADC0 sysCfg.my_gp.io[MAX_GPIO_PIN -1] = 0; // Clear ADC0
} }
if (sysCfg.version < 0x04000700) { if (sysCfg.version < 0x04000700) {
for (byte i = 0; i < 5; i++) { for (byte i = 0; i < MAX_PWMS; i++) {
sysCfg.pwmvalue[i] = 0; sysCfg.pwmvalue[i] = 0;
} }
} }

View File

@ -788,6 +788,7 @@ boolean mqtt_command(boolean grpflg, char *type, uint16_t index, char *dataBuf,
if (!payload) { if (!payload) {
mqtt_data[0] = '\0'; mqtt_data[0] = '\0';
mqtt_publish_topic_P(2, PSTR(D_RSLT_SENSOR), sysCfg.flag.mqtt_sensor_retain); mqtt_publish_topic_P(2, PSTR(D_RSLT_SENSOR), sysCfg.flag.mqtt_sensor_retain);
mqtt_publish_topic_P(2, PSTR(D_RSLT_ENERGY), sysCfg.flag.mqtt_sensor_retain);
} }
sysCfg.flag.mqtt_sensor_retain = payload; sysCfg.flag.mqtt_sensor_retain = payload;
} }
@ -1807,7 +1808,7 @@ void state_mqttPresent()
void sensors_mqttPresent(uint8_t* djson) void sensors_mqttPresent(uint8_t* djson)
{ {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_TIME "\":\"%s\""), mqtt_data, getDateTime().c_str()); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_TIME "\":\"%s\""), mqtt_data, getDateTime().c_str());
for (byte i = 0; i < 4; i++) { for (byte i = 0; i < MAX_SWITCHES; i++) {
if (pin[GPIO_SWT1 +i] < 99) { if (pin[GPIO_SWT1 +i] < 99) {
boolean swm = ((FOLLOW_INV == sysCfg.switchmode[i]) || (PUSHBUTTON_INV == sysCfg.switchmode[i]) || (PUSHBUTTONHOLD_INV == sysCfg.switchmode[i])); boolean swm = ((FOLLOW_INV == sysCfg.switchmode[i]) || (PUSHBUTTON_INV == sysCfg.switchmode[i]) || (PUSHBUTTONHOLD_INV == sysCfg.switchmode[i]));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_SWITCH "%d\":\"%s\""), mqtt_data, i +1, getStateText(swm ^ lastwallswitch[i])); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_SWITCH "%d\":\"%s\""), mqtt_data, i +1, getStateText(swm ^ lastwallswitch[i]));
@ -2370,7 +2371,7 @@ void stateloop()
if (sysCfg.flag.savestate) { if (sysCfg.flag.savestate) {
power_t mask = POWER_MASK; power_t mask = POWER_MASK;
for (byte i = 0; i < MAX_PULSETIMERS; i++) { for (byte i = 0; i < MAX_PULSETIMERS; i++) {
if ((sysCfg.pulsetime[i] > 0) && (sysCfg.pulsetime[i] < 30)) { if ((sysCfg.pulsetime[i] > 0) && (sysCfg.pulsetime[i] < 30)) { // 3 seconds
mask &= ~(1 << i); mask &= ~(1 << i);
} }
} }
@ -2640,9 +2641,6 @@ void GPIO_init()
pinMode(pin[GPIO_REL1 +i], OUTPUT); pinMode(pin[GPIO_REL1 +i], OUTPUT);
Maxdevice++; Maxdevice++;
} }
// if (pin[GPIO_KEY1 +i] < 99) {
// pinMode(pin[GPIO_KEY1 +i], (16 == pin[GPIO_KEY1 +i]) ? INPUT_PULLDOWN_16 : INPUT_PULLUP);
// }
} }
} }
for (byte i = 0; i < MAX_KEYS; i++) { for (byte i = 0; i < MAX_KEYS; i++) {
@ -2724,6 +2722,7 @@ extern struct rst_info resetInfo;
void setup() void setup()
{ {
byte idx; byte idx;
uint8_t maxdev;
Serial.begin(Baudrate); Serial.begin(Baudrate);
delay(10); delay(10);
@ -2817,15 +2816,20 @@ void setup()
} }
// Issue #526 // Issue #526
uint8_t maxdev = (Maxdevice > MAX_RELAYS) ? MAX_RELAYS : Maxdevice; maxdev = (Maxdevice > MAX_RELAYS) ? MAX_RELAYS : Maxdevice;
for (byte i = 0; i < maxdev; i++) { for (byte i = 0; i < maxdev; i++) {
if (pin[GPIO_REL1 +i] < 99) { if (pin[GPIO_REL1 +i] < 99) {
if (digitalRead(pin[GPIO_REL1 +i]) ^ bitRead(rel_inverted, i)) { if (digitalRead(pin[GPIO_REL1 +i]) ^ bitRead(rel_inverted, i)) {
bitSet(power, i); bitSet(power, i);
pulse_timer[i] = sysCfg.pulsetime[i]; // MAX_PULSETIMERS must be equal to MAX_RELAYS for this to work here
} }
} }
} }
maxdev = (Maxdevice > MAX_PULSETIMERS) ? MAX_PULSETIMERS : Maxdevice;
for (byte i = 0; i < maxdev; i++) {
if (bitRead(power, i)) {
pulse_timer[i] = sysCfg.pulsetime[i]; // MAX_PULSETIMERS must be equal to MAX_RELAYS for this to work here
}
}
blink_powersave = power; blink_powersave = power;

View File

@ -732,7 +732,7 @@ int32_t i2c_read(uint8_t addr, uint8_t reg, uint8_t size)
if (0 == Wire.endTransmission(false)) { // Try to become I2C Master, send data and collect bytes, keep master status for next request... if (0 == Wire.endTransmission(false)) { // Try to become I2C Master, send data and collect bytes, keep master status for next request...
Wire.requestFrom((int)addr, (int)size); // send data n-bytes read Wire.requestFrom((int)addr, (int)size); // send data n-bytes read
if (Wire.available() == size) { if (Wire.available() == size) {
for(byte i = 0; i < size; i++) { for (byte i = 0; i < size; i++) {
data <<= 8; data <<= 8;
data |= Wire.read(); // receive DATA data |= Wire.read(); // receive DATA
} }