From fd20706ef79665e5fede9d58cdb15f9f89c8bc80 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 27 Nov 2018 14:38:09 +0100 Subject: [PATCH] Move static to dynamic buffers * Add support for SM Smart Wifi Dimmer PS-16-DZ (#4465) * Move some static (serial) buffers to dynamic buffers --- sonoff/_changelog.ino | 2 ++ sonoff/my_user_config.h | 2 +- sonoff/xdrv_05_irremote.ino | 17 ++++++++-------- sonoff/xdsp_03_matrix.ino | 39 +++++++++++++++++++++---------------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 3de9daa3cfeb..1d0eee7fee88 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,7 @@ /* 6.3.0.14 20181127 * Add Command CalcRes to set number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE (#4420) + * Add support for SM Smart Wifi Dimmer PS-16-DZ (#4465) + * Move some static (serial) buffers to dynamic buffers * * 6.3.0.13 20181126 * Add command SetOption59 0/1 to change state topic from tele/STATE to stat/RESULT (#4450) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 510827497305..d3244669cfab 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -174,7 +174,6 @@ #define SWITCH_DEBOUNCE_TIME 50 // [SwitchDebounce] Number of mSeconds switch press debounce time #define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE (the wall switch state) #define WS2812_LEDS 30 // [Pixels] Number of WS2812 LEDs to start with (max is 512) -#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE #define TEMP_CONVERSION 0 // [SetOption8] Return temperature in (0 = Celsius or 1 = Fahrenheit) #define PRESSURE_CONVERSION 0 // [SetOption24] Return pressure in (0 = hPa or 1 = mmHg) @@ -182,6 +181,7 @@ #define HUMIDITY_RESOLUTION 1 // [HumRes] Maximum number of decimals (0 - 3) showing sensor Humidity #define PRESSURE_RESOLUTION 1 // [PressRes] Maximum number of decimals (0 - 3) showing sensor Pressure #define ENERGY_RESOLUTION 3 // [EnergyRes] Maximum number of decimals (0 - 5) showing energy usage in kWh +#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE /*********************************************************************************************\ * END OF SECTION 1 diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 7cd38c2d553f..ef02e61ba8d8 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -379,8 +379,8 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P hvacOn = true; } - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); - AddLog(LOG_LEVEL_DEBUG); +// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); +// AddLog(LOG_LEVEL_DEBUG); // Set code for HVAC temperature - data[4] if (HVAC_Temp > 30) { @@ -412,8 +412,8 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04 } - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); - AddLog(LOG_LEVEL_DEBUG); +// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); +// AddLog(LOG_LEVEL_DEBUG); // Set CRC code - data[6] data[6] = (data[3] + data[4] + data[5]) & 0x0f; // CRC @@ -426,8 +426,8 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P } LG_Code = LG_Code + data[6]; - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); - AddLog(LOG_LEVEL_DEBUG); +// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); +// AddLog(LOG_LEVEL_DEBUG); // Send LG IR Code noInterrupts(); @@ -446,8 +446,8 @@ boolean IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H { const char kFujitsuHvacModeOptions[] = "HDCAF"; - char stemp[64]; - snprintf_P(stemp, sizeof(stemp), PSTR("FUJITSU: mode:%s, fan:%s, power:%u, temp:%u"), HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); +// snprintf_P(log_data, sizeof(log_data), PSTR("FUJITSU: mode:%s, fan:%s, power:%u, temp:%u"), HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); +// AddLog(LOG_LEVEL_DEBUG); IRFujitsuAC ac(pin[GPIO_IRSEND]); @@ -536,7 +536,6 @@ boolean IrSendCommand(void) raw_array[i++] = strtoul(str, NULL, 0); // Allow decimal (5246996) and hexadecimal (0x501014) input } -// DebugFreeMem(); // snprintf_P(log_data, sizeof(log_data), PSTR("IRS: Count %d, Freq %d, Arr[0] %d, Arr[count -1] %d"), // count, freq, raw_array[0], raw_array[count -1]); // AddLog(LOG_LEVEL_DEBUG); diff --git a/sonoff/xdsp_03_matrix.ino b/sonoff/xdsp_03_matrix.ino index 63222c637354..da458cb1583f 100644 --- a/sonoff/xdsp_03_matrix.ino +++ b/sonoff/xdsp_03_matrix.ino @@ -36,7 +36,9 @@ uint8_t mtx_counter = 0; int16_t mtx_x = 0; int16_t mtx_y = 0; -char mtx_buffer[MTX_MAX_SCREEN_BUFFER]; +//char mtx_buffer[MTX_MAX_SCREEN_BUFFER]; +char *mtx_buffer = NULL; + uint8_t mtx_mode = 0; uint8_t mtx_loop = 0; uint8_t mtx_done = 0; @@ -194,24 +196,27 @@ void MatrixInit(uint8_t mode) void MatrixInitDriver(void) { - if (!Settings.display_model) { - if (I2cDevice(Settings.display_address[1])) { - Settings.display_model = XDSP_03; + mtx_buffer = (char*)(malloc(MTX_MAX_SCREEN_BUFFER)); + if (mtx_buffer != NULL) { + if (!Settings.display_model) { + if (I2cDevice(Settings.display_address[1])) { + Settings.display_model = XDSP_03; + } } - } - if (XDSP_03 == Settings.display_model) { - mtx_state = 1; - for (mtx_matrices = 0; mtx_matrices < 8; mtx_matrices++) { - if (Settings.display_address[mtx_matrices]) { - matrix[mtx_matrices] = new Adafruit_8x8matrix(); - matrix[mtx_matrices]->begin(Settings.display_address[mtx_matrices]); - } else { - break; + if (XDSP_03 == Settings.display_model) { + mtx_state = 1; + for (mtx_matrices = 0; mtx_matrices < 8; mtx_matrices++) { + if (Settings.display_address[mtx_matrices]) { + matrix[mtx_matrices] = new Adafruit_8x8matrix(); + matrix[mtx_matrices]->begin(Settings.display_address[mtx_matrices]); + } else { + break; + } } - } - MatrixInitMode(); + MatrixInitMode(); + } } } @@ -222,7 +227,7 @@ void MatrixOnOff(void) void MatrixDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint8_t flag) { - snprintf(mtx_buffer, sizeof(mtx_buffer), str); + snprintf(mtx_buffer, MTX_MAX_SCREEN_BUFFER, str); mtx_mode = x &1; // Use x for selecting scroll up (0) or scroll left (1) mtx_loop = y &1; // Use y for selecting no loop (0) or loop (1) if (!mtx_state) { mtx_state = 1; } @@ -251,7 +256,7 @@ void MatrixPrintLog(uint8_t direction) space = 0; } if (space < 2) { - strncat(mtx_buffer, (const char*)txt +i, (strlen(mtx_buffer) < sizeof(mtx_buffer) -1) ? 1 : 0); + strncat(mtx_buffer, (const char*)txt +i, (strlen(mtx_buffer) < MTX_MAX_SCREEN_BUFFER -1) ? 1 : 0); } i++; }