stock mbed AnalogReads current loop closed and working

Dependencies:   mbed

Fork of priustroller_2 by N K

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug.cpp Source File

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     _triggered = 0;
00013     _buffer = (float*)malloc(_size * _channels * sizeof(float));
00014     _context->serial->printf("Debugger channels: %d\n\r", _channels);
00015     _context->serial->printf("Debugger depth: %d\n\r", _size);
00016 }
00017 
00018 void BufferedDebugger::Write(int channel, float f) {
00019     if (_context->user->throttle > 0.1f) _triggered = 1;
00020     if (!_triggered) return;
00021     if (_index[channel] * _channels + channel < _size * _channels) {
00022         _buffer[_channels * _index[channel] + channel] = f;
00023         _index[channel]++;
00024     } else if (!_done) {
00025         Flush();
00026         _done = 1;
00027     }
00028 }
00029 
00030 void BufferedDebugger::Flush() {
00031     _context->inverter->Disable();
00032     _context->serial->printf("%s\n\r", "--Begin Debug log--");
00033     for (int i = 0; i < _size; i++) {
00034         for (int j = 0; j < _channels; j++) {
00035             _context->serial->printf("%f", _buffer[i * _channels + j]);
00036             if (j < _channels - 1) _context->serial->printf(", ");
00037         }
00038         _context->serial->printf("%\n\r");
00039     }
00040 }
00041 
00042 void BufferedDebugger::Restart() {
00043     _index = 0;
00044     _done = 0;
00045 }
00046