Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of priustroller_2 by
debug/debug.cpp
- Committer:
- bwang
- Date:
- 2015-03-09
- Revision:
- 24:f1ff9c7256b5
- Child:
- 53:ef62d7a958f2
File content as of revision 24:f1ff9c7256b5:
#include "includes.h" #include "context.h" #include "debug.h" BufferedDebugger::BufferedDebugger(Context *context, int channels, int size) { _context = context; _size = size; _channels = channels; _index = (int*)malloc(_channels*sizeof(int)); for (int i = 0; i < _channels; i++) _index[i] = 0; _done = 0; _buffer = (float*)malloc(_size * _channels * sizeof(float)); _context->serial->printf("Debugger channels: %d\n\r", _channels); _context->serial->printf("Debugger depth: %d\n\r", _size); } void BufferedDebugger::Write(int channel, float f) { if (_index[channel] * _channels + channel < _size * _channels) { _buffer[_channels * _index[channel] + channel] = f; _index[channel]++; } else if (!_done) { Flush(); _done = 1; } } void BufferedDebugger::Flush() { _context->inverter->Disable(); _context->serial->printf("%s\n\r", "--Begin Debug log--"); for (int i = 0; i < _size; i++) { for (int j = 0; j < _channels; j++) { _context->serial->printf("%f", _buffer[i * _channels + j]); if (j < _channels - 1) _context->serial->printf(", "); } _context->serial->printf("%\n\r"); } } void BufferedDebugger::Restart() { _index = 0; _done = 0; }