Skip to content

Commit fd20706

Browse files
committed
Move static to dynamic buffers
* Add support for SM Smart Wifi Dimmer PS-16-DZ (#4465) * Move some static (serial) buffers to dynamic buffers
1 parent 0df7df9 commit fd20706

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

Diff for: sonoff/_changelog.ino

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* 6.3.0.14 20181127
22
* Add Command CalcRes to set number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE (#4420)
3+
* Add support for SM Smart Wifi Dimmer PS-16-DZ (#4465)
4+
* Move some static (serial) buffers to dynamic buffers
35
*
46
* 6.3.0.13 20181126
57
* Add command SetOption59 0/1 to change state topic from tele/STATE to stat/RESULT (#4450)

Diff for: sonoff/my_user_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@
174174
#define SWITCH_DEBOUNCE_TIME 50 // [SwitchDebounce] Number of mSeconds switch press debounce time
175175
#define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE (the wall switch state)
176176
#define WS2812_LEDS 30 // [Pixels] Number of WS2812 LEDs to start with (max is 512)
177-
#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE
178177

179178
#define TEMP_CONVERSION 0 // [SetOption8] Return temperature in (0 = Celsius or 1 = Fahrenheit)
180179
#define PRESSURE_CONVERSION 0 // [SetOption24] Return pressure in (0 = hPa or 1 = mmHg)
181180
#define TEMP_RESOLUTION 1 // [TempRes] Maximum number of decimals (0 - 3) showing sensor Temperature
182181
#define HUMIDITY_RESOLUTION 1 // [HumRes] Maximum number of decimals (0 - 3) showing sensor Humidity
183182
#define PRESSURE_RESOLUTION 1 // [PressRes] Maximum number of decimals (0 - 3) showing sensor Pressure
184183
#define ENERGY_RESOLUTION 3 // [EnergyRes] Maximum number of decimals (0 - 5) showing energy usage in kWh
184+
#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE
185185

186186
/*********************************************************************************************\
187187
* END OF SECTION 1

Diff for: sonoff/xdrv_05_irremote.ino

+8-9
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P
379379
hvacOn = true;
380380
}
381381

382-
snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]);
383-
AddLog(LOG_LEVEL_DEBUG);
382+
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]);
383+
// AddLog(LOG_LEVEL_DEBUG);
384384

385385
// Set code for HVAC temperature - data[4]
386386
if (HVAC_Temp > 30) {
@@ -412,8 +412,8 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P
412412
data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04
413413
}
414414

415-
snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]);
416-
AddLog(LOG_LEVEL_DEBUG);
415+
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]);
416+
// AddLog(LOG_LEVEL_DEBUG);
417417

418418
// Set CRC code - data[6]
419419
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
426426
}
427427
LG_Code = LG_Code + data[6];
428428

429-
snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code);
430-
AddLog(LOG_LEVEL_DEBUG);
429+
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code);
430+
// AddLog(LOG_LEVEL_DEBUG);
431431

432432
// Send LG IR Code
433433
noInterrupts();
@@ -446,8 +446,8 @@ boolean IrHvacFujitsu(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H
446446
{
447447
const char kFujitsuHvacModeOptions[] = "HDCAF";
448448

449-
char stemp[64];
450-
snprintf_P(stemp, sizeof(stemp), PSTR("FUJITSU: mode:%s, fan:%s, power:%u, temp:%u"), HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
449+
// 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);
450+
// AddLog(LOG_LEVEL_DEBUG);
451451

452452
IRFujitsuAC ac(pin[GPIO_IRSEND]);
453453

@@ -536,7 +536,6 @@ boolean IrSendCommand(void)
536536
raw_array[i++] = strtoul(str, NULL, 0); // Allow decimal (5246996) and hexadecimal (0x501014) input
537537
}
538538

539-
// DebugFreeMem();
540539
// snprintf_P(log_data, sizeof(log_data), PSTR("IRS: Count %d, Freq %d, Arr[0] %d, Arr[count -1] %d"),
541540
// count, freq, raw_array[0], raw_array[count -1]);
542541
// AddLog(LOG_LEVEL_DEBUG);

Diff for: sonoff/xdsp_03_matrix.ino

+22-17
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ uint8_t mtx_counter = 0;
3636
int16_t mtx_x = 0;
3737
int16_t mtx_y = 0;
3838

39-
char mtx_buffer[MTX_MAX_SCREEN_BUFFER];
39+
//char mtx_buffer[MTX_MAX_SCREEN_BUFFER];
40+
char *mtx_buffer = NULL;
41+
4042
uint8_t mtx_mode = 0;
4143
uint8_t mtx_loop = 0;
4244
uint8_t mtx_done = 0;
@@ -194,24 +196,27 @@ void MatrixInit(uint8_t mode)
194196

195197
void MatrixInitDriver(void)
196198
{
197-
if (!Settings.display_model) {
198-
if (I2cDevice(Settings.display_address[1])) {
199-
Settings.display_model = XDSP_03;
199+
mtx_buffer = (char*)(malloc(MTX_MAX_SCREEN_BUFFER));
200+
if (mtx_buffer != NULL) {
201+
if (!Settings.display_model) {
202+
if (I2cDevice(Settings.display_address[1])) {
203+
Settings.display_model = XDSP_03;
204+
}
200205
}
201-
}
202206

203-
if (XDSP_03 == Settings.display_model) {
204-
mtx_state = 1;
205-
for (mtx_matrices = 0; mtx_matrices < 8; mtx_matrices++) {
206-
if (Settings.display_address[mtx_matrices]) {
207-
matrix[mtx_matrices] = new Adafruit_8x8matrix();
208-
matrix[mtx_matrices]->begin(Settings.display_address[mtx_matrices]);
209-
} else {
210-
break;
207+
if (XDSP_03 == Settings.display_model) {
208+
mtx_state = 1;
209+
for (mtx_matrices = 0; mtx_matrices < 8; mtx_matrices++) {
210+
if (Settings.display_address[mtx_matrices]) {
211+
matrix[mtx_matrices] = new Adafruit_8x8matrix();
212+
matrix[mtx_matrices]->begin(Settings.display_address[mtx_matrices]);
213+
} else {
214+
break;
215+
}
211216
}
212-
}
213217

214-
MatrixInitMode();
218+
MatrixInitMode();
219+
}
215220
}
216221
}
217222

@@ -222,7 +227,7 @@ void MatrixOnOff(void)
222227

223228
void MatrixDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint8_t flag)
224229
{
225-
snprintf(mtx_buffer, sizeof(mtx_buffer), str);
230+
snprintf(mtx_buffer, MTX_MAX_SCREEN_BUFFER, str);
226231
mtx_mode = x &1; // Use x for selecting scroll up (0) or scroll left (1)
227232
mtx_loop = y &1; // Use y for selecting no loop (0) or loop (1)
228233
if (!mtx_state) { mtx_state = 1; }
@@ -251,7 +256,7 @@ void MatrixPrintLog(uint8_t direction)
251256
space = 0;
252257
}
253258
if (space < 2) {
254-
strncat(mtx_buffer, (const char*)txt +i, (strlen(mtx_buffer) < sizeof(mtx_buffer) -1) ? 1 : 0);
259+
strncat(mtx_buffer, (const char*)txt +i, (strlen(mtx_buffer) < MTX_MAX_SCREEN_BUFFER -1) ? 1 : 0);
255260
}
256261
i++;
257262
}

0 commit comments

Comments
 (0)