Skip to content

Commit

Permalink
Move static to dynamic buffers
Browse files Browse the repository at this point in the history
 * Add support for SM Smart Wifi Dimmer PS-16-DZ (arendst#4465)
 * Move some static (serial) buffers to dynamic buffers
  • Loading branch information
arendst committed Nov 27, 2018
1 parent e1d3dca commit b14c537
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
2 changes: 2 additions & 0 deletions sonoff/_changelog.ino
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sonoff/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@
#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)
#define TEMP_RESOLUTION 1 // [TempRes] Maximum number of decimals (0 - 3) showing sensor Temperature
#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
Expand Down
17 changes: 8 additions & 9 deletions sonoff/xdrv_05_irremote.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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]);

Expand Down Expand Up @@ -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);
Expand Down
39 changes: 22 additions & 17 deletions sonoff/xdsp_03_matrix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}

Expand All @@ -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; }
Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit b14c537

Please sign in to comment.