Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a couple of bugs and many warnings #1774

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sonoff/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const char kUnitNames[] PROGMEM =
D_UNIT_WATTHOUR ;

const char S_JSON_COMMAND_NVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%d %s\"}";
const char S_JSON_COMMAND_LVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%lu %s\"}";
const char S_JSON_COMMAND_SVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%s %s\"}";
const char S_JSON_COMMAND_NVALUE_UNIT[] PROGMEM = "{\"%s\":\"%d%s\"}";
const char S_JSON_COMMAND_NVALUE_UNIT_NVALUE_UNIT[] PROGMEM = "{\"%s\":\"%d%s (%d%s)\"}";
Expand All @@ -390,10 +391,12 @@ const char S_JSON_COMMAND_NVALUE_SVALUE[] PROGMEM = "{\"%s\":\"%d (%s)
const char S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s\":\"%d (" D_JSON_ACTIVE " %d)\"}";

const char S_JSON_COMMAND_NVALUE[] PROGMEM = "{\"%s\":%d}";
const char S_JSON_COMMAND_LVALUE[] PROGMEM = "{\"%s\":%lu}";
const char S_JSON_COMMAND_SVALUE[] PROGMEM = "{\"%s\":\"%s\"}";
const char S_JSON_COMMAND_XVALUE[] PROGMEM = "{\"%s\":%s}"; // %s must provide quotes on non-number

const char S_JSON_COMMAND_INDEX_NVALUE[] PROGMEM = "{\"%s%d\":%d}";
const char S_JSON_COMMAND_INDEX_LVALUE[] PROGMEM = "{\"%s%d\":%lu}";
const char S_JSON_COMMAND_INDEX_SVALUE[] PROGMEM = "{\"%s%d\":\"%s\"}";
const char S_JSON_COMMAND_INDEX_SVALUE_SVALUE[] PROGMEM = "{\"%s%d\":\"%s%s\"}";

Expand Down
16 changes: 6 additions & 10 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ boolean MqttCommand(boolean grpflg, char *type, uint16_t index, char *dataBuf, u
char command [CMDSZ];
boolean serviced = true;
char stemp1[TOPSZ];
char stemp2[10];
char scommand[CMDSZ];
uint16_t i;

Expand Down Expand Up @@ -797,9 +796,7 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
char command [CMDSZ];
char stemp1[TOPSZ];
char *p;
char *mtopic = NULL;
char *type = NULL;
byte otype = 0;
byte ptype = 0;
byte jsflg = 0;
byte lines = 1;
Expand Down Expand Up @@ -999,12 +996,12 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
// type = NULL;
// }
}
else if ((CMND_SETOPTION == command_code) && ((index >= 0) && (index <= 20)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
else if ((CMND_SETOPTION == command_code) && ((index <= 20) || ((index > 31) && (index <= P_MAX_PARAM8 + 31)))) {
if (index <= 31) {
ptype = 0; // SetOption0 .. 31
} else {
ptype = 1; // SetOption32 ..
index = index -32;
index = index - 32;
}
if (payload >= 0) {
if (0 == ptype) { // SetOption0 .. 31
Expand Down Expand Up @@ -1205,7 +1202,7 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
else if (CMND_PWMRANGE == command_code) {
if ((1 == payload) || ((payload > 254) && (payload < 1024))) {
Settings.pwm_range = (1 == payload) ? PWM_RANGE : payload;
for (byte i; i < MAX_PWMS; i++) {
for (byte i = 0; i < MAX_PWMS; i++) {
if (Settings.pwm_value[i] > Settings.pwm_range) {
Settings.pwm_value[i] = Settings.pwm_range;
}
Expand All @@ -1219,7 +1216,7 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
RtcSettings.pulse_counter[index -1] = payload16;
Settings.pulse_counter[index -1] = payload16;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, index, RtcSettings.pulse_counter[index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_LVALUE, command, index, RtcSettings.pulse_counter[index -1]);
}
else if ((CMND_COUNTERTYPE == command_code) && (index > 0) && (index <= MAX_COUNTERS)) {
if ((payload >= 0) && (payload <= 1) && (pin[GPIO_CNTR1 + index -1] < 99)) {
Expand Down Expand Up @@ -1545,7 +1542,6 @@ boolean send_button_power(byte key, byte device, byte state)

char stopic[TOPSZ];
char scommand[CMDSZ];
char stemp1[10];
boolean result = false;

char *key_topic = (key) ? Settings.switch_topic : Settings.button_topic;
Expand Down Expand Up @@ -2451,7 +2447,7 @@ void SerialInput()

else if (serial_in_byte == '\n') {
serial_in_buffer[serial_in_byte_counter] = 0; // serial data completed
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? LOG_LEVEL_INFO : Settings.seriallog_level;
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (byte)LOG_LEVEL_INFO : Settings.seriallog_level;
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), serial_in_buffer);
AddLog(LOG_LEVEL_INFO);
ExecuteCommand(serial_in_buffer);
Expand Down Expand Up @@ -2721,7 +2717,7 @@ void setup()
SetDevicePower(power);
break;
case POWER_ALL_SAVED_TOGGLE:
power = Settings.power & ((1 << devices_present) -1) ^ POWER_MASK;
power = (Settings.power & ((1 << devices_present) -1)) ^ POWER_MASK;
if (Settings.flag.save_state) {
SetDevicePower(power);
}
Expand Down
9 changes: 4 additions & 5 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -998,17 +998,16 @@ String GetBuildDateAndTime()
{
// "2017-03-07T11:08:02" - ISO8601:2004
char bdt[21];
char *str;
char *p;
char *smonth;
char mdate[] = __DATE__; // "Mar 7 2017"
char *smonth = mdate;
int month;
int day;
int year;
int day = 0;
int year = 0;

// sscanf(mdate, "%s %d %d", bdt, &day, &year); // Not implemented in 2.3.0 and probably too many code
byte i = 0;
for (str = strtok_r(mdate, " ", &p); str && i < 3; str = strtok_r(NULL, " ", &p)) {
for (char * str = strtok_r(mdate, " ", &p); str && i < 3; str = strtok_r(NULL, " ", &p)) {
switch (i++) {
case 0: // Month
smonth = str;
Expand Down
2 changes: 1 addition & 1 deletion sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void HandleAjaxStatusRefresh()
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{t}"));
XsnsCall(FUNC_WEB_APPEND);
if (D_DECIMAL_SEPARATOR[0] != '.') {
for (int i = 0; i < strlen(mqtt_data); i++) {
for (unsigned int i = 0; i < strlen(mqtt_data); i++) {
if ('.' == mqtt_data[i]) {
mqtt_data[i] = D_DECIMAL_SEPARATOR[0];
}
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xdrv_01_light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void LightSetPower()
void LightAnimate()
{
uint8_t cur_col[5];
uint16_t light_still_on;
uint16_t light_still_on = 0;

strip_timer_counter++;
if (!light_power) { // Power Off
Expand Down
15 changes: 6 additions & 9 deletions sonoff/xdrv_02_irremote.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
byte data[HVAC_TOSHIBA_DATALEN] = {0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};

char *p;
char *token;
uint8_t mode;

if (HVAC_Mode == NULL) {
Expand Down Expand Up @@ -176,7 +175,7 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
else {
Temp = HVAC_Temp;
}
data[5] = (byte)Temp - 17 << 4;
data[5] = (byte)(Temp - 17) << 4;

data[HVAC_TOSHIBA_DATALEN - 1] = 0;
for (int x = 0; x < HVAC_TOSHIBA_DATALEN - 1; x++) {
Expand Down Expand Up @@ -219,7 +218,6 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
{
char *p;
char *token;
uint8_t mode;

mitsubir->stateReset();
Expand Down Expand Up @@ -286,12 +284,6 @@ boolean IrSendCommand()
uint32_t bits = 0;
uint32_t data = 0;

const char *HVAC_Mode;
const char *HVAC_FanMode;
const char *HVAC_Vendor;
int HVAC_Temp = 21;
boolean HVAC_Power = true;

for (uint16_t i = 0; i <= sizeof(dataBufUc); i++) {
dataBufUc[i] = toupper(XdrvMailbox.data[i]);
}
Expand Down Expand Up @@ -349,6 +341,11 @@ boolean IrSendCommand()
}
#ifdef USE_IR_HVAC
else if (!strcasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_IRHVAC))) {
const char *HVAC_Mode;
const char *HVAC_FanMode;
const char *HVAC_Vendor;
int HVAC_Temp = 21;
boolean HVAC_Power = true;
if (XdrvMailbox.data_len) {
StaticJsonBuffer<164> jsonBufer;
JsonObject &root = jsonBufer.parseObject(dataBufUc);
Expand Down
10 changes: 5 additions & 5 deletions sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void PzemSend(uint8_t cmd)
PZEMCommand pzem;

pzem.command = cmd;
for (int i = 0; i < sizeof(pzem.addr); i++) {
for (unsigned int i = 0; i < sizeof(pzem.addr); i++) {
pzem.addr[i] = pzem_ip[i];
}
pzem.data = 0;
Expand All @@ -310,7 +310,7 @@ void PzemSend(uint8_t cmd)

bool PzemReceiveReady()
{
return PzemSerial->available() >= sizeof(PZEMCommand);
return PzemSerial->available() >= (int)sizeof(PZEMCommand);
}

bool PzemRecieve(uint8_t resp, float *data)
Expand Down Expand Up @@ -511,7 +511,7 @@ void EnergySetPowerSteadyCounter()
void EnergyMarginCheck()
{
uint16_t energy_daily_u;
uint16_t energy_power_u;
uint16_t energy_power_u = 0;
uint16_t energy_voltage_u;
uint16_t energy_current_u;
boolean flag;
Expand Down Expand Up @@ -833,9 +833,9 @@ boolean EnergyCommand()
}
if (!status_flag) {
if (Settings.flag.value_units) {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SPACE_UNIT, command, nvalue, GetTextIndexed(sunit, sizeof(sunit), unit, kUnitNames));
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_LVALUE_SPACE_UNIT, command, nvalue, GetTextIndexed(sunit, sizeof(sunit), unit, kUnitNames));
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, nvalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_LVALUE, command, nvalue);
}
}
return serviced;
Expand Down
9 changes: 4 additions & 5 deletions sonoff/xdrv_05_domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const char kDomoticzSensors[] PROGMEM =
D_DOMOTICZ_TEMP "|" D_DOMOTICZ_TEMP_HUM "|" D_DOMOTICZ_TEMP_HUM_BARO "|" D_DOMOTICZ_POWER_ENERGY "|" D_DOMOTICZ_ILLUMINANCE "|" D_DOMOTICZ_COUNT "|" D_DOMOTICZ_VOLTAGE "|" D_DOMOTICZ_CURRENT "|" D_DOMOTICZ_AIRQUALITY ;

const char S_JSON_DOMOTICZ_COMMAND_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_DOMOTICZ "%s%d\":%d}";
const char S_JSON_DOMOTICZ_COMMAND_INDEX_LVALUE[] PROGMEM = "{\"" D_CMND_DOMOTICZ "%s%d\":%lu}";

char domoticz_in_topic[] = DOMOTICZ_IN_TOPIC;
char domoticz_out_topic[] = DOMOTICZ_OUT_TOPIC;
Expand Down Expand Up @@ -127,7 +128,6 @@ void DomoticzMqttSubscribe()
boolean DomoticzMqttData()
{
char stemp1[10];
char scommand[10];
unsigned long idx = 0;
int16_t nvalue;
int16_t found = 0;
Expand Down Expand Up @@ -165,7 +165,7 @@ boolean DomoticzMqttData()
snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), nvalue);
found = 1;
} else {
if (((power >> i) &1) == nvalue) {
if (((power >> i) &1) == (power_t)nvalue) {
return 1;
}
snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_POWER "%s"), (devices_present > 1) ? stemp1 : "");
Expand Down Expand Up @@ -205,13 +205,13 @@ boolean DomoticzCommand()
Settings.domoticz_relay_idx[XdrvMailbox.index -1] = XdrvMailbox.payload;
restart_flag = 2;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_DOMOTICZ_COMMAND_INDEX_NVALUE, command, XdrvMailbox.index, Settings.domoticz_relay_idx[XdrvMailbox.index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_DOMOTICZ_COMMAND_INDEX_LVALUE, command, XdrvMailbox.index, Settings.domoticz_relay_idx[XdrvMailbox.index -1]);
}
else if ((CMND_KEYIDX == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_DOMOTICZ_IDX)) {
if (XdrvMailbox.payload >= 0) {
Settings.domoticz_key_idx[XdrvMailbox.index -1] = XdrvMailbox.payload;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_DOMOTICZ_COMMAND_INDEX_NVALUE, command, XdrvMailbox.index, Settings.domoticz_key_idx[XdrvMailbox.index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_DOMOTICZ_COMMAND_INDEX_LVALUE, command, XdrvMailbox.index, Settings.domoticz_key_idx[XdrvMailbox.index -1]);
}
else if ((CMND_SWITCHIDX == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_DOMOTICZ_IDX)) {
if (XdrvMailbox.payload >= 0) {
Expand Down Expand Up @@ -332,7 +332,6 @@ void HandleDomoticzConfiguration()
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_DOMOTICZ);

char stemp[32];
char *sensortype;

String page = FPSTR(HTTP_HEAD);
page.replace(F("{v}"), FPSTR(S_CONFIGURE_DOMOTICZ));
Expand Down
6 changes: 2 additions & 4 deletions sonoff/xplg_wemohue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void HueConfigResponse(String *response)
response->replace("{id", GetHueUserId());
}

void HueConfig(String *path)
void HueConfig(String *path __attribute__((unused)))
{
String response = "";
HueConfigResponse(&response);
Expand Down Expand Up @@ -600,7 +600,7 @@ void HueGlobalConfig(String *path)
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
}

void HueAuthentication(String *path)
void HueAuthentication(String *path __attribute__((unused)))
{
char response[38];

Expand All @@ -616,15 +616,13 @@ void HueLights(String *path)
String response;
uint8_t device = 1;
uint16_t tmp = 0;
int16_t pos = 0;
float bri = 0;
float hue = 0;
float sat = 0;
uint16_t ct = 0;
bool resp = false;
bool on = false;
bool change = false;
char id[4];
uint8_t maxhue = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;

path->remove(0,path->indexOf("/lights")); // Remove until /lights
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xsns_06_dht.ino
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int32_t DhtExpectPulse(byte sensor, bool level)
int32_t count = 0;

while (digitalRead(Dht[sensor].pin) == level) {
if (count++ >= dht_max_cycles) {
if (count++ >= (int32_t)dht_max_cycles) {
return -1; // Timeout
}
}
Expand Down
1 change: 1 addition & 0 deletions sonoff/xsns_08_htu21.ino
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ float HtuCompensatedHumidity(float humidity, float temperature)
if(temperature > 0.00 && temperature < 80.00) {
return (-0.15)*(25-temperature)+humidity;
}
return humidity; // TODO is this correct?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the correctness of the return value, but the return statement was missing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes humidity is fine.

}

/********************************************************************************************/
Expand Down
17 changes: 7 additions & 10 deletions sonoff/xsns_09_bmp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ boolean Bmp180Calibration()
return false;
}

if ((cal_ac1 == 0xFFFF) |
(cal_ac2 == 0xFFFF) |
(cal_ac3 == 0xFFFF) |
if ((cal_ac1 == (int16_t)0xFFFF) |
(cal_ac2 == (int16_t)0xFFFF) |
(cal_ac3 == (int16_t)0xFFFF) |
(cal_ac4 == 0xFFFF) |
(cal_ac5 == 0xFFFF) |
(cal_ac6 == 0xFFFF) |
(cal_b1 == 0xFFFF) |
(cal_b2 == 0xFFFF) |
(cal_mc == 0xFFFF) |
(cal_md == 0xFFFF)) {
(cal_b1 == (int16_t)0xFFFF) |
(cal_b2 == (int16_t)0xFFFF) |
(cal_mc == (int16_t)0xFFFF) |
(cal_md == (int16_t)0xFFFF)) {
return false;
}
return true;
Expand All @@ -128,9 +128,6 @@ double Bmp180ReadTemperature()
double Bmp180ReadPressure()
{
int32_t p;
uint8_t msb;
uint8_t lsb;
uint8_t xlsb;

I2cWrite8(bmp_address, BMP180_REG_CONTROL, BMP180_PRESSURE3); // Highest resolution
delay(2 + (4 << BMP180_OSS)); // 26ms conversion time at ultra high resolution
Expand Down