Fixed Animation stuff by not sending so many debug messages via MQTT.

This commit is contained in:
Fabian Schlenz 2020-04-29 20:23:57 +02:00
parent f014fd7cae
commit 65dd09ca0d
2 changed files with 32 additions and 41 deletions

View File

@ -96,22 +96,18 @@
Serial.println(buffer);\
} while (0);
#else
#define LOG(msg, ...) do { \
char buffer[128]; \
snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\
Serial.print(buffer);\
} while (0);
#define LOGln(msg, ...) do { \
char buffer[128]; \
snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\
Serial.println(buffer);\
} while (0);
#define LOG(x, ...) Serial.printf(x, ##__VA_ARGS__);
#define LOGln(x, ...) Serial.printf(x, ##__VA_ARGS__); Serial.println();
#endif
#define DBG(msg, ...) Serial.printf(msg, ##__VA_ARGS__); Serial.println();
#else
#define LOG(msg, ...) do {} while(0);
#define LOGln(msg, ...) do {} while(0);
#define LOG(x) do {} while(0);
#define LOGln(x) do {} while(0);
#define DBG(msg, ...) do {} while(0);
#endif
#if !defined( ESP8266 ) && !defined( ESP32 )
#error "Neither ESP8266 nor ESP32 are set. Maybe you are compiling this for another platform...?"
#endif

View File

@ -84,16 +84,16 @@ bool Animation::_load_from_file(const char* filename) {
// Now we can be sure to have the right amount of bytes available for reading
_width = file.read();
LOGln("Animation * width: %d", _width);
DBG("Animation * width: %d", _width);
_height = file.read();
LOGln("Animation * height: %d", _height);
DBG("Animation * height: %d", _height);
_frame_count = file.read();
LOGln("Animation * frame_count: %d", _frame_count);
DBG("Animation * frame_count: %d", _frame_count);
_color_count = file.read();
LOGln("Animation * color_count: %d", _color_count);
DBG("Animation * color_count: %d", _color_count);
LOGln("Animation * Loading colors...");
DBG("Animation * Loading colors...");
_colors = new CRGB*[_color_count];
char* temp = new char[_color_count*3];
int bytes_read = file.readBytes(temp, _color_count*3);
@ -102,36 +102,33 @@ bool Animation::_load_from_file(const char* filename) {
_colors[i] = new CRGB(temp[i*3], temp[i*3+1], temp[i*3+2]);
}
delete [] temp;
LOGln("Animation * Color loading done.");
DBG("Animation * Color loading done.");
LOG("Animation * Loading frame times...");
DBG("Animation * Loading frame times...");
_frame_times = new uint16_t[_frame_count];
for (int i=0; i<_frame_count; i++) {
_frame_times[i] = (file.read() << 8) | file.read();
}
LOGln(" done.");
DBG(" done.");
LOGln("Animation * Loading frame lengths...");
DBG("Animation * Loading frame lengths...");
_frame_data_lengths = new uint16_t[_frame_count];
temp = new char[_frame_count*2];
bytes_read = file.readBytes(temp, _frame_count*2);
LOGln("Animation * Read %d bytes.", bytes_read);
DBG("Animation * Read %d bytes.", bytes_read);
for (int i=0; i<_frame_count; i++) {
//LOGln("Animation * Raw frame lengths: %d, %d", temp[i*2], temp[i*2+1]);
_frame_data_lengths[i] = (temp[i*2]<<8) | temp[i*2+1];
}
delete [] temp;
LOGln("Animation * Frame length loading done.");
DBG("Animation * Frame length loading done.");
LOGln("Animation * Loading frame data...");
DBG("Animation * Loading frame data...");
_frame_data = new uint8_t*[_frame_count];
for (int i=0; i<_frame_count; i++) {
uint16_t fl = _frame_data_lengths[i];
LOGln("Animation * Loading frame %d with %d bytes...", i, fl);
DBG("Animation * Loading frame %d/%d with %d bytes...", i, _frame_count, fl);
_frame_data[i] = new uint8_t[fl];
/*for (int b=0; b<fl; b++) {
_frame_data[i][b] = file.read();
}*/
file.readBytes((char*)_frame_data[i], fl);
}
LOGln("Animation * Frame data loaded.");
@ -208,27 +205,25 @@ void Animation::setSingleFrame(uint8_t frame) {
Animation::~Animation() {
for (int i=0; i<_color_count; i++) delete _colors[i];
LOGln("Animation * Deleting _colors...");
if (_colors) delete [] _colors;
DBG("Animation * Deleting _colors...");
if (_colors) delete[] _colors;
LOGln("Animation * Deleting fgColor...");
DBG("Animation * Deleting fgColor...");
if (fgColor != NULL) delete fgColor;
LOGln("Animation * Deleting bgColor...");
DBG("Animation * Deleting bgColor...");
if (bgColor != NULL) delete bgColor;
LOGln("Animation * Deleting _frame_data_lengths...");
if (_frame_data_lengths) delete [] _frame_data_lengths;
DBG("Animation * Deleting _frame_data_lengths...");
if (_frame_data_lengths) delete[] _frame_data_lengths;
LOGln("Animation * Deleting _frame_times...");
if (_frame_times) delete [] _frame_times;
DBG("Animation * Deleting _frame_times...");
if (_frame_times) delete[] _frame_times;
for (int i=0; i<_frame_count; i++) {
delete [] _frame_data[i];
delete[] _frame_data[i];
}
LOGln("Animation * Deleting _frame_data...");
if (_frame_data) delete [] _frame_data;
DBG("Animation * Deleting _frame_data...");
if (_frame_data) delete[] _frame_data;
LOGln("Animation * Deletion done.");
}