Bayley Wang
/
priustroller_3
temp repo
Fork of priustroller_2 by
Embed:
(wiki syntax)
Show/hide line numbers
debug.cpp
00001 #include "includes.h" 00002 #include "context.h" 00003 #include "debug.h" 00004 00005 BufferedDebugger::BufferedDebugger(Context *context, int channels, int size) { 00006 _context = context; 00007 _size = size; 00008 _channels = channels; 00009 _index = (int*)malloc(_channels*sizeof(int)); 00010 for (int i = 0; i < _channels; i++) _index[i] = 0; 00011 _done = 0; 00012 _buffer = (float*)malloc(_size * _channels * sizeof(float)); 00013 _context->serial->printf("Debugger channels: %d\n\r", _channels); 00014 _context->serial->printf("Debugger depth: %d\n\r", _size); 00015 } 00016 00017 void BufferedDebugger::Write(int channel, float f) { 00018 if (_index[channel] * _channels + channel < _size * _channels) { 00019 _buffer[_channels * _index[channel] + channel] = f; 00020 _index[channel]++; 00021 } else if (!_done) { 00022 Flush(); 00023 _done = 1; 00024 } 00025 } 00026 00027 void BufferedDebugger::Flush() { 00028 _context->inverter->Disable(); 00029 _context->serial->printf("%s\n\r", "--Begin Debug log--"); 00030 for (int i = 0; i < _size; i++) { 00031 for (int j = 0; j < _channels; j++) { 00032 _context->serial->printf("%f", _buffer[i * _channels + j]); 00033 if (j < _channels - 1) _context->serial->printf(", "); 00034 } 00035 _context->serial->printf("%\n\r"); 00036 } 00037 } 00038 00039 void BufferedDebugger::Restart() { 00040 _index = 0; 00041 _done = 0; 00042 } 00043
Generated on Tue Jul 12 2022 20:58:06 by 1.7.2